-
Notifications
You must be signed in to change notification settings - Fork 0
/
u_cx_socket.c
247 lines (226 loc) · 10.1 KB
/
u_cx_socket.c
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* This file was automatically generated using csnake v0.3.5.
*
* This file should not be edited directly, any changes will be
* overwritten next time the script is run.
*
* Source code for csnake is available at:
* https://gitlab.com/andrejr/csnake
*
* csnake is also available on PyPI, at :
* https://pypi.org/project/csnake
*/
#include "u_cx_at_client.h"
#include "u_cx_socket.h"
int32_t uCxSocketCreate1(uCxHandle_t * puCxHandle, uProtocol_t protocol, int32_t * pSocketHandle)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USOCR=", "d", protocol, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USOCR:", NULL, NULL, "d", pSocketHandle, U_CX_AT_UTIL_PARAM_LAST);
{
// Always call uCxAtClientCmdEnd() even any previous function failed
int32_t endRet = uCxAtClientCmdEnd(pAtClient);
if (ret >= 0) {
ret = endRet;
}
}
return ret;
}
int32_t uCxSocketCreate2(uCxHandle_t * puCxHandle, uProtocol_t protocol, uPreferredProtocolType_t preferred_protocol_type, int32_t * pSocketHandle)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USOCR=", "dd", protocol, preferred_protocol_type, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USOCR:", NULL, NULL, "d", pSocketHandle, U_CX_AT_UTIL_PARAM_LAST);
{
// Always call uCxAtClientCmdEnd() even any previous function failed
int32_t endRet = uCxAtClientCmdEnd(pAtClient);
if (ret >= 0) {
ret = endRet;
}
}
return ret;
}
int32_t uCxSocketSetTLS2(uCxHandle_t * puCxHandle, int32_t socket_handle, uTlsVersion_t tls_version)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
return uCxAtClientExecSimpleCmdF(pAtClient, "AT+USOTLS=", "dd", socket_handle, tls_version, U_CX_AT_UTIL_PARAM_LAST);
}
int32_t uCxSocketSetTLS3(uCxHandle_t * puCxHandle, int32_t socket_handle, uTlsVersion_t tls_version, const char * ca_name)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
return uCxAtClientExecSimpleCmdF(pAtClient, "AT+USOTLS=", "dds", socket_handle, tls_version, ca_name, U_CX_AT_UTIL_PARAM_LAST);
}
int32_t uCxSocketSetTLS5(uCxHandle_t * puCxHandle, int32_t socket_handle, uTlsVersion_t tls_version, const char * ca_name, const char * client_cert_name, const char * client_key_name)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
return uCxAtClientExecSimpleCmdF(pAtClient, "AT+USOTLS=", "ddsss", socket_handle, tls_version, ca_name, client_cert_name, client_key_name, U_CX_AT_UTIL_PARAM_LAST);
}
int32_t uCxSocketConnect(uCxHandle_t * puCxHandle, int32_t socket_handle, const char * host_address, int32_t remote_port)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
return uCxAtClientExecSimpleCmdF(pAtClient, "AT+USOC=", "dsd", socket_handle, host_address, remote_port, U_CX_AT_UTIL_PARAM_LAST);
}
int32_t uCxSocketSetReadMode(uCxHandle_t * puCxHandle, uReadMode_t read_mode)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
return uCxAtClientExecSimpleCmdF(pAtClient, "AT+USORM=", "d", read_mode, U_CX_AT_UTIL_PARAM_LAST);
}
int32_t uCxSocketGetReadMode(uCxHandle_t * puCxHandle, uReadMode_t * pReadMode)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USORM?", "", U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USORM:", NULL, NULL, "d", pReadMode, U_CX_AT_UTIL_PARAM_LAST);
{
// Always call uCxAtClientCmdEnd() even any previous function failed
int32_t endRet = uCxAtClientCmdEnd(pAtClient);
if (ret >= 0) {
ret = endRet;
}
}
return ret;
}
int32_t uCxSocketWriteString(uCxHandle_t * puCxHandle, int32_t socket_handle, const char * string_data, int32_t * pWrittenLength)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USOWS=", "ds", socket_handle, string_data, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USOWS:", NULL, NULL, "-d", pWrittenLength, U_CX_AT_UTIL_PARAM_LAST);
{
// Always call uCxAtClientCmdEnd() even any previous function failed
int32_t endRet = uCxAtClientCmdEnd(pAtClient);
if (ret >= 0) {
ret = endRet;
}
}
return ret;
}
int32_t uCxSocketWriteBinary(uCxHandle_t * puCxHandle, int32_t socket_handle, uint8_t * pWData, size_t wDataLen)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t written_length;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USOWB=", "dB", socket_handle, pWData, wDataLen, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USOWB:", NULL, NULL, "-d", &written_length, U_CX_AT_UTIL_PARAM_LAST);
{
// Always call uCxAtClientCmdEnd() even any previous function failed
int32_t endRet = uCxAtClientCmdEnd(pAtClient);
if (ret >= 0) {
ret = endRet;
}
}
if (ret >= 0) {
ret = written_length;
}
return ret;
}
int32_t uCxSocketClose(uCxHandle_t * puCxHandle, int32_t socket_handle)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
return uCxAtClientExecSimpleCmdF(pAtClient, "AT+USOCL=", "d", socket_handle, U_CX_AT_UTIL_PARAM_LAST);
}
bool uCxBeginSocketReadString(uCxHandle_t * puCxHandle, int32_t socket_handle, int32_t length, uCxSocketReadString_t * pSocketReadStringRsp)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USORS=", "dd", socket_handle, length, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USORS:", NULL, NULL, "-ds", &pSocketReadStringRsp->length, &pSocketReadStringRsp->string_data, U_CX_AT_UTIL_PARAM_LAST);
return ret > 0;
}
int32_t uCxSocketReadBinary(uCxHandle_t * puCxHandle, int32_t socket_handle, int32_t length, uint8_t * pRData)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
uint8_t *pBinBuffer = pRData;
size_t binBufferLen = length;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USORB=", "dd", socket_handle, length, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USORB:", pBinBuffer, &binBufferLen, "-", U_CX_AT_UTIL_PARAM_LAST);
{
// Always call uCxAtClientCmdEnd() even any previous function failed
int32_t endRet = uCxAtClientCmdEnd(pAtClient);
if (ret >= 0) {
ret = endRet;
}
}
if (ret >= 0) {
ret = binBufferLen;
}
return ret;
}
int32_t uCxSocketListen(uCxHandle_t * puCxHandle, int32_t socket_handle, int32_t port)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
return uCxAtClientExecSimpleCmdF(pAtClient, "AT+USOL=", "dd", socket_handle, port, U_CX_AT_UTIL_PARAM_LAST);
}
bool uCxBeginSocketReceiveFrom(uCxHandle_t * puCxHandle, int32_t socket_handle, int32_t length, uCxSocketReceiveFrom_t * pSocketReceiveFromRsp)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USORF=", "dd", socket_handle, length, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USORF:", NULL, NULL, "-idds", &pSocketReceiveFromRsp->remote_ip, &pSocketReceiveFromRsp->remote_port, &pSocketReceiveFromRsp->length, &pSocketReceiveFromRsp->string_data, U_CX_AT_UTIL_PARAM_LAST);
return ret > 0;
}
void uCxBeginSocketListStatus(uCxHandle_t * puCxHandle)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
uCxAtClientCmdBeginF(pAtClient, "AT+USOST?", "", U_CX_AT_UTIL_PARAM_LAST);
}
bool uCxSocketListStatusGetResponse(uCxHandle_t * puCxHandle, uCxSocketListStatus_t * pSocketListStatusRsp)
{
int32_t ret;
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USOST:", NULL, NULL, "ddd", &pSocketListStatusRsp->socket_handle, &pSocketListStatusRsp->protocol, &pSocketListStatusRsp->socket_status, U_CX_AT_UTIL_PARAM_LAST);
return ret >= 0;
}
int32_t uCxSocketGetStatus(uCxHandle_t * puCxHandle, int32_t socket_handle, uCxSocketGetStatus_t * pSocketGetStatusRsp)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USOST=", "d", socket_handle, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USOST:", NULL, NULL, "-dd", &pSocketGetStatusRsp->protocol, &pSocketGetStatusRsp->socket_status, U_CX_AT_UTIL_PARAM_LAST);
{
// Always call uCxAtClientCmdEnd() even any previous function failed
int32_t endRet = uCxAtClientCmdEnd(pAtClient);
if (ret >= 0) {
ret = endRet;
}
}
return ret;
}
int32_t uCxSocketSetOption(uCxHandle_t * puCxHandle, int32_t socket_handle, uOption_t option, int32_t value)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
return uCxAtClientExecSimpleCmdF(pAtClient, "AT+USOO=", "ddd", socket_handle, option, value, U_CX_AT_UTIL_PARAM_LAST);
}
int32_t uCxSocketGetOption(uCxHandle_t * puCxHandle, int32_t socket_handle, uOption_t option, int32_t * pValue)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USOO=", "dd", socket_handle, option, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USOO:", NULL, NULL, "--d", pValue, U_CX_AT_UTIL_PARAM_LAST);
{
// Always call uCxAtClientCmdEnd() even any previous function failed
int32_t endRet = uCxAtClientCmdEnd(pAtClient);
if (ret >= 0) {
ret = endRet;
}
}
return ret;
}
int32_t uCxSocketGetHostByName(uCxHandle_t * puCxHandle, const char * host_name, uSockIpAddress_t * pHostIp)
{
uCxAtClient_t *pAtClient = puCxHandle->pAtClient;
int32_t ret;
uCxAtClientCmdBeginF(pAtClient, "AT+USOH=", "s", host_name, U_CX_AT_UTIL_PARAM_LAST);
ret = uCxAtClientCmdGetRspParamsF(pAtClient, "+USOH:", NULL, NULL, "i", pHostIp, U_CX_AT_UTIL_PARAM_LAST);
{
// Always call uCxAtClientCmdEnd() even any previous function failed
int32_t endRet = uCxAtClientCmdEnd(pAtClient);
if (ret >= 0) {
ret = endRet;
}
}
return ret;
}