Просмотр исходного кода

update: mreport,放到components里

??? 6 месяцев назад
Родитель
Сommit
91d0a976cf

+ 32 - 3
components/network/netdrv/src/luat_netdrv_mreport.c → components/mreport/src/luat_mreport.c

@@ -1,13 +1,13 @@
 #include "luat_base.h"
 #include "luat_base.h"
 #include "luat_netdrv.h"
 #include "luat_netdrv.h"
 #include "luat_network_adapter.h"
 #include "luat_network_adapter.h"
-#include "luat_netdrv_napt.h"
 #include "lwip/pbuf.h"
 #include "lwip/pbuf.h"
 #include "lwip/ip.h"
 #include "lwip/ip.h"
 #include "lwip/udp.h"
 #include "lwip/udp.h"
 #include "luat_mcu.h"
 #include "luat_mcu.h"
 #include "luat_mem.h"
 #include "luat_mem.h"
 #include "luat_mobile.h"
 #include "luat_mobile.h"
+#include "luat_str.h"
 #include "cJSON.h"
 #include "cJSON.h"
 
 
 #define LUAT_LOG_TAG "netdrv.napt.mreport"
 #define LUAT_LOG_TAG "netdrv.napt.mreport"
@@ -57,6 +57,7 @@ void luat_mreport_mobile(cJSON* mreport_data) {
     cJSON_AddNumberToObject(mreport_data, "sdk", 0);
     cJSON_AddNumberToObject(mreport_data, "sdk", 0);
 }
 }
 
 
