ソースを参照

fix: 修复编译报错, socket相关的新代码先用宏隔离起来

Wendal Chen 3 年 前
コミット
4d40614c93

+ 9 - 9
luatos/components/luat/CMakeLists.txt

@@ -65,11 +65,11 @@ idf_component_register(SRC_DIRS ${LUATOS_ROOT}/luat/modules
                                 ${LUATOS_ROOT}/components/lora/sx126x
                                 ${LUATOS_ROOT}/components/network/httpsrv/src
                                 ${LUATOS_ROOT}/components/rsa/binding
-                                // ${LUATOS_ROOT}/components/network/adapter
-                                // ${LUATOS_ROOT}/components/ethernet/common
-                                // ${LUATOS_ROOT}/components/common
-                                // ${LUATOS_ROOT}/components/rtos/freertos
-                                // ${LUATOS_ROOT}/components/network/posix
+                                # ${LUATOS_ROOT}/components/network/adapter
+                                # ${LUATOS_ROOT}/components/ethernet/common
+                                # ${LUATOS_ROOT}/components/common
+                                # ${LUATOS_ROOT}/components/rtos/freertos
+                                # ${LUATOS_ROOT}/components/network/posix
                     EXCLUDE_SRCS
                                 ${LUATOS_ROOT}/luat/modules/luat_lib_http.c
                     INCLUDE_DIRS ../../include
@@ -115,10 +115,10 @@ idf_component_register(SRC_DIRS ${LUATOS_ROOT}/luat/modules
                                 ${LUATOS_ROOT}/components/lora/sx126x
                                 ${LUATOS_ROOT}/components/network/httpsrv/inc
                                 ${LUATOS_ROOT}/components/nimble/inc
-                                // ${LUATOS_ROOT}/components/network/adapter
-                                // ${LUATOS_ROOT}/components/ethernet/common
-                                // ${LUATOS_ROOT}/components/common
-                                // ${LUATOS_ROOT}/components/network/posix
+                                # ${LUATOS_ROOT}/components/network/adapter
+                                # ${LUATOS_ROOT}/components/ethernet/common
+                                # ${LUATOS_ROOT}/components/common
+                                # ${LUATOS_ROOT}/components/network/posix
                     REQUIRES esp-tls lwip esp_http_client mbedtls spiffs driver heap esp_netif esp_event
                              esp_wifi esp_rom http_parser mqtt esp_adc bt console spi_flash
                     )

+ 4 - 0
luatos/components/luat/port/luat_base_idf5.c

@@ -197,6 +197,10 @@ static const luaL_Reg loadedlibs[] = {
   {"http", luaopen_http},
   {"mqtt", luaopen_mqtt},
 #endif
+
+#ifdef LUAT_USE_NETWORK
+  {"socket", luaopen_socket_adapter},
+#endif
 #ifdef LUAT_USE_HTTPSRV
   {"httpsrv", luaopen_httpsrv},
 #endif

+ 22 - 0
luatos/components/luat/port/luat_network_idf5.c

@@ -0,0 +1,22 @@
+#include "luat_base.h"
+
+#ifdef LUAT_USE_NETWORK
+#include "luat_network_posix.h"
+
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
+static void client_entry(void* args) {
+    posix_socket_t *ps = (posix_socket_t*)args;
+    posix_network_client_thread_entry(ps);
+    vTaskDelete(NULL);
+}
+
+int network_posix_client_thread_start(posix_socket_t* ps){
+    int err = xTaskCreate(client_entry, "socket", 4096, ps, 30, NULL);
+    if (err == pdPASS)
+        return 0;
+    return -1;
+}
+
+#endif

+ 8 - 0
luatos/components/luat/port/luat_wlan_idf5.c

@@ -15,6 +15,8 @@
 #define LUAT_LOG_TAG "wlan"
 #include "luat_log.h"
 
+void posix_network_set_ready(uint8_t ready);
+
 static uint8_t wlan_inited = 0;
 static uint8_t wlan_is_ready = 0;
 
@@ -161,6 +163,9 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base,
     LLOGD("wifi event %d", event_id);
     if (event_id == WIFI_EVENT_STA_DISCONNECTED) {
         wlan_is_ready = 0;
+#ifdef LUAT_USE_NETWORK
+        posix_network_set_ready(0);
+#endif
         wifi_event_sta_disconnected_t* sta = (wifi_event_sta_disconnected_t*)event_data;
         memset(sta_connected_bssid, 0, sizeof(sta_connected_bssid));
     }
@@ -182,6 +187,9 @@ static void ip_event_handler(void *arg, esp_event_base_t event_base,
     LLOGD("ip event %d", event_id);
     if (event_id == IP_EVENT_STA_GOT_IP) {
         wlan_is_ready = 1;
+#ifdef LUAT_USE_NETWORK
+        posix_network_set_ready(1);
+#endif
         event = (ip_event_got_ip_t*)event_data;
         sprintf(sta_ip, IPSTR, IP2STR(&event->ip_info.ip));
         sprintf(sta_gw, IPSTR, IP2STR(&event->ip_info.gw));

+ 3 - 0
luatos/include/luat_conf_bsp.h

@@ -91,6 +91,9 @@
 
 #define LUAT_USE_RSA 1
 
+// ------------------
+//#define LUAT_USE_NETWORK 1
+
 //---------------------
 // UI
 // LCD  是彩屏, 若使用LVGL就必须启用LCD

+ 8 - 0
luatos/main/idf5_main.c

@@ -32,6 +32,11 @@ static void luat_lvgl_callback(TimerHandle_t xTimer){
 }
 #endif
 
+#ifdef LUAT_USE_NETWORK
+#include "luat_network_adapter.h"
+extern network_adapter_info network_posix;
+#endif
+
 void app_main(void){
 #ifdef LUAT_USE_SHELL
     extern void luat_shell_poweron(int _drv);
@@ -54,6 +59,9 @@ void app_main(void){
     lv_init();
     TimerHandle_t os_timer = xTimerCreate("lvgl_timer", 10 / portTICK_PERIOD_MS, true, NULL, luat_lvgl_callback);
     xTimerStart(os_timer, 0);
+#endif
+#ifdef LUAT_USE_NETWORK
+    network_register_adapter(0, &network_posix, NULL);
 #endif
     luat_main();
 }