Pārlūkot izejas kodu

add: libgnss支持获取原始RMC语句

Wendal Chen 1 gadu atpakaļ
vecāks
revīzija
a46b41eb9c
2 mainītis faili ar 45 papildinājumiem un 12 dzēšanām
  1. 4 2
      components/minmea/luat_gnss.c
  2. 41 10
      components/minmea/luat_lib_libgnss.c

+ 4 - 2
components/minmea/luat_gnss.c

@@ -101,6 +101,7 @@ int luat_libgnss_parse_nmea(const char* line) {
     switch (id) {
         case MINMEA_SENTENCE_RMC: {
             if (minmea_parse_rmc(frame_rmc, line)) {
+                copynmea(&gnssctx.rmc, line);
                 if (frame_rmc->valid) {
                     memcpy(&(gnssctx.frame_rmc), frame_rmc, sizeof(struct minmea_sentence_rmc));
                     #ifdef LUAT_USE_MCU
@@ -205,9 +206,10 @@ int luat_libgnss_parse_nmea(const char* line) {
             copynmea(&gnssctx.txt, line);
             break;
         }
-        default:
-            //LLOGD("why happen");
+        default: {
+            luat_libgnss_on_rawdata(line, strlen(line), 2);
             break;
+        }
     }
     return 0;
 }

+ 41 - 10
components/minmea/luat_lib_libgnss.c

@@ -62,6 +62,11 @@ extern char* libgnss_recvbuff;
 extern int libgnss_route_uart_id;
 extern int gnss_debug;
 
+static int gnss_raw_cb = 0;
+static int gnss_txt_cb = 0;
+// static int gnss_rmc_cb = 0;
+static int gnss_other_cb = 0;
+
 void luat_uart_set_app_recv(int id, luat_uart_recv_callback_t cb);
 
 static inline void push_gnss_value(lua_State *L, struct minmea_float *f, int mode) {
@@ -285,7 +290,7 @@ static int l_libgnss_get_int_location(lua_State *L) {
 /**
 获取原始RMC位置信息
 @api libgnss.getRmc(data_mode)
-@int 坐标类数据的格式, 0-DDMM.MMM格式, 1-DDDDDDD格式, 2-DD.DDDDD格式
+@int 坐标类数据的格式, 0-DDMM.MMM格式, 1-DDDDDDD格式, 2-DD.DDDDD格式, 3-原始RMC字符串
 @return table 原始rmc数据
 @usage
 -- 解析nmea
@@ -315,6 +320,13 @@ static int l_libgnss_get_rmc(lua_State *L) {
 
     struct tm rtime = {0};
 
+    if (mode == 3) {
+        if (gnssctx.rmc == NULL)
+            return 0;
+        lua_pushstring(L, gnssctx.rmc->data);
+        return 1;
+    }
+
     if (1) {
         lua_pushboolean(L, gnssctx.frame_rmc.valid);
         lua_setfield(L, -2, "valid");
@@ -987,11 +999,6 @@ static int l_libgnss_rtc_auto(lua_State *L) {
     return 0;
 }
 
-//临时处理, 当前GNSS处理均在lua线程
-// static lua_State *gnss_L;
-static int gnss_raw_cb = 0;
-static int gnss_txt_cb = 0;
-
 static int l_libgnss_data_cb(lua_State *L, void* ptr) {
     rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
     // lua_getglobal(L, "sys_pub");
@@ -1010,9 +1017,23 @@ static int l_libgnss_data_cb(lua_State *L, void* ptr) {
 }
 
 int luat_libgnss_on_rawdata(const char* data, size_t len, int type) {
-    if (gnss_raw_cb == 0 && type == 0)
-        return 0;
-    if (gnss_txt_cb == 0 && type == 1) {
+    int cb = 0;
+    if (type == 0) {
+        if (gnss_raw_cb == 0)
+            return 0;
+        cb = gnss_raw_cb;
+    }
+    else if (type == 1) {
+        if (gnss_txt_cb == 0)
+            return 0;
+        cb = gnss_txt_cb;
+    }
+    else if (type == 2) {
+        if (gnss_other_cb == 0)
+            return 0;
+        cb = gnss_other_cb;
+    }
+    else {
         return 0;
     }
     char* ptr = luat_heap_malloc(len);
@@ -1022,7 +1043,7 @@ int luat_libgnss_on_rawdata(const char* data, size_t len, int type) {
     rtos_msg_t msg = {
         .handler = l_libgnss_data_cb,
         .arg1 = len,
-        .arg2 = type == 1 ? gnss_txt_cb : gnss_raw_cb,
+        .arg2 = cb,
         .ptr = ptr
     };
     luat_msgbus_put(&msg, 0);
@@ -1062,6 +1083,16 @@ static int l_libgnss_on(lua_State *L) {
             gnss_txt_cb = luaL_ref(L, LUA_REGISTRYINDEX);
         }
     }
+    else if (!strcmp("other", tp)) {
+        if (gnss_other_cb != 0) {
+            luaL_unref(L, LUA_REGISTRYINDEX, gnss_other_cb);
+            gnss_other_cb = 0;
+        }
+        if (lua_isfunction(L, 2)) {
+            lua_pushvalue(L, 2);
+            gnss_other_cb = luaL_ref(L, LUA_REGISTRYINDEX);
+        }
+    }
     return 0;
 }