Bläddra i källkod

update: 调整libgnss调试开关的实现.

但总感觉是哪里把原本的debug标识给设置为0, 还没找到原因
Wendal Chen 3 år sedan
förälder
incheckning
b9b2fd78a5
2 ändrade filer med 30 tillägg och 28 borttagningar
  1. 26 25
      components/minmea/luat_gnss.c
  2. 4 3
      components/minmea/luat_lib_libgnss.c

+ 26 - 25
components/minmea/luat_gnss.c

@@ -14,6 +14,7 @@ luat_libgnss_t *libgnss_gnss;
 luat_libgnss_tmp_t *libgnss_gnsstmp;
 char *libgnss_recvbuff;
 int libgnss_route_uart_id = -1;
+int gnss_debug = 0;
 
 // static int parse_nmea(const char* line);
 // static int parse_data(const char* data, size_t len);
@@ -32,12 +33,12 @@ void luat_libgnss_uart_recv_cb(int uart_id, uint32_t data_len) {
             luat_uart_write(libgnss_route_uart_id, libgnss_recvbuff, len);
         }
         luat_libgnss_on_rawdata(libgnss_recvbuff, len);
-        //LLOGD("uart recv %d", len);
         libgnss_recvbuff[len] = 0;
         if (libgnss_gnss == NULL)
             continue;
-        if (libgnss_gnss->debug) {
-            // LLOGD(">> %s", libgnss_recvbuff);
+        // LLOGD("uart recv %d %d", len, gnss_debug);
+        if (gnss_debug) {
+            LLOGD(">> %s", libgnss_recvbuff);
         }
         luat_libgnss_parse_data(libgnss_recvbuff, len);
     }
@@ -47,33 +48,33 @@ void luat_libgnss_uart_recv_cb(int uart_id, uint32_t data_len) {
 static uint32_t msg_counter[MINMEA_SENTENCE_MAX_ID];
 
 int luat_libgnss_init(void) {
+    if (libgnss_gnss)
+        return 0;
+    libgnss_gnss = luat_heap_malloc(sizeof(luat_libgnss_t));
     if (libgnss_gnss == NULL) {
-        libgnss_gnss = luat_heap_malloc(sizeof(luat_libgnss_t));
-        if (libgnss_gnss == NULL) {
-            LLOGW("out of memory for libgnss data parse");
-            return 0;
-        }
-        libgnss_gnsstmp = luat_heap_malloc(sizeof(luat_libgnss_tmp_t));
-        if (libgnss_gnsstmp == NULL) {
-            luat_heap_free(libgnss_gnss);
-            LLOGW("out of memory for libgnss data parse");
-            return 0;
-        }
-        // gnss->lua_ref = luaL_ref(L, LUA_REGISTRYINDEX);
-        memset(libgnss_gnss, 0, sizeof(luat_libgnss_t));
-        memset(libgnss_gnsstmp, 0, sizeof(luat_libgnss_tmp_t));
+        LLOGW("out of memory for libgnss data parse");
+        return -1;
+    }
+    libgnss_gnsstmp = luat_heap_malloc(sizeof(luat_libgnss_tmp_t));
+    if (libgnss_gnsstmp == NULL) {
+        luat_heap_free(libgnss_gnss);
+        LLOGW("out of memory for libgnss data parse");
+        return -1;
     }
+    // gnss->lua_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+    memset(libgnss_gnss, 0, sizeof(luat_libgnss_t));
+    memset(libgnss_gnsstmp, 0, sizeof(luat_libgnss_tmp_t));
     //lua_pushboolean(L, 1);
-    return 1;
+    return 0;
 }
 
 int luat_libgnss_parse_data(const char* data, size_t len) {
     size_t prev = 0;
     #define MAX_LEN (120)
     static char nmea_tmp_buff[MAX_LEN] = {0}; // nmea 最大长度82,含换行符
-    if (data[0] == 0xAA && data[1] == 0xF0) {
-        LLOGD("EPH data resp?");
-    }
+    // if (data[0] == 0xAA && data[1] == 0xF0) {
+    //     LLOGD("EPH data resp?");
+    // }
 
     for (size_t offset = 0; offset < len; offset++)
     {
@@ -89,9 +90,9 @@ int luat_libgnss_parse_data(const char* data, size_t len) {
             if (offset - prev - 1 < MAX_LEN) {
                 memcpy(nmea_tmp_buff, data + prev, offset - prev - 1);
                 nmea_tmp_buff[offset - prev - 1] = 0x00;
-                if (libgnss_gnss->debug) {
-                    LLOGD(">> %s", nmea_tmp_buff);
-                }
+                // if (gnss_debug) {
+                //     LLOGD(">> %s", nmea_tmp_buff);
+                // }
                 luat_libgnss_parse_nmea((const char*)nmea_tmp_buff);
             }
             else {
@@ -104,7 +105,7 @@ int luat_libgnss_parse_data(const char* data, size_t len) {
 }
 
 int luat_libgnss_parse_nmea(const char* line) {
-    if (libgnss_gnss == NULL && !luat_libgnss_init()) {
+    if (libgnss_gnss == NULL && luat_libgnss_init()) {
         return 0;
     }
     struct minmea_sentence_gsv *frame_gsv = &libgnss_gnsstmp->frame_gsv;

+ 4 - 3
components/minmea/luat_lib_libgnss.c

@@ -50,6 +50,7 @@ extern luat_libgnss_t *libgnss_gnss;
 // extern luat_libgnss_t *libgnss_gnsstmp;
 extern char* libgnss_recvbuff;
 extern int libgnss_route_uart_id;
+extern int gnss_debug;
 
 void luat_uart_set_app_recv(int id, luat_uart_recv_callback_t cb);
 
@@ -584,12 +585,12 @@ static int l_libgnss_debug(lua_State *L) {
     }
     if (lua_isboolean(L, 1) && lua_toboolean(L, 1)) {
         LLOGD("Debug ON");
-        libgnss_gnss->debug = 1;
+        gnss_debug = 1;
     }
     else
     {
         LLOGD("Debug OFF");
-        libgnss_gnss->debug = 0;
+        gnss_debug = 0;
     }
 
     return 0;
@@ -745,7 +746,7 @@ static int l_libgnss_get_gll(lua_State* L) {
  */
 static int l_libgnss_clear(lua_State*L) {
     (void)L;
-    if (libgnss_gnss == NULL && !luat_libgnss_init())
+    if (libgnss_gnss == NULL && luat_libgnss_init())
         return 0;
     memset(libgnss_gnss, 0, sizeof(luat_libgnss_t));
     return 0;