Skip to content

Commit 736bbe2

Browse files
authored
Merge pull request #49 from Lawlieta/master
【修改】ec20、m26、sim800c 等模块部分命令发送修改为 resp 响应模式
2 parents c831488 + 7d16f36 commit 736bbe2

File tree

3 files changed

+95
-13
lines changed

3 files changed

+95
-13
lines changed

at_socket_ec20.c

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,18 +454,31 @@ static int at_socket_event_recv(uint32_t event, uint32_t timeout, rt_uint8_t opt
454454
static int ec20_socket_close(int socket)
455455
{
456456
int result = 0;
457+
at_response_t resp = RT_NULL;
458+
459+
resp = at_create_resp(128, 0, RT_TICK_PER_SECOND);
460+
if (!resp)
461+
{
462+
LOG_E("No memory for response structure!");
463+
return -RT_ENOMEM;
464+
}
457465

458466
rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
459467

460468
/* default connection timeout is 10 seconds, but it set to 1 seconds is convenient to use.*/
461-
result = at_exec_cmd(RT_NULL, "AT+QICLOSE=%d,1", socket);
469+
result = at_exec_cmd(resp, "AT+QICLOSE=%d,1", socket);
462470
if (result < 0)
463471
{
464472
return result;
465473
}
466474

467475
rt_mutex_release(at_event_lock);
468476

477+
if (resp)
478+
{
479+
at_delete_resp(resp);
480+
}
481+
469482
return result;
470483
}
471484

@@ -487,10 +500,18 @@ static int ec20_socket_connect(int socket, char *ip, int32_t port, enum at_socke
487500
{
488501
int result = 0, event_result = 0;
489502
rt_bool_t retryed = RT_FALSE;
503+
at_response_t resp = RT_NULL;
490504

491505
RT_ASSERT(ip);
492506
RT_ASSERT(port >= 0);
493507

508+
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
509+
if (!resp)
510+
{
511+
LOG_E("No memory for response structure!");
512+
return -RT_ENOMEM;
513+
}
514+
494515
/* lock AT socket connect */
495516
rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
496517

@@ -508,15 +529,15 @@ static int ec20_socket_connect(int socket, char *ip, int32_t port, enum at_socke
508529
/* contextID = 1 : use same contextID as AT+QICSGP & AT+QIACT */
509530
/* local_port=0 : local port assigned automatically */
510531
/* access_mode = 1 : Direct push mode */
511-
if (at_exec_cmd(RT_NULL, "AT+QIOPEN=1,%d,\"TCP\",\"%s\",%d,0,1", socket, ip, port) < 0)
532+
if (at_exec_cmd(resp, "AT+QIOPEN=1,%d,\"TCP\",\"%s\",%d,0,1", socket, ip, port) < 0)
512533
{
513534
result = -RT_ERROR;
514535
goto __exit;
515536
}
516537
break;
517538

518539
case AT_SOCKET_UDP:
519-
if (at_exec_cmd(RT_NULL, "AT+QIOPEN=1,%d,\"UDP\",\"%s\",%d,0,1", socket, ip, port) < 0)
540+
if (at_exec_cmd(resp, "AT+QIOPEN=1,%d,\"UDP\",\"%s\",%d,0,1", socket, ip, port) < 0)
520541
{
521542
result = -RT_ERROR;
522543
goto __exit;
@@ -551,7 +572,11 @@ static int ec20_socket_connect(int socket, char *ip, int32_t port, enum at_socke
551572
{
552573
LOG_W("socket (%d) connect failed, maybe the socket was not be closed at the last time and now will retry.", socket);
553574
/* default connection timeout is 10 seconds, but it set to 1 seconds is convenient to use.*/
554-
at_exec_cmd(RT_NULL, "AT+QICLOSE=%d,1", socket);
575+
if (ec20_socket_close < 0)
576+
{
577+
result = -RT_ERROR;
578+
goto __exit;
579+
}
555580
retryed = RT_TRUE;
556581
goto __retry;
557582
}
@@ -564,6 +589,11 @@ static int ec20_socket_connect(int socket, char *ip, int32_t port, enum at_socke
564589
/* unlock AT socket connect */
565590
rt_mutex_release(at_event_lock);
566591

592+
if (resp)
593+
{
594+
at_delete_resp(resp);
595+
}
596+
567597
return result;
568598
}
569599

@@ -879,9 +909,9 @@ static void urc_close_func(const char *data, rt_size_t size)
879909
at_evt_cb_set[AT_SOCKET_EVT_CLOSED](socket, AT_SOCKET_EVT_CLOSED, NULL, 0);
880910
}
881911

882-
/* when TCP socket service is closed, host must send "AT+QICLOSE= <connID>,0" command to close socket */
883-
at_exec_cmd(RT_NULL, "AT+QICLOSE=%d,0\r\n", socket);
884-
rt_thread_mdelay(100);
912+
// /* when TCP socket service is closed, host must send "AT+QICLOSE= <connID>,0" command to close socket */
913+
// at_exec_cmd(RT_NULL, "AT+QICLOSE=%d,0\r\n", socket);
914+
// rt_thread_mdelay(100);
885915
}
886916

887917
static void urc_recv_func(const char *data, rt_size_t size)

at_socket_m26.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,22 @@ static int at_socket_event_recv(uint32_t event, uint32_t timeout, rt_uint8_t opt
105105
static int m26_socket_close(int socket)
106106
{
107107
int result = 0;
108+
at_response_t resp = RT_NULL;
109+
110+
resp = at_create_resp(128, 0, RT_TICK_PER_SECOND);
111+
if (!resp)
112+
{
113+
LOG_E("No memory for response structure!");
114+
return -RT_ENOMEM;
115+
}
108116

109117
rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
110118
cur_socket = socket;
111119

112120
/* Clear socket close event */
113121
at_socket_event_recv(SET_EVENT(socket, M26_EVNET_CLOSE_OK), 0, RT_EVENT_FLAG_OR);
114122

115-
if (at_exec_cmd(RT_NULL, "AT+QICLOSE=%d", socket) < 0)
123+
if (at_exec_cmd(resp, "AT+QICLOSE=%d", socket) < 0)
116124
{
117125
result = -RT_ERROR;
118126
goto __exit;
@@ -128,6 +136,11 @@ static int m26_socket_close(int socket)
128136
__exit:
129137
rt_mutex_release(at_event_lock);
130138

139+
if (resp)
140+
{
141+
at_delete_resp(resp);
142+
}
143+
131144
return result;
132145
}
133146

@@ -150,10 +163,18 @@ static int m26_socket_connect(int socket, char *ip, int32_t port, enum at_socket
150163
{
151164
int result = 0, event_result = 0;
152165
rt_bool_t retryed = RT_FALSE;
166+
at_response_t resp = RT_NULL;
153167

154168
RT_ASSERT(ip);
155169
RT_ASSERT(port >= 0);
156170

171+
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
172+
if (!resp)
173+
{
174+
LOG_E("No memory for response structure!");
175+
return -RT_ENOMEM;
176+
}
177+
157178
/* lock AT socket connect */
158179
rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
159180

@@ -168,15 +189,15 @@ static int m26_socket_connect(int socket, char *ip, int32_t port, enum at_socket
168189
{
169190
case AT_SOCKET_TCP:
170191
/* send AT commands(eg: AT+QIOPEN=0,"TCP","x.x.x.x", 1234) to connect TCP server */
171-
if (at_exec_cmd(RT_NULL, "AT+QIOPEN=%d,\"TCP\",\"%s\",%d", socket, ip, port) < 0)
192+
if (at_exec_cmd(resp, "AT+QIOPEN=%d,\"TCP\",\"%s\",%d", socket, ip, port) < 0)
172193
{
173194
result = -RT_ERROR;
174195
goto __exit;
175196
}
176197
break;
177198

178199
case AT_SOCKET_UDP:
179-
if (at_exec_cmd(RT_NULL, "AT+QIOPEN=%d,\"UDP\",\"%s\",%d", socket, ip, port) < 0)
200+
if (at_exec_cmd(resp, "AT+QIOPEN=%d,\"UDP\",\"%s\",%d", socket, ip, port) < 0)
180201
{
181202
result = -RT_ERROR;
182203
goto __exit;
@@ -226,6 +247,11 @@ static int m26_socket_connect(int socket, char *ip, int32_t port, enum at_socket
226247
/* unlock AT socket connect */
227248
rt_mutex_release(at_event_lock);
228249

250+
if (resp)
251+
{
252+
at_delete_resp(resp);
253+
}
254+
229255
return result;
230256
}
231257

at_socket_sim800c.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,22 @@ static int at_socket_event_recv(uint32_t event, uint32_t timeout, rt_uint8_t opt
112112
static int sim800c_socket_close(int socket)
113113
{
114114
int result = 0;
115+
at_response_t resp = RT_NULL;
116+
117+
resp = at_create_resp(128, 0, RT_TICK_PER_SECOND);
118+
if (!resp)
119+
{
120+
LOG_E("No memory for response structure!");
121+
return -RT_ENOMEM;
122+
}
115123

116124
rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
117125
cur_socket = socket;
118126

119127
/* Clear socket close event */
120128
at_socket_event_recv(SET_EVENT(socket, SIM800C_EVNET_CLOSE_OK), 0, RT_EVENT_FLAG_OR);
121129

122-
if (at_exec_cmd(RT_NULL, "AT+CIPCLOSE=%d", socket) < 0)
130+
if (at_exec_cmd(resp, "AT+CIPCLOSE=%d", socket) < 0)
123131
{
124132
result = -RT_ERROR;
125133
goto __exit;
@@ -135,6 +143,11 @@ static int sim800c_socket_close(int socket)
135143
__exit:
136144
rt_mutex_release(at_event_lock);
137145

146+
if (resp)
147+
{
148+
at_delete_resp(resp);
149+
}
150+
138151
return result;
139152
}
140153

@@ -157,10 +170,18 @@ static int sim800c_socket_connect(int socket, char *ip, int32_t port, enum at_so
157170
{
158171
int result = 0, event_result = 0;
159172
rt_bool_t retryed = RT_FALSE;
173+
at_response_t resp = RT_NULL;
160174

161175
RT_ASSERT(ip);
162176
RT_ASSERT(port >= 0);
163177

178+
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
179+
if (!resp)
180+
{
181+
LOG_E("No memory for response structure!");
182+
return -RT_ENOMEM;
183+
}
184+
164185
/* lock AT socket connect */
165186
rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
166187

@@ -175,15 +196,15 @@ static int sim800c_socket_connect(int socket, char *ip, int32_t port, enum at_so
175196
{
176197
case AT_SOCKET_TCP:
177198
/* send AT commands(eg: AT+QIOPEN=0,"TCP","x.x.x.x", 1234) to connect TCP server */
178-
if (at_exec_cmd(RT_NULL, "AT+CIPSTART=%d,\"TCP\",\"%s\",%d", socket, ip, port) < 0)
199+
if (at_exec_cmd(resp, "AT+CIPSTART=%d,\"TCP\",\"%s\",%d", socket, ip, port) < 0)
179200
{
180201
result = -RT_ERROR;
181202
goto __exit;
182203
}
183204
break;
184205

185206
case AT_SOCKET_UDP:
186-
if (at_exec_cmd(RT_NULL, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", socket, ip, port) < 0)
207+
if (at_exec_cmd(resp, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", socket, ip, port) < 0)
187208
{
188209
result = -RT_ERROR;
189210
goto __exit;
@@ -234,6 +255,11 @@ static int sim800c_socket_connect(int socket, char *ip, int32_t port, enum at_so
234255
/* unlock AT socket connect */
235256
rt_mutex_release(at_event_lock);
236257

258+
if (resp)
259+
{
260+
at_delete_resp(resp);
261+
}
262+
237263
return result;
238264
}
239265

0 commit comments

Comments
 (0)