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

fix: https://github.com/openLuat/LuatOS/issues/47

Wendal Chen 5 лет назад
Родитель
Сommit
539bc64bd9
2 измененных файлов с 34 добавлено и 2 удалено
  1. 33 0
      bsp/air640w/rtt/applications/luat_init_w60x.c
  2. 1 2
      luat/rtt/luat_lib_wlan.c

+ 33 - 0
bsp/air640w/rtt/applications/luat_init_w60x.c

@@ -3,6 +3,7 @@
 #include "luat_msgbus.h"
 #include "luat_timer.h"
 #include "luat_gpio.h"
+#include "luat_fs.h"
 
 #include "rtthread.h"
 #include <rtdevice.h>
@@ -16,6 +17,36 @@
 #include <rtdbg.h>
 
 #ifdef BSP_USING_WM_LIBRARIES
+
+static int w60x_read_cfg(void *buff, int len) {
+  int fd = luat_fs_fopen("/wlan.cfg", "rb");
+  if (fd) {
+    luat_fs_fread(buff, 1, len, fd);
+    luat_fs_fclose(fd);
+    return len;
+  }
+  return 0;
+};
+static int w60x_get_len(void) {
+  return luat_fs_fsize("/wlan.cfg");
+};
+static int w60x_write_cfg(void *buff, int len) {
+  int fd = luat_fs_fopen("/wlan.cfg", "w");
+  if (fd) {
+    luat_fs_fwrite(buff, 1, len, fd);
+    luat_fs_fclose(fd);
+    return len;
+  }
+  return 0;
+};
+
+static struct rt_wlan_cfg_ops cfg_ops = {
+  w60x_read_cfg,
+  w60x_get_len,
+  w60x_write_cfg
+};
+
+
 static rt_err_t w600_bt(void *context) {
   rt_kprintf("\r\nFUCK!!\r\n");
   return 0;
@@ -23,6 +54,8 @@ static rt_err_t w600_bt(void *context) {
 static int rtt_w60x_init() {
   #ifdef RT_USING_WIFI
   rt_wlan_set_mode("wlan0", RT_WLAN_STATION);
+  rt_wlan_cfg_set_ops(&cfg_ops);
+  rt_wlan_cfg_cache_refresh();
   #endif
   rt_hw_exception_install(w600_bt);
   return RT_EOK;

+ 1 - 2
luat/rtt/luat_lib_wlan.c

@@ -101,6 +101,7 @@ static join_info_t jinfo = {0};
 
 
 static void _wlan_connect(void* params) {
+    rt_wlan_config_autoreconnect(1);
     rt_wlan_connect(jinfo.ssid, jinfo.passwd);
 }
 
@@ -143,8 +144,6 @@ static int l_wlan_connect(lua_State *L) {
     }
     // 自动重连
     
-    rt_wlan_config_autoreconnect(1);
-    
     return 0;
 }