增加通过4G的OTA功能
authorkyz <kongyuzhong@google.com>
Fri, 31 May 2024 08:01:02 +0000 (16:01 +0800)
committerkyz <kongyuzhong@google.com>
Tue, 11 Jun 2024 02:03:35 +0000 (10:03 +0800)
user/at_parser_4g.c
user/user_4g.c
user/user_ota.c
user/user_report.c

index 1b70504ad321d96d7247dcedf090fe1e890f65c4..3a150602eaa097dabd8237160cd2a74a6d7f91b4 100644 (file)
@@ -11,7 +11,7 @@
 #define OOB_MAX 5
 
 #define HAL_MutexCreate()         osMutexNew(NULL)
-#define HAL_MutexDestroy(mutex)   osMutexRelease(mutex)
+#define HAL_MutexDestroy(mutex)   osMutexDelete(mutex)
 #define HAL_MutexLock(mutex)      osMutexAcquire(mutex, portMAX_DELAY )
 #define HAL_MutexUnlock(mutex)    osMutexRelease(mutex)
 
@@ -724,6 +724,10 @@ static void at_worker(void *arg)
         //ret = at_getc(&c, at._timeout);
         ret = at_getc(&c, 100 );
         if (ret != 0) {
+            if( slist_empty(&at.task_l) &&  at_task_reponse_begin ){
+                               debug_printf( "-----error------  clear at_task_reponse_begin = 0\n " );
+                               at_task_reponse_begin = 0;
+                       }
             osDelay(10);
             continue;
         }
index fbe1317811a0906c8449969c07d87f5770c09b8c..15abdf2c85e0690013f68ba94cc2079e25558b59 100644 (file)
@@ -320,6 +320,12 @@ static int32_t cat1_tcp_server_connect( uint8_t conn_id, const char * tcp_server
 
 static int32_t cat1_tcp_server_close( uint8_t conn_id )
 {
+#if 1
+       char cmd[20];
+       sprintf( cmd, "AT+QICLOSE=%d",conn_id  );
+       cat1_at_send_no_reply( cmd, strlen(cmd), true );
+       return 0;
+#else
        char cmd[20];
        atcmd_config_t at_cfg;
        char resp_buf[20];
@@ -327,7 +333,7 @@ static int32_t cat1_tcp_server_close( uint8_t conn_id )
        //连接TCP服务器
        //AT+CIPSTART="TCP","192.168.3.116",8080                         //protocol,    server  IP      and     port
        at_cfg.reply_prefix = NULL;
-       at_cfg.reply_success_postfix="OK"; //"+QIOPEN:conn_id,err\r\n";
+       at_cfg.reply_success_postfix="OK\r\n"; //"+QIOPEN:conn_id,err\r\n";
        at_cfg.reply_fail_postfix ="ERROR"; //"ERROR  CLOSED";
        sprintf( cmd, "AT+QICLOSE=%d",conn_id  );
        memset( resp_buf, 0, sizeof(resp_buf) );
@@ -339,6 +345,7 @@ static int32_t cat1_tcp_server_close( uint8_t conn_id )
        }else{
                return -1;
        }
+#endif
 }
 
 
@@ -417,7 +424,7 @@ static void tcp_rx_data_handle(void *arg, char *rspinfo, int rsplen)
                        cat1_tcp_rx_buf[cat1_tcp_rx_n] = 0;
 #if 1
                        { extern int32_t iot_cmd_parse( uint32_t link, char *cmd );
-                       int32_t act = iot_cmd_parse( 0, (char *)cat1_tcp_rx_buf );
+                       int32_t act = iot_cmd_parse( 2, (char *)cat1_tcp_rx_buf );
                                                                
                                if( act == 1 || act == 2 ){
                                                //char * s = lock_resp_str();
@@ -473,7 +480,7 @@ static void tcp_rx_data_handle(void *arg, char *rspinfo, int rsplen)
                        if( len <= sizeof(ota_rx_buf ) ){
                                 int n =cat1_at_read( (char*)(ota_rx_buf), len );
                                ota_rx_n = len;
-                               debug_printf( " ota recv data %d bytes, rd:%d, wifi buf:%d[%d..%d]\n", len, n, rx_buf_wr-rx_buf_rd, rx_buf_rd, rx_buf_wr );
+                               debug_printf( "cat1 - ota recv data %d bytes, rd:%d, wifi buf:%d[%d..%d]\n", len, n, rx_buf_wr-rx_buf_rd, rx_buf_rd, rx_buf_wr );
                                ota_handle_http_resp_data( ota_rx_buf, ota_rx_n );
                        }       
                }
@@ -489,8 +496,10 @@ int32_t cat1_tcp_tx( uint8_t conn_id, uint8_t *data, uint32_t sz )
     atcmd_config_t at_cfg;
                int32_t ret = 0;
 
-    at_cfg.reply_prefix = ">";
-    at_cfg.reply_success_postfix="SEND";
+if(conn_id==4) debug_printf( "cat1  ota req:[%s]\n", data);
+
+    at_cfg.reply_prefix = NULL; //">";
+    at_cfg.reply_success_postfix="SEND OK\r\n";
     at_cfg.reply_fail_postfix = "ERROR";
     sprintf( cmd, "AT+QISEND=%d,%d", conn_id, sz );
                resp_buf[0] = 0;
@@ -518,6 +527,12 @@ static void cat1_tcp_closed_cb(void *arg, char *rspinfo, int rsplen)
                g_dev.cat1_connected = 1 ;
 }
 
