#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_interface.h"
#include "espconn.h"
#include "key.h"
#include "c_types.h"
#include "time.h"
#include "mem.h"
#include "uart.h"
#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
os_event_t user_procTaskQueue[user_procTaskQueueLen];
// static void loop(os_event_t *events);
LOCAL os_timer_t network_timer;
static volatile os_timer_t some_timer;
extern char cmdBuffer[];
char ssid_str[32] = "CO2";
char pass_str[64] = "co2passwd";
char id_send0_str[8] = "012EF412";
char id_send1_str[8] = "012EF419";
// static void ICACHE_FLASH_ATTR loop(os_event_t *events)
// {
// int c = uart0_rx_one_char();
// if(c == 0x30)
// {
// uart0_tx_buffer("0123456789", 10);
// }
// if(c == 0x31)
// {
// uart0_tx_buffer("9876543210", 10);
// }
// system_os_post(user_procTaskPrio, 0, 0 );
// }
void some_timerfunc(void *arg)
{
//debag i am alive
os_printf("On working! \r\n");
}
char string_search(char *str1,char *str2)
{
unsigned int addr=0,x=0,y=0;
str1+=0;
str2+=0;
while(str1[addr]!=0)
{
addr++;
}
while(str1[y]!=0 && str2[x]!=0)
{
if(str1[y] == str2[x])
{
y++;
x++;
}
else
{
if(y<addr)y=0;
x++; // ��������� ���������� ������� ������� ������
}
//printf("Y=%d,X=%d,ADDR=%d, str1=%c , str2=%c \r\n" , y,x,addr,str1[y] , str2[x]);
}
//printf("Y=%d,X=%d,ADDR=%d\r\n" , y,x,addr);
if(y && (addr==y))return x; // ��������� ���! ���������� ��������� ����� ��������� ������
return 0;
}
void AT_cmd()
{
static char buff_at[64], x=0, timer_at=0;
static char y=0;
////////////////////////
if(string_search("AT+REV?",cmdBuffer))
{
#ifdef PLATFORM_DEBUG
ets_uart_printf("REV1.0 , Autor: Ugrimov A.O. ,\r\nOK\r\n");
clear_buf();
#endif
}
else if(string_search("AT+AP_NSET=",cmdBuffer))
{
x=0;
while(cmdBuffer[x++]!=0)
{
y++;
}
for(x=11; x<y; x++)ssid_str[x-11] = cmdBuffer[x];
//os_memcpy(wifiApConf.ssid, &buff_at, sizeof (buff_at));
data_write();
y=0;
data_read();
#ifdef PLATFORM_DEBUG
ets_uart_printf("wifiApConf=%s \r\n", ssidAp.ssid);
ets_uart_printf("%s \r\n", ssid_str);
ets_uart_printf("NSET OK\r\n");
clear_buf();
#endif
}
else if(string_search("AT+AP_NSET?",cmdBuffer))
{
data_read();
#ifdef PLATFORM_DEBUG
ets_uart_printf("result ssid: %s\n", ssidAp);
#endif
clear_buf();
}
else if(string_search("AT+AP_PSET=",cmdBuffer))
{
#ifdef PLATFORM_DEBUG
ets_uart_printf("PSET OK\r\n");
clear_buf();
#endif
}
else if(string_search("AT+ID0_SET=",cmdBuffer))
{
#ifdef PLATFORM_DEBUG
ets_uart_printf("ID0_SET OK\r\n");
clear_buf();
#endif
}
else if(string_search("AT+ID1_SET=",cmdBuffer))
{
#ifdef PLATFORM_DEBUG
ets_uart_printf("ID1_SET OK\r\n");
clear_buf();
#endif
}
else if(string_search("AT+SDK_VER?",cmdBuffer))
{
#ifdef PLATFORM_DEBUG
ets_uart_printf("SDK version:%s\n OK\r\n", system_get_sdk_version());
#endif
clear_buf();
}
else if(cmdBuffer[0]!=0)// ������� �� �������
{
if(++timer_at>10)
{
#ifdef PLATFORM_DEBUG
ets_uart_printf("ERR_CMD!\r\n");
clear_buf();
#endif
timer_at=0;
}
}
else if(cmdBuffer[0]==0)
{
timer_at=0;
}
}
void ICACHE_FLASH_ATTR user_init()
{
// init gpio subsytem
gpio_init();
//uart_init
uart_init(74400, 74400);
os_printf("\r\n ESP8266 started!\r\n");
wifi_set_opmode(0x00);
os_printf("\r\n Wi-Fi off!\r\n");
// setup timer (500ms, repeating)
os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);
os_timer_arm(&some_timer, 1000, 1);
// system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen);
// system_os_post(user_procTaskPrio, 0, 0 );
}