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
+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");
}