+// 网络信息
 void luat_mreport_sim_network(cJSON* mreport_data, struct netif* netif) {
 void luat_mreport_sim_network(cJSON* mreport_data, struct netif* netif) {
     cJSON* cells = cJSON_CreateArray();
     cJSON* cells = cJSON_CreateArray();
     // ICCID
     // ICCID
@@ -90,6 +91,7 @@ void luat_mreport_sim_network(cJSON* mreport_data, struct netif* netif) {
         else {
         else {
             cJSON_AddNumberToObject(mreport_data, "cid", cell_info->lte_service_info.cid);
             cJSON_AddNumberToObject(mreport_data, "cid", cell_info->lte_service_info.cid);
             cJSON_AddNumberToObject(mreport_data, "tac", cell_info->lte_service_info.tac);
             cJSON_AddNumberToObject(mreport_data, "tac", cell_info->lte_service_info.tac);
+            cJSON_AddNumberToObject(mreport_data, "band", cell_info->lte_service_info.band);
             
             
             if (cell_info->lte_neighbor_info_num > 0) {
             if (cell_info->lte_neighbor_info_num > 0) {
                 for (size_t i = 0; i < cell_info->lte_neighbor_info_num; i++) {
                 for (size_t i = 0; i < cell_info->lte_neighbor_info_num; i++) {
@@ -132,6 +134,10 @@ void luat_mreport_send(void) {
     cJSON* mreport_data = cJSON_CreateObject();
     cJSON* mreport_data = cJSON_CreateObject();
 
 
     luat_netdrv_t* netdrv = luat_netdrv_get(NW_ADAPTER_INDEX_LWIP_GPRS);
     luat_netdrv_t* netdrv = luat_netdrv_get(NW_ADAPTER_INDEX_LWIP_GPRS);
+    if (netdrv == NULL || netdrv->netif == NULL) {
+        return 0;
+    }
+
     struct netif *netif = netdrv->netif;
     struct netif *netif = netdrv->netif;
     if (netif == NULL || ip_addr_isany(&netif->ip_addr)) {
     if (netif == NULL || ip_addr_isany(&netif->ip_addr)) {
         // LLOGD("还没联网");
         // LLOGD("还没联网");
@@ -192,7 +198,7 @@ void luat_mreport_send(void) {
 
 
     // 结束 转换成json字符串
     // 结束 转换成json字符串
     char* json = cJSON_PrintUnformatted(mreport_data);
     char* json = cJSON_PrintUnformatted(mreport_data);
-    LLOGE("json len --- %d", strlen(json));
+    LLOGE("json len --- %d\r\n%s", strlen(json), json);
 
 
     struct pbuf* p = pbuf_alloc(PBUF_TRANSPORT, strlen(json), PBUF_RAM);
     struct pbuf* p = pbuf_alloc(PBUF_TRANSPORT, strlen(json), PBUF_RAM);
     if (p == NULL) {
     if (p == NULL) {
@@ -219,7 +225,7 @@ void luat_mreport_start(void) {
         LLOGE("luat_rtos_timer_create %d", ret);
         LLOGE("luat_rtos_timer_create %d", ret);
         return;
         return;
     }
     }
-    ret = luat_rtos_timer_start(mreport_timer, 3*60*1000, 1, mreport_timer_cb, NULL);
+    ret = luat_rtos_timer_start(mreport_timer, 1*60*1000, 1, mreport_timer_cb, NULL);
     if (ret) {
     if (ret) {
         LLOGE("luat_rtos_timer_start %d", ret);
         LLOGE("luat_rtos_timer_start %d", ret);
     }
     }
@@ -231,4 +237,27 @@ void luat_mreport_stop(void) {
         luat_rtos_timer_delete(mreport_timer);
         luat_rtos_timer_delete(mreport_timer);
         mreport_timer = NULL;
         mreport_timer = NULL;
     }
     }
+}
+
+void luat_mreport_config(const char* config, int val) {
+    LLOGD("luat_netdrv_mreport %s %d", config, val);
+    if (strcmp(config, "enable") == 0) {
+        if (val == 0) {
+            luat_mreport_stop();
+        }
+        else if (val == 1){
+            luat_mreport_start();
+        }
+        else
+        {
+            LLOGE("luat_netdrv_mreport enable %d error", val);
+        }
+    }
+}
+
+int l_mreport_config(lua_State *L) {
+    char* config = luaL_checkstring(L, 1);
+    int value = lua_toboolean(L, 2);
+    luat_mreport_config(config, value);
+    return 0;
 }
 }

+ 2 - 8
components/network/netdrv/binding/luat_lib_netdrv.c

@@ -338,13 +338,7 @@ netdrv.mreport("custom", {abc=1234})
 -- 清除自定义数据
 -- 清除自定义数据
 netdrv.mreport("custom")
 netdrv.mreport("custom")
 */
 */
-static int l_netdrv_mreport(lua_State *L) {
-    char* config = luaL_checkstring(L, 1);
-    int value = lua_toboolean(L, 2);
-    luat_netdrv_mreport(config, value);
-    return 0;
-}
-
+extern int l_mreport_config(lua_State* L);
 
 
 #include "rotable2.h"
 #include "rotable2.h"
 static const rotable_Reg_t reg_netdrv[] =
 static const rotable_Reg_t reg_netdrv[] =
@@ -360,7 +354,7 @@ static const rotable_Reg_t reg_netdrv[] =
     { "ctrl",           ROREG_FUNC(l_netdrv_ctrl)},
     { "ctrl",           ROREG_FUNC(l_netdrv_ctrl)},
     { "debug",          ROREG_FUNC(l_netdrv_debug)},
     { "debug",          ROREG_FUNC(l_netdrv_debug)},
 #ifdef LUAT_USE_MREPORT
 #ifdef LUAT_USE_MREPORT
-    { "mreport",        ROREG_FUNC(l_netdrv_mreport)},
+    { "mreport",        ROREG_FUNC(l_mreport_config)},
 #endif
 #endif
 
 
     //@const CH390 number 南京沁恒CH390系列,支持CH390D/CH390H, SPI通信
     //@const CH390 number 南京沁恒CH390系列,支持CH390D/CH390H, SPI通信

+ 0 - 16
components/network/netdrv/src/luat_netdrv.c

@@ -318,19 +318,3 @@ void luat_netdrv_netif_set_link_down(struct netif* netif) {
     nd6_cleanup_netif(netif);
     nd6_cleanup_netif(netif);
     #endif /* LWIP_IPV6 */
     #endif /* LWIP_IPV6 */
 }
 }
-
-void luat_netdrv_mreport(const char* config, int val) {
-    LLOGD("luat_netdrv_mreport %s %d", config, val);
-    if (strcmp(config, "enable") == 0) {
-        if (val == 0) {
-            luat_mreport_stop();
-        }
-        else if (val == 1){
-            luat_mreport_start();
-        }
-        else
-        {
-            LLOGE("luat_netdrv_mreport enable %d error", val);
-        }
-    }
-}