forked from xuos/xiuos
				
			Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into xidatong
This commit is contained in:
		
						commit
						63d26584b7
					
				|  | @ -33,7 +33,7 @@ | ||||||
| #define AT_CMD_MAX_LEN 128 | #define AT_CMD_MAX_LEN 128 | ||||||
| #define AT_AGENT_MAX 2 | #define AT_AGENT_MAX 2 | ||||||
| static char send_buf[AT_CMD_MAX_LEN]; | static char send_buf[AT_CMD_MAX_LEN]; | ||||||
| static uint32 last_cmd_len = 0; | static uint32_t last_cmd_len = 0; | ||||||
| 
 | 
 | ||||||
| static struct ATAgent at_agent_table[AT_AGENT_MAX] = {0}; | static struct ATAgent at_agent_table[AT_AGENT_MAX] = {0}; | ||||||
| 
 | 
 | ||||||
|  | @ -126,7 +126,7 @@ void ATSprintf(int fd, const char *format, va_list params) | ||||||
| 	PrivWrite(fd, send_buf, last_cmd_len); | 	PrivWrite(fd, send_buf, last_cmd_len); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...) | int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const char *cmd_expr, ...) | ||||||
| { | { | ||||||
|     if (agent == NULL) { |     if (agent == NULL) { | ||||||
|         printf("ATAgent is null"); |         printf("ATAgent is null"); | ||||||
|  | @ -147,8 +147,8 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch | ||||||
|     agent->entm_recv_len = 0; |     agent->entm_recv_len = 0; | ||||||
| 
 | 
 | ||||||
|     va_list params; |     va_list params; | ||||||
|     uint32 cmd_size = 0; |     uint32_t cmd_size = 0; | ||||||
|     uint32 result = 0; |     uint32_t result = 0; | ||||||
|     const char *cmd = NULL; |     const char *cmd = NULL; | ||||||
| 
 | 
 | ||||||
|     agent->reply = reply; |     agent->reply = reply; | ||||||
|  | @ -317,7 +317,7 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s) | ||||||
| 
 | 
 | ||||||
| static int GetCompleteATReply(ATAgentType agent) | static int GetCompleteATReply(ATAgentType agent) | ||||||
| { | { | ||||||
|     uint32 read_len = 0; |     uint32_t read_len = 0; | ||||||
|     char ch = 0, last_ch = 0; |     char ch = 0, last_ch = 0; | ||||||
|     bool is_full = false; |     bool is_full = false; | ||||||
| 
 | 
 | ||||||
|  | @ -335,7 +335,9 @@ static int GetCompleteATReply(ATAgentType agent) | ||||||
|     { |     { | ||||||
|         PrivRead(agent->fd, &ch, 1); |         PrivRead(agent->fd, &ch, 1); | ||||||
| #ifdef CONNECTION_FRAMEWORK_DEBUG | #ifdef CONNECTION_FRAMEWORK_DEBUG | ||||||
|  |         if(ch != 0){ | ||||||
|             printf(" %c (0x%x)\n", ch, ch); |             printf(" %c (0x%x)\n", ch, ch); | ||||||
|  |         } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|         PrivMutexObtain(&agent->lock); |         PrivMutexObtain(&agent->lock); | ||||||
|  | @ -364,10 +366,14 @@ static int GetCompleteATReply(ATAgentType agent) | ||||||
|         else if (agent->receive_mode == AT_MODE)  |         else if (agent->receive_mode == AT_MODE)  | ||||||
|         { |         { | ||||||
|             if (read_len < agent->maintain_max) |             if (read_len < agent->maintain_max) | ||||||
|  |             { | ||||||
|  |                 if(ch != 0) ///< if the char is null then do not save it to the buff
 | ||||||
|                 { |                 { | ||||||
|                     agent->maintain_buffer[read_len] = ch; |                     agent->maintain_buffer[read_len] = ch; | ||||||
|                     read_len++; |                     read_len++; | ||||||
|                     agent->maintain_len = read_len; |                     agent->maintain_len = read_len; | ||||||
|  |                 } | ||||||
|  |                  | ||||||
|             } else { |             } else { | ||||||
|                 printf("maintain_len is_full ...\n"); |                 printf("maintain_len is_full ...\n"); | ||||||
|                 is_full = true; |                 is_full = true; | ||||||
|  | @ -516,7 +522,7 @@ static int ATAgentInit(ATAgentType agent) | ||||||
| 
 | 
 | ||||||
| #else | #else | ||||||
|     pthread_attr_t attr; |     pthread_attr_t attr; | ||||||
|     attr.schedparam.sched_priority = 18; |     attr.schedparam.sched_priority = 25; | ||||||
|     attr.stacksize = 4096; |     attr.stacksize = 4096; | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -87,7 +87,7 @@ int InitATAgent(const char *agent_name, int fd, uint32 maintain_max); | ||||||
| int DeleteATAgent(ATAgentType agent); | int DeleteATAgent(ATAgentType agent); | ||||||
| int ParseATReply(char* str, const char *format, ...); | int ParseATReply(char* str, const char *format, ...); | ||||||
| void DeleteATReply(ATReplyType reply); | void DeleteATReply(ATReplyType reply); | ||||||
| int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...); | int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const char *cmd_expr, ...); | ||||||
| int AtCmdConfigAndCheck(ATAgentType agent, char *cmd, char *check); | int AtCmdConfigAndCheck(ATAgentType agent, char *cmd, char *check); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  | @ -7,3 +7,11 @@ config ADAPTER_HFA21_WIFI | ||||||
| if ADAPTER_HFA21_WIFI | if ADAPTER_HFA21_WIFI | ||||||
|     source "$APP_DIR/Framework/connection/wifi/hfa21_wifi/Kconfig" |     source "$APP_DIR/Framework/connection/wifi/hfa21_wifi/Kconfig" | ||||||
| endif | endif | ||||||
|  | 
 | ||||||
|  | config ADAPTER_ESP07S_WIFI | ||||||
|  |         bool "Using wifi adapter device esp07s" | ||||||
|  |         default n | ||||||
|  | 
 | ||||||
|  | if ADAPTER_ESP07S_WIFI | ||||||
|  |     source "$APP_DIR/Framework/connection/wifi/esp07s_wifi/Kconfig" | ||||||
|  | endif  | ||||||
|  |  | ||||||
|  | @ -4,4 +4,8 @@ ifeq ($(CONFIG_ADAPTER_HFA21_WIFI),y) | ||||||
| 	SRC_DIR += hfa21_wifi | 	SRC_DIR += hfa21_wifi | ||||||
| endif | endif | ||||||
| 
 | 
 | ||||||
|  | ifeq ($(CONFIG_ADAPTER_ESP07S_WIFI),y) | ||||||
|  | 	SRC_DIR += esp07s_wifi | ||||||
|  | endif | ||||||
|  | 
 | ||||||
| include $(KERNEL_ROOT)/compiler.mk | include $(KERNEL_ROOT)/compiler.mk | ||||||
|  |  | ||||||
|  | @ -19,11 +19,15 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <adapter.h> | #include <adapter.h> | ||||||
|  | #include "adapter_wifi.h" | ||||||
| #include <bus_pin.h> | #include <bus_pin.h> | ||||||
| 
 | 
 | ||||||
| #ifdef ADAPTER_HFA21_WIFI | #ifdef ADAPTER_HFA21_WIFI | ||||||
| extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter); | extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter); | ||||||
| #endif | #endif | ||||||
|  | #ifdef ADAPTER_ESP07S_WIFI | ||||||
|  | extern AdapterProductInfoType Esp07sWifiAttach(struct Adapter *adapter); | ||||||
|  | #endif | ||||||
| 
 | 
 | ||||||
| static int AdapterWifiRegister(struct Adapter *adapter) | static int AdapterWifiRegister(struct Adapter *adapter) | ||||||
| { | { | ||||||
|  | @ -75,13 +79,26 @@ int AdapterWifiInit(void) | ||||||
|     adapter->info = product_info; |     adapter->info = product_info; | ||||||
|     adapter->done = product_info->model_done; |     adapter->done = product_info->model_done; | ||||||
| 
 | 
 | ||||||
|  | #endif | ||||||
|  | #ifdef ADAPTER_ESP07S_WIFI | ||||||
|  |     AdapterProductInfoType product_info = Esp07sWifiAttach(adapter); | ||||||
|  |     if (!product_info) { | ||||||
|  |         printf("AdapterWifiInit ESP07S attach error\n"); | ||||||
|  |         PrivFree(adapter); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     adapter->product_info_flag = 1; | ||||||
|  |     adapter->info = product_info; | ||||||
|  |     adapter->done = product_info->model_done; | ||||||
|  | 
 | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|     return ret; |     return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /******************wifi TEST*********************/ | /******************wifi TEST*********************/ | ||||||
| int AdapterWifiTest(void) | int AdapterwifiTest(void) | ||||||
| { | { | ||||||
|     char cmd[64]; |     char cmd[64]; | ||||||
|     int baud_rate = BAUD_RATE_57600; |     int baud_rate = BAUD_RATE_57600; | ||||||
|  | @ -138,14 +155,14 @@ int AdapterWifiTest(void) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     AdapterDeviceOpen(adapter); |     AdapterDeviceOpen(adapter); | ||||||
|     AdapterDeviceControl(adapter, OPE_INT, &baud_rate); |     // AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
 | ||||||
| 
 | 
 | ||||||
|     AdapterDeviceSetUp(adapter); |     AdapterDeviceSetUp(adapter); | ||||||
|     AdapterDeviceSetAddr(adapter, "192.168.66.253", "255.255.255.0", "192.168.66.1"); |     AdapterDeviceSetAddr(adapter, "192.168.64.253", "192.168.66.1", "255.255.252.0"); | ||||||
|     AdapterDevicePing(adapter, "36.152.44.95"); |     AdapterDevicePing(adapter, "36.152.44.95"); | ||||||
|     AdapterDeviceNetstat(adapter); |     AdapterDeviceNetstat(adapter); | ||||||
| 
 | 
 | ||||||
|     const char *ip = "192.168.66.211"; |     const char *ip = "192.168.64.60"; | ||||||
|     const char *port = "12345"; |     const char *port = "12345"; | ||||||
|     enum NetRoleType net_role = CLIENT; |     enum NetRoleType net_role = CLIENT; | ||||||
|     enum IpType ip_type = IPV4; |     enum IpType ip_type = IPV4; | ||||||
|  | @ -164,4 +181,97 @@ int AdapterWifiTest(void) | ||||||
|     } |     } | ||||||
|      |      | ||||||
| } | } | ||||||
| SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterWifiTest, AdapterWifiTest, show adapter wifi information); | SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterwifiTest, AdapterwifiTest, show adapter wifi information); | ||||||
|  | 
 | ||||||
|  | int wifiopen(void) | ||||||
|  | { | ||||||
|  |     struct Adapter* adapter =  AdapterDeviceFindByName(ADAPTER_WIFI_NAME); | ||||||
|  | 
 | ||||||
|  |     AdapterDeviceOpen(adapter); | ||||||
|  | } | ||||||
|  | SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wifiopen, wifiopen, open adapter wifi ); | ||||||
|  | int wificlose(void) | ||||||
|  | { | ||||||
|  |     struct Adapter* adapter =  AdapterDeviceFindByName(ADAPTER_WIFI_NAME); | ||||||
|  | 
 | ||||||
|  |     AdapterDeviceClose(adapter); | ||||||
|  | } | ||||||
|  | SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wificlose, wificlose, close adapter wifi ); | ||||||
|  | 
 | ||||||
|  | int wifisetup(int argc, char *argv[]) | ||||||
|  | { | ||||||
|  |     struct Adapter* adapter =  AdapterDeviceFindByName(ADAPTER_WIFI_NAME); | ||||||
|  |     struct WifiParam param; | ||||||
|  |     memset(¶m,0,sizeof(struct WifiParam)); | ||||||
|  |     strncpy(param.wifi_ssid, argv[1], strlen(argv[1])); | ||||||
|  |     strncpy(param.wifi_pwd, argv[2], strlen(argv[2])); | ||||||
|  | 
 | ||||||
|  |     adapter->adapter_param = ¶m; | ||||||
|  | 
 | ||||||
|  |     AdapterDeviceSetUp(adapter); | ||||||
|  | } | ||||||
|  | SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisetup, wifisetup, setup adapter wifi ); | ||||||
|  | int wifiaddrset(int argc, char *argv[]) | ||||||
|  | { | ||||||
|  |     struct Adapter* adapter =  AdapterDeviceFindByName(ADAPTER_WIFI_NAME); | ||||||
|  |     char *ip = argv[1]; | ||||||
|  |     char *gateway = argv[2]; | ||||||
|  |     char *netmask = argv[3]; | ||||||
|  | 
 | ||||||
|  |     AdapterDeviceSetAddr(adapter, ip, gateway, netmask); | ||||||
|  |     AdapterDevicePing(adapter, "36.152.44.95");///< ping www.baidu.com
 | ||||||
|  |     AdapterDeviceNetstat(adapter); | ||||||
|  | } | ||||||
|  | SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wifiaddrset, wifiaddrset, addrset adapter wifi); | ||||||
|  | 
 | ||||||
|  | int wifiping(int argc, char *argv[]) | ||||||
|  | { | ||||||
|  |     struct Adapter* adapter =  AdapterDeviceFindByName(ADAPTER_WIFI_NAME); | ||||||
|  |     printf("ping %s\n",argv[1]); | ||||||
|  |     AdapterDevicePing(adapter, argv[1]); | ||||||
|  | } | ||||||
|  | SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3), wifiping, wifiping, wifiping adapter ); | ||||||
|  | 
 | ||||||