+static void cat1_ota_closed_cb(void *arg, char *rspinfo, int rsplen)
+{
+       if( ota_link_connected  )
+               ota_link_connected = 0 ;
+}
+
 void user_cat1_task( void* unused )
 {
          uint32_t rpt_secs = 0;
@@ -543,6 +558,7 @@ void user_cat1_task( void* unused )
                cat1_at_register_callback("+QIURC: \"recv\"", NULL, NULL, 0, tcp_rx_data_handle, NULL);
                //+QIURC: "closed",<connectID>
                cat1_at_register_callback( "+QIURC: \"closed\",3", NULL, NULL, 0, cat1_tcp_closed_cb, NULL );
+               cat1_at_register_callback( "+QIURC: \"closed\",4", NULL, NULL, 0, cat1_ota_closed_cb, NULL );
                while( 1 ){
 
                        if( cat1_connect() != 0 ){
@@ -643,8 +659,8 @@ int32_t cat1_ota_requst( char *host, uint16_t port, char *req )
                                if( cat1_tcp_server_connect( CONN_ID_OTA, host, port ) == 0 ){
                                 ota_link_connected = 1;
                                }else{
-                                       osDelay(1000);
                                        cat1_tcp_server_close( CONN_ID_OTA );
+                                       osDelay(2000);
                                        continue;
                                }
                        }
index b659414b32086414cf34d18adf4c759ee10ca24c..0c332839eca728101aed1b07b4a4b0deba7c415c 100644 (file)
@@ -4,6 +4,7 @@
 
 #define OTA_LINK_WIFI 0
 #define OTA_LINK_ETH  1
+#define OTA_LINK_CAT1 2
 
 #define OTA_FW_HEAD_FLAG  0xAA01
        
@@ -88,7 +89,7 @@ char * ota_status( void )
 
 int32_t ota_start( uint32_t link, char * url, char *ver )
 {
-    if( link != OTA_LINK_WIFI && link != OTA_LINK_ETH ){
+    if( link != OTA_LINK_WIFI && link != OTA_LINK_ETH && link != OTA_LINK_CAT1 ){
         return -1;
     } 
 
@@ -123,6 +124,12 @@ int32_t eth_ota_start( char * url, char *ver )
        //return 0;
 }
 
+int32_t cat1_ota_start( char * url, char *ver )
+{
+       return ota_start( OTA_LINK_CAT1, url, ver );
+       //return 0;
+}
+
 int32_t ota_handle_http_resp( uint8_t *rx_data, uint32_t rx_sz )
 {
        //http_resp_flag = 1;
@@ -228,6 +235,12 @@ int32_t http_get_blk( void )
                                  //tcp connect fail, ota fail
                                  return ret;
                          }
+    }else if( g_ota.link == OTA_LINK_CAT1 ){
+                         ret = cat1_ota_requst( g_ota.host, g_ota.port, http_req );
+                         if(ret < 0){
+                                 //tcp connect fail, ota fail
+                                 return ret;
+                         }
     }else{
                          return -1;
                }
index bef75e8929611d35215c6bb6852b8d054467f499..64fed7ca01accd73e0edabb7153bd9282c1136da 100644 (file)
@@ -378,6 +378,8 @@ int32_t iot_cmd_parse( uint32_t link, char *cmd )
                                                                                wifi_ota_start( url->valuestring, ver->valuestring );
                                                                        }else if(link==1){
                                                                                eth_ota_start( url->valuestring, ver->valuestring );
+                                                                       }else if(link== 2){
+                                                                               cat1_ota_start( url->valuestring, ver->valuestring );
                                                                        }
                                                                act = 3;
                                                        }
@@ -422,7 +424,7 @@ void resp_data_clean( void )
 
 int32_t is_iot_connected( void )
 {
-       return (g_dev.eth_connected == 2 || g_dev.wifi_connected == 2)?1:0;
+       return (g_dev.eth_connected == 2 || g_dev.wifi_connected == 2 || g_dev.cat1_connected == 2 )?1:0;
 }
 
 int32_t is_dev_locked( void )