Pārlūkot izejas kodu

Merge branch 'master' of https://gitee.com/openLuat/LuatOS

alienwalker 11 mēneši atpakaļ
vecāks
revīzija
4f0289f6b4

+ 27 - 3
components/network/iperf/src/luat_lwiperf.c

@@ -57,6 +57,11 @@
  #include "lwip/opt.h"
  
  #include <string.h>
+ #include "luat_base.h"
+ #include "luat_mem.h"
+
+ #define LUAT_LOG_TAG "lwiperf"
+ #include "luat_log.h"
  
  /* Currently, only TCP is implemented */
  #if LWIP_TCP && LWIP_CALLBACK_API
@@ -73,12 +78,16 @@
  #ifndef LWIPERF_SERVER_IP_TYPE
  #define LWIPERF_SERVER_IP_TYPE      IPADDR_TYPE_ANY
  #endif
+
+static void* iperf_malloc(size_t line, size_t len);
+static void iperf_free(size_t line, void* ptr);
  
  /* File internal memory allocation (struct lwiperf_*): this defaults to
     the heap */
+ #undef LWIPERF_ALLOC
  #ifndef LWIPERF_ALLOC
- #define LWIPERF_ALLOC(type)         mem_malloc(sizeof(type))
- #define LWIPERF_FREE(type, item)    mem_free(item)
+ #define LWIPERF_ALLOC(type)         iperf_malloc(__LINE__, sizeof(type))
+ #define LWIPERF_FREE(type, item)    iperf_free(__LINE__, item)
  #endif
  
  /** If this is 1, check that received data has the correct format */
@@ -386,6 +395,7 @@
      lwiperf_tcp_close(conn, LWIPERF_TCP_ABORTED_REMOTE);
      return ERR_OK;
    }
+   LLOGD("连接成功!!");
    conn->poll_count = 0;
    conn->time_started = sys_now();
    return lwiperf_tcp_client_send_more(conn);
@@ -439,6 +449,7 @@
 
    if (local_ip != NULL) {
     err = tcp_bind(newpcb, local_ip, 0);
+    LLOGD("绑定本地ip ret %d", err);
     if (err != ERR_OK) {
       return err;
     }
@@ -804,7 +815,7 @@
    settings.remote_port = htonl(LWIPERF_TCP_PORT_DEFAULT);
    /* TODO: implement passing duration/amount of bytes to transfer */
    settings.amount = htonl((u32_t)-1000);
- 
+   LLOGD("准备启动iperf客户端");
    ret = lwiperf_tx_start_impl(remote_addr, remote_port, &settings, report_fn, report_arg, NULL, &state, local_addr);
    if (ret == ERR_OK) {
      LWIP_ASSERT("state != NULL", state != NULL);
@@ -857,5 +868,18 @@
      }
    }
  }
+
+static void* iperf_malloc(size_t line, size_t len) {
+  void* ptr = luat_heap_malloc(len);
+  LLOGD("iperf_malloc %d %d 0x%p", line, len, ptr);
+  return ptr;
+}
+static void iperf_free(size_t line, void* ptr) {
+  if (ptr == NULL) {
+    return;
+  }
+  LLOGD("iperf_free %d %p", line, ptr);
+  luat_heap_free(ptr);
+}
  
  #endif /* LWIP_TCP && LWIP_CALLBACK_API */

+ 5 - 4
components/network/netdrv/src/ch390h_task.c

@@ -5,7 +5,7 @@
 #include "luat_netdrv_napt.h"
 #include "luat_ch390h.h"
 #include "luat_malloc.h"
-#include "luat_spi.h"
+// #include "luat_spi.h"
 #include "luat_gpio.h"
 #include "net_lwip2.h"
 #include "luat_ulwip.h"
