Przeglądaj źródła

fix: libgnss,执行bind操作后无法拿到数据,原因是l_uart_handler函数缺了个取反操作,导致回调函数没有执行

Wendal Chen 9 miesięcy temu
rodzic
commit
e126288ae3

+ 4 - 0
components/minmea/luat_gnss.c

@@ -34,7 +34,11 @@ void luat_libgnss_uart_recv_cb(int uart_id, uint32_t data_len) {
         if (len < 1 || len >= RECV_BUFF_SIZE)
             break;
         if (libgnss_route_uart_id > 0) {
+            #ifdef LUAT_USE_DRV_UART
+            luat_drv_uart_write(libgnss_route_uart_id, libgnss_recvbuff, len);
+            #else
             luat_uart_write(libgnss_route_uart_id, libgnss_recvbuff, len);
+            #endif
         }
         luat_libgnss_on_rawdata(libgnss_recvbuff, len, 0);
         libgnss_recvbuff[len] = 0;

+ 7 - 1
components/minmea/luat_lib_libgnss.c

@@ -942,13 +942,19 @@ libgnss.bind(2, uart.VUART_0)
 */
 static int l_libgnss_bind(lua_State* L) {
     int uart_id = luaL_checkinteger(L, 1);
+    int next_uart_id = 0;
     l_libgnss_clear(L);
     if (libgnss_recvbuff == NULL) {
         libgnss_recvbuff = luat_heap_malloc(RECV_BUFF_SIZE);
     }
     luat_uart_set_app_recv(uart_id, l_libgnss_uart_recv_cb);
     if (lua_isinteger(L, 2)) {
-        libgnss_route_uart_id = luaL_checkinteger(L, 2);
+        next_uart_id = luaL_checkinteger(L, 2);
+        if (uart_id == libgnss_route_uart_id) {
+            LLOGW("id == next_id , is NOT allow. %d", uart_id);
+            return 0;
+        }
+        libgnss_route_uart_id = next_uart_id;
     }
     return 0;
 }

+ 6 - 2
luat/modules/luat_lib_uart.c

@@ -340,6 +340,9 @@ void luat_uart_set_app_recv(int id, luat_uart_recv_callback_t cb) {
         luat_setup_cb(id, 1, 0); // 暂时覆盖
 		#endif
     }
+	else {
+		LLOGW("not exist uart id=%d", id);
+	}
 }
 
 int l_uart_handler(lua_State *L, void* ptr) {
@@ -349,10 +352,11 @@ int l_uart_handler(lua_State *L, void* ptr) {
     int uart_id = msg->arg1;
     // LLOGD("l_uart_handler %d", uart_id);
 	#ifdef LUAT_USE_DRV_UART
-	if (luat_drv_uart_exist(uart_id)) {
+	if (!luat_drv_uart_exist(uart_id))
 	#else
-    if (!luat_uart_exist(uart_id)) {
+    if (!luat_uart_exist(uart_id))
 	#endif
+	{
         //LLOGW("not exist uart id=%ld but event fired?!", uart_id);
         return 0;
     }