Ver código fonte

1、修复4G初次启动,MQTT无法连接及发送消息的缺陷。

liyuezong 1 ano atrás
pai
commit
b3ef078fea
4 arquivos alterados com 32 adições e 17 exclusões
  1. 9 6
      pro/src/Cellular.c
  2. 11 1
      pro/src/appweb_handle.c
  3. 1 1
      pro/src/mqtt.c
  4. 11 9
      pro/src/thread.c

+ 9 - 6
pro/src/Cellular.c

@@ -181,7 +181,7 @@ typedef struct {
 typedef struct {
     int             fd;
     CellInfo_t      *pcell;
-    lock_t          lck;
+    //lock_t          lck;
     char             prod_id[32];
 
     int             stat;
@@ -477,7 +477,7 @@ static void reset_var( cell_handle_t *h)
    h->all.stat.utctime = 0;
     h->all.stat.linked = 0;
     sprintf(h->all.stat.ipv4, "-");
-    sprintf(h->all.stat.ipv4, "-");
+    sprintf(h->all.stat.ipv6, "-");
 
     sprintf(h->all.info.apn, "-");
     sprintf(h->all.info.cnum, "-");
@@ -1579,6 +1579,8 @@ static void* cellular_thread(void *arg)
         UpdateCellularManager(&h->all);
         sleep(1);
     }
+    reset_var(h);
+    UpdateCellularManager(&h->all);
     cell_deinit(h);
     port_deinit(h);
 
@@ -1601,20 +1603,21 @@ int cellular_init(void)
     int r;
     cell_handle_t *h=&ceHandle;
 
-    if (__globalDeviceManage._globalDevInfo.cell.Cellular_enable)
+    if (__globalDeviceManage._globalDevInfo.cell.Cellular_enable && __globalDeviceManage._globalDevInfo.cell.mode &&  !thread_is_running(THREAD_ID_CELLULAR))
     {
         memset(h, 0, sizeof(cell_handle_t));
 
         h->dm = &__globalDeviceManage;
         h->pcell = &h->dm->_globalDevInfo.cell;
         strcpy( h->prod_id,h->dm->_globalDevInfo.product.number);
-        h->lck = lock_d_init();
+       // h->lck = lock_d_init();
         nic_set(NIC_USB, 1);
 
        dev_SMS_get(h->dm->db, h->pcell);
 
         thread_start(THREAD_ID_CELLULAR, cellular_thread, h);
     }
+    else return -1;
 
     return 0;
 }
@@ -1623,10 +1626,10 @@ int cellular_deinit(void)
 {
     cell_handle_t *h=&ceHandle;
 
-    if (__globalDeviceManage._globalDevInfo.cell.Cellular_enable)
+    if (__globalDeviceManage._globalDevInfo.cell.Cellular_enable && !__globalDeviceManage._globalDevInfo.cell.mode)
     {
-        lock_d_deinit(h->lck);
         thread_stop(THREAD_ID_CELLULAR);
+        nic_set(NIC_USB, 0);
     }
 
     return 0;

+ 11 - 1
pro/src/appweb_handle.c

@@ -3972,8 +3972,18 @@ static void communicationManagement(void *conn)
         }
 
          dev_SMS_update_recv(__globalDeviceManage.db, & __globalDeviceManage._globalDevInfo.cell);
- 
 
+         if (__globalDeviceManage._globalDevInfo.cell.mode)
+         {
+            cellular_init();
+            sleep(1);
+         }
+         else
+        {
+            cellular_deinit(); 
+            sleep(1);
+        }
+ 
         ack_str = ctrl_sts_ack_to_json(); 
     }
 

+ 1 - 1
pro/src/mqtt.c

@@ -374,7 +374,7 @@ static int conn_one(mqtt_conn_t *conn)
             .clean = true,
             .qos = 1,
             .version = 4,
-            .keepalive = 60,
+            .keepalive = 30,
             .topic = mg_str("hello"),
             .message = mg_str("bye"),
             .client_id = mg_str(conn->ser.cid),

+ 11 - 9
pro/src/thread.c

@@ -138,16 +138,18 @@ int thread_stop(int id)
     if(id<0 || id>=THREAD_ID_MAX) {
         return -1;
     }
-    thread_handle_t *h=&thdHandles[id];
+    thread_handle_t *h = &thdHandles[id];
 
-    h->quit = 1;
-    //pthread_detach();
-    pthread_join(h->tid, NULL);
-    h->tid = 0;
-    h->running = 0;
-    h->arg = NULL;
-    h->fn  = NULL;
-    
+    if (h->running)
+    {
+        h->quit = 1;
+        // pthread_detach();
+        pthread_join(h->tid, NULL);
+        h->tid = 0;
+        h->running = 0;
+        h->arg = NULL;
+        h->fn = NULL;
+    }
     return 0;
 }