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

【修复】1.更改内存扫描函数 2.一些头文件名兼容问题 3.添加 wifi 扫描函数代码

shihao.zhao 2 лет назад
Родитель
Сommit
db13680ded
4 измененных файлов с 90 добавлено и 3 удалено
  1. 2 2
      port/modules/machine/modmachine.c
  2. 84 0
      port/modules/modnetwork_wlan.c
  3. 1 0
      port/modules/modusocket.c
  4. 3 1
      port/mpy_main.c

+ 2 - 2
port/modules/machine/modmachine.c

@@ -60,13 +60,13 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) {
         mp_printf(&mp_plat_print, "---------------------------------------------\n");
 
 #ifdef RT_USING_FINSH
-        extern void list_mem(void);
+        extern void cmd_free(void);
         extern void list_memheap(void);
 
 #ifdef RT_USING_MEMHEAP_AS_HEAP
         list_memheap();
 #else
-        list_mem();
+        cmd_free();
 #endif
 
         list_thread();

+ 84 - 0
port/modules/modnetwork_wlan.c

@@ -34,6 +34,7 @@
 #include "lib/netutils/netutils.h"
 
 #if MICROPY_PY_WLAN
+#include <rtdbg.h>
 #include <rtthread.h>
 #include <wlan_mgnt.h>
 #include <wlan_cfg.h>
@@ -207,6 +208,89 @@ STATIC mp_obj_t wlan_status(size_t n_args, const mp_obj_t *args) {
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_status_obj, 1, 2, wlan_status);
 
+#if (RTTHREAD_VERSION >= RT_VERSION_CHECK(4, 1, 0)) && defined(RT_USING_WIFI)
+#include <wlan_mgnt.h>
+#include <wlan_prot.h>
+#include <wlan_cfg.h>
+
+static struct rt_semaphore scan_done;
+struct rt_wlan_scan_result *scan_result_cache = RT_NULL;
+
+static void wlan_scan_report_hander(int event,struct rt_wlan_buff *buff,void *parameter)
+{
+    struct rt_wlan_info *info = RT_NULL;
+    int index = 0;
+    int ret = RT_EOK;
+    RT_ASSERT(event == RT_WLAN_EVT_SCAN_REPORT);
+    RT_ASSERT(buff != RT_NULL);
+    RT_ASSERT(parameter != RT_NULL);
+
+    info = (struct rt_wlan_info *)buff->data;
+    index = *((int *)(parameter));
+    if (scan_result_cache == RT_NULL)
+    {
+        RT_ASSERT(index == 0);
+        scan_result_cache = rt_malloc(sizeof(struct rt_wlan_scan_result) + (rt_ubase_t)sizeof(struct rt_wlan_info));
+        scan_result_cache->num = 0;
+        scan_result_cache->info = (struct rt_wlan_info *)(rt_ubase_t)((rt_ubase_t)&scan_result_cache->info + sizeof(struct rt_wlan_info *));
+    }
+    else
+    {
+        scan_result_cache = rt_realloc(scan_result_cache, sizeof(struct rt_wlan_scan_result) +
+                              (uint32_t)sizeof(struct rt_wlan_info) * (index + 1));
+        scan_result_cache->info = (struct rt_wlan_info *)(rt_ubase_t)((rt_ubase_t)&scan_result_cache->info + sizeof(struct rt_wlan_info *));
+    }
+    if (scan_result_cache == RT_NULL)
+    {
+        LOG_E("malloc failed!");
+    }
+    rt_memcpy(&(scan_result_cache->info)[index], info, sizeof(struct rt_wlan_info));
+    scan_result_cache->num = index + 1;
+    ++ *((int *)(parameter));
+}
+
+static void wlan_scan_done_hander(int event,struct rt_wlan_buff *buff,void *parameter)
+{
+    RT_ASSERT(event == RT_WLAN_EVT_SCAN_DONE);
+    rt_sem_release(&scan_done);
+}
+
+struct rt_wlan_scan_result *rt_wlan_scan_sync(void)
+{
+    static int _init = 0;
+    static int i = 0;
+
+    LOG_D("start to scan ap ...");
+    if (!_init)
+    {
+        _init = 1;
+        rt_sem_init(&scan_done, "scan_done", 0 , RT_IPC_FLAG_FIFO);
+    }
+    rt_wlan_register_event_handler(RT_WLAN_EVT_SCAN_REPORT, wlan_scan_report_hander,&i);
+    rt_wlan_register_event_handler(RT_WLAN_EVT_SCAN_DONE, wlan_scan_done_hander,RT_NULL);
+    if(rt_wlan_scan() == RT_EOK)
+    {
+        LOG_D("the scan is started... ");
+    }
+    else
+    {
+        LOG_E("scan failed");
+    }
+    rt_sem_take(&scan_done, RT_WAITING_FOREVER);
+    i = 0;
+    return scan_result_cache;
+}
+
+void rt_wlan_scan_result_clean(void)
+{
+    if(scan_result_cache)
+    {
+        rt_free(scan_result_cache);
+        scan_result_cache = 0;
+    }
+}
+#endif
+
 STATIC mp_obj_t *wlan_scan_list = NULL;
 
 void wlan_station_scan(void)

+ 1 - 0
port/modules/modusocket.c

@@ -36,6 +36,7 @@
 #include <fcntl.h>
 #include <sys/time.h>
 #include <sys/select.h>
+#include <errno.h>
 
 #include "py/objtuple.h"
 #include "py/objlist.h"

+ 3 - 1
port/mpy_main.c

@@ -29,7 +29,9 @@
 #include <string.h>
 #include <rtthread.h>
 #ifdef RT_USING_DFS
-#include <dfs_posix.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <dfs.h>
 #endif
 #include <py/compile.h>
 #include <py/runtime.h>