@@ -210,7 +210,7 @@ static int check_vid_pid(ch390h_t* ch) {
 
 
 static int task_loop_one(ch390h_t* ch, luat_ch390h_cstring_t* cs) {
-    uint8_t buff[16] = {0};
+    uint8_t buff[32] = {0};
     int ret = 0;
     uint16_t len = 0;
     
@@ -233,8 +233,9 @@ static int task_loop_one(ch390h_t* ch, luat_ch390h_cstring_t* cs) {
             }
         }
         luat_ch390h_read_mac(ch, buff + 6);
-        if (memcmp(buff, buff+6, 6)) {
-            LLOGE("读取2次mac地址不匹配!!! %02X%02X%02X%02X%02X%02X", buff[0], buff[1], buff[2], buff[3], buff[4], buff[5]);
+        luat_ch390h_read_mac(ch, buff + 12);
+        if (memcmp(buff, buff+6, 6) || memcmp(buff, buff+12, 6)) {
+            LLOGE("读取3次mac地址不匹配!!! %02X%02X%02X%02X%02X%02X", buff[0], buff[1], buff[2], buff[3], buff[4], buff[5]);
             return 0;
         }
         

+ 1 - 0
components/network/netdrv/src/luat_netdrv.c

@@ -185,6 +185,7 @@ void luat_netdrv_netif_input(void* args) {
     // luat_airlink_hexdump("收到IP数据,注入到netif", ptr->buff, ptr->len);
     int ret = ptr->netif->input(p, ptr->netif);
     if (ret) {
+        LLOGW("netif->input ret %d", ret);
         pbuf_free(p);
     }
     luat_heap_free(ptr);

+ 5 - 1
components/network/netdrv/src/luat_netdrv_napt.c

@@ -30,7 +30,11 @@ int luat_netdrv_gw_adapter_id = -1;
 #define NAPT_ETH_HDR_LEN             sizeof(struct ethhdr)
 #define NAPT_CHKSUM_16BIT_LEN        sizeof(u16)
 
-int luat_netdrv_napt_pkg_input(int id, uint8_t* buff, size_t len) {
+#ifndef __USER_FUNC_IN_RAM__
+#define __USER_FUNC_IN_RAM__ 
+#endif
+
+__USER_FUNC_IN_RAM__ int luat_netdrv_napt_pkg_input(int id, uint8_t* buff, size_t len) {
     if (luat_netdrv_gw_adapter_id < 0) {
         // LLOGD("NAPT 未开启");
         return 0; // NAPT没有开启

+ 13 - 4
script/libs/airlbs.lua

@@ -25,7 +25,10 @@ sys.taskInit(function()
     end
 
 end)
-]] sys = require("sys")
+]] 
+
+
+sys = require("sys")
 sysplus = require("sysplus")
 libnet = require "libnet"
 
@@ -41,9 +44,9 @@ local airlbs_timeout = 15000
 
 local airlbs = {}
 
-local function airlbs_task(task_name, buff, timeout)
+local function airlbs_task(task_name, buff, timeout, adapter)
     local netc = socket.create(nil, lib_name)
-    socket.config(netc, nil, true) -- udp
+    socket.config(netc, adapter, true) -- udp
 
     sysplus.cleanMsg(lib_name)
     local result = libnet.connect(lib_name, 15000, netc, airlbs_host, airlbs_port)
@@ -103,6 +106,12 @@ local result , data = airlbs.request({project_id = airlbs_project_id,project_key
 if result then
     print("airlbs", json.encode(data))
 end
+-- 2025.4.10 新增adapter参数
+local result , data = airlbs.request({
+    project_id = airlbs_project_id,
+    project_key = airlbs_project_key,
+    adapter = socket.LWIP_STA
+})
 ]]
 function airlbs.request(param)
     if not mobile then
@@ -165,7 +174,7 @@ function airlbs.request(param)
     log.info("扫描出的数据",lbs_jdata)
     udp_buff:write(string.char(auth_type) .. project_id .. imei .. muid .. timestamp .. nonce .. hmac_data:fromHex() .. string.char(lbs_data_type) .. lbs_jdata)
 
-    sysplus.taskInitEx(airlbs_task, lib_name, netCB, lib_name, udp_buff, param.timeout or airlbs_timeout)
+    sysplus.taskInitEx(airlbs_task, lib_name, netCB, lib_name, udp_buff, param.timeout or airlbs_timeout, param.adapter)
 
     while 1 do
         local result, tp, data = sys.waitUntil(lib_topic, param.timeout or airlbs_timeout)