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.
365 lines
11 KiB
365 lines
11 KiB
////////////////////////////////////////////////////////////////////////////
|
|
///@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;
|
|
|
|
#define LEN_GPRS_TCP_PKG 18
|
|
|
|
U8 ins_cipsend[30] = "AT+CIPSEND=000\r\n";
|
|
|
|
U8 * _cipsend_hex(U8 len)
|
|
{
|
|
U8 pos = libc_strlen("AT+CIPSEND=");
|
|
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.debug)
|
|
{
|
|
L0_uart0_sendstr(str);
|
|
}
|
|
}
|
|
|
|
//将数据放入gm35待发送缓冲区
|
|
void L3_gm35_send_data(U8 *buf , U8 len)
|
|
{
|
|
L3_gm35_send_str(_cipsend_hex(len));
|
|
L0_uart4_sendArray(buf,len);
|
|
if(G.debug)
|
|
{
|
|
L0_uart0_sendArray(buf,len);
|
|
}
|
|
}
|
|
|
|
void L3_gm35_rcv_data(U8* buf,U8 num)
|
|
{
|
|
if(G.debug)
|
|
{
|
|
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)
|
|
{
|
|
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.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.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);
|
|
|
|
P55 = 1; //灯灭
|
|
}
|
|
|
|
//------------------------ 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)
|
|
{
|
|
//do sth...
|
|
}
|
|
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();
|
|
}
|
|
|
|
//------------------------ 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()
|
|
{
|
|
L2_task_gm35_daemon_handle(&s_task_gm35_daemon);
|
|
L2_task_gm35_flow_handle(&s_task_gm35_flow);
|
|
}
|
|
|
|
|
|
|
|
|