Sfoglia il codice sorgente

add: airlink,添加实现wlan.setMac 写入mac地址

??? 10 mesi fa
parent
commit
4add5bdf36

+ 21 - 1
components/airlink/src/driver/luat_airlink_drv_wlan.c

@@ -138,7 +138,27 @@ int luat_airlink_drv_wlan_smartconfig_stop(void);
 
 // 数据类
 int luat_airlink_drv_wlan_get_mac(int id, char* mac);
-int luat_airlink_drv_wlan_set_mac(int id, const char* mac);
+
+int luat_airlink_drv_wlan_set_mac(int id, const char* mac)
+{
+    uint8_t c_id = id;
+    
+    uint64_t luat_airlink_next_cmd_id = luat_airlink_get_next_cmd_id();
+    airlink_queue_item_t item = {
+        .len = sizeof(luat_airlink_cmd_t) + 8 + 6
+    };
+    luat_airlink_cmd_t* cmd = luat_airlink_cmd_new(0x207, item.len) ;
+    if (cmd == NULL) {
+        return -101;
+    }
+    // LLOGE("未传递之前 id = %d, mac = %02X%02X%02X%02X%02X%02X", c_id, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+    memcpy(cmd->data, &luat_airlink_next_cmd_id, 8);
+    memcpy(cmd->data + 8, &c_id, 1);
+    memcpy(cmd->data + 9, mac, 6);
+    item.cmd = cmd;
+    luat_airlink_queue_send(LUAT_AIRLINK_QUEUE_CMD, &item);
+    return 0;
+}
 
 int luat_airlink_drv_wlan_get_ip(int type, char* data);
 

+ 12 - 1
components/airlink/src/exec/luat_airlink_cmd_exec_wlan.c

@@ -90,4 +90,15 @@ int luat_airlink_cmd_exec_wlan_scan_result_cb(luat_airlink_cmd_t* cmd, void* use
     msg.handler = scan_result_handler;
     luat_msgbus_put(&msg, 0);
     return 0;
-}
+}
+
+int luat_airlink_cmd_exec_wlan_set_mac(luat_airlink_cmd_t* cmd, void* userdata) {
+
+    uint8_t id = cmd->data[8];
+    uint8_t mac[6] = {0};
+    memcpy(mac, cmd->data + 9, 6);
+    // LLOGE("luat_airlink_cmd_exec_wlan_set_mac id: %d", (int)id);
+    // LLOGE("luat_airlink_cmd_exec_wlan_set_mac mac: %02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+    int ret = luat_wlan_set_mac((int)id, (char*)mac);
+    return ret;
+}

+ 2 - 0
components/airlink/src/luat_airlink_cmds.c

@@ -46,6 +46,7 @@ CMD_DEFINE(wlan_ap_start);
 CMD_DEFINE(wlan_ap_stop);
 CMD_DEFINE(wlan_scan);
 CMD_DEFINE(wlan_scan_result_cb);
+CMD_DEFINE(wlan_set_mac);
 
 // GPIO指令, 0x300开始
 CMD_DEFINE(gpio_setup);
@@ -88,6 +89,7 @@ __USER_FUNC_IN_RAM__ const luat_airlink_cmd_reg_t airlink_cmds[] = {
     CMD_REG(0x203, wlan_ap_start),
     CMD_REG(0x204, wlan_ap_stop),
     CMD_REG(0x205, wlan_scan),
+    CMD_REG(0x207, wlan_set_mac),
 #else
     CMD_REG(0x206, wlan_scan_result_cb),
 #endif

+ 1 - 1
components/drv/src/luat_drv_wlan.c

@@ -59,7 +59,7 @@ int luat_drv_wlan_get_mac(int id, char* mac) {
     return 0;
 }
 int luat_drv_wlan_set_mac(int id, const char* mac) {
-    return 0;
+    return luat_airlink_drv_wlan_set_mac(id, mac);
 }
 
 int luat_drv_wlan_get_ip(int type, char* data) {

+ 17 - 2
components/wlan/luat_lib_wlan.c

@@ -333,9 +333,24 @@ local mac = string.fromHex("000000000000")
 wlan.setMac(0, mac)
 */
 static int l_wlan_set_mac(lua_State* L){
-    // int id = luaL_optinteger(L, 1, 0);
+    int id = luaL_optinteger(L, 1, 0);
     const char* mac = luaL_checkstring(L, 2);
-    int ret = luat_wlan_set_mac(luaL_optinteger(L, 1, 0), mac);
+#ifdef LUAT_USE_DRV_WLAN
+    if (id == 2)
+        id = 0;
+    else if (id == 3)
+        id = 1;
+    else
+    {
+        LLOGE("mac parm id error %d", id);
+        return 0;
+    }
+    int ret = luat_drv_wlan_set_mac(id, mac);
+    // LLOGD("l_wlan_set_mac %02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+    // LLOGD("set mac result %d", ret);
+#else
+    int ret = luat_wlan_set_mac(id, mac);
+#endif
     lua_pushboolean(L, ret == 0 ? 1 : 0);
     return 1;
 }