ziyan_mop_channel.h
7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
********************************************************************
* @file ziyan_mop_channel.h
* @brief This is the header file for "ziyan_mop_channel.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2021 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef ZIYAN_MOP_CHANNEL_H
#define ZIYAN_MOP_CHANNEL_H
/* Includes ------------------------------------------------------------------*/
#include "ziyan_typedef.h"
#include "ziyan_low_speed_data_channel.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/**
* @brief Mop channel handle.
*/
typedef void *T_ZiyanMopChannelHandle;
/**
* @brief Mop channel transmission type.
*/
typedef enum {
ZIYAN_MOP_CHANNEL_TRANS_RELIABLE = 0, /*!< Reliable transmission type. */
ZIYAN_MOP_CHANNEL_TRANS_UNRELIABLE, /*!< Unreliable transmission type. */
} E_ZiyanMopChannelTransType;
/* Exported functions --------------------------------------------------------*/
/**
* @brief Initialize the mop channel for operation about mop channel handle later.
* @note This interface needs to be called before calling other mop channel interfaces. Please make sure the network port
* is connected properly before calling this interface. Mop channel feature currently only supports linux platform.
* @return Execution result.
*/
T_ZiyanReturnCode ZiyanMopChannel_Init(void);
/**
* @brief Create the mop channel handle by specified transmission type.
* @note After calling this interface, you should follow below cases:
* 1. When mop channel handle created successfully, you need bind channel id to this created mop channel handle and
* accept other client device connections, such as MSDK or OSDK device;
* 2. When mop channel accept successfully, you can use send or receive data interface to write or read data by accepted
* output channel handle;
* 3. When the mop channel handle do not used, you can use close or destroy interface to release the resource;
* @param channelHandle: pointer to the created mop channel.
* @param transType: the transmission type for mop channel ::E_ZiyanMopChannelTransType.
* @return Execution result.
*/
T_ZiyanReturnCode ZiyanMopChannel_Create(T_ZiyanMopChannelHandle *channelHandle, E_ZiyanMopChannelTransType transType);
/**
* @brief Destroy the created mop channel and release the resource that referenced by the channel handle.
* @note After calling this interface, we can not do any operation about this channel handle expect create channel handle.
* @param channelHandle: pointer to the created mop channel.
* @return Execution result.
*/
T_ZiyanReturnCode ZiyanMopChannel_Destroy(T_ZiyanMopChannelHandle channelHandle);
/**
* @brief Bind the channel id to the created mop channel handle.
* @note When mop channel handle created successfully, you can bind channel id to this created mop handle and calling
* interface ::ZiyanMopChannel_Accept, then other client device can use this binded channel id to connect created mop handle.
* @param channelHandle: pointer to the created mop channel handle.
* @param channelId: the channel id of mop handle for accepting client device connection.
* @return Execution result.
*/
T_ZiyanReturnCode ZiyanMopChannel_Bind(T_ZiyanMopChannelHandle channelHandle,
uint16_t channelId);
/**
* @brief Accept the connection by binded channel id for created mop channel.
* @note The mop accept channel extracts the connection request on the queue of pennding connections for listening channel
* handle ::channelHandle. Create a new connected channel handle and return to user ::outChannelHandle by referrng to a new
* connection. Payload can be a server that allow multiple client connections by binded channel id.
* @param channelHandle: pointer to the created mop channel.
* @param outChannelHandle: pointer to the accepted output mop channel.
* @return Execution result.
*/
T_ZiyanReturnCode ZiyanMopChannel_Accept(T_ZiyanMopChannelHandle channelHandle,
T_ZiyanMopChannelHandle *outChannelHandle);
T_ZiyanReturnCode ZiyanMopChannel_Connect(T_ZiyanMopChannelHandle channelHandle, E_ZiyanChannelAddress channelAddress,
uint16_t channelId);
/**
* @brief Close the created mop channel.
* @note After calling this interface, we can not do any operation about this channel handle expect destroy channel handle.
* @param channelHandle: pointer to the created mop channel.
* @return Execution result.
*/
T_ZiyanReturnCode ZiyanMopChannel_Close(T_ZiyanMopChannelHandle channelHandle);
/**
* @brief Send data by the accepted output mop channel.
* @note This interface should be called after successfully calling the interface ::ZiyanMopChannel_Accept. It is recommended
* to send more bytes of data at a time to improve read and write efficiency. Need to determine whether the send is
* successful according to the return code and the actual sent data length.
* @param channelHandle: pointer to accepted output mop handle ::outChannelHandle by calling interface ::ZiyanMopChannel_Accept.
* @param data: pointer to data to be sent.
* @param len: length of data to be sent via accepted output mop handle, unit: byte.
* @param realLen: pointer to real length of data that already sent.
* @return Execution result.
*/
T_ZiyanReturnCode ZiyanMopChannel_SendData(T_ZiyanMopChannelHandle channelHandle,
uint8_t *data,
uint32_t len,
uint32_t *realLen);
/**
* @brief Receive data from the accepted output mop channel.
* @note This interface should be called after successfully calling the interface ::ZiyanMopChannel_Accept. It is recommended
* to receive more bytes of data at a time to improve read and write efficiency. Need to determine whether the receive
* is successful according to the return code and the actual received data length.
* @param channelHandle: pointer to accepted output mop handle ::outChannelHandle by calling interface ::ZiyanMopChannel_Accept.
* @param data: pointer to data to store the received data.
* @param len: length of data to be received via accepted output mop handle, unit: byte.
* @param realLen: pointer to real length of data that already received.
* @return Execution result.
*/
T_ZiyanReturnCode ZiyanMopChannel_RecvData(T_ZiyanMopChannelHandle channelHandle,
uint8_t *data,
uint32_t len,
uint32_t *realLen);
#ifdef __cplusplus
}
#endif
#endif
/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/