From 22e35a70aadbfa67bb0cf37f7c6cc1c26ff4bc23 Mon Sep 17 00:00:00 2001 From: wuzheng Date: Fri, 25 Nov 2022 09:29:37 +0800 Subject: [PATCH] adapt wifi framework and fix 'strncat' problem --- .../Framework/connection/wifi/Makefile | 4 + .../connection/wifi/esp8285_wifi/Kconfig | 6 + .../connection/wifi/esp8285_wifi/Makefile | 5 + .../wifi/esp8285_wifi/esp8285_wifi.c | 106 +++++++++--------- APP_Framework/Framework/sensor/Makefile | 54 --------- 5 files changed, 68 insertions(+), 107 deletions(-) diff --git a/APP_Framework/Framework/connection/wifi/Makefile b/APP_Framework/Framework/connection/wifi/Makefile index cfa6cac9f..5e466adc5 100644 --- a/APP_Framework/Framework/connection/wifi/Makefile +++ b/APP_Framework/Framework/connection/wifi/Makefile @@ -17,5 +17,9 @@ ifeq ($(CONFIG_ADAPTER_ESP07S_WIFI),y) SRC_DIR += esp07s_wifi endif +ifeq ($(CONFIG_ADAPTER_ESP8285_WIFI),y) + SRC_DIR += esp8285_wifi +endif + include $(KERNEL_ROOT)/compiler.mk endif diff --git a/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig index f44e5d47a..6fea4cc6f 100644 --- a/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig +++ b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Kconfig @@ -8,3 +8,9 @@ if ADD_NUTTX_FETURES default "/dev/ttyS1" endif +if ADD_XIZI_FETURES + config ADAPTER_ESP8285_DRIVER + string "ESP8285 device uart driver path" + default "/dev/uart1_dev1" +endif + diff --git a/APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile index c1ee6bd29..0431e2732 100644 --- a/APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile +++ b/APP_Framework/Framework/connection/wifi/esp8285_wifi/Makefile @@ -5,3 +5,8 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) include $(APPDIR)/Application.mk endif + +ifeq ($(CONFIG_ADD_XIZI_FETURES),y) + SRC_FILES := esp8285_wifi.c + include $(KERNEL_ROOT)/compiler.mk +endif \ No newline at end of file diff --git a/APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c b/APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c index f0a3b77c8..3c87225f1 100644 --- a/APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c +++ b/APP_Framework/Framework/connection/wifi/esp8285_wifi/esp8285_wifi.c @@ -205,16 +205,16 @@ static int Esp8285WifiSetUp(struct Adapter *adapter) PrivTaskDelay(2000); /* connect the router */ memset(cmd,0,sizeof(cmd)); - strncpy(cmd,"AT+CWJAP=",strlen("AT+CWJAP=")); - strncat(cmd,"\"",1); - strncat(cmd,param->wifi_ssid,strlen(param->wifi_ssid)); + strcat(cmd,"AT+CWJAP="); + strcat(cmd,"\""); + strcat(cmd,param->wifi_ssid); - strncat(cmd,"\"",1); - strncat(cmd,",",1); - strncat(cmd,"\"",1); - strncat(cmd,param->wifi_pwd,strlen(param->wifi_pwd)); + strcat(cmd,"\""); + strcat(cmd,","); + strcat(cmd,"\""); + strcat(cmd,param->wifi_pwd); - strncat(cmd,"\"",1); + strcat(cmd,"\""); strcat(cmd,"\r\n"); ret = AtCmdConfigAndCheck(agent, cmd, "OK"); @@ -279,17 +279,17 @@ static int Esp8285WifiSetAddr(struct Adapter *adapter, const char *ip, const cha /* e.g. AT+CIPSTA_DEF="192.168.6.100","192.168.6.1","255.255.255.0" */ memset(cmd,0,sizeof(cmd)); strncpy(cmd,"AT+CIPAP_DEF=",strlen(" AT+CIPAP_DEF=")); - strncat(cmd,"\"",1); - strncat(cmd,ip,strlen(ip)); - strncat(cmd,"\"",1); - strncat(cmd,",",1); - strncat(cmd,"\"",1); - strncat(cmd,gateway,strlen(gateway)); - strncat(cmd,"\"",1); - strncat(cmd,",",1); - strncat(cmd,"\"",1); - strncat(cmd,netmask,strlen(netmask)); - strncat(cmd,"\"",1); + strcat(cmd,"\""); + strcat(cmd,ip); + strcat(cmd,"\""); + strcat(cmd,","); + strcat(cmd,"\""); + strcat(cmd,gateway); + strcat(cmd,"\""); + strcat(cmd,","); + strcat(cmd,"\""); + strcat(cmd,netmask); + strcat(cmd,"\""); strcat(cmd,"\r\n"); ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK"); @@ -314,9 +314,9 @@ static int Esp8285WifiPing(struct Adapter *adapter, const char *destination) memset(cmd,0,sizeof(cmd)); strncpy(cmd,"AT+PING=",strlen("AT+PING=")); - strncat(cmd,"\"",1); - strncat(cmd,destination,strlen(destination)); - strncat(cmd,"\"",1); + strcat(cmd,"\""); + strcat(cmd,destination); + strcat(cmd,"\""); strcat(cmd,"\r\n"); ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK"); ///< config as softAP+station mode @@ -387,15 +387,15 @@ static int Esp8285WifiConnect(struct Adapter *adapter, enum NetRoleType net_role { //e.g. AT+CIPSTART="TCP","192.168.3.116",8080 protocol, server IP and port strncpy(cmd,"AT+CIPSTART=",strlen("AT+CIPSTART=")); - strncat(cmd,"\"",1); - strncat(cmd,"TCP",strlen("TCP")); - strncat(cmd,"\"",1); - strncat(cmd, ",", 1); - strncat(cmd,"\"",1); - strncat(cmd, ip, strlen(ip)); - strncat(cmd, "\"", 1); - strncat(cmd, ",", 1); - strncat(cmd, port, strlen(port)); + strcat(cmd,"\""); + strcat(cmd,"TCP"); + strcat(cmd,"\""); + strcat(cmd, ","); + strcat(cmd,"\""); + strcat(cmd, ip); + strcat(cmd, "\""); + strcat(cmd, ","); + strcat(cmd, port); strcat(cmd,"\r\n"); ret = AtCmdConfigAndCheck(agent, cmd, "OK"); @@ -408,19 +408,19 @@ static int Esp8285WifiConnect(struct Adapter *adapter, enum NetRoleType net_role { //e.g. AT+CIPSTART="UDP","192.168.3.116",8080,2233,0 UDP protocol, server IP, port,local port,udp mode strncpy(cmd,"AT+CIPSTART=",strlen("AT+CIPSTART=")); - strncat(cmd,"\"",1); - strncat(cmd,"UDP",strlen("UDP")); - strncat(cmd,"\"",1); - strncat(cmd, ",", 1); - strncat(cmd,"\"",1); - strncat(cmd, ip, strlen(ip)); - strncat(cmd, "\"", 1); - strncat(cmd, ",", 1); - strncat(cmd, port, strlen(port)); - strncat(cmd, ",", 1); - strncat(cmd, "2233", strlen("2233")); ///< local port - strncat(cmd, ",", 1); - strncat(cmd, "0", 1); ///< udp transparent transmission mode must be 0 + strcat(cmd,"\""); + strcat(cmd,"UDP"); + strcat(cmd,"\""); + strcat(cmd, ","); + strcat(cmd,"\""); + strcat(cmd, ip); + strcat(cmd, "\""); + strcat(cmd, ","); + strcat(cmd, port); + strcat(cmd, ","); + strcat(cmd, "2233"); ///< local port + strcat(cmd, ","); + strcat(cmd, "0"); ///< udp transparent transmission mode must be 0 strcat(cmd,"\r\n"); ret = AtCmdConfigAndCheck(agent, cmd, "OK"); @@ -523,15 +523,15 @@ static int Esp8285WifiIoctl(struct Adapter *adapter, int cmd, void *args) itoa(baud_rate, baud_str, 10); strncpy(at_cmd, "AT+UART_DEF=", strlen("AT+UART_DEF=")); - strncat(at_cmd, baud_str, strlen(baud_str)); - strncat(at_cmd, ",", 1); - strncat(at_cmd, "8", 1); - strncat(at_cmd, ",", 1); - strncat(at_cmd, "1", 1); - strncat(at_cmd, ",", 1); - strncat(at_cmd, "0", 1); - strncat(at_cmd, ",", 1); - strncat(at_cmd, "3", 1); + strcat(at_cmd, baud_str); + strcat(at_cmd, ","); + strcat(at_cmd, "8"); + strcat(at_cmd, ","); + strcat(at_cmd, "1"); + strcat(at_cmd, ","); + strcat(at_cmd, "0"); + strcat(at_cmd, ","); + strcat(at_cmd, "3"); strcat(at_cmd,"\r\n"); ret = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK"); diff --git a/APP_Framework/Framework/sensor/Makefile b/APP_Framework/Framework/sensor/Makefile index d278876be..2ac3900a9 100644 --- a/APP_Framework/Framework/sensor/Makefile +++ b/APP_Framework/Framework/sensor/Makefile @@ -65,57 +65,3 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y) include $(KERNEL_ROOT)/compiler.mk endif - -ifeq ($(ADD_XIZI_FETURES),y) - SRC_FILES := sensor.c - - ifeq ($(CONFIG_SENSOR_HCHO),y) - SRC_DIR += hcho - endif - - ifeq ($(CONFIG_SENSOR_TVOC),y) - SRC_DIR += tvoc - endif - - ifeq ($(CONFIG_SENSOR_IAQ),y) - SRC_DIR += iaq - endif - - ifeq ($(CONFIG_SENSOR_CH4),y) - SRC_DIR += ch4 - endif - - ifeq ($(CONFIG_SENSOR_CO2),y) - SRC_DIR += co2 - endif - - ifeq ($(CONFIG_SENSOR_PM),y) - SRC_DIR += pm - endif - - ifeq ($(CONFIG_SENSOR_VOICE),y) - SRC_DIR += voice - endif - - ifeq ($(CONFIG_SENSOR_TEMPERATURE),y) - SRC_DIR += temperature - endif - - ifeq ($(CONFIG_SENSOR_HUMIDITY),y) - SRC_DIR += humidity - endif - - ifeq ($(CONFIG_SENSOR_WINDSPEED),y) - SRC_DIR += windspeed - endif - - ifeq ($(CONFIG_SENSOR_WINDDIRECTION),y) - SRC_DIR += winddirection - endif - - ifeq ($(CONFIG_SENSOR_ALTITUDE),y) - SRC_DIR += altitude - endif - - include $(KERNEL_ROOT)/compiler.mk -endif \ No newline at end of file