forked from ccsens_hardware/stc_touch_pen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
715 lines
21 KiB
715 lines
21 KiB
3 years ago
|
////////////////////////////////////////////////////////////////////////////
|
||
|
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
|
||
|
///-------------------------------------------------------------------------
|
||
|
/// @file bsp_test.c.c
|
||
|
/// @brief bsp @ driver config
|
||
|
///-------------------------------------------------------------------------
|
||
|
/// @version 1.0
|
||
|
/// @author CC
|
||
|
/// @date 20180331
|
||
|
/// @note cc_AS_stc02
|
||
|
//////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
#include "app_task_gm35.h"
|
||
|
|
||
|
#include "../clib/bit.h"
|
||
|
#include "../clib/clib.h"
|
||
|
#include "../msp/uart0.h"
|
||
|
|
||
|
#include "../msp/uart4.h"
|
||
|
#include "../app/app_common.h"
|
||
|
#include "../app/app_task_wdt.h"
|
||
|
#include "../app/app_paraid.h"
|
||
|
#include "../app/app_common.h"
|
||
|
|
||
|
struct _at_send_status g_at_send_status;
|
||
|
struct _s_task_gm35_gprs_ s_task_gm35_flow;
|
||
|
struct _s_task_gm35_gprs_ s_task_gm35_daemon;
|
||
|
// struct _s_task_gm35_gprs_ s_task_gm35_send;
|
||
|
struct _s_task_NB_open s_task_nb_open;
|
||
|
int gprs[] = {1,2,3,4};
|
||
|
|
||
|
|
||
|
#define LEN_GPRS_TCP_PKG 18
|
||
|
|
||
|
U8 ins_cipsend[30] = "AT+IPSEND=0,000,";
|
||
|
|
||
|
U8 * _cipsend_hex(U8 len)
|
||
|
{
|
||
|
U8 pos = libc_strlen("AT+IPSEND=0,");
|
||
|
|
||
|
ins_cipsend[pos++] = len % 1000 / 100 + '0';
|
||
|
ins_cipsend[pos++] = len % 100 / 10 + '0';
|
||
|
ins_cipsend[pos++] = len % 10 / 1 + '0';
|
||
|
|
||
|
return ins_cipsend;
|
||
|
}
|
||
|
|
||
|
void L3_gm35_send_str(U8 *str)
|
||
|
{
|
||
|
L0_uart4_sendstr(str);
|
||
|
if(G.runmode == MODE_DEBUG_COMMON)
|
||
|
{
|
||
|
L0_uart0_sendstr(str);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//将数据放入gm35待发送缓冲区
|
||
|
void L3_gm35_send_data(U8 *buf , U8 len)
|
||
|
{
|
||
|
L3_gm35_send_str(_cipsend_hex(len / 2));
|
||
|
L0_uart4_uc('"');
|
||
|
L0_uart4_sendArray(buf,len);
|
||
|
//L0_uart4_uc('A');
|
||
|
L0_uart4_uc('"');
|
||
|
L0_uart4_0d0a();
|
||
|
//L0_uart0_uc('#');
|
||
|
//L0_uart0_sendArray(buf,len);
|
||
|
if(G.runmode == MODE_DEBUG_COMMON)
|
||
|
{
|
||
|
L0_uart0_sendArray(buf,len);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void L3_gm35_rcv_data(U8* buf,U8 num)
|
||
|
{
|
||
|
if(G.runmode == MODE_DEBUG_COMMON)
|
||
|
{
|
||
|
L0_uart0_sendstr("ATRCV=");
|
||
|
L0_uart0_uchex(num);
|
||
|
L0_uart0_sendArray(buf,num);
|
||
|
}
|
||
|
}
|
||
|
//------------------------------------------------------ gm35 tasks --------------------------------
|
||
|
|
||
|
// void L3_task_gm35_send_init(void)
|
||
|
// {
|
||
|
// L1_task_init(&s_task_gm35_send.task);
|
||
|
// L3_task_s_go(s_task_gm35_send,D_task_init);
|
||
|
// }
|
||
|
|
||
|
void L3_task_gm35_flow_init(void)
|
||
|
{
|
||
|
NB_key = 0;
|
||
|
L1_task_init(&s_task_gm35_flow.task);
|
||
|
L3_task_s_go(s_task_gm35_flow,D_task_init);
|
||
|
g_at_send_status.send_lock = 0;
|
||
|
g_at_send_status.send_ok = 0;
|
||
|
g_at_send_status.module_ok = 0;
|
||
|
g_at_send_status.sim_ok = 0;
|
||
|
g_at_send_status.net_ok = 0;
|
||
|
g_at_send_status.gprs_ok = 0;
|
||
|
g_at_send_status.conn_ok = 0;
|
||
|
g_at_send_status.return_off_ok = 0;
|
||
|
g_at_send_status.print_ok = 0;
|
||
|
g_at_send_status.send_num = 0;
|
||
|
g_at_send_status.ins_stmp = 0; //每次发送指令时设置
|
||
|
|
||
|
g_at_send_status.heart_stmp = 0; //连接成功时设置
|
||
|
g_at_send_status.data_stmp = 0;
|
||
|
g_at_send_status.sign_flag = 0;
|
||
|
g_at_send_status.ack_flag = 0;
|
||
|
|
||
|
g_at_send_status.gprs_last_recv_stmp = 0; //接收到指令时设置
|
||
|
g_at_send_status.tcp_last_recv_stmp = 0; //连接成功和接收到数据时设置
|
||
|
g_at_send_status.tcp_close_stmp = 0; //重新上电和检测到断开时设置
|
||
|
g_at_send_status.gm35_reboot_times = 0; //连接成功时清0
|
||
|
}
|
||
|
|
||
|
void L3_task_gm35_daemon_init(void)
|
||
|
{
|
||
|
L1_task_init(&s_task_gm35_daemon.task);
|
||
|
L3_task_s_go(s_task_gm35_daemon,D_task_init);
|
||
|
L3_task_s_go(s_task_nb_open,D_task_init);
|
||
|
|
||
|
P55 = 1; //灯灭
|
||
|
}
|
||
|
|
||
|
|
||
|
//------------------------ NB模块开机-----------------------------------
|
||
|
#define TTSS_TASK_NB_PWR_H 0x01
|
||
|
#define TTSS_TASK_NB_PWR_L 0x02
|
||
|
|
||
|
void L3_task_NB_open(struct _s_task_NB_open *s)
|
||
|
{
|
||
|
TTSS_Task_init()
|
||
|
L2_task_go(TTSS_TASK_NB_PWR_H);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_NB_PWR_H)
|
||
|
NB_key = 1;
|
||
|
L2_task_go_Tdelay(TTSS_TASK_NB_PWR_L,D_Tdelay_2s); //拉高2s
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_NB_PWR_L)
|
||
|
NB_key = 0;
|
||
|
|
||
|
TTSS_Task_end();
|
||
|
}
|
||
|
|
||
|
#if 0
|
||
|
|
||
|
//------------------------ GM35 Daemon Handle -----------------------------------
|
||
|
#define TTSS_TASK_GM35_DAEMON_CIPSTATUS 0x01
|
||
|
#define TTSS_TASK_GM35_DAEMON_JUDGE 0x02
|
||
|
#define TTSS_TASK_GM35_DAEMON_CLOSE0 0x03
|
||
|
#define TTSS_TASK_GM35_DAEMON_REBOOT0 0x04
|
||
|
#define TTSS_TASK_GM35_DAEMON_REBOOT1 0x05
|
||
|
#define TTSS_TASK_GM35_DAEMON_REBOOT2 0x06
|
||
|
#define TTSS_TASK_BOARD_REBOOT 0x0A
|
||
|
|
||
|
#define GPRS_MAX_IDLE 20
|
||
|
#define TCP_MAX_IDLE 130
|
||
|
#define TCP_MAX_DISCONN 120
|
||
|
#define TCP_MAX_GM35_REBOOT_TIMES 3
|
||
|
|
||
|
void L2_task_gm35_daemon_handle(struct _s_task_gm35_gprs_ *s)
|
||
|
{
|
||
|
TTSS_Task_init();
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_10s);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_DAEMON_CIPSTATUS)
|
||
|
L3_gm35_send_str(AT_INS_CIPSTATUS);
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_JUDGE,D_Tdelay_2s);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_DAEMON_JUDGE)
|
||
|
if(1 == g_at_send_status.conn_ok) //已连接
|
||
|
{
|
||
|
P55 = 0; //灯亮
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.gprs_last_recv_stmp > GPRS_MAX_IDLE) //连续GPRS_MAX_IDLE秒没有收到 AT指令
|
||
|
{
|
||
|
//关闭连接
|
||
|
g_at_send_status.conn_ok = 0;
|
||
|
}
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.tcp_last_recv_stmp > TCP_MAX_IDLE) //连续TCP_MAX_IDLE秒没有收到 协议数据
|
||
|
{
|
||
|
//关闭连接
|
||
|
g_at_send_status.conn_ok = 0;
|
||
|
L3_gm35_send_str(AT_INS_CLOSED);
|
||
|
}
|
||
|
}
|
||
|
else //未连接
|
||
|
{
|
||
|
P55 = 1; //灯灭
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.tcp_close_stmp > TCP_MAX_DISCONN)
|
||
|
{
|
||
|
L0_uart0_uc('>');
|
||
|
if(++g_at_send_status.gm35_reboot_times >= TCP_MAX_GM35_REBOOT_TIMES)
|
||
|
{
|
||
|
L2_do_board_reset();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
L2_do_gm35_reset();
|
||
|
g_at_send_status.tcp_close_stmp = s_nos_tick.t_1s;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_10s);
|
||
|
TTSS_Task_end();
|
||
|
}
|
||
|
|
||
|
//------------------------ GM35 Flow Handle -----------------------------------
|
||
|
|
||
|
#define TTSS_TASK_GM35_FLOW_ATEQV 0x01
|
||
|
#define TTSS_TASK_GM35_FLOW_ATEQV_WAIT 0x02
|
||
|
#define TTSS_TASK_GM35_FLOW_CCID 0x03
|
||
|
#define TTSS_TASK_GM35_FLOW_CCID_WAIT 0x04
|
||
|
#define TTSS_TASK_GM35_FLOW_CREG 0x05
|
||
|
#define TTSS_TASK_GM35_FLOW_CREG_WAIT 0x06
|
||
|
#define TTSS_TASK_GM35_FLOW_GPRS 0x07
|
||
|
#define TTSS_TASK_GM35_FLOW_GPRS_WAIT 0x08
|
||
|
#define TTSS_TASK_GM35_FLOW_CIPSTART 0x09
|
||
|
#define TTSS_TASK_GM35_FLOW_CIPSTART_WAIT 0x0A
|
||
|
#define TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS 0x0B
|
||
|
|
||
|
#define INS_TIMEOUT 2
|
||
|
#define GM35_SEND_DATA_INTERVAL 300
|
||
|
#define GM35_SEND_HEART_INTERVAL 60
|
||
|
#define GM35_SEND_CIPSTATUS_INTERVAL 5
|
||
|
|
||
|
void L2_task_gm35_flow_handle(struct _s_task_gm35_gprs_ *s)
|
||
|
{
|
||
|
TTSS_Task_init()
|
||
|
//data init;
|
||
|
G.boardstatus.a9RecvDataInterval = 0;
|
||
|
G.boardstatus.a9Status = 0;
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_ATEQV,D_Tdelay_10s);//上电等待10s
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_ATEQV)
|
||
|
L3_gm35_send_str(AT_INS_ATEQV);
|
||
|
g_at_send_status.module_ok = 0;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_ATEQV_WAIT,D_Tdelay_300ms); //指令发送完毕等待300ms
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_ATEQV_WAIT)
|
||
|
if(1 == g_at_send_status.module_ok)
|
||
|
{
|
||
|
G.boardstatus.a9Status = STATUS_GM35_MODULE_OK;//修改状态
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CCID,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_ATEQV,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_ATEQV_WAIT,D_Tdelay_300ms);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CCID)
|
||
|
L3_gm35_send_str(AT_INS_CCID);
|
||
|
g_at_send_status.sim_ok = 0;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CCID_WAIT,D_Tdelay_300ms); //指令发送完毕等待300ms
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CCID_WAIT)
|
||
|
if(1 == g_at_send_status.sim_ok)
|
||
|
{
|
||
|
//Lc_print_buf("ccid: %s,",G.ccid);
|
||
|
L0_uart0_uc('C');
|
||
|
L0_uart0_sendArray(G.ccid,20);
|
||
|
Lc_delay_ms(100);// 2000--7s
|
||
|
L0_uart0_uc('S');
|
||
|
L0_uart0_sendArray(G.ccid_passwd,21);
|
||
|
//Lc_print_buf("%s\r\n",G.ccid_passwd);
|
||
|
|
||
|
G.boardstatus.a9Status = STATUS_GM35_SIM_OK;//修改状态
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CREG,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CCID,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CCID_WAIT,D_Tdelay_300ms);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CREG)
|
||
|
L3_gm35_send_str(AT_INS_CREG);
|
||
|
g_at_send_status.net_ok = 0;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CREG_WAIT,D_Tdelay_300ms); //指令发送完毕等待300ms
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CREG_WAIT)
|
||
|
if(1 == g_at_send_status.net_ok)
|
||
|
{
|
||
|
G.boardstatus.a9Status = STATUS_GM35_NET_OK;//修改状态
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_GPRS,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CREG,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CREG_WAIT,D_Tdelay_300ms);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_GPRS)
|
||
|
L3_gm35_send_str(AT_INS_GPRS);
|
||
|
g_at_send_status.gprs_ok = 0;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_GPRS_WAIT,D_Tdelay_300ms); //指令发送完毕等待300ms
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_GPRS_WAIT)
|
||
|
if(1 == g_at_send_status.gprs_ok)
|
||
|
{
|
||
|
G.boardstatus.a9Status = STATUS_GM35_GPRS_OK;//修改状态
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_GPRS,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_GPRS_WAIT,D_Tdelay_300ms);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CIPSTART)
|
||
|
L3_gm35_send_str(AT_INS_CIPSTART);
|
||
|
g_at_send_status.conn_ok = 0;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART_WAIT,D_Tdelay_300ms); //指令发送完毕等待300ms
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CIPSTART_WAIT)
|
||
|
if(1 == g_at_send_status.conn_ok)
|
||
|
{
|
||
|
g_at_send_status.heart_stmp = s_nos_tick.t_1s;
|
||
|
g_at_send_status.data_stmp = s_nos_tick.t_1s;//连接成功后立刻发送账号密码
|
||
|
g_at_send_status.sign_flag = 1;
|
||
|
g_at_send_status.ack_flag = 0;
|
||
|
g_at_send_status.tcp_last_recv_stmp = s_nos_tick.t_1s; //设置数据接收时间
|
||
|
g_at_send_status.tcp_conn_stmp = s_nos_tick.t_1s; //记录连接时间
|
||
|
G.boardstatus.a9Status = STATUS_GM35_TCP_OK;//修改状态
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART,0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART_WAIT,D_Tdelay_300ms);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS)
|
||
|
if(1 == g_at_send_status.conn_ok)
|
||
|
{
|
||
|
if(g_at_send_status.sign_flag == 1) //发送登陆包
|
||
|
{
|
||
|
L0_uart0_uc('l');
|
||
|
g_at_send_status.sign_flag = 0; //只发一次
|
||
|
L2_gprs_send_signin_pkg();
|
||
|
}
|
||
|
|
||
|
else if(g_at_send_status.ack_flag == 1)
|
||
|
{
|
||
|
L0_uart0_uc('z');
|
||
|
g_at_send_status.ack_flag = 0;
|
||
|
L2_gprs_send_ack_pkg();
|
||
|
}
|
||
|
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.heart_stmp >= GM35_SEND_HEART_INTERVAL) //每隔60s发送心跳
|
||
|
{
|
||
|
L0_uart0_uc('x');
|
||
|
g_at_send_status.heart_stmp = s_nos_tick.t_1s;
|
||
|
L2_gprs_send_heart_pkg();
|
||
|
}
|
||
|
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.data_stmp >= GM35_SEND_DATA_INTERVAL) //每隔300s发送数据
|
||
|
{
|
||
|
L0_uart0_uc('y');
|
||
|
g_at_send_status.data_stmp = s_nos_tick.t_1s;
|
||
|
L2_gprs_send_report_pkg();
|
||
|
}
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS,D_Tdelay_1s);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
g_at_send_status.tcp_close_stmp = s_nos_tick.t_1s;
|
||
|
g_at_send_status.gm35_reboot_times = 0;
|
||
|
//L0_uart4_uc(0x1a); //关闭send
|
||
|
L2_task_go_Tdelay(D_task_init,D_Tdelay_100ms); //重新连接、初始化数据
|
||
|
}
|
||
|
|
||
|
TTSS_Task_end();
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
//------------------------ GM35 Daemon Handle -----------------------------------
|
||
|
#define TTSS_TASK_GM35_DAEMON_CIPSTATUS 0x01
|
||
|
#define TTSS_TASK_GM35_DAEMON_JUDGE 0x02
|
||
|
#define TTSS_TASK_GM35_DAEMON_CLOSE0 0x03
|
||
|
#define TTSS_TASK_GM35_DAEMON_REBOOT0 0x04
|
||
|
#define TTSS_TASK_GM35_DAEMON_REBOOT1 0x05
|
||
|
#define TTSS_TASK_GM35_DAEMON_REBOOT2 0x06
|
||
|
#define TTSS_TASK_BOARD_REBOOT 0x0A
|
||
|
|
||
|
#define GPRS_MAX_IDLE 20
|
||
|
#define TCP_MAX_IDLE 130
|
||
|
#define TCP_MAX_DISCONN 120
|
||
|
#define TCP_MAX_GM35_REBOOT_TIMES 3
|
||
|
|
||
|
void L2_task_gm35_daemon_handle(struct _s_task_gm35_gprs_ *s)
|
||
|
{
|
||
|
TTSS_Task_init();
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_10s);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_DAEMON_CIPSTATUS)
|
||
|
L3_gm35_send_str(AT_INS_CIPSTATUS);
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_JUDGE,D_Tdelay_2s);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_DAEMON_JUDGE)
|
||
|
if(1 == g_at_send_status.conn_ok) //已连接
|
||
|
{
|
||
|
P55 = 0; //灯亮
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.gprs_last_recv_stmp > GPRS_MAX_IDLE) //连续GPRS_MAX_IDLE秒没有收到 AT指令
|
||
|
{
|
||
|
//关闭连接
|
||
|
g_at_send_status.conn_ok = 0;
|
||
|
}
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.tcp_last_recv_stmp > TCP_MAX_IDLE) //连续TCP_MAX_IDLE秒没有收到 协议数据
|
||
|
{
|
||
|
//关闭连接
|
||
|
g_at_send_status.conn_ok = 0;
|
||
|
L3_gm35_send_str(AT_INS_CLOSED);
|
||
|
}
|
||
|
}
|
||
|
else //未连接
|
||
|
{
|
||
|
P55 = 1; //灯灭
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.tcp_close_stmp > TCP_MAX_DISCONN)
|
||
|
{
|
||
|
L0_uart0_uc('>');
|
||
|
if(++g_at_send_status.gm35_reboot_times >= TCP_MAX_GM35_REBOOT_TIMES)
|
||
|
{
|
||
|
L2_do_board_reset();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
L2_do_gm35_reset();
|
||
|
g_at_send_status.tcp_close_stmp = s_nos_tick.t_1s;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_10s);
|
||
|
TTSS_Task_end();
|
||
|
}
|
||
|
|
||
|
#if 1
|
||
|
//------------------------ NB Flow Handle -----------------------------------
|
||
|
|
||
|
#define TTSS_TASK_GM35_FLOW_ATEQV 0x01
|
||
|
#define TTSS_TASK_GM35_FLOW_ATEQV_WAIT 0x02
|
||
|
#define TTSS_TASK_GM35_FLOW_CCID 0x03
|
||
|
#define TTSS_TASK_GM35_FLOW_CCID_WAIT 0x04
|
||
|
#define TTSS_TASK_GM35_FLOW_CREG 0x05
|
||
|
#define TTSS_TASK_GM35_FLOW_CREG_WAIT 0x06
|
||
|
#define TTSS_TASK_GM35_FLOW_GPRS 0x07
|
||
|
#define TTSS_TASK_GM35_FLOW_GPRS_WAIT 0x08
|
||
|
#define TTSS_TASK_GM35_FLOW_CIPSTART 0x09
|
||
|
#define TTSS_TASK_GM35_FLOW_CIPSTART_WAIT 0x0A
|
||
|
#define TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS 0x0B
|
||
|
#define TTSS_TASK_BOARD_OFF_RETURN 0x0C
|
||
|
#define TTSS_TASK_BOARD_OFF_RETURN_WAIT 0x0D
|
||
|
#define TTSS_TASK_BOARD_UART_PRINT 0x0E
|
||
|
#define TTSS_TASK_BOARD_UART_PRINT_WAIT 0x0F
|
||
|
#define TTSS_TASK 0x10
|
||
|
#define TTSS_TASK1 0x11
|
||
|
#define TTSS_TASK2 0x12
|
||
|
#define TTSS_TASK_BOARD_WORK_LED 0x13
|
||
|
#define TTSS_TASK_BOARD_NET_LED 0x14
|
||
|
|
||
|
|
||
|
#define INS_TIMEOUT 2
|
||
|
#define GM35_SEND_DATA_INTERVAL 300
|
||
|
#define GM35_SEND_HEART_INTERVAL 60
|
||
|
#define GM35_SEND_CIPSTATUS_INTERVAL 5
|
||
|
|
||
|
void L2_task_gm35_flow_handle(struct _s_task_gm35_gprs_ *s)
|
||
|
{
|
||
|
TTSS_Task_init()
|
||
|
//data init;
|
||
|
G.boardstatus.a9RecvDataInterval = 0;
|
||
|
G.boardstatus.a9Status = 0;
|
||
|
L2_task_go_Tdelay(TTSS_TASK_BOARD_OFF_RETURN,D_Tdelay_5s);//上电等待10s
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_BOARD_OFF_RETURN)//发送关闭回显指令
|
||
|
L3_gm35_send_str(AT_OFFRX);
|
||
|
L2_task_go_Tdelay(TTSS_TASK_BOARD_UART_PRINT,D_Tdelay_2s);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_BOARD_UART_PRINT)//发送串口接收数据指令
|
||
|
L3_gm35_send_str(AT_PRINT);
|
||
|
L2_task_go_Tdelay(TTSS_TASK_BOARD_WORK_LED,D_Tdelay_2s);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_BOARD_WORK_LED)//打开工作状态指示灯
|
||
|
L3_gm35_send_str(AT_WORK_LED);
|
||
|
L2_task_go_Tdelay(TTSS_TASK_BOARD_NET_LED,D_Tdelay_2s);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_BOARD_NET_LED)//打开网络指示灯
|
||
|
L3_gm35_send_str(AT_NET_LED);
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_ATEQV,D_Tdelay_2s);
|
||
|
|
||
|
#if 0
|
||
|
TTSS_Task_step(TTSS_TASK1)//AT
|
||
|
L3_gm35_send_str(AT_INS_ATEQV);
|
||
|
L2_task_go_Tdelay(TTSS_TASK2,D_Tdelay_2s);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK2)//tcp
|
||
|
L3_gm35_send_str(AT_INS_CIPSTART);
|
||
|
L2_task_go_Tdelay(TTSS_TASK,D_Tdelay_2s);
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK)
|
||
|
if(s_nos_tick.t_1s - g_at_send_status.heart_stmp >= GM35_SEND_HEART_INTERVAL) //每隔60s发送心跳
|
||
|
{
|
||
|
L0_uart0_uc('x');
|
||
|
g_at_send_status.heart_stmp = s_nos_tick.t_1s;
|
||
|
L3_gm35_send_str(AT_INS_CSQ);
|
||
|
L3_gm35_send_str(AT_INS_CREG);
|
||
|
L2_gprs_send_signin_pkg();
|
||
|
}
|
||
|
L2_task_go_Tdelay(TTSS_TASK,D_Tdelay_1s);
|
||
|
#endif
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_ATEQV)
|
||
|
if(g_at_send_status.send_ok == 0)
|
||
|
{
|
||
|
L3_gm35_send_str(AT_INS_ATEQV);
|
||
|
g_at_send_status.module_ok = 0;
|
||
|
g_at_send_status.send_ok = 1;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
}
|
||
|
else if(1 == g_at_send_status.module_ok)
|
||
|
{
|
||
|
g_at_send_status.send_ok = 0;
|
||
|
G.boardstatus.a9Status = STATUS_GM35_MODULE_OK;//修改状态
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CCID,D_Tdelay_1s);
|
||
|
}
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
g_at_send_status.send_ok = 0;
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CCID)
|
||
|
if(g_at_send_status.send_ok == 0)
|
||
|
{
|
||
|
L3_gm35_send_str(AT_INS_CCID);
|
||
|
g_at_send_status.sim_ok = 0;
|
||
|
g_at_send_status.send_ok = 1;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
}
|
||
|
else if(1 == g_at_send_status.sim_ok)
|
||
|
{
|
||
|
g_at_send_status.send_ok = 0;
|
||
|
//Lc_print_buf("ccid: %s,",G.ccid);
|
||
|
L0_uart0_uc('C');
|
||
|
L0_uart0_sendArray(G.ccid,20);
|
||
|
Lc_delay_ms(100);// 2000--7s
|
||
|
L0_uart0_uc('S');
|
||
|
L0_uart0_sendArray(G.ccid_passwd,21);
|
||
|
//Lc_print_buf("%s\r\n",G.ccid_passwd);
|
||
|
G.boardstatus.a9Status = STATUS_GM35_SIM_OK;//修改状态
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CREG,D_Tdelay_1s);
|
||
|
}
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
g_at_send_status.send_ok = 0;
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CREG)
|
||
|
if(g_at_send_status.send_ok == 0)
|
||
|
{
|
||
|
L3_gm35_send_str(AT_INS_CREG);
|
||
|
g_at_send_status.net_ok = 0;
|
||
|
g_at_send_status.send_ok = 1;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
}
|
||
|
else if(1 == g_at_send_status.net_ok)
|
||
|
{
|
||
|
g_at_send_status.send_ok = 0;
|
||
|
G.boardstatus.a9Status = STATUS_GM35_NET_OK;//修改状态
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_GPRS,D_Tdelay_1s);
|
||
|
}
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
g_at_send_status.send_ok = 0;
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_GPRS)
|
||
|
if(g_at_send_status.send_ok == 0)
|
||
|
{
|
||
|
L3_gm35_send_str(AT_INS_GPRS);
|
||
|
g_at_send_status.gprs_ok = 0;
|
||
|
g_at_send_status.send_ok = 1;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
}
|
||
|
else if(1 == g_at_send_status.gprs_ok)
|
||
|
{
|
||
|
G.boardstatus.a9Status = STATUS_GM35_GPRS_OK;//修改状态
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART,D_Tdelay_1s);
|
||
|
}
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
g_at_send_status.send_ok = 0;
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CIPSTART)
|
||
|
if(g_at_send_status.send_ok == 0)
|
||
|
{
|
||
|
L3_gm35_send_str(AT_INS_CIPSTART);
|
||
|
g_at_send_status.conn_ok = 0;
|
||
|
g_at_send_status.send_ok = 1;
|
||
|
g_at_send_status.ins_stmp = s_nos_tick.t_1s;
|
||
|
}
|
||
|
else if(1 == g_at_send_status.conn_ok)
|
||
|
{
|
||
|
g_at_send_status.heart_stmp = s_nos_tick.t_1s;
|
||
|
g_at_send_status.data_stmp = s_nos_tick.t_1s;//连接成功后立刻发送账号密码
|
||
|
g_at_send_status.sign_flag = 1;
|
||
|
g_at_send_status.ack_flag = 0;
|
||
|
g_at_send_status.tcp_last_recv_stmp = s_nos_tick.t_1s; //设置数据接收时间
|
||
|
g_at_send_status.tcp_conn_stmp = s_nos_tick.t_1s; //记录连接时间
|
||
|
G.boardstatus.a9Status = STATUS_GM35_TCP_OK;//修改状态
|
||
|
//L2_task_go_Tdelay(TTSS_TASK,0);
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS,0);
|
||
|
}
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.ins_stmp > INS_TIMEOUT)
|
||
|
{
|
||
|
g_at_send_status.send_ok = 0;
|
||
|
}
|
||
|
|
||
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS)
|
||
|
if(1 == g_at_send_status.conn_ok)
|
||
|
{
|
||
|
if(g_at_send_status.sign_flag == 1) //发送登陆包
|
||
|
{
|
||
|
L0_uart0_uc('l');
|
||
|
g_at_send_status.sign_flag = 0; //只发一次
|
||
|
L2_gprs_send_signin_pkg();
|
||
|
}
|
||
|
|
||
|
else if(g_at_send_status.ack_flag == 1)
|
||
|
{
|
||
|
L0_uart0_uc('z');
|
||
|
g_at_send_status.ack_flag = 0;
|
||
|
L2_gprs_send_ack_pkg();
|
||
|
}
|
||
|
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.heart_stmp >= GM35_SEND_HEART_INTERVAL) //每隔60s发送心跳
|
||
|
{
|
||
|
L0_uart0_uc('x');
|
||
|
g_at_send_status.heart_stmp = s_nos_tick.t_1s;
|
||
|
L2_gprs_send_heart_pkg();
|
||
|
}
|
||
|
|
||
|
else if(s_nos_tick.t_1s - g_at_send_status.data_stmp >= GM35_SEND_DATA_INTERVAL) //每隔300s发送数据
|
||
|
{
|
||
|
L0_uart0_uc('y');
|
||
|
g_at_send_status.data_stmp = s_nos_tick.t_1s;
|
||
|
L2_gprs_send_report_pkg();
|
||
|
}
|
||
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS,D_Tdelay_1s);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
g_at_send_status.tcp_close_stmp = s_nos_tick.t_1s;
|
||
|
g_at_send_status.gm35_reboot_times = 0;
|
||
|
//L0_uart4_uc(0x1a); //关闭send
|
||
|
L2_task_go_Tdelay(D_task_init,D_Tdelay_100ms); //重新连接、初始化数据
|
||
|
}
|
||
|
|
||
|
TTSS_Task_end();
|
||
|
}
|
||
|
#endif
|
||
|
//------------------------ GM35 Core Handle -----------------------------------
|
||
|
|
||
|
void L3_task_gm35_core_init(void)
|
||
|
{
|
||
|
L3_task_gm35_daemon_init();
|
||
|
L3_task_gm35_flow_init();
|
||
|
}
|
||
|
|
||
|
void L3_task_gm35_core_handle()
|
||
|
{
|
||
|
L3_task_NB_open(&s_task_nb_open);
|
||
|
L2_task_gm35_daemon_handle(&s_task_gm35_daemon);
|
||
|
L2_task_gm35_flow_handle(&s_task_gm35_flow);
|
||
|
}
|
||
|
|