Added the (possibly modified) Espressif SDK to the project to avoid problems with building. This may not be OK license wise, but who cares

This commit is contained in:
2017-05-28 17:39:17 +02:00
parent c04433b7f5
commit 13564727d9
171 changed files with 23154 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
Notice: AT added some functions so it's larger than before, if you want to compile it, please compile it as 1024KB or larger flash in compilation STEP 5.
1¡¢compile options
(1) COMPILE
Possible value: gcc
Default value:
If not set, use xt-xcc by default.
(2) BOOT
Possible value: none/old/new
none: no need boot
old: use boot_v1.1
new: use boot_v1.2+
Default value: none
(3) APP
Possible value: 0/1/2
0: original mode, generate eagle.app.v6.flash.bin and eagle.app.v6.irom0text.bin
1: generate user1
2: generate user2
Default value: 0
(3) SPI_SPEED
Possible value: 20/26.7/40/80
Default value: 40
(4) SPI_MODE
Possible value: QIO/QOUT/DIO/DOUT
Default value: QIO
(4) SPI_SIZE
Possible value: 0/2/3/4/5/6
Default value: 0
For example:
make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=0
2¡¢You can also use gen_misc to make and generate specific bin you needed.
Linux: ./gen_misc.sh
Windows: gen_misc.bat
Follow the tips and steps.
+149
View File
@@ -0,0 +1,149 @@
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of object file images to be generated ()
# GEN_BINS - list of binaries to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
TARGET = eagle
#FLAVOR = release
FLAVOR = debug
#EXTRA_CCFLAGS += -u
ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin
SPECIAL_MKTARGETS=$(APP_MKTARGETS)
SUBDIRS= \
user
ifdef AT_OPEN_SRC
SUBDIRS += \
at
endif
endif # } PDIR
APPDIR = .
LDDIR = ../ld
CCFLAGS += -Os
TARGET_LDFLAGS = \
-nostdlib \
-Wl,-EL \
--longcalls \
--text-section-literals
ifeq ($(FLAVOR),debug)
TARGET_LDFLAGS += -g -O2
endif
ifeq ($(FLAVOR),release)
TARGET_LDFLAGS += -g -O0
endif
COMPONENTS_eagle.app.v6 = \
user/libuser.a
ifdef AT_OPEN_SRC
COMPONENTS_eagle.app.v6 += \
at/libat.a
endif
LINKFLAGS_eagle.app.v6 = \
-L../lib \
-nostdlib \
-T$(LD_FILE) \
-Wl,--no-check-sections \
-u call_user_start \
-Wl,-static \
-Wl,--start-group \
-lc \
-lgcc \
-lhal \
-lphy \
-lpp \
-lnet80211 \
-llwip \
-lwpa \
-lcrypto \
-lmain \
-ljson \
-lupgrade \
-lssl \
-lwps \
-lsmartconfig \
-lairkiss \
$(DEP_LIBS_eagle.app.v6)
ifndef AT_OPEN_SRC
LINKFLAGS_eagle.app.v6 += \
-lat
endif
LINKFLAGS_eagle.app.v6 += \
-Wl,--end-group
DEPENDS_eagle.app.v6 = \
$(LD_FILE) \
$(LDDIR)/eagle.rom.addr.v6.ld
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#UNIVERSAL_TARGET_DEFINES = \
# Other potential configuration flags include:
# -DTXRX_TXBUF_DEBUG
# -DTXRX_RXBUF_DEBUG
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -DICACHE_FLASH
ifdef AT_OPEN_SRC
CONFIGURATION_DEFINES += \
-DAT_OPEN_SRC
endif
ifeq ($(APP),0)
else
CONFIGURATION_DEFINES += \
-DAT_UPGRADE_SUPPORT
endif
DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
DDEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
.PHONY: FORCE
FORCE:
+147
View File
@@ -0,0 +1,147 @@
@echo off
echo gen_misc.bat version 20150511
echo .
echo Please follow below steps(1-5) to generate specific bin(s):
echo STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none)
set input=default
set /p input=enter(0/1/2, default 2):
if %input% equ 0 (
set boot=old
) else (
if %input% equ 1 (
set boot=new
) else (
set boot=none
)
)
echo boot mode: %boot%
echo.
echo STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin)
set input=default
set /p input=enter (0/1/2, default 0):
if %input% equ 1 (
if %boot% equ none (
set app=0
echo choose no boot before
echo generate bin: eagle.flash.bin+eagle.irom0text.bin
) else (
set app=1
echo generate bin: user1.bin
)
) else (
if %input% equ 2 (
if %boot% equ none (
set app=0
echo choose no boot before
echo generate bin: eagle.flash.bin+eagle.irom0text.bin
) else (
set app=2
echo generate bin: user2.bin
)
) else (
if %boot% neq none (
set boot=none
echo ignore boot
)
set app=0
echo generate bin: eagle.flash.bin+eagle.irom0text.bin
))
echo.
echo STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz)
set input=default
set /p input=enter (0/1/2/3, default 2):
if %input% equ 0 (
set spi_speed=20
) else (
if %input% equ 1 (
set spi_speed=26.7
) else (
if %input% equ 3 (
set spi_speed=80
) else (
set spi_speed=40
)))
echo spi speed: %spi_speed% MHz
echo.
echo STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT)
set input=default
set /p input=enter (0/1/2/3, default 0):
if %input% equ 1 (
set spi_mode=QOUT
) else (
if %input% equ 2 (
set spi_mode=DIO
) else (
if %input% equ 3 (
set spi_mode=DOUT
) else (
set spi_mode=QIO
)))
echo spi mode: %spi_mode%
echo.
echo STEP 5: choose flash size and map
echo 0= 512KB( 256KB+ 256KB)
echo 2=1024KB( 512KB+ 512KB)
echo 3=2048KB( 512KB+ 512KB)
echo 4=4096KB( 512KB+ 512KB)
echo 5=2048KB(1024KB+1024KB)
echo 6=4096KB(1024KB+1024KB)
set input=default
set /p input=enter (0/1/2/3/4/5/6, default 0):
if %input% equ 2 (
set spi_size_map=2
echo spi size: 1024KB
echo spi ota map: 512KB + 512KB
) else (
if %input% equ 3 (
set spi_size_map=3
echo spi size: 2048KB
echo spi ota map: 512KB + 512KB
) else (
if %input% equ 4 (
set spi_size_map=4
echo spi size: 4096KB
echo spi ota map: 512KB + 512KB
) else (
if %input% equ 5 (
set spi_size_map=5
echo spi size: 2048KB
echo spi ota map: 1024KB + 1024KB
) else (
if %input% equ 6 (
set spi_size_map=6
echo spi size: 4096KB
echo spi ota map: 1024KB + 1024KB
) else (
set spi_size_map=0
echo spi size: 512KB
echo spi ota map: 256KB + 256KB
)
)
)
)
)
touch user/user_main.c
echo.
echo start...
echo.
make BOOT=%boot% APP=%app% SPI_SPEED=%spi_speed% SPI_MODE=%spi_mode% SPI_SIZE=%spi_size_map%
+150
View File
@@ -0,0 +1,150 @@
#!/bin/bash
echo "gen_misc.sh version 20150511"
echo ""
echo "Please follow below steps(1-5) to generate specific bin(s):"
echo "STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none)"
echo "enter(0/1/2, default 2):"
read input
if [ -z "$input" ]; then
boot=none
elif [ $input == 0 ]; then
boot=old
elif [ $input == 1 ]; then
boot=new
else
boot=none
fi
echo "boot mode: $boot"
echo ""
echo "STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin)"
echo "enter (0/1/2, default 0):"
read input
if [ -z "$input" ]; then
if [ $boot != none ]; then
boot=none
echo "ignore boot"
fi
app=0
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
elif [ $input == 1 ]; then
if [ $boot == none ]; then
app=0
echo "choose no boot before"
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
else
app=1
echo "generate bin: user1.bin"
fi
elif [ $input == 2 ]; then
if [ $boot == none ]; then
app=0
echo "choose no boot before"
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
else
app=2
echo "generate bin: user2.bin"
fi
else
if [ $boot != none ]; then
boot=none
echo "ignore boot"
fi
app=0
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
fi
echo ""
echo "STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz)"
echo "enter (0/1/2/3, default 2):"
read input
if [ -z "$input" ]; then
spi_speed=40
elif [ $input == 0 ]; then
spi_speed=20
elif [ $input == 1 ]; then
spi_speed=26.7
elif [ $input == 3 ]; then
spi_speed=80
else
spi_speed=40
fi
echo "spi speed: $spi_speed MHz"
echo ""
echo "STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT)"
echo "enter (0/1/2/3, default 0):"
read input
if [ -z "$input" ]; then
spi_mode=QIO
elif [ $input == 1 ]; then
spi_mode=QOUT
elif [ $input == 2 ]; then
spi_mode=DIO
elif [ $input == 3 ]; then
spi_mode=DOUT
else
spi_mode=QIO
fi
echo "spi mode: $spi_mode"
echo ""
echo "STEP 5: choose spi size and map"
echo " 0= 512KB( 256KB+ 256KB)"
echo " 2=1024KB( 512KB+ 512KB)"
echo " 3=2048KB( 512KB+ 512KB)"
echo " 4=4096KB( 512KB+ 512KB)"
echo " 5=2048KB(1024KB+1024KB)"
echo " 6=4096KB(1024KB+1024KB)"
echo "enter (0/2/3/4/5/6, default 0):"
read input
if [ -z "$input" ]; then
spi_size_map=0
echo "spi size: 512KB"
echo "spi ota map: 256KB + 256KB"
elif [ $input == 2 ]; then
spi_size_map=2
echo "spi size: 1024KB"
echo "spi ota map: 512KB + 512KB"
elif [ $input == 3 ]; then
spi_size_map=3
echo "spi size: 2048KB"
echo "spi ota map: 512KB + 512KB"
elif [ $input == 4 ]; then
spi_size_map=4
echo "spi size: 4096KB"
echo "spi ota map: 512KB + 512KB"
elif [ $input == 5 ]; then
spi_size_map=5
echo "spi size: 2048KB"
echo "spi ota map: 1024KB + 1024KB"
elif [ $input == 6 ]; then
spi_size_map=6
echo "spi size: 4096KB"
echo "spi ota map: 1024KB + 1024KB"
else
spi_size_map=0
echo "spi size: 512KB"
echo "spi ota map: 256KB + 256KB"
fi
echo ""
touch user/user_main.c
echo ""
echo "start..."
echo ""
make COMPILE=gcc BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map
@@ -0,0 +1,12 @@
#ifndef __USER_CONFIG_H__
#define __USER_CONFIG_H__
#define AT_CUSTOM_UPGRADE
#ifdef AT_CUSTOM_UPGRADE
#ifndef AT_UPGRADE_SUPPORT
#error "upgrade is not supported when eagle.flash.bin+eagle.irom0text.bin!!!"
#endif
#endif
#endif
+45
View File
@@ -0,0 +1,45 @@
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = libuser.a
endif
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../../include/ets
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
+290
View File
@@ -0,0 +1,290 @@
/******************************************************************************
* Copyright 2015-2018 Espressif Systems (Wuxi)
*
* FileName: user_main.c
*
* Description: entry file of user application
*
* Modification history:
* 2015/3/06, v1.0 create this file.
*******************************************************************************/
#include "c_types.h"
#include "user_interface.h"
#include "espconn.h"
#include "mem.h"
#include "osapi.h"
#include "upgrade.h"
#ifdef AT_UPGRADE_SUPPORT
#ifdef AT_CUSTOM_UPGRADE
#define UPGRADE_FRAME "{\"path\": \"/v1/messages/\", \"method\": \"POST\", \"meta\": {\"Authorization\": \"token %s\"},\
\"get\":{\"action\":\"%s\"},\"body\":{\"pre_rom_version\":\"%s\",\"rom_version\":\"%s\"}}\n"
#define pheadbuffer "Connection: keep-alive\r\n\
Cache-Control: no-cache\r\n\
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 \r\n\
Accept: */*\r\n\
Accept-Encoding: gzip,deflate\r\n\
Accept-Language: zh-CN,eb-US;q=0.8\r\n\r\n"
/**/
struct espconn *pespconn = NULL;
struct upgrade_server_info *upServer = NULL;
static os_timer_t at_delay_check;
static struct espconn *pTcpServer = NULL;
static ip_addr_t host_ip;
/******************************************************************************
* FunctionName : user_esp_platform_upgrade_cb
* Description : Processing the downloaded data from the server
* Parameters : pespconn -- the espconn used to connetion with the host
* Returns : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
at_upDate_rsp(void *arg)
{
struct upgrade_server_info *server = arg;
if(server->upgrade_flag == true)
{
os_printf("device_upgrade_success\r\n");
at_response_ok();
system_upgrade_reboot();
}
else
{
os_printf("device_upgrade_failed\r\n");
at_response_error();
}
os_free(server->url);
server->url = NULL;
os_free(server);
server = NULL;
}
/**
* @brief Tcp client disconnect success callback function.
* @param arg: contain the ip link information
* @retval None
*/
static void ICACHE_FLASH_ATTR
at_upDate_discon_cb(void *arg)
{
struct espconn *pespconn = (struct espconn *)arg;
uint8_t idTemp = 0;
if(pespconn->proto.tcp != NULL)
{
os_free(pespconn->proto.tcp);
}
if(pespconn != NULL)
{
os_free(pespconn);
}
os_printf("disconnect\r\n");
if(system_upgrade_start(upServer) == false)
{
at_response_error();
}
else
{
at_port_print("+CIPUPDATE:4\r\n");
}
}
/**
* @brief Udp server receive data callback function.
* @param arg: contain the ip link information
* @retval None
*/
LOCAL void ICACHE_FLASH_ATTR
at_upDate_recv(void *arg, char *pusrdata, unsigned short len)
{
struct espconn *pespconn = (struct espconn *)arg;
char temp[32] = {0};
uint8_t user_bin[12] = {0};
uint8_t i = 0;
os_timer_disarm(&at_delay_check);
at_port_print("+CIPUPDATE:3\r\n");
upServer = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info));
upServer->upgrade_version[5] = '\0';
upServer->pespconn = pespconn;
os_memcpy(upServer->ip, pespconn->proto.tcp->remote_ip, 4);
upServer->port = pespconn->proto.tcp->remote_port;
upServer->check_cb = at_upDate_rsp;
upServer->check_times = 60000;
if(upServer->url == NULL)
{
upServer->url = (uint8 *) os_zalloc(1024);
}
if(system_upgrade_userbin_check() == UPGRADE_FW_BIN1)
{
os_memcpy(user_bin, "user2.bin", 10);
}
else if(system_upgrade_userbin_check() == UPGRADE_FW_BIN2)
{
os_memcpy(user_bin, "user1.bin", 10);
}
os_sprintf(upServer->url,
"GET /%s HTTP/1.1\r\nHost: "IPSTR"\r\n"pheadbuffer"",
user_bin, IP2STR(upServer->ip));
}
LOCAL void ICACHE_FLASH_ATTR
at_upDate_wait(void *arg)
{
struct espconn *pespconn = arg;
os_timer_disarm(&at_delay_check);
if(pespconn != NULL)
{
espconn_disconnect(pespconn);
}
else
{
at_response_error();
}
}
/******************************************************************************
* FunctionName : user_esp_platform_sent_cb
* Description : Data has been sent successfully and acknowledged by the remote host.
* Parameters : arg -- Additional argument to pass to the callback function
* Returns : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
at_upDate_sent_cb(void *arg)
{
struct espconn *pespconn = arg;
os_timer_disarm(&at_delay_check);
os_timer_setfn(&at_delay_check, (os_timer_func_t *)at_upDate_wait, pespconn);
os_timer_arm(&at_delay_check, 5000, 0);
os_printf("at_upDate_sent_cb\r\n");
}
/**
* @brief Tcp client connect success callback function.
* @param arg: contain the ip link information
* @retval None
*/
static void ICACHE_FLASH_ATTR
at_upDate_connect_cb(void *arg)
{
struct espconn *pespconn = (struct espconn *)arg;
uint8_t user_bin[9] = {0};
char *temp = NULL;
at_port_print("+CIPUPDATE:2\r\n");
espconn_regist_disconcb(pespconn, at_upDate_discon_cb);
espconn_regist_recvcb(pespconn, at_upDate_recv);////////
espconn_regist_sentcb(pespconn, at_upDate_sent_cb);
temp = (uint8 *) os_zalloc(512);
os_sprintf(temp,"GET /v1/device/rom/?is_format_simple=true HTTP/1.0\r\nHost: "IPSTR"\r\n"pheadbuffer"",
IP2STR(pespconn->proto.tcp->remote_ip));
espconn_sent(pespconn, temp, os_strlen(temp));
os_free(temp);
}
/**
* @brief Tcp client connect repeat callback function.
* @param arg: contain the ip link information
* @retval None
*/
static void ICACHE_FLASH_ATTR
at_upDate_recon_cb(void *arg, sint8 errType)
{
struct espconn *pespconn = (struct espconn *)arg;
at_response_error();
if(pespconn->proto.tcp != NULL)
{
os_free(pespconn->proto.tcp);
}
os_free(pespconn);
os_printf("disconnect\r\n");
if(upServer != NULL)
{
os_free(upServer);
upServer = NULL;
}
at_response_error();
}
/******************************************************************************
* FunctionName : upServer_dns_found
* Description : dns found callback
* Parameters : name -- pointer to the name that was looked up.
* ipaddr -- pointer to an ip_addr_t containing the IP address of
* the hostname, or NULL if the name could not be found (or on any
* other error).
* callback_arg -- a user-specified callback argument passed to
* dns_gethostbyname
* Returns : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
upServer_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
{
struct espconn *pespconn = (struct espconn *) arg;
// char temp[32];
if(ipaddr == NULL)
{
at_response_error();
return;
}
at_port_print("+CIPUPDATE:1\r\n");
if(host_ip.addr == 0 && ipaddr->addr != 0)
{
if(pespconn->type == ESPCONN_TCP)
{
os_memcpy(pespconn->proto.tcp->remote_ip, &ipaddr->addr, 4);
espconn_regist_connectcb(pespconn, at_upDate_connect_cb);
espconn_regist_reconcb(pespconn, at_upDate_recon_cb);
espconn_connect(pespconn);
}
}
}
void ICACHE_FLASH_ATTR
at_exeCmdCiupdate(uint8_t id)
{
pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn));
pespconn->type = ESPCONN_TCP;
pespconn->state = ESPCONN_NONE;
pespconn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
pespconn->proto.tcp->local_port = espconn_port();
pespconn->proto.tcp->remote_port = 80;
host_ip.addr = ipaddr_addr("192.168.10.9");
at_port_print("+CIPUPDATE:1\r\n");
os_memcpy(pespconn->proto.tcp->remote_ip, &host_ip.addr, 4);
espconn_regist_connectcb(pespconn, at_upDate_connect_cb);
espconn_regist_reconcb(pespconn, at_upDate_recon_cb);
espconn_connect(pespconn);
}
#endif
#endif
+145
View File
@@ -0,0 +1,145 @@
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_main.c
*
* Description: entry file of user application
*
* Modification history:
* 2015/1/23, v1.0 create this file.
*******************************************************************************/
#include "osapi.h"
#include "at_custom.h"
#include "user_interface.h"
#include "mem.h"
#include "espconn.h"
static struct espconn *at_espconn_demo_espconn_ptr = NULL;
#define AT_ESPCONN_DEMO_BUFFER_SIZE (2920)
static uint8 at_espconn_demo_buffer[AT_ESPCONN_DEMO_BUFFER_SIZE];
static uint32 at_espconn_demo_data_len = 0;
static bool at_espconn_demo_flag = FALSE;
static void ICACHE_FLASH_ATTR
at_espconn_demo_recon_cb(void *arg, sint8 errType)
{
struct espconn *espconn_ptr = (struct espconn *)arg;
os_printf("at demo espconn reconnect\r\n");
at_espconn_demo_flag = FALSE;
espconn_connect(espconn_ptr);
}
// notify at module that espconn has received data
static void ICACHE_FLASH_ATTR
at_espconn_demo_recv(void *arg, char *pusrdata, unsigned short len)
{
at_fake_uart_rx(pusrdata,len);
}
static void ICACHE_FLASH_ATTR
at_espconn_demo_send_cb(void *arg)
{
at_espconn_demo_flag = TRUE;
if(at_espconn_demo_data_len) {
espconn_send(at_espconn_demo_espconn_ptr,at_espconn_demo_buffer,at_espconn_demo_data_len);
at_espconn_demo_data_len = 0;
}
}
static void ICACHE_FLASH_ATTR
at_espconn_demo_discon_cb(void *arg)
{
struct espconn *espconn_ptr = (struct espconn *)arg;
os_printf("at demo espconn disconnected\r\n");
at_espconn_demo_flag = FALSE;
espconn_connect(espconn_ptr);
}
static void ICACHE_FLASH_ATTR
at_espconn_demo_connect_cb(void *arg)
{
os_printf("at demo espconn connected\r\n");
espconn_set_opt((struct espconn*)arg,ESPCONN_COPY);
at_espconn_demo_flag = TRUE;
at_espconn_demo_data_len = 0;
}
static void ICACHE_FLASH_ATTR at_espconn_demo_response(const uint8*data,uint32 length)
{
if((data == NULL) || (length == 0)) {
return;
}
if(at_espconn_demo_flag) {
espconn_send(at_espconn_demo_espconn_ptr,(uint8*)data,length);
at_espconn_demo_flag = FALSE;
} else {
if(length <= (AT_ESPCONN_DEMO_BUFFER_SIZE - at_espconn_demo_data_len)) {
os_memcpy(at_espconn_demo_buffer + at_espconn_demo_data_len,data,length);
at_espconn_demo_data_len += length;
} else {
os_printf("at espconn buffer full\r\n");
}
}
}
static void ICACHE_FLASH_ATTR at_espconn_demo_init(void)
{
uint32 ip = 0;
at_espconn_demo_espconn_ptr = (struct espconn *)os_zalloc(sizeof(struct espconn));
at_espconn_demo_espconn_ptr->type = ESPCONN_TCP;
at_espconn_demo_espconn_ptr->state = ESPCONN_NONE;
at_espconn_demo_espconn_ptr->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
at_espconn_demo_espconn_ptr->proto.tcp->local_port = espconn_port();
at_espconn_demo_espconn_ptr->proto.tcp->remote_port = 8999;
ip = ipaddr_addr("192.168.1.120");
os_memcpy(at_espconn_demo_espconn_ptr->proto.tcp->remote_ip,&ip,sizeof(ip));
espconn_regist_connectcb(at_espconn_demo_espconn_ptr, at_espconn_demo_connect_cb);
espconn_regist_reconcb(at_espconn_demo_espconn_ptr, at_espconn_demo_recon_cb);
espconn_regist_disconcb(at_espconn_demo_espconn_ptr, at_espconn_demo_discon_cb);
espconn_regist_recvcb(at_espconn_demo_espconn_ptr, at_espconn_demo_recv);
espconn_regist_sentcb(at_espconn_demo_espconn_ptr, at_espconn_demo_send_cb);
espconn_connect(at_espconn_demo_espconn_ptr);
at_fake_uart_enable(TRUE,at_espconn_demo_response);
}
static void ICACHE_FLASH_ATTR
at_exeCmdTest(uint8_t id)
{
at_response_ok();
at_espconn_demo_init();
}
extern void at_exeCmdCiupdate(uint8_t id);
at_funcationType at_custom_cmd[] = {
{"+TEST", 5, NULL, NULL, NULL, at_exeCmdTest},
#ifdef AT_UPGRADE_SUPPORT
{"+CIUPDATE", 9, NULL, NULL, NULL, at_exeCmdCiupdate}
#endif
};
void ICACHE_FLASH_ATTR user_init(void)
{
char buf[64] = {0};
at_customLinkMax = 5;
at_init();
os_sprintf(buf,"compile time:%s %s",__DATE__,__TIME__);
at_set_custom_info(buf);
at_port_print("\r\nready\r\n");
at_cmd_array_regist(&at_custom_cmd[0], sizeof(at_custom_cmd)/sizeof(at_custom_cmd[0]));
at_port_print("\r\n***==================================***");
at_port_print("\r\n*** Welcome to at espconn demo!!! ***");
at_port_print("\r\n*** Please create a TCP Server on PC,***");
at_port_print("\r\n*** then enter command AT+TEST. ***");
at_port_print("\r\n***==================================***\r\n");
}