|  | int wificonnect(int argc, char *argv[]) | ||||||
|  | { | ||||||
|  |     struct Adapter* adapter =  AdapterDeviceFindByName(ADAPTER_WIFI_NAME); | ||||||
|  |     char *ip = argv[1]; | ||||||
|  |     char *port = argv[2]; | ||||||
|  |     enum NetRoleType net_role = CLIENT; | ||||||
|  |     enum IpType ip_type = IPV4; | ||||||
|  | 
 | ||||||
|  |     if(0 == strncmp("tcp",argv[3],strlen("tcp"))) { | ||||||
|  |         adapter->socket.protocal = SOCKET_PROTOCOL_TCP; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if(0 == strncmp("udp",argv[3],strlen("udp"))) { | ||||||
|  |         adapter->socket.protocal = SOCKET_PROTOCOL_UDP; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     AdapterDeviceConnect(adapter, net_role, ip, port, ip_type); | ||||||
|  | } | ||||||
|  | SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wificonnect, wificonnect, wificonnect adapter); | ||||||
|  | int wifisend(int argc, char *argv[]) | ||||||
|  | { | ||||||
|  |     struct Adapter* adapter =  AdapterDeviceFindByName(ADAPTER_WIFI_NAME); | ||||||
|  | 
 | ||||||
|  |     const char *wifi_msg = argv[1]; | ||||||
|  |     int len = strlen(wifi_msg); | ||||||
|  |     for(int i = 0;i < 10; ++i) { | ||||||
|  |         AdapterDeviceSend(adapter, wifi_msg, len); | ||||||
|  |         PrivTaskDelay(1000); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisend, wifisend, wifisend adapter wifi information); | ||||||
|  | int wifirecv(int argc, char *argv[]) | ||||||
|  | { | ||||||
|  |     struct Adapter* adapter =  AdapterDeviceFindByName(ADAPTER_WIFI_NAME); | ||||||
|  | 
 | ||||||
|  |     char wifi_recv_msg[128]; | ||||||
|  |     while (1) { | ||||||
|  |         AdapterDeviceRecv(adapter, wifi_recv_msg, 128); | ||||||
|  |         PrivTaskDelay(1000); | ||||||
|  |         printf("wifi recv [%s]\n",wifi_recv_msg); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifirecv, wifirecv, wifirecv adapter wifi information); | ||||||
|  |  | ||||||
|  | @ -0,0 +1,19 @@ | ||||||
|  | #ifndef ADAPTER_WIFI_H | ||||||
|  | #define ADAPTER_WIFI_H | ||||||
|  | 
 | ||||||
|  | #define CONFIG_WIFI_RESET            (0) | ||||||
|  | #define CONFIG_WIFI_RESTORE          (1) | ||||||
|  | #define CONFIG_WIFI_BAUDRATE         (2) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #define SOCKET_PROTOCOL_TCP  (6) | ||||||
|  | #define SOCKET_PROTOCOL_UDP  (17) | ||||||
|  | 
 | ||||||
|  | struct WifiParam | ||||||
|  | { | ||||||
|  |     uint8_t wifi_ssid[128]; | ||||||
|  |     uint8_t wifi_pwd[128]; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
|  | @ -0,0 +1,33 @@ | ||||||
|  | config ADAPTER_WIFI_ESP07S | ||||||
|  |         string "ESP07S WIFI adapter name" | ||||||
|  |         default "esp07s_wifi" | ||||||
|  | 
 | ||||||
|  | if ADD_XIZI_FETURES | ||||||
|  | 
 | ||||||
|  |         config ADAPTER_ESP07S_DRIVER_EXTUART | ||||||
|  |                 bool "Using extra uart to support wifi" | ||||||
|  |                 default n | ||||||
|  | 
 | ||||||
|  |         config ADAPTER_ESP07S_DRIVER | ||||||
|  |                 string "ESP07S device uart driver path" | ||||||
|  |                 default "/dev/uart2_dev2" | ||||||
|  |                 depends on !ADAPTER_ESP07S_DRIVER_EXTUART | ||||||
|  | 
 | ||||||
|  |         if ADAPTER_ESP07S_DRIVER_EXTUART                     | ||||||
|  |                 config ADAPTER_ESP07S_DRIVER | ||||||
|  |                         string "ESP07S device extra uart driver path" | ||||||
|  |                         default "/dev/extuart_dev6" | ||||||
|  | 
 | ||||||
|  |                 config ADAPTER_ESP07S_DRIVER_EXT_PORT | ||||||
|  |                         int "if ESP07S device using extuart, choose port" | ||||||
|  |                         default "6" | ||||||
|  |         endif | ||||||
|  | endif | ||||||
|  | 
 | ||||||
|  | if ADD_NUTTX_FETURES | ||||||
|  | 
 | ||||||
|  | endif | ||||||
|  | 
 | ||||||
|  | if ADD_RTTHREAD_FETURES | ||||||
|  | 
 | ||||||
|  | endif | ||||||
|  | @ -0,0 +1,3 @@ | ||||||
|  | SRC_FILES := esp07s_wifi.c | ||||||
|  | 
 | ||||||
|  | include $(KERNEL_ROOT)/compiler.mk | ||||||
|  | @ -0,0 +1,587 @@ | ||||||
|  | /*
 | ||||||
|  | * Copyright (c) 2020 AIIT XUOS Lab | ||||||
|  | * XiUOS is licensed under Mulan PSL v2. | ||||||
|  | * You can use this software according to the terms and conditions of the Mulan PSL v2. | ||||||
|  | * You may obtain a copy of Mulan PSL v2 at: | ||||||
|  | *        http://license.coscl.org.cn/MulanPSL2
 | ||||||
|  | * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||||||
|  | * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||||||
|  | * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||||||
|  | * See the Mulan PSL v2 for more details. | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @file esp07_wifi.c | ||||||
|  |  * @brief Implement the connection wifi adapter function, using ESP07S device | ||||||
|  |  * @version 1.1 | ||||||
|  |  * @author AIIT XUOS Lab | ||||||
|  |  * @date 2022.04.08 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #include <adapter.h> | ||||||
|  | #include <at_agent.h> | ||||||
|  | #include "../adapter_wifi.h" | ||||||
|  | #include <stdlib.h> | ||||||
|  | 
 | ||||||
|  | #define LEN_PARA_BUF 128 | ||||||
|  | 
 | ||||||
|  | static int Esp07sWifiSetDown(struct Adapter *adapter_at); | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: check AT startup status | ||||||
|  |  * @param at_agent - wifi device agent pointer | ||||||
|  |  * @return success: EOK | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiTestAtCmd(ATAgentType at_agent) | ||||||
|  | { | ||||||
|  |     int ret = 0; | ||||||
|  | 
 | ||||||
|  |     ret = AtCmdConfigAndCheck(at_agent, "ATE0\r\n", "OK"); ///< close echo function
 | ||||||
|  |     if(ret < 0) { | ||||||
|  |         printf("%s %d cmd[ATE0] config failed!\n",__func__,__LINE__); | ||||||
|  |         ret = -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     PrivTaskDelay(2000); | ||||||
|  |     ret = AtCmdConfigAndCheck(at_agent, "AT\r\n", "OK"); | ||||||
|  |     if(ret < 0) { | ||||||
|  |         printf("%s %d cmd[AT] config failed!\n",__func__,__LINE__); | ||||||
|  |         ret = -1; | ||||||
|  |     } | ||||||
|  |     return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static int Esp07sUartOpen(struct Adapter *adapter) | ||||||
|  | { | ||||||
|  |     if (NULL == adapter) { | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /* Open device in read-write mode */ | ||||||
|  |     adapter->fd = PrivOpen(ADAPTER_ESP07S_DRIVER, O_RDWR); | ||||||
|  |     if (adapter->fd < 0) { | ||||||
|  |         printf("Esp07sWifiOpen get serial %s fd error\n", ADAPTER_ESP07S_DRIVER); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  |     /* set serial config, serial_baud_rate = 115200 */ | ||||||
|  | 
 | ||||||
|  |     struct SerialDataCfg cfg; | ||||||
|  |     memset(&cfg, 0 ,sizeof(struct SerialDataCfg)); | ||||||
|  | 
 | ||||||
|  |     cfg.serial_baud_rate = BAUD_RATE_115200; | ||||||
|  |     cfg.serial_data_bits = DATA_BITS_8; | ||||||
|  |     cfg.serial_stop_bits = STOP_BITS_1; | ||||||
|  |     cfg.serial_parity_mode = PARITY_NONE; | ||||||
|  |     cfg.serial_bit_order = BIT_ORDER_LSB; | ||||||
|  |     cfg.serial_invert_mode = NRZ_NORMAL; | ||||||
|  |     cfg.serial_buffer_size = SERIAL_RB_BUFSZ; | ||||||
|  | 
 | ||||||
|  | #ifdef ADAPTER_ESP07S_DRIVER_EXT_PORT | ||||||
|  |     cfg.ext_uart_no         = ADAPTER_ESP07S_DRIVER_EXT_PORT; | ||||||
|  |     cfg.port_configure      = PORT_CFG_INIT; | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |     struct PrivIoctlCfg ioctl_cfg; | ||||||
|  |     ioctl_cfg.ioctl_driver_type = SERIAL_TYPE; | ||||||
|  |     ioctl_cfg.args = &cfg; | ||||||
|  | 
 | ||||||
|  |     PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg); | ||||||
|  |     PrivTaskDelay(1000); | ||||||
|  | 
 | ||||||
|  |     printf("esp07s uart config ready\n"); | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: Open wifi | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @return success: EOK, failure: ENOMEMORY | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiOpen(struct Adapter *adapter) | ||||||
|  | { | ||||||
|  |     /*step1: open esp07s serial port*/ | ||||||
|  |     Esp07sUartOpen(adapter); | ||||||
|  | 
 | ||||||
|  |     /*step2: init AT agent*/ | ||||||
|  |     if (!adapter->agent) { | ||||||
|  |         char *agent_name = "wifi_uart_client"; | ||||||
|  |         if (EOK != InitATAgent(agent_name, adapter->fd, 512)) { | ||||||
|  |             printf("at agent init failed !\n"); | ||||||
|  |             return -1; | ||||||
|  |         } | ||||||
|  |         ATAgentType at_agent = GetATAgent(agent_name); | ||||||
|  | 
 | ||||||
|  |         adapter->agent = at_agent; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     AtSetReplyEndChar(adapter->agent,'O','K'); | ||||||
|  | 
 | ||||||
|  |     ADAPTER_DEBUG("Esp07sWifi open done\n");  | ||||||
|  | 
 | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: Close wifi | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @return success: EOK | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiClose(struct Adapter *adapter) | ||||||
|  | { | ||||||
|  |     Esp07sWifiSetDown(adapter); | ||||||
|  |     PrivClose(adapter->fd); | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: send data to adapter | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @param data - data buffer | ||||||
|  |  * @param data - data length | ||||||
|  |  * @return success: EOK | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiSend(struct Adapter *adapter, const void *data, size_t len) | ||||||
|  | { | ||||||
|  |     x_err_t result = EOK; | ||||||
|  |     if (adapter->agent) { | ||||||
|  |         EntmSend(adapter->agent, (const char *)data, len); | ||||||
|  |     }else { | ||||||
|  |         printf("Esp07sWifiSend can not find agent!\n"); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  |     return result; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: receive data from adapter | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @param data - data buffer | ||||||
|  |  * @param data - data length | ||||||
|  |  * @return success: EOK | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len) | ||||||
|  | { | ||||||
|  |     x_err_t result = EOK; | ||||||
|  |     printf("esp07s receive waiting ... \n"); | ||||||
|  | 
 | ||||||
|  |     if (adapter->agent) { | ||||||
|  |         return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40); | ||||||
|  |     } else { | ||||||
|  |         printf("Esp07sWifiReceive can not find agent!\n"); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  |     return result; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: connnect wifi to internet | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @return success: EOK | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiSetUp(struct Adapter *adapter) | ||||||
|  | { | ||||||
|  |     char cmd[LEN_PARA_BUF]; | ||||||
|  |     int ret = 0; | ||||||
|  |     char *result = NULL; | ||||||
|  | 
 | ||||||
|  |     struct WifiParam *param = (struct WifiParam *)adapter->adapter_param; | ||||||
|  |     struct ATAgent *agent = adapter->agent; | ||||||
|  | 
 | ||||||
|  |     PrivTaskDelay(2000); | ||||||
|  | 
 | ||||||
|  |     if(Esp07sWifiTestAtCmd(agent) < 0) | ||||||
|  |     { | ||||||
|  |         printf("wifi at cmd startup failed.\n"); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  |     PrivTaskDelay(2000); | ||||||
|  |     /* config as softAP+station mode */ | ||||||
|  |     ret = AtCmdConfigAndCheck(agent, "AT+CWMODE=3\r\n", "OK");  | ||||||
|  |     if(ret < 0) { | ||||||
|  |         printf("%s %d cmd[AT+CWMODE=3] config failed!\n",__func__,__LINE__); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  |     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)); | ||||||
|  | 
 | ||||||
|  |     strncat(cmd,"\"",1); | ||||||
|  |     strncat(cmd,",",1); | ||||||
|  |     strncat(cmd,"\"",1); | ||||||
|  |     strncat(cmd,param->wifi_pwd,strlen(param->wifi_pwd)); | ||||||
|  | 
 | ||||||
|  |     strncat(cmd,"\"",1); | ||||||
|  |     strcat(cmd,"\r\n"); | ||||||
|  | 
 | ||||||
|  |     ret = AtCmdConfigAndCheck(agent, cmd, "OK"); | ||||||
|  |     if(ret < 0) { | ||||||
|  |         printf("%s %d cmd[%s] connect[%s] failed!\n",__func__,__LINE__,cmd,param->wifi_ssid); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /* check the wifi ip address */  | ||||||
|  |     ATReplyType reply = CreateATReply(256); | ||||||
|  |     if (NULL == reply) { | ||||||
|  |         printf("%s %d at_create_resp failed!\n",__func__,__LINE__); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  |     ret = ATOrderSend(agent, REPLY_TIME_OUT, reply, "AT+CIFSR\r\n"); | ||||||
|  |     if(ret < 0){ | ||||||
|  |         printf("%s %d ATOrderSend AT+CIFSR failed.\n",__func__,__LINE__); | ||||||
|  |         ret = -1; | ||||||
|  |         goto __exit; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     result = GetReplyText(reply); | ||||||
|  |     if (!result) { | ||||||
|  |         printf("%s %n get reply failed.\n",__func__,__LINE__); | ||||||
|  |         ret = -1; | ||||||
|  |         goto __exit; | ||||||
|  |     } | ||||||
|  |     printf("[%s]\n", result); | ||||||
|  | 
 | ||||||
|  | __exit: | ||||||
|  |     DeleteATReply(reply); | ||||||
|  | 
 | ||||||
|  |     return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: disconnnect wifi from internet | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @return success: EOK | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiSetDown(struct Adapter *adapter) | ||||||
|  | { | ||||||
|  |     ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+RESTORE\r\n"); | ||||||
|  |     PrivTaskDelay(2000); | ||||||
|  | 
 | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: set wifi ip/gateway/netmask address(in sta mode) | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @param ip - ip address | ||||||
|  |  * @param gateway - gateway address | ||||||
|  |  * @param netmask - netmask address | ||||||
|  |  * @return success: EOK, failure: ENOMEMORY | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask) | ||||||
|  | { | ||||||
|  |     int ret = 0; | ||||||
|  |     char cmd[LEN_PARA_BUF]; | ||||||
|  | 
 | ||||||
|  |     /* 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,"\r\n"); | ||||||
|  | 
 | ||||||
|  |     ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK");  | ||||||
|  |     if(ret < 0) { | ||||||
|  |         printf("%s %d cmd[%s] config ip failed!\n",__func__,__LINE__,cmd); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: wifi ping function | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @param destination - domain name or ip address | ||||||
|  |  * @return success: EOK, failure: ENOMEMORY | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiPing(struct Adapter *adapter, const char *destination) | ||||||
|  | { | ||||||
|  |     char cmd[LEN_PARA_BUF]; | ||||||
|  |     int ret = 0; | ||||||
|  | 
 | ||||||
|  |     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,"\r\n"); | ||||||
|  | 
 | ||||||
|  |     ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK"); ///< config as softAP+station mode
 | ||||||
|  |     if(ret < 0) { | ||||||
|  |         printf("%s %d ping [%s] failed!\n",__func__,__LINE__,destination); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     printf("ping [%s] ok\n", destination); | ||||||
|  | 
 | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: display wifi network configuration | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @return success: EOK, failure: ENOMEMORY | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiNetstat(struct Adapter *adapter) | ||||||
|  | { | ||||||
|  |     int ret = 0; | ||||||
|  |     char *result = NULL; | ||||||
|  | 
 | ||||||
|  |     /* check the wifi ip address */  | ||||||
|  |     ATReplyType reply = CreateATReply(256); | ||||||
|  |     if (NULL == reply) { | ||||||
|  |         printf("%s %d at_create_resp failed!\n",__func__,__LINE__); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  |     ret = ATOrderSend(adapter->agent, REPLY_TIME_OUT, reply, "AT+CIFSR\r\n"); | ||||||
|  |     if(ret < 0){ | ||||||
|  |         printf("%s %d ATOrderSend AT+CIFSR failed.\n",__func__,__LINE__); | ||||||
|  |         ret = -1; | ||||||
|  |         goto __exit; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     result = GetReplyText(reply); | ||||||
|  |     if (!result) { | ||||||
|  |         printf("%s %n get reply failed.\n",__func__,__LINE__); | ||||||
|  |         ret = -1; | ||||||
|  |         goto __exit; | ||||||
|  |     } | ||||||
|  |     printf("[%s]\n", result); | ||||||
|  |      | ||||||
|  | __exit: | ||||||
|  |     DeleteATReply(reply); | ||||||
|  | 
 | ||||||
|  |     return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: wifi connect function | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @param net_role - net role, CLIENT or SERVER | ||||||
|  |  * @param ip - ip address | ||||||
|  |  * @param port - port num | ||||||
|  |  * @param ip_type - ip type, IPV4 or IPV6 | ||||||
|  |  * @return success: 0, failure: -1 | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type) | ||||||
|  | { | ||||||
|  |     int ret = EOK; | ||||||
|  |     char cmd[LEN_PARA_BUF]; | ||||||
|  |     struct ATAgent *agent = adapter->agent; | ||||||
|  |      | ||||||
|  |     memset(cmd,0,sizeof(cmd)); | ||||||
|  |     if(adapter->socket.protocal == SOCKET_PROTOCOL_TCP && net_role == CLIENT) //esp07s as tcp client to connect server
 | ||||||
|  |     { | ||||||
|  |         //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,"\r\n"); | ||||||
|  | 
 | ||||||
|  |         ret = AtCmdConfigAndCheck(agent, cmd, "OK");  | ||||||
|  |         if(ret < 0) { | ||||||
|  |             printf("%s %d tcp connect [%s] failed!\n",__func__,__LINE__,ip); | ||||||
|  |             return -1; | ||||||
|  |         } | ||||||
|  |     }  | ||||||
|  |     else if(adapter->socket.protocal == SOCKET_PROTOCOL_UDP)  | ||||||
|  |     { | ||||||
|  |         //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,"\r\n"); | ||||||
|  | 
 | ||||||
|  |         ret = AtCmdConfigAndCheck(agent, cmd, "OK");  | ||||||
|  |         if(ret < 0) { | ||||||
|  |             printf("%s %d udp connect [%s] failed!\n",__func__,__LINE__,ip); | ||||||
|  |             return -1; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     ret = AtCmdConfigAndCheck(agent, "AT+CIPMODE=1\r\n", "OK"); ///< config as transparent transmission
 | ||||||
|  |     if(ret < 0) { | ||||||
|  |         printf("%s %d cmd[%s] config as transparent transmission failed!\n",__func__,__LINE__,cmd); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  |     ATOrderSend(agent, REPLY_TIME_OUT, NULL, "AT+CIPSEND\r\n"); | ||||||
|  | 
 | ||||||
|  |     printf("[%s] connection config as transparent transmission\n",adapter->socket.protocal == SOCKET_PROTOCOL_UDP ? "udp" : "tcp"); | ||||||
|  |     adapter->net_role = net_role; | ||||||
|  | 
 | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: wifi disconnect function | ||||||
|  |  * @param adapter - wifi device pointer | ||||||
|  |  * @return success: 0, failure: -1 | ||||||
|  |  */ | ||||||
|  | static int Esp07sWifiDisconnect(struct Adapter *adapter) | ||||||
|  | { | ||||||
|  |     int ret = EOK; | ||||||
|  |     char cmd[LEN_PARA_BUF]; | ||||||
|  |     struct ATAgent *agent = adapter->agent; | ||||||
|  |     memset(cmd,0,sizeof(cmd)); | ||||||
|  | 
 | ||||||
|  |     /* step1: stop transparent transmission mode */ | ||||||
|  |     ATOrderSend(agent, REPLY_TIME_OUT, NULL, "+++\r\n");  | ||||||
|  | 
 | ||||||
|  |     /* step2: exit transparent transmission mode */ | ||||||
|  |     ret = AtCmdConfigAndCheck(agent, "AT+CIPMODE=0\r\n", "OK");  | ||||||
|  |     if(ret < 0) { | ||||||
|  |         printf("%s %d cmd[AT+CIPMODE=0] exit failed!\n",__func__,__LINE__); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /* step3: disconnect */ | ||||||
|  |     ret = AtCmdConfigAndCheck(agent, "AT+CIPCLOSE\r\n", "OK");  | ||||||
|  |     if(ret < 0) { | ||||||
|  |         printf("%s %d cmd [AT+CIPCLOSE] disconnect failed!\n",__func__,__LINE__); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static int Esp07sWifiIoctl(struct Adapter *adapter, int cmd, void *args) | ||||||
|  | { | ||||||
|  |     int32_t ret = 0; | ||||||
|  |     char baud_str[LEN_PARA_BUF]; | ||||||
|  |     struct SerialDataCfg cfg; | ||||||
|  |     char at_cmd[LEN_PARA_BUF]; | ||||||
|  |     uint32_t baud_rate = 0 ; | ||||||
|  | 
 | ||||||
|  |     switch (cmd) | ||||||
|  |     { | ||||||
|  |         case CONFIG_WIFI_RESET: /* reset wifi */ | ||||||
|  |             ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+RST\r\n"); | ||||||
|  |             break; | ||||||
|  |         case CONFIG_WIFI_RESTORE: /* resore wifi */ | ||||||
|  |             ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+RESTORE\r\n"); | ||||||
|  |             break; | ||||||
|  |         case CONFIG_WIFI_BAUDRATE:  | ||||||
|  |             /* step1: config mcu uart*/ | ||||||
|  |             baud_rate = *((uint32_t *)args); | ||||||
|  | 
 | ||||||
|  |             memset(at_cmd, 0, sizeof(at_cmd)); | ||||||
|  |             memset(baud_str, 0, sizeof(baud_str)); | ||||||
|  |             memset(&cfg, 0 ,sizeof(struct SerialDataCfg)); | ||||||
|  | 
 | ||||||
|  |             cfg.serial_baud_rate = baud_rate; | ||||||
|  |             cfg.serial_data_bits = DATA_BITS_8; | ||||||
|  |             cfg.serial_stop_bits = STOP_BITS_1; | ||||||
|  |             cfg.serial_parity_mode = PARITY_NONE; | ||||||
|  |             cfg.serial_bit_order = BIT_ORDER_LSB; | ||||||
|  |             cfg.serial_invert_mode = NRZ_NORMAL; | ||||||
|  |             cfg.serial_buffer_size = SERIAL_RB_BUFSZ; | ||||||
|  | 
 | ||||||
|  | #ifdef ADAPTER_ESP07S_DRIVER_EXT_PORT | ||||||
|  |             cfg.ext_uart_no         = ADAPTER_ESP07S_DRIVER_EXT_PORT; | ||||||
|  |             cfg.port_configure      = PORT_CFG_INIT; | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  |             struct PrivIoctlCfg ioctl_cfg; | ||||||
|  |             ioctl_cfg.ioctl_driver_type = SERIAL_TYPE; | ||||||
|  |             ioctl_cfg.args = &cfg; | ||||||
|  | 
 | ||||||
|  |             PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg); | ||||||
|  | 
 | ||||||
|  |             /* step2: config wifi uart*/ | ||||||
|  |             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,"\r\n"); | ||||||
|  | 
 | ||||||
|  |             ret = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");  | ||||||
|  |             if(ret < 0) { | ||||||
|  |                 printf("%s %d cmd [%s] config uart failed!\n",__func__,__LINE__,at_cmd); | ||||||
|  |                 ret = -1; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             break; | ||||||
|  |         default: | ||||||
|  |             ret = -1; | ||||||
|  |             break;   | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static const struct IpProtocolDone esp07s_wifi_done = | ||||||
|  | { | ||||||
|  |     .open = Esp07sWifiOpen, | ||||||
|  |     .close =  Esp07sWifiClose, | ||||||
|  |     .ioctl = Esp07sWifiIoctl, | ||||||
|  |     .setup = Esp07sWifiSetUp, | ||||||
|  |     .setdown = Esp07sWifiSetDown, | ||||||
|  |     .setaddr = Esp07sWifiSetAddr, | ||||||
|  |     .setdns = NULL, | ||||||
|  |     .setdhcp = NULL, | ||||||
|  |     .ping = Esp07sWifiPing, | ||||||
|  |     .netstat = Esp07sWifiNetstat, | ||||||
|  |     .connect = Esp07sWifiConnect, | ||||||
|  |     .send = Esp07sWifiSend, | ||||||
|  |     .recv = Esp07sWifiReceive, | ||||||
|  |     .disconnect = Esp07sWifiDisconnect, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * @description: Register wifi device esp07s | ||||||
|  |  * @return success: EOK, failure: ERROR | ||||||
|  |  */ | ||||||
|  | AdapterProductInfoType Esp07sWifiAttach(struct Adapter *adapter) | ||||||
|  | { | ||||||
|  |     struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo)); | ||||||
|  |     if (!product_info)  | ||||||
|  |     { | ||||||
|  |         printf("Esp07sWifiAttach Attach malloc product_info error\n"); | ||||||
|  |         PrivFree(product_info); | ||||||
|  |         return NULL; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     strncpy(product_info->model_name, ADAPTER_WIFI_ESP07S, strlen(ADAPTER_WIFI_ESP07S)); | ||||||
|  | 
 | ||||||
|  |     product_info->model_done = (void *)&esp07s_wifi_done; | ||||||
|  | 
 | ||||||
|  |     return product_info; | ||||||
|  | } | ||||||
|  | @ -18,6 +18,13 @@ endchoice | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| if ADD_XIZI_FETURES | if ADD_XIZI_FETURES | ||||||
|  |         config ADAPTER_E18_MODEPIN | ||||||
|  |                 int "E18 MODE pin number" | ||||||
|  |                 default "61" | ||||||
|  | 
 | ||||||
|  |         config ADAPTER_BC28_PIN_DRIVER | ||||||
|  |                 string "BC28 device pin driver path" | ||||||
|  |                 default "/dev/pin_dev" | ||||||
| 
 | 
 | ||||||
|         config ADAPTER_E18_DRIVER_EXTUART |         config ADAPTER_E18_DRIVER_EXTUART | ||||||
|                 bool "Using extra uart to support zigbee" |                 bool "Using extra uart to support zigbee" | ||||||
|  |  | ||||||
|  | @ -37,6 +37,33 @@ char *cmd_role_as_e = "AT+DEV=E"; /*set device type for end device*/ | ||||||
| char *cmd_role_as_r = "AT+DEV=R"; /*set device type for router*/ | char *cmd_role_as_r = "AT+DEV=R"; /*set device type for router*/ | ||||||
| char *cmd_set_ch = "AT+CH=11";    /*set channel as 11*/ | char *cmd_set_ch = "AT+CH=11";    /*set channel as 11*/ | ||||||
| 
 | 
 | ||||||
|  | #define E18_AS_HEX_MODE 0 | ||||||
|  | #define E18_AS_AT_MODE  1 | ||||||
|  | 
 | ||||||
|  | static int E18HardwareModeGet() | ||||||
|  | { | ||||||
|  |     int ret = 0; | ||||||
|  |     int pin_fd; | ||||||
|  | 
 | ||||||
|  |     pin_fd = PrivOpen(ADAPTER_BC28_PIN_DRIVER, O_RDWR); | ||||||
|  | 
 | ||||||
|  |     struct PinStat pin_stat; | ||||||
|  |     pin_stat.pin = ADAPTER_E18_MODEPIN; | ||||||
|  | 
 | ||||||
|  |     ret = PrivRead(pin_fd, &pin_stat, 1); | ||||||
|  | 
 | ||||||
|  |     PrivTaskDelay(200); | ||||||
|  | 
 | ||||||
|  |     PrivClose(pin_fd); | ||||||
|  | 
 | ||||||
|  |     if(pin_stat.val == GPIO_HIGH) { | ||||||
|  |         printf(" E18 as AT mode\n"); | ||||||
|  |         return E18_AS_AT_MODE; | ||||||
|  |     } else { | ||||||
|  |         printf(" E18 as HEX mode\n"); | ||||||
|  |         return E18_AS_HEX_MODE; | ||||||
|  |     }  | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| #ifdef ADD_NUTTX_FETURES | #ifdef ADD_NUTTX_FETURES | ||||||
| static int E18UartOpen(struct Adapter *adapter) | static int E18UartOpen(struct Adapter *adapter) | ||||||
|  | @ -96,15 +123,22 @@ static int E18UartOpen(struct Adapter *adapter) | ||||||
| static int E18NetworkModeConfig(struct Adapter *adapter) | static int E18NetworkModeConfig(struct Adapter *adapter) | ||||||
| { | { | ||||||
|     int ret = 0; |     int ret = 0; | ||||||
|  |     int mode = -1; | ||||||
|  | 
 | ||||||
|     if (NULL == adapter) { |     if (NULL == adapter) { | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|  |     mode = E18HardwareModeGet(); | ||||||
|  |     if(E18_AS_HEX_MODE == mode) | ||||||
|  |     { | ||||||
|         ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK"); |         ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK"); | ||||||
|         if(ret < 0) { |         if(ret < 0) { | ||||||
|             printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at); |             printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at); | ||||||
|             ret = -1; |             ret = -1; | ||||||
|             goto out; |             goto out; | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
| 
 | 
 | ||||||
|     switch (adapter->info->work_mode) |     switch (adapter->info->work_mode) | ||||||
|     { |     { | ||||||
|  | @ -141,26 +175,35 @@ static int E18NetworkModeConfig(struct Adapter *adapter) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| out: | out: | ||||||
|  |     if(E18_AS_HEX_MODE == mode){ | ||||||
|         AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK"); |         AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK"); | ||||||
|  |     } | ||||||
|  |      | ||||||
|     return ret; |     return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int E18NetRoleConfig(struct Adapter *adapter) | static int E18NetRoleConfig(struct Adapter *adapter) | ||||||
| { | { | ||||||
|     int ret = 0; |     int ret = 0; | ||||||
|  |     int mode = -1; | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|     if (NULL == adapter) { |     if (NULL == adapter) { | ||||||
|         printf("%s %d adapter is null!\n",__func__,__LINE__); |         printf("%s %d adapter is null!\n",__func__,__LINE__); | ||||||
|         ret = -1; |         ret = -1; | ||||||
|         goto out; |         goto out; | ||||||
|     } |     } | ||||||
| 
 |     mode = E18HardwareModeGet(); | ||||||
|  |     if(E18_AS_HEX_MODE == mode) | ||||||
|  |     { | ||||||
|         ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK"); |         ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK"); | ||||||
|         if(ret < 0) { |         if(ret < 0) { | ||||||
|             printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at); |             printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at); | ||||||
|             ret = -1; |             ret = -1; | ||||||
|             goto out; |             goto out; | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
| 
 | 
 | ||||||
|     switch (adapter->net_role) |     switch (adapter->net_role) | ||||||
|     { |     { | ||||||
|  | @ -197,7 +240,10 @@ static int E18NetRoleConfig(struct Adapter *adapter) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| out: | out: | ||||||
|  |     if(E18_AS_HEX_MODE == mode) { | ||||||
|         AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK"); |         AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     return ret; |     return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -205,6 +251,7 @@ static int E18Open(struct Adapter *adapter) | ||||||
| { | { | ||||||
|     int ret = 0; |     int ret = 0; | ||||||
|     int try_times = 5; |     int try_times = 5; | ||||||
|  |     int count = 0; | ||||||
| 
 | 
 | ||||||
|     if (NULL == adapter) { |     if (NULL == adapter) { | ||||||
|         return -1; |         return -1; | ||||||
|  | @ -231,9 +278,12 @@ static int E18Open(struct Adapter *adapter) | ||||||
| try_again: | try_again: | ||||||
|     while(try_times--){ |     while(try_times--){ | ||||||
|         ret = E18NetRoleConfig(adapter); |         ret = E18NetRoleConfig(adapter); | ||||||
|  |         count++; | ||||||
|         if(ret < 0){ |         if(ret < 0){ | ||||||
|             printf("E18NetRoleConfig failed [%d] times.\n",try_times); |             printf("E18NetRoleConfig failed [%d] times.\n",count); | ||||||
|             goto try_again; |             continue; | ||||||
|  |         } else { | ||||||
|  |             break; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  | @ -274,13 +324,18 @@ static int E18Ioctl(struct Adapter *adapter, int cmd, void *args) | ||||||
| static int E18Join(struct Adapter *adapter, unsigned char *priv_net_group) | static int E18Join(struct Adapter *adapter, unsigned char *priv_net_group) | ||||||
| { | { | ||||||
|     int ret = 0; |     int ret = 0; | ||||||
|  |     int mode = -1; | ||||||
| 
 | 
 | ||||||
|  |     mode = E18HardwareModeGet(); | ||||||
|  |     if(E18_AS_HEX_MODE == mode) | ||||||
|  |     { | ||||||
|         ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK"); |         ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK"); | ||||||
|         if(ret < 0) { |         if(ret < 0) { | ||||||
|             printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at); |             printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at); | ||||||
|             ret = -1; |             ret = -1; | ||||||
|             goto out; |             goto out; | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     switch (adapter->net_role) |     switch (adapter->net_role) | ||||||
|     { |     { | ||||||
|  | @ -327,11 +382,15 @@ static int E18Join(struct Adapter *adapter, unsigned char *priv_net_group) | ||||||
| 
 | 
 | ||||||
|     // }
 |     // }
 | ||||||
|     if(!ret){ |     if(!ret){ | ||||||
|  |         if(E18_AS_HEX_MODE == mode) { | ||||||
|             ret = AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK"); |             ret = AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK"); | ||||||
|             if(ret < 0) { |             if(ret < 0) { | ||||||
|                 printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_exit); |                 printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_exit); | ||||||
|                 ret = -1; |                 ret = -1; | ||||||
|             } |             } | ||||||
|  |         } else { | ||||||
|  |             ret = -1; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| out: | out: | ||||||
|  |  | ||||||
|  | @ -39,13 +39,12 @@ struct SerialHardwareDevice serial_device_1; | ||||||
| 
 | 
 | ||||||
| void LPUART1_IRQHandler(int irqn, void *arg) | void LPUART1_IRQHandler(int irqn, void *arg) | ||||||
| { | { | ||||||
|     x_base lock = 0; | 
 | ||||||
|     // KPrintf("LPUART1_IRQHandler \n");
 |     DisableIRQ(UART1_IRQn); | ||||||
|     lock = DISABLE_INTERRUPT(); |  | ||||||
| 
 | 
 | ||||||
|     UartIsr(&serial_bus_1, &serial_driver_1, &serial_device_1); |     UartIsr(&serial_bus_1, &serial_driver_1, &serial_device_1); | ||||||
|  |      EnableIRQ(UART1_IRQn); | ||||||
| 
 | 
 | ||||||
|     ENABLE_INTERRUPT(lock); |  | ||||||
| } | } | ||||||
| DECLARE_HW_IRQ(UART1_IRQn, LPUART1_IRQHandler, NONE); | DECLARE_HW_IRQ(UART1_IRQn, LPUART1_IRQHandler, NONE); | ||||||
| #endif | #endif | ||||||
|  | @ -57,12 +56,12 @@ struct SerialHardwareDevice serial_device_2; | ||||||
| 
 | 
 | ||||||
| void LPUART2_IRQHandler(int irqn, void *arg) | void LPUART2_IRQHandler(int irqn, void *arg) | ||||||
| { | { | ||||||
|     x_base lock = 0; | 
 | ||||||
|     lock = DISABLE_INTERRUPT(); |     DisableIRQ(UART2_IRQn); | ||||||
| 
 | 
 | ||||||
|     UartIsr(&serial_bus_2, &serial_driver_2, &serial_device_2); |     UartIsr(&serial_bus_2, &serial_driver_2, &serial_device_2); | ||||||
|  |     EnableIRQ(UART2_IRQn); | ||||||
| 
 | 
 | ||||||
|     ENABLE_INTERRUPT(lock); |  | ||||||
| } | } | ||||||
| DECLARE_HW_IRQ(UART2_IRQn, LPUART2_IRQHandler, NONE); | DECLARE_HW_IRQ(UART2_IRQn, LPUART2_IRQHandler, NONE); | ||||||
| #endif | #endif | ||||||
|  | @ -187,6 +186,13 @@ static uint32 SerialInit(struct SerialDriver *serial_drv, struct BusConfigureInf | ||||||
| 
 | 
 | ||||||
|     LPUART_Init(uart_base, &config, GetUartSrcFreq()); |     LPUART_Init(uart_base, &config, GetUartSrcFreq()); | ||||||
| 
 | 
 | ||||||
|  |     if (configure_info->private_data) { | ||||||
|  |         DisableIRQ(serial_cfg->hw_cfg.serial_irq_interrupt); | ||||||
|  |         LPUART_EnableInterrupts(uart_base, kLPUART_RxDataRegFullInterruptEnable); | ||||||
|  |         NVIC_SetPriority(serial_cfg->hw_cfg.serial_irq_interrupt, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 4, 0)); | ||||||
|  |         EnableIRQ(serial_cfg->hw_cfg.serial_irq_interrupt); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     return EOK; |     return EOK; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -196,6 +202,10 @@ static uint32 SerialConfigure(struct SerialDriver *serial_drv, int serial_operat | ||||||
| 
 | 
 | ||||||
|     struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_drv->private_data; |     struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_drv->private_data; | ||||||
|     LPUART_Type *uart_base = (LPUART_Type *)serial_cfg->hw_cfg.private_data; |     LPUART_Type *uart_base = (LPUART_Type *)serial_cfg->hw_cfg.private_data; | ||||||
|  |     struct BusConfigureInfo configure_info; | ||||||
|  |     configure_info.private_data = NONE; | ||||||
|  | 
 | ||||||
|  |     SerialInit(serial_drv, &configure_info); | ||||||
| 
 | 
 | ||||||
|     switch (serial_operation_cmd) |     switch (serial_operation_cmd) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -41,12 +41,12 @@ extern usb_status_t USB_HostMsdWriteApi(usb_host_msd_command_instance_t *msdComm | ||||||
| //USB HOST ISR
 | //USB HOST ISR
 | ||||||
| void UsbOtg2IrqHandler(int irqn, void *arg) | void UsbOtg2IrqHandler(int irqn, void *arg) | ||||||
| { | { | ||||||
|     x_base lock = 0; | 
 | ||||||
|     lock = DISABLE_INTERRUPT(); |     DisableIRQ(USB2_IRQn); | ||||||
| 
 | 
 | ||||||
|     USB_HostEhciIsrFunction(g_HostHandle); |     USB_HostEhciIsrFunction(g_HostHandle); | ||||||
|  |     EnableIRQ(USB2_IRQn); | ||||||
| 
 | 
 | ||||||
|     ENABLE_INTERRUPT(lock); |  | ||||||
| } | } | ||||||
| DECLARE_HW_IRQ(USB2_IRQn, UsbOtg2IrqHandler, NONE); | DECLARE_HW_IRQ(USB2_IRQn, UsbOtg2IrqHandler, NONE); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -46,7 +46,7 @@ __attribute__((aligned(MEM_ALIGN_SIZE))) | ||||||
| void RunningIntoLowPowerMode() | void RunningIntoLowPowerMode() | ||||||
| { | { | ||||||
| #ifdef ARCH_ARM  | #ifdef ARCH_ARM  | ||||||
|     __asm volatile("WFI");     |     // __asm volatile("WFI");    
 | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef ARCH_RISCV  | #ifdef ARCH_RISCV  | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue