forked from xuos/xiuos
Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into develop
This commit is contained in:
@@ -1,29 +1,37 @@
|
||||
SRC_FILES := test_shell.c
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_ADC),y)
|
||||
SRC_FILES += test_adc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_DAC),y)
|
||||
SRC_FILES += test_dac.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_SEMC),y)
|
||||
SRC_FILES += test_extsram.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_LCD),y)
|
||||
SRC_FILES +=
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += test_extsram.c test_lcd.c
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_SEMC),y)
|
||||
CSRCS += test_extsram.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_LCD),y)
|
||||
CSRCS += test_lcd.c
|
||||
endif
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := test_shell.c
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_ADC),y)
|
||||
SRC_FILES += test_adc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_DAC),y)
|
||||
SRC_FILES += test_dac.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_SEMC),y)
|
||||
SRC_FILES += test_extsram.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_LCD),y)
|
||||
SRC_FILES +=
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
@@ -22,17 +22,11 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <transform.h>
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
|
||||
#ifdef CONFIG_K210_LCD
|
||||
|
||||
#include "nuttx/arch.h"
|
||||
#include "nuttx/lcd/lt768.h"
|
||||
#include "nuttx/lcd/lt768_lib.h"
|
||||
#include "nuttx/lcd/k210_lcd.h"
|
||||
|
||||
void LcdDemo(void)
|
||||
{
|
||||
int x1 = 50, y1 = 50, x2 = LCD_XSIZE_TFT - 50, y2 = LCD_YSIZE_TFT - 50;
|
||||
@@ -72,18 +66,6 @@ void LcdDemo(void)
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/video/fb.h>
|
||||
#include <nuttx/video/rgbcolors.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Preprocessor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
@@ -8,6 +8,14 @@ if ADAPTER_HFA21_WIFI
|
||||
source "$APP_DIR/Framework/connection/wifi/hfa21_wifi/Kconfig"
|
||||
endif
|
||||
|
||||
config ADAPTER_ESP8285_WIFI
|
||||
bool "Using wifi adapter device esp8285"
|
||||
default n
|
||||
|
||||
if ADAPTER_ESP8285_WIFI
|
||||
source "$APP_DIR/Framework/connection/wifi/esp8285_wifi/Kconfig"
|
||||
endif
|
||||
|
||||
config ADAPTER_ESP07S_WIFI
|
||||
bool "Using wifi adapter device esp07s"
|
||||
default n
|
||||
|
||||
@@ -28,6 +28,10 @@ extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter);
|
||||
extern AdapterProductInfoType Esp07sWifiAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#ifdef ADAPTER_ESP8285_WIFI
|
||||
extern AdapterProductInfoType Esp8285WifiAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
static int AdapterWifiRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -91,11 +95,27 @@ int AdapterWifiInit(void)
|
||||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ADAPTER_ESP8285_WIFI
|
||||
AdapterProductInfoType product_info = Esp8285WifiAttach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterWifiInit ESP8285 attach error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
adapter->product_info_flag = 1;
|
||||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/******************wifi TEST*********************/
|
||||
int AdapterWifiTest(void)
|
||||
{
|
||||
@@ -364,7 +384,6 @@ int AdapterWifiTestWithParam(int argc, char *argv[])
|
||||
strcpy(apt_param->wifi_ssid, wifi_param[APT_WIFI_PARAM_SSID]);
|
||||
strcpy(apt_param->wifi_pwd, wifi_param[APT_WIFI_PARAM_PWD]);
|
||||
|
||||
printf("2022-10-14 Mr. Wang commit Wifi\n");
|
||||
printf("apt %p ssid %p %s\n", apt_param, apt_param->wifi_ssid);
|
||||
|
||||
CHECK_RET(AdapterDeviceOpen(adapter));
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
config ADAPTER_WIFI_ESP8285
|
||||
string "ESP8285 WIFI adapter name"
|
||||
default "esp8285_wifi"
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
config ADAPTER_ESP8285_DRIVER
|
||||
string "ESP8285 device uart driver path"
|
||||
default "/dev/ttyS1"
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/connection/wifi/esp8285/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_ADAPTER_ESP8285_WIFI),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/wifi/esp8285_wifi
|
||||
endif
|
||||
@@ -0,0 +1,7 @@
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += esp8285_wifi.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,589 @@
|
||||
/*
|
||||
* 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 ESP8285 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 Esp8285WifiSetDown(struct Adapter *adapter_at);
|
||||
|
||||
/**
|
||||
* @description: check AT startup status
|
||||
* @param at_agent - wifi device agent pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Esp8285WifiTestAtCmd(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 Esp8285UartOpen(struct Adapter *adapter)
|
||||
{
|
||||
if (NULL == adapter) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Open device in read-write mode */
|
||||
adapter->fd = PrivOpen(ADAPTER_ESP8285_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("Esp8285WifiOpen get serial %s fd error\n", ADAPTER_ESP8285_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;
|
||||
cfg.is_ext_uart = 0;
|
||||
#ifdef ADAPTER_ESP8285_DRIVER_EXT_PORT
|
||||
cfg.is_ext_uart = 1;
|
||||
cfg.ext_uart_no = ADAPTER_ESP8285_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("esp8285 uart config ready\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Open wifi
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK, failure: ENOMEMORY
|
||||
*/
|
||||
static int Esp8285WifiOpen(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: open esp8285 serial port*/
|
||||
Esp8285UartOpen(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("Esp8285Wifi open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Close wifi
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Esp8285WifiClose(struct Adapter *adapter)
|
||||
{
|
||||
Esp8285WifiSetDown(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 Esp8285WifiSend(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("Esp8285WifiSend 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 Esp8285WifiReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len)
|
||||
{
|
||||
x_err_t result = EOK;
|
||||
printf("esp8285 receive waiting ... \n");
|
||||
|
||||
if (adapter->agent) {
|
||||
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40);
|
||||
} else {
|
||||
printf("Esp8285WifiReceive can not find agent!\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: connnect wifi to internet
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Esp8285WifiSetUp(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(Esp8285WifiTestAtCmd(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 %d 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 Esp8285WifiSetDown(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 Esp8285WifiSetAddr(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 Esp8285WifiPing(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 Esp8285WifiNetstat(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 %d 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 Esp8285WifiConnect(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) //esp8285 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 Esp8285WifiDisconnect(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 Esp8285WifiIoctl(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;
|
||||
cfg.is_ext_uart = 0;
|
||||
#ifdef ADAPTER_ESP8285_DRIVER_EXT_PORT
|
||||
cfg.is_ext_uart = 1;
|
||||
cfg.ext_uart_no = ADAPTER_ESP8285_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 esp8285_wifi_done =
|
||||
{
|
||||
.open = Esp8285WifiOpen,
|
||||
.close = Esp8285WifiClose,
|
||||
.ioctl = Esp8285WifiIoctl,
|
||||
.setup = Esp8285WifiSetUp,
|
||||
.setdown = Esp8285WifiSetDown,
|
||||
.setaddr = Esp8285WifiSetAddr,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = Esp8285WifiPing,
|
||||
.netstat = Esp8285WifiNetstat,
|
||||
.connect = Esp8285WifiConnect,
|
||||
.send = Esp8285WifiSend,
|
||||
.recv = Esp8285WifiReceive,
|
||||
.disconnect = Esp8285WifiDisconnect,
|
||||
};
|
||||
|
||||
/**
|
||||
* @description: Register wifi device esp8285
|
||||
* @return success: EOK, failure: ERROR
|
||||
*/
|
||||
AdapterProductInfoType Esp8285WifiAttach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info)
|
||||
{
|
||||
printf("Esp8285WifiAttach Attach malloc product_info error\n");
|
||||
PrivFree(product_info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strncpy(product_info->model_name, ADAPTER_WIFI_ESP8285, strlen(ADAPTER_WIFI_ESP8285));
|
||||
|
||||
product_info->model_done = (void *)&esp8285_wifi_done;
|
||||
|
||||
return product_info;
|
||||
}
|
||||
@@ -139,10 +139,30 @@ static int PrivSerialIoctl(int fd, int cmd, void *args)
|
||||
{
|
||||
struct SerialDataCfg *serial_cfg = (struct SerialDataCfg *)args;
|
||||
unsigned long serial_baud_rate = (unsigned long)serial_cfg->serial_baud_rate;
|
||||
struct termios term;
|
||||
|
||||
/* Extended serial port */
|
||||
if(serial_cfg->is_ext_uart == 1)
|
||||
{
|
||||
return ioctl(fd, OPE_INT, serial_baud_rate);
|
||||
}
|
||||
|
||||
/* Standard serial port,only the baud rate is set */
|
||||
else if(serial_cfg->is_ext_uart == 0)
|
||||
{
|
||||
if(ioctl(fd, TCGETS, (unsigned long)&term) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if ((cfsetispeed(&term, serial_baud_rate) < 0) ||(cfsetospeed(&term, serial_baud_rate) < 0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(ioctl(fd, TCSETS, (unsigned long)&term) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,33 @@
|
||||
#include <nuttx/pthread.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <nuttx/wireless/lpwan/sx127x.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/ioexpander/gpio.h>
|
||||
#include <termios.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#ifdef CONFIG_ADAPTER_SX1278
|
||||
#include <nuttx/wireless/lpwan/sx127x.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USER_TEST_LCD
|
||||
#ifdef CONFIG_K210_LCD
|
||||
# include "nuttx/lcd/lt768.h"
|
||||
# include "nuttx/lcd/lt768_lib.h"
|
||||
# include "nuttx/lcd/if_port.h"
|
||||
#else
|
||||
# include <sys/mman.h>
|
||||
# include <nuttx/video/fb.h>
|
||||
# include <nuttx/video/rgbcolors.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
|
||||
Reference in New Issue
Block a user