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.
400 lines
12 KiB
400 lines
12 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";
|
|
|
|
#define GM35_TCP_CIPSEND(x) L0_uart4_sendstr(x); g_at_send_status.send_lock = 1
|
|
#define GM35_TCP_CIPSEND_COMPLETE() g_at_send_status.send_lock = 0
|
|
|
|
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;
|
|
}
|
|
|
|
//将数据放入gm35待发送缓冲区
|
|
void L3_gm35_send(U8 *buf , U8 len)
|
|
{
|
|
//g_at_send_status.tcp_last_send_stmp = s_nos_tick.t_1s;
|
|
int i = 0x20000;
|
|
GM35_TCP_CIPSEND(_cipsend_hex(len));
|
|
while(i--);
|
|
L0_uart4_sendArray(buf,len);
|
|
GM35_TCP_CIPSEND_COMPLETE();
|
|
}
|
|
|
|
|
|
//------------------------------------------------------ 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)
|
|
{
|
|
U8 i = 0;
|
|
|
|
//task init;
|
|
L1_task_init(&s_task_gm35_flow.task);
|
|
L3_task_s_go(s_task_gm35_flow,D_task_init);
|
|
|
|
//data 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.status = STATUS_GM35_INIT;
|
|
|
|
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.heart_flag = 0;
|
|
g_at_send_status.data_flag = 0;
|
|
g_at_send_status.ack_flag = 0;
|
|
|
|
g_at_send_status.ins_flag = 0;
|
|
|
|
g_at_send_status.tcp_close_stmp = s_nos_tick.t_1s; //重新上电和检测到断开时设置
|
|
g_at_send_status.ins_stmp = 0; //每次发送指令时设置
|
|
g_at_send_status.tcp_last_recv_stmp = 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);
|
|
}
|
|
|
|
//------------------------ 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 TCP_MAX_IDLE 130
|
|
#define TCP_MAX_DISCONN 120
|
|
#define GM35_REBOOT_MAXTIMES 10
|
|
|
|
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)
|
|
if(0 == g_at_send_status.send_lock)
|
|
{
|
|
L0_uart4_sendstr(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)
|
|
{
|
|
if(s_nos_tick.t_1s - g_at_send_status.tcp_last_recv_stmp > TCP_MAX_IDLE * 2)
|
|
{
|
|
//g_at_send_status.conn_ok = 0; //强制关闭连接
|
|
//g_at_send_status.tcp_close_stmp = s_nos_tick.t_1s;
|
|
//L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_JUDGE,D_Tdelay_1s);
|
|
|
|
L0_uart0_sendstr("GM35 reboot.");
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_REBOOT0,0); //重启GM35
|
|
}
|
|
else if(s_nos_tick.t_1s - g_at_send_status.tcp_last_recv_stmp > TCP_MAX_IDLE)
|
|
{
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CLOSE0,0); //关闭连接
|
|
}
|
|
else
|
|
{
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_3s);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(g_at_send_status.gm35_reboot_times >= GM35_REBOOT_MAXTIMES)
|
|
{
|
|
L0_uart0_sendstr("Board reboot.");
|
|
g_at_send_status.gm35_reboot_times = 0; //重启需要时间,这里提前设置一下
|
|
|
|
//不写入继电器状态,重启自动回到初始状态
|
|
//L3_flash_write_page0(); //写继电器状态
|
|
L2_task_go_Tdelay(TTSS_TASK_BOARD_REBOOT,0); //重启板卡
|
|
}
|
|
else if(s_nos_tick.t_1s - g_at_send_status.tcp_close_stmp > TCP_MAX_DISCONN)
|
|
{
|
|
L0_uart0_sendstr("GM35 reboot.");
|
|
g_at_send_status.tcp_close_stmp = s_nos_tick.t_1s;
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_REBOOT0,0); //重启GM35
|
|
}
|
|
else
|
|
{
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_3s);
|
|
}
|
|
}
|
|
|
|
TTSS_Task_step(TTSS_TASK_GM35_DAEMON_CLOSE0)
|
|
L0_uart4_sendstr(AT_INS_CLOSED);
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_3s);
|
|
#ifdef BOARD_MAIN04_GM35_M42
|
|
TTSS_Task_step(TTSS_TASK_GM35_DAEMON_REBOOT0)
|
|
//set low
|
|
L2_gm35_disable();
|
|
g_at_send_status.gm35_reboot_times++;
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_REBOOT1,D_Tdelay_1s);
|
|
TTSS_Task_step(TTSS_TASK_GM35_DAEMON_REBOOT1)
|
|
//set high
|
|
L2_gm35_enable();
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_REBOOT2,D_Tdelay_1s);
|
|
#elif defined BOARD_MAIN03_A9
|
|
TTSS_Task_step(TTSS_TASK_GM35_DAEMON_REBOOT0)
|
|
L0_uart4_sendstr(AT_RESET);
|
|
g_at_send_status.gm35_reboot_times++;
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_REBOOT2,D_Tdelay_1s);
|
|
#endif
|
|
|
|
TTSS_Task_step(TTSS_TASK_GM35_DAEMON_REBOOT2)
|
|
L3_task_gm35_flow_init();
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_3s);
|
|
|
|
TTSS_Task_step(TTSS_TASK_BOARD_REBOOT)
|
|
//s_task_wdt.seed_flag = FLAG_WDT_hunger; //饿死看门狗
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_3s);
|
|
|
|
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 10
|
|
#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()
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_ATEQV,D_Tdelay_10s);//上电等待10s
|
|
|
|
TTSS_Task_step(TTSS_TASK_GM35_FLOW_ATEQV)
|
|
L0_uart4_sendstr(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)
|
|
L0_uart4_sendstr(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_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)
|
|
L0_uart4_sendstr(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)
|
|
{
|
|
L0_uart0_sendstr("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)
|
|
L0_uart4_sendstr(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)
|
|
{
|
|
L0_uart0_sendstr("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)
|
|
L0_uart0_uc('L');
|
|
L0_uart0_uc( g_at_send_status.conn_ok + '0');
|
|
L0_uart4_sendstr(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)
|
|
{
|
|
L0_uart0_sendstr("conn ok");
|
|
//L3_task_gm35_send_init(); //初始化发送任务
|
|
|
|
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.heart_flag = 0;
|
|
g_at_send_status.data_flag = 0; //login
|
|
g_at_send_status.ack_flag = 0;
|
|
//g_at_send_status.pending_flag = 0;
|
|
|
|
g_at_send_status.tcp_last_recv_stmp = s_nos_tick.t_1s; //设置数据接收时间
|
|
g_at_send_status.gm35_reboot_times = 0; //gm35重启次数清0
|
|
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(0 == g_at_send_status.conn_ok)
|
|
{
|
|
L0_uart4_uc(0x1a); //关闭send
|
|
L2_task_go_Tdelay(TTSS_TASK_GM35_FLOW_CIPSTART,D_Tdelay_300ms); //断线重连
|
|
}
|
|
|
|
TTSS_Task_end();
|
|
}
|
|
|
|
//------------------------ GM35 Core Handle -----------------------------------
|
|
|
|
void L3_task_gm35_core_init(void)
|
|
{
|
|
g_at_send_status.gm35_reboot_times = 0;
|
|
|
|
//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);
|
|
}
|
|
|
|
|
|
|