소스 검색

【修改】ec20、m26、sim800c 等模块部分命令发送修改为 resp 响应模式

Signed-off-by: chenyong <1521761801@qq.com>
chenyong 6 년 전
부모
커밋
7d16f36a54
3개의 변경된 파일95개의 추가작업 그리고 13개의 파일을 삭제
  1. 37 7
      at_socket_ec20.c
  2. 29 3
      at_socket_m26.c
  3. 29 3
      at_socket_sim800c.c

+ 37 - 7
at_socket_ec20.c

@@ -454,11 +454,19 @@ static int at_socket_event_recv(uint32_t event, uint32_t timeout, rt_uint8_t opt
 static int ec20_socket_close(int socket)
 {
     int result = 0;
+    at_response_t resp = RT_NULL;
+
+    resp = at_create_resp(128, 0, RT_TICK_PER_SECOND);
+    if (!resp)
+    {
+        LOG_E("No memory for response structure!");
+        return -RT_ENOMEM;
+    }
 
     rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
 
     /* default connection timeout is 10 seconds, but it set to 1 seconds is convenient to use.*/
-    result = at_exec_cmd(RT_NULL, "AT+QICLOSE=%d,1", socket);
+    result = at_exec_cmd(resp, "AT+QICLOSE=%d,1", socket);
     if (result < 0)
     {
         return result;
@@ -466,6 +474,11 @@ static int ec20_socket_close(int socket)
 
     rt_mutex_release(at_event_lock);
 
+    if (resp)
+    {
+        at_delete_resp(resp);
+    }
+
     return result;
 }
 
@@ -487,10 +500,18 @@ static int ec20_socket_connect(int socket, char *ip, int32_t port, enum at_socke
 {
     int result = 0, event_result = 0;
     rt_bool_t retryed = RT_FALSE;
+    at_response_t resp = RT_NULL;
 
     RT_ASSERT(ip);
     RT_ASSERT(port >= 0);
 
+    resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
+    if (!resp)
+    {
+        LOG_E("No memory for response structure!");
+        return -RT_ENOMEM;
+    }
+
     /* lock AT socket connect */
     rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
 
@@ -508,7 +529,7 @@ __retry:
             /* contextID = 1 : use same contextID as AT+QICSGP & AT+QIACT */
             /* local_port=0 : local port assigned automatically */
             /* access_mode = 1 : Direct push mode */
-            if (at_exec_cmd(RT_NULL, "AT+QIOPEN=1,%d,\"TCP\",\"%s\",%d,0,1", socket, ip, port) < 0)
+            if (at_exec_cmd(resp, "AT+QIOPEN=1,%d,\"TCP\",\"%s\",%d,0,1", socket, ip, port) < 0)
             {
                 result = -RT_ERROR;
                 goto __exit;
@@ -516,7 +537,7 @@ __retry:
             break;
 
         case AT_SOCKET_UDP:
-            if (at_exec_cmd(RT_NULL, "AT+QIOPEN=1,%d,\"UDP\",\"%s\",%d,0,1", socket, ip, port) < 0)
+            if (at_exec_cmd(resp, "AT+QIOPEN=1,%d,\"UDP\",\"%s\",%d,0,1", socket, ip, port) < 0)
             {
                 result = -RT_ERROR;
                 goto __exit;
@@ -551,7 +572,11 @@ __retry:
         {
             LOG_W("socket (%d) connect failed, maybe the socket was not be closed at the last time and now will retry.", socket);
             /* default connection timeout is 10 seconds, but it set to 1 seconds is convenient to use.*/
-            at_exec_cmd(RT_NULL, "AT+QICLOSE=%d,1", socket);
+            if (ec20_socket_close < 0)
+            {
+                result = -RT_ERROR;
+                goto __exit;
+            }
             retryed = RT_TRUE;
             goto __retry;
         }
@@ -564,6 +589,11 @@ __exit:
     /* unlock AT socket connect */
     rt_mutex_release(at_event_lock);
 
+    if (resp)
+    {
+        at_delete_resp(resp);
+    }
+
     return result;
 }
 
@@ -879,9 +909,9 @@ static void urc_close_func(const char *data, rt_size_t size)
         at_evt_cb_set[AT_SOCKET_EVT_CLOSED](socket, AT_SOCKET_EVT_CLOSED, NULL, 0);
     }
     
-    /* when TCP socket service is closed, host must send "AT+QICLOSE= <connID>,0" command to close socket */
-    at_exec_cmd(RT_NULL, "AT+QICLOSE=%d,0\r\n", socket);
-    rt_thread_mdelay(100);
+    // /* when TCP socket service is closed, host must send "AT+QICLOSE= <connID>,0" command to close socket */
+    // at_exec_cmd(RT_NULL, "AT+QICLOSE=%d,0\r\n", socket);
+    // rt_thread_mdelay(100);
 }
 
 static void urc_recv_func(const char *data, rt_size_t size)

+ 29 - 3
at_socket_m26.c

@@ -105,6 +105,14 @@ static int at_socket_event_recv(uint32_t event, uint32_t timeout, rt_uint8_t opt
 static int m26_socket_close(int socket)
 {
     int result = 0;
+    at_response_t resp = RT_NULL;
+
+    resp = at_create_resp(128, 0, RT_TICK_PER_SECOND);
+    if (!resp)
+    {
+        LOG_E("No memory for response structure!");
+        return -RT_ENOMEM;
+    }
 
     rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
     cur_socket = socket;
@@ -112,7 +120,7 @@ static int m26_socket_close(int socket)
     /* Clear socket close event */
     at_socket_event_recv(SET_EVENT(socket, M26_EVNET_CLOSE_OK), 0, RT_EVENT_FLAG_OR);
 
-    if (at_exec_cmd(RT_NULL, "AT+QICLOSE=%d", socket) < 0)
+    if (at_exec_cmd(resp, "AT+QICLOSE=%d", socket) < 0)
     {
         result = -RT_ERROR;
         goto __exit;
@@ -128,6 +136,11 @@ static int m26_socket_close(int socket)
 __exit:
     rt_mutex_release(at_event_lock);
 
+    if (resp)
+    {
+        at_delete_resp(resp);
+    }
+
     return result;
 }
 
@@ -150,10 +163,18 @@ static int m26_socket_connect(int socket, char *ip, int32_t port, enum at_socket
 {
     int result = 0, event_result = 0;
     rt_bool_t retryed = RT_FALSE;
+    at_response_t resp = RT_NULL;
 
     RT_ASSERT(ip);
     RT_ASSERT(port >= 0);
 
+    resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
+    if (!resp)
+    {
+        LOG_E("No memory for response structure!");
+        return -RT_ENOMEM;
+    }
+
     /* lock AT socket connect */
     rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
 
@@ -168,7 +189,7 @@ __retry:
         {
         case AT_SOCKET_TCP:
             /* send AT commands(eg: AT+QIOPEN=0,"TCP","x.x.x.x", 1234) to connect TCP server */
-            if (at_exec_cmd(RT_NULL, "AT+QIOPEN=%d,\"TCP\",\"%s\",%d", socket, ip, port) < 0)
+            if (at_exec_cmd(resp, "AT+QIOPEN=%d,\"TCP\",\"%s\",%d", socket, ip, port) < 0)
             {
                 result = -RT_ERROR;
                 goto __exit;
@@ -176,7 +197,7 @@ __retry:
             break;
 
         case AT_SOCKET_UDP:
-            if (at_exec_cmd(RT_NULL, "AT+QIOPEN=%d,\"UDP\",\"%s\",%d", socket, ip, port) < 0)
+            if (at_exec_cmd(resp, "AT+QIOPEN=%d,\"UDP\",\"%s\",%d", socket, ip, port) < 0)
             {
                 result = -RT_ERROR;
                 goto __exit;
@@ -226,6 +247,11 @@ __exit:
     /* unlock AT socket connect */
     rt_mutex_release(at_event_lock);
 
+    if (resp)
+    {
+        at_delete_resp(resp);
+    }
+
     return result;
 }
 

+ 29 - 3
at_socket_sim800c.c

@@ -112,6 +112,14 @@ static int at_socket_event_recv(uint32_t event, uint32_t timeout, rt_uint8_t opt
 static int sim800c_socket_close(int socket)
 {
     int result = 0;
+    at_response_t resp = RT_NULL;
+
+    resp = at_create_resp(128, 0, RT_TICK_PER_SECOND);
+    if (!resp)
+    {
+        LOG_E("No memory for response structure!");
+        return -RT_ENOMEM;
+    }
 
     rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
     cur_socket = socket;
@@ -119,7 +127,7 @@ static int sim800c_socket_close(int socket)
     /* Clear socket close event */
     at_socket_event_recv(SET_EVENT(socket, SIM800C_EVNET_CLOSE_OK), 0, RT_EVENT_FLAG_OR);
 
-    if (at_exec_cmd(RT_NULL, "AT+CIPCLOSE=%d", socket) < 0)
+    if (at_exec_cmd(resp, "AT+CIPCLOSE=%d", socket) < 0)
     {
         result = -RT_ERROR;
         goto __exit;
@@ -135,6 +143,11 @@ static int sim800c_socket_close(int socket)
 __exit:
     rt_mutex_release(at_event_lock);
 
+    if (resp)
+    {
+        at_delete_resp(resp);
+    }
+
     return result;
 }
 
@@ -157,10 +170,18 @@ static int sim800c_socket_connect(int socket, char *ip, int32_t port, enum at_so
 {
     int result = 0, event_result = 0;
     rt_bool_t retryed = RT_FALSE;
+    at_response_t resp = RT_NULL;
 
     RT_ASSERT(ip);
     RT_ASSERT(port >= 0);
 
+    resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
+    if (!resp)
+    {
+        LOG_E("No memory for response structure!");
+        return -RT_ENOMEM;
+    }
+
     /* lock AT socket connect */
     rt_mutex_take(at_event_lock, RT_WAITING_FOREVER);
 
@@ -175,7 +196,7 @@ __retry:
         {
         case AT_SOCKET_TCP:
             /* send AT commands(eg: AT+QIOPEN=0,"TCP","x.x.x.x", 1234) to connect TCP server */
-            if (at_exec_cmd(RT_NULL, "AT+CIPSTART=%d,\"TCP\",\"%s\",%d", socket, ip, port) < 0)
+            if (at_exec_cmd(resp, "AT+CIPSTART=%d,\"TCP\",\"%s\",%d", socket, ip, port) < 0)
             {
                 result = -RT_ERROR;
                 goto __exit;
@@ -183,7 +204,7 @@ __retry:
             break;
 
         case AT_SOCKET_UDP:
-            if (at_exec_cmd(RT_NULL, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", socket, ip, port) < 0)
+            if (at_exec_cmd(resp, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d", socket, ip, port) < 0)
             {
                 result = -RT_ERROR;
                 goto __exit;
@@ -234,6 +255,11 @@ __exit:
     /* unlock AT socket connect */
     rt_mutex_release(at_event_lock);
 
+    if (resp)
+    {
+        at_delete_resp(resp);
+    }
+
     return result;
 }