diff --git a/keilp/cc_as_stc02_gsm_main.uvproj b/keilp/cc_as_stc02_gsm_main.uvproj index 0d90277..ad5c857 100644 --- a/keilp/cc_as_stc02_gsm_main.uvproj +++ b/keilp/cc_as_stc02_gsm_main.uvproj @@ -416,6 +416,11 @@ 1 ..\source\app\app_task_gm35.c + + app_task_wdt.c + 1 + ..\source\app\app_task_wdt.c + @@ -496,6 +501,11 @@ 1 ..\source\bsp\bsp_relay.c + + bsp_wdt.c + 1 + ..\source\bsp\bsp_wdt.c + diff --git a/si4/soft_gsm_main.si4project/soft_gsm_main.sip_sym b/si4/soft_gsm_main.si4project/soft_gsm_main.sip_sym index c0c880a..a9b59b7 100644 Binary files a/si4/soft_gsm_main.si4project/soft_gsm_main.sip_sym and b/si4/soft_gsm_main.si4project/soft_gsm_main.sip_sym differ diff --git a/si4/soft_gsm_main.si4project/soft_gsm_main.siwork b/si4/soft_gsm_main.si4project/soft_gsm_main.siwork index 190b81f..1e53d54 100644 Binary files a/si4/soft_gsm_main.si4project/soft_gsm_main.siwork and b/si4/soft_gsm_main.si4project/soft_gsm_main.siwork differ diff --git a/source/app/app_common.c b/source/app/app_common.c index a73f447..3551c66 100644 --- a/source/app/app_common.c +++ b/source/app/app_common.c @@ -10,7 +10,7 @@ struct printer_maintenance_global G; U8 ccmodbus_len = 0; -void Lu_register_init() +void L2_register_init() { U8 i = 0; G.p.slaverId = 0x10; @@ -112,10 +112,13 @@ void Lu_register_init() G.flowStartVal = 1; G._keyled = G._rfid = 0; + + G.reset = 0; } void L3_protocol_handler_uart4_fun(U8 *pPara) { +#if 0 if(g_at_send_status.module_ok == 0) { if(StrStartsWith(pPara,"OK")) //module ok @@ -166,4 +169,70 @@ void L3_protocol_handler_uart4_fun(U8 *pPara) g_at_send_status.tcp_close_stmp = s_nos_tick.t_1s; } } -} \ No newline at end of file +#else + if(g_at_send_status.conn_ok == 0) + { + if(StrStartsWith(pPara,"CONNECT OK") || StrStartsWith(pPara,"STATE:CONNECT OK") /*|| StrStartsWith(pPara,"ALREAY")*/ ) //conn ok + { //ALREAY CONNECT不需要判断了,使用AT+CTPSTATUS指令进行查询连接状态 + + L0_uart0_uc('c'); + g_at_send_status.conn_ok = 1; + } + else if(g_at_send_status.module_ok == 0) + { + if(StrStartsWith(pPara,"OK")) //module ok + { + g_at_send_status.module_ok = 1; + } + } + else if(g_at_send_status.sim_ok == 0) + { + if(StrStartsWith(pPara,"+CCID")) //sim ok + { + L0_uart0_uc('s'); + libc_memcpy(G.ccid,pPara+7,20); + getPwd(G.ccid, G.ccid_passwd); + g_at_send_status.sim_ok = 1; + } + } + else if(g_at_send_status.net_ok == 0) + { + if(StrStartsWith(pPara,"+CREG: 1,1")) //net ok + { + L0_uart0_uc('n'); + g_at_send_status.net_ok = 1; + } + } + else if(g_at_send_status.gprs_ok == 0) + { + if(StrStartsWith(pPara,"+CGATT:1")) //gprs ok + { + L0_uart0_uc('g'); + g_at_send_status.gprs_ok = 1; + } + } + } + else + { + if(StrStartsWith(pPara,"CLOSE") || StrStartsWith(pPara,"STATE:CLOSED")) //conn close //CLOSE OK / CLOSED + { + L0_uart0_uc('d'); + g_at_send_status.conn_ok = 0; + } + } +#endif +} + +void L2_do_board_reset(void) +{ + G.reset = 1; //wdt stop feed + GM35_DISABLE(); //gm35 poweroff +} + +void L2_do_gm35_reset(void) +{ + GM35_DISABLE(); //gm35 poweroff + Lc_delay_ms(5000); + GM35_ENABLE(); +} + diff --git a/source/app/app_common.h b/source/app/app_common.h index 8c2d073..9028e72 100644 --- a/source/app/app_common.h +++ b/source/app/app_common.h @@ -6,7 +6,7 @@ #include "../tpc/tpc_modbus.h" #include "../tpc/tpc_ccmodbus.h" -#define APP_VERSION_HEX 0x12 //高4位主版本,低4位次版本 +#define APP_VERSION_HEX 0x20 //高4位主版本,低4位次版本 // #define BOARD_MAIN03_A9 // #define BOARD_MAIN04_GM35 @@ -73,15 +73,6 @@ enum TS_485_OPER #define SLAVER_ID_MAX 0x03 #define SLAVER_ID_N 0xee -typedef struct printer_paper -{ - U8 version; //版本号(板卡对应版本号)APP_VERSION_HEX - vU16 paperNum:10; //10bit纸张数据 表示最大量程1024 实际170张 - vU16 cameraIndex:4; //摄像头编号 - vU16 cameraNotWorking:1; //是否正常工作 - vU16 LowPower:1; // =1 lowPower 提醒需要充电,或者未连接电池 -}TS_P_paper; - typedef struct boardstatus { U8 a9Status; @@ -97,63 +88,6 @@ typedef struct printer_paper_calib U16 angle1; //y1 }TS_PaperCalib; -/** - * 用户协议 - */ -//数据上报协议 -typedef struct printer_report -{ - TS_P_paper papers[PAPER_BOX_NUM-1]; - TS_BoardStatus boardstatus; - U8 ir; -}TS_Printer_Report; - -//校准协议 -typedef struct -{ - U8 no; //paper box no - U8 point; //校准点 - U8 paperNum0; //当前纸张数量高位 - U8 paperNum1; //当前纸张数量低位 -}TS_Paper_Upper_Calib; - -typedef struct -{ - U8 no; //paper box no -}TS_Paper_Upper_Calib_Read; - -typedef struct -{ - U16 num0; //x0 - U16 angle0; //y0 - U16 num1; //x1 - U16 angle1; //y1 -}TS_Paper_Upper_calib_ack; - -//读取当前纸张数量 -typedef struct -{ - U8 no; //paper box no -}TS_Paper_Count; - -typedef struct -{ - U8 no; //paper box no - U8 num[2]; //高位在前 -}TS_Paper_Count_Ack; - -//设置当前angle id -typedef struct -{ - U8 id; //paper box no -}TS_Angle_SetId; - -//gprs相关协议 -typedef struct -{ - U8 version; -}TS_gprs_heart; - /** * Register Memory Map */ @@ -183,7 +117,6 @@ typedef struct cc_asga_info U16 zaxis; }CCAsGaInfo; -#if 1 typedef struct printer_maintenance_global { GlobalNeedPersistParam p; @@ -206,43 +139,14 @@ typedef struct printer_maintenance_global U16 flowStartVal; U8 ccid[21]; //保存ccid卡号空间 20+'\0' - TS_BoardStatus boardstatus; + U8 ccid_passwd[22]; //保存ccid密码空间 21+'\0' + TS_BoardStatus boardstatus; U8 _keyled; U8 _rfid; S32 pi_weight; S32 total_weight; + U8 reset; }PMGlobal; -#else -typedef struct printer_maintenance_global -{ - GlobalNeedPersistParam p; - - S32 jing_weight; - U16 pi_weight; - U16 total_weight; - U16 hold_val; - CCAsGaInfo asga; - U16 rfid; - S32 weight[4]; - //U16 reserved2[16 - 9]; - - MD_SLAVER_INFO md_slaver_info[MD_SLAVER_INFO_MAX]; - CCMD_SLAVER_INFO ccmd_slaver_info[CCMD_SLAVER_INFO_MAX]; - - vU32 modbusstmp; - U16 authed; - U16 flowStarted; - U16 flowStartVal; - - U8 ccid[21]; //保存ccid卡号空间 20+'\0' - TS_BoardStatus boardstatus; - U8 _keyled; - U8 _rfid; - U16 thrombolytic_val; - U16 bolus_val; -}PMGlobal; - -#endif //寄存器内存基地址 #define REG_MEM_BASE ((U16*)(&G)) //寄存器基础地址(本文件外部不应该使用该宏定义) @@ -253,8 +157,10 @@ typedef struct printer_maintenance_global extern struct printer_maintenance_global G; -extern void Lu_register_init(void); +extern void L2_register_init(void); extern void L3_protocol_handler_uart4_fun(U8 *pPara); +extern void L2_do_board_reset(void); +extern void L2_do_gm35_reset(void); #endif diff --git a/source/app/app_drv.c b/source/app/app_drv.c index 25fe836..e01ba03 100644 --- a/source/app/app_drv.c +++ b/source/app/app_drv.c @@ -54,26 +54,23 @@ void L3_UARTcom4_exp_protocol(TS_Handle_0d0a *p) { if (1 == p->ok ) { - #if 1 + #if 0 + //U8 array[D_s_SSTR_0D0A_len+1]; U8 num = p->buf[0]; byte_copy_uc(array,p->buf+1,num); - + array[num] = 0; L3_protocol_handler_uart4_fun(array); + p->ok = 0; #else - if(p->buf[0] > D_s_SSTR_0D0A_len) - { - p->buf[0] = D_s_SSTR_0D0A_len; - } - p->buf[p->buf[0]] = 0; - L3_protocol_handler_uart4_fun(p->buf + 1); - #endif + g_at_send_status.gprs_last_recv_stmp = s_nos_tick.t_1s; + L3_protocol_handler_uart4_fun(p->buf+1); p->ok = 0; + #endif } } - -void L3_UARTcom3_exp_protocol(TS_Handle_PH3 *p) +void L3_UARTcom0_exp_protocol(TS_Handle_PH3 *p) { if (1 == p->ok) { @@ -95,11 +92,25 @@ void L3_UARTcom3_exp_protocol(TS_Handle_PH3 *p) } -void L3_UARTcom0_exp_protocol(TS_Handle_PH3 *p) +void L3_UARTcom3_exp_protocol(TS_Handle_PH3 *p) { if (1 == p->ok) { + #if 0 + TS_PH3_ccmodbus ccmodbus; + byte_copy_uc((U8*)&ccmodbus,(U8*)&p->ts_ccmodbus,p->ts_ccmodbus.num + 3); + if(ccmodbus.buf[0] != G._rfid) //rfid发生改变 + { + G.rfid = G._rfid = ccmodbus.buf[0]; + } + #else + if(p->ts_ccmodbus.buf[0] != G._rfid) //rfid发生改变 + { + G.rfid = G._rfid = p->ts_ccmodbus.buf[0]; + } + #endif p->ok = 0; } } + diff --git a/source/app/app_task_gm35.c b/source/app/app_task_gm35.c index fb63b28..c2a497b 100644 --- a/source/app/app_task_gm35.c +++ b/source/app/app_task_gm35.c @@ -66,34 +66,26 @@ void L3_gm35_send(U8 *buf , U8 len) 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.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.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.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) @@ -111,9 +103,10 @@ void L3_task_gm35_daemon_init(void) #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 GM35_REBOOT_MAXTIMES 10 +#define TCP_MAX_GM35_REBOOT_TIMES 3 void L2_task_gm35_daemon_handle(struct _s_task_gm35_gprs_ *s) { @@ -121,84 +114,43 @@ void L2_task_gm35_daemon_handle(struct _s_task_gm35_gprs_ *s) 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); - } + //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(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) + if(s_nos_tick.t_1s - g_at_send_status.gprs_last_recv_stmp > GPRS_MAX_IDLE) //连续GPRS_MAX_IDLE秒没有收到 AT指令 { - L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CLOSE0,0); //关闭连接 + //关闭连接 + g_at_send_status.conn_ok = 0; } - else + else if(s_nos_tick.t_1s - g_at_send_status.tcp_last_recv_stmp > TCP_MAX_IDLE) //连续TCP_MAX_IDLE秒没有收到 协议数据 { - L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_3s); + //关闭连接 + g_at_send_status.conn_ok = 0; + L0_uart4_sendstr(AT_INS_CLOSED); } } - else + 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 + if(s_nos_tick.t_1s - g_at_send_status.tcp_close_stmp > TCP_MAX_DISCONN) { - L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_3s); + 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; + } } } - - 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); - + L2_task_go_Tdelay(TTSS_TASK_GM35_DAEMON_CIPSTATUS,D_Tdelay_10s); TTSS_Task_end(); } @@ -216,7 +168,7 @@ void L2_task_gm35_daemon_handle(struct _s_task_gm35_gprs_ *s) #define TTSS_TASK_GM35_FLOW_CIPSTART_WAIT 0x0A #define TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS 0x0B -#define INS_TIMEOUT 10 +#define INS_TIMEOUT 2 #define GM35_SEND_DATA_INTERVAL 300 #define GM35_SEND_HEART_INTERVAL 60 #define GM35_SEND_CIPSTATUS_INTERVAL 5 @@ -224,7 +176,10 @@ void L2_task_gm35_daemon_handle(struct _s_task_gm35_gprs_ *s) 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_2s);//上电等待10s + //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) L0_uart4_sendstr(AT_INS_ATEQV); @@ -260,10 +215,11 @@ void L2_task_gm35_flow_handle(struct _s_task_gm35_gprs_ *s) 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); + 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;//修改状态 @@ -290,7 +246,6 @@ void L2_task_gm35_flow_handle(struct _s_task_gm35_gprs_ *s) 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); } @@ -315,7 +270,6 @@ void L2_task_gm35_flow_handle(struct _s_task_gm35_gprs_ *s) 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); } @@ -332,8 +286,6 @@ void L2_task_gm35_flow_handle(struct _s_task_gm35_gprs_ *s) } 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; @@ -342,20 +294,12 @@ void L2_task_gm35_flow_handle(struct _s_task_gm35_gprs_ *s) 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_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); } @@ -374,21 +318,16 @@ void L2_task_gm35_flow_handle(struct _s_task_gm35_gprs_ *s) TTSS_Task_step(TTSS_TASK_GM35_FLOW_CIPSTART_SUCCESS) if(1 == g_at_send_status.conn_ok) { - //连续20s没有收到数据,断线重连 - if(s_nos_tick.t_1s - g_at_send_status.tcp_last_recv_stmp >= 60) //20 - { - L0_uart0_uc('D'); - L0_uart4_sendstr(AT_INS_CLOSED); - g_at_send_status.conn_ok = 0; //等待收到close 自动关闭 - } + //do sth... } - - if(0 == g_at_send_status.conn_ok) + 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(TTSS_TASK_GM35_FLOW_CIPSTART,D_Tdelay_300ms); //断线重连 + L2_task_go_Tdelay(D_task_init,D_Tdelay_100ms); //重新连接、初始化数据 } - + TTSS_Task_end(); } @@ -396,16 +335,15 @@ void L2_task_gm35_flow_handle(struct _s_task_gm35_gprs_ *s) void L3_task_gm35_core_init(void) { - g_at_send_status.gm35_reboot_times = 0; - - //L3_task_gm35_daemon_init(); + 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_daemon_handle(&s_task_gm35_daemon); L2_task_gm35_flow_handle(&s_task_gm35_flow); } + diff --git a/source/app/app_task_gm35.c.1 b/source/app/app_task_gm35.c.1 new file mode 100644 index 0000000..942a8db --- /dev/null +++ b/source/app/app_task_gm35.c.1 @@ -0,0 +1,411 @@ +//////////////////////////////////////////////////////////////////////////// +///@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_2s);//上电等待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(1 == g_at_send_status.conn_ok) + { + //连续20s没有收到数据,断线重连 + if(s_nos_tick.t_1s - g_at_send_status.tcp_last_recv_stmp >= 60) //20 + { + L0_uart0_uc('D'); + L0_uart4_sendstr(AT_INS_CLOSED); + g_at_send_status.conn_ok = 0; //等待收到close 自动关闭 + } + } + + 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); +} + + diff --git a/source/app/app_task_gm35.h b/source/app/app_task_gm35.h index c909e58..26891a8 100644 --- a/source/app/app_task_gm35.h +++ b/source/app/app_task_gm35.h @@ -24,11 +24,9 @@ #define AT_INS_CCID "AT+CCID\r\n" //SIM卡查询指令 #define AT_INS_CREG "AT+CREG?\r\n" //网络查询指令 #define AT_INS_GPRS "AT+CGATT=1;+CGDCONT=1,\"IP\",\"CMNET\";+CGACT=1,1\r\n" //GPRS操作指令 -//#define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"test.tall.wiki\",38195\r\n" #define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"www.tall.wiki\",8195\r\n" -//#define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"43.249.193.233\",38916\r\n" //#define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"weizezhao.imwork.net\",49809\r\n" //连接服务器 -// #define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"43.249.193.233\",38916\r\n" //连接服务器 +//#define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"test.tall.wiki\",49000\r\n" //连接服务器 #define AT_INS_CIPSEND "AT+CIPSEND\r\n" //发送数据 #define AT_INS_CLOSED "AT+CIPCLOSE\r\n" //主动关闭连接 #define AT_INS_CIPSTATUS "AT+CIPSTATUS\r\n" //查询连接状态 @@ -61,20 +59,23 @@ struct _at_send_status vU8 net_ok; vU8 gprs_ok; vU8 conn_ok; - vU8 status; + vU8 status_query_ok; + //vU8 status; vU32 ins_stmp; //指令时间戳 + vU32 gprs_last_recv_stmp; //上次接收指令时间戳 vU32 tcp_last_recv_stmp; //上次接收数据时间戳 + vU32 tcp_conn_stmp; //断开连接时间戳 vU32 tcp_close_stmp; //断开连接时间戳 vU32 heart_stmp; //连接成功后,等待发送时间 vU32 data_stmp;//数据发送时间记录 vU8 sign_flag; //发送登录数据标志 - vU8 heart_flag; //发送心跳标志 - vU8 data_flag;//定时发送数据标志 + //vU8 heart_flag; //发送心跳标志 + //vU8 data_flag;//定时发送数据标志 vU8 ack_flag;//下行数据ack vU8 gm35_reboot_times; //gm35重启次数 - vU8 ins_flag; //at指令ok标志 + //vU8 ins_flag; //at指令ok标志 }; extern struct _at_send_status g_at_send_status; @@ -105,4 +106,5 @@ extern void L3_gm35_send(U8 *d , U8 len); + diff --git a/source/app/app_task_gm35.h.1 b/source/app/app_task_gm35.h.1 new file mode 100644 index 0000000..9859829 --- /dev/null +++ b/source/app/app_task_gm35.h.1 @@ -0,0 +1,108 @@ +//////////////////////////////////////////////////////////////////////////// +///@copyright Copyright (c) 2018, 传控科技 All rights reserved. +///------------------------------------------------------------------------- +/// @file bsp_gc6133.c.h +/// @brief bsp @ driver config +///------------------------------------------------------------------------- +/// @version 1.0 +/// @author CC +/// @date 20180331 +/// @note cc_AS_stc02 + +////////////////////////////////////////////////////////////////////////////// + +#ifndef _app_gm35_gprs_H +#define _app_gm35_gprs_H + +#include "../bsp/bsp_config.h" +#include "../bsp/bsp_gm35.h" +#include "../tpc/tpc_uart.h" +#include "../ctask/task.h" + +////<<<<<<<<<<<<<<<<<<< GM35模块 AT操作指令 <<<<<<<<<<<<<<<<<<<<<<<< +#define AT_INS_ATEQV "ATE0Q0V1\r\n" //模块查询指令 +#define AT_INS_CCID "AT+CCID\r\n" //SIM卡查询指令 +#define AT_INS_CREG "AT+CREG?\r\n" //网络查询指令 +#define AT_INS_GPRS "AT+CGATT=1;+CGDCONT=1,\"IP\",\"CMNET\";+CGACT=1,1\r\n" //GPRS操作指令 +//#define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"test.tall.wiki\",38195\r\n" +#define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"www.tall.wiki\",8195\r\n" +//#define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"43.249.193.233\",38916\r\n" +//#define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"weizezhao.imwork.net\",49809\r\n" //连接服务器 +// #define AT_INS_CIPSTART "AT+CIPSTART=\"TCP\",\"43.249.193.233\",38916\r\n" //连接服务器 +#define AT_INS_CIPSEND "AT+CIPSEND\r\n" //发送数据 +#define AT_INS_CLOSED "AT+CIPCLOSE\r\n" //主动关闭连接 +#define AT_INS_CIPSTATUS "AT+CIPSTATUS\r\n" //查询连接状态 +#define AT_INS_CSQ "AT+CSQ\r\n" //查询信号指令 + +#define AT_RESET "AT+RST=2\r\n" //a9重启指令 AT+RST=2硬件重启(vUSB供电) AT+RST=1软件重启 + +////<<<<<<<<<<<<<<<<<<<_s_task_test_<<<<<<<<<<<<<<<<<<<<<<<< +struct _s_task_gm35_gprs_ +{ + TS_task task; +}; + +#define STATUS_GM35_INIT 0 +#define STATUS_GM35_MODULE_OK 1 +#define STATUS_GM35_SIM_OK 2 +#define STATUS_GM35_NET_OK 3 +#define STATUS_GM35_GPRS_OK 4 +#define STATUS_GM35_TCP_OK 5 + + +#define BUF_SIZE 5 +#define BUF_MAX 32 //注意缓冲区的长度 + +struct _at_send_status +{ + vU8 send_lock; + vU8 module_ok; + vU8 sim_ok; + vU8 net_ok; + vU8 gprs_ok; + vU8 conn_ok; + vU8 status; + vU32 ins_stmp; //指令时间戳 + vU32 tcp_last_recv_stmp; //上次接收数据时间戳 + vU32 tcp_close_stmp; //断开连接时间戳 + + vU32 heart_stmp; //连接成功后,等待发送时间 + vU32 data_stmp;//数据发送时间记录 + + vU8 sign_flag; //发送登录数据标志 + vU8 heart_flag; //发送心跳标志 + vU8 data_flag;//定时发送数据标志 + vU8 ack_flag;//下行数据ack + vU8 gm35_reboot_times; //gm35重启次数 + vU8 ins_flag; //at指令ok标志 +}; + +extern struct _at_send_status g_at_send_status; +extern struct _s_task_gm35_gprs_ s_task_gm35_gprs; +extern struct _s_task_gm35_gprs_ s_task_connect_gprs; + +extern void L3_task_gm35_core_init(void); +extern void L3_task_gm35_core_handle(void); +extern void L3_gm35_send(U8 *d , U8 len); + +#endif + + + + + + + + + + + + + + + + + + + + diff --git a/source/app/app_task_tcp.c b/source/app/app_task_tcp.c index d67fff9..da41485 100644 --- a/source/app/app_task_tcp.c +++ b/source/app/app_task_tcp.c @@ -75,20 +75,6 @@ void L3_task_tcp_handle(TS_tcp *s) default: break; } - #if 0 - if(s->pAckPkg->oper == MODBUS_OPER_WRITE_M) - { - s->treg = (U16)(s->pAckPkg->buf[0]) << 8 | (U16)(s->pAckPkg->buf[1]); - if(s->treg == G.ccmd_slaver_info[0].reg) - { - G.authed = 1; - } - else if(s->treg == G.ccmd_slaver_info[2].reg) - { - G.flowStarted = 1; - } - } - #endif } } if(s->ackFlag == 1 || s_nos_tick.t_1s - s->sendStamp >= 5) //收到ack或者超时 diff --git a/source/app/app_task_wdt.c b/source/app/app_task_wdt.c index 899cfee..981d0d6 100644 --- a/source/app/app_task_wdt.c +++ b/source/app/app_task_wdt.c @@ -1,6 +1,7 @@ #include "app_task_wdt.h" #include "../bsp/bsp_wdt.h" #include "../msp/uart0.h" +#include "app_common.h" struct _s_task_wdt s_task_wdt; @@ -8,7 +9,6 @@ void L3_task_wdt_init(void) { L1_task_init(&s_task_wdt.task); L3_task_s_go(s_task_wdt,D_task_init); - s_task_wdt.seed_flag = FLAG_WDT_SEED; } #define TTSS_TASK_WDT_STP_01 0x1 @@ -18,7 +18,7 @@ void L3_task_wdt_handle(struct _s_task_wdt *s) TTSS_Task_init() L2_task_go(TTSS_TASK_WDT_STP_01); TTSS_Task_step(TTSS_TASK_WDT_STP_01) - if(FLAG_WDT_SEED == s->seed_flag) + if(G.reset == 0) { L0_wdt_feed(); } diff --git a/source/app/app_task_wdt.h b/source/app/app_task_wdt.h index a2f6d57..a94ccf1 100644 --- a/source/app/app_task_wdt.h +++ b/source/app/app_task_wdt.h @@ -6,14 +6,9 @@ struct _s_task_wdt { TS_task task; - vU8 seed_flag; }; -#define FLAG_WDT_SEED 0 -#define FLAG_WDT_hunger 1 - extern struct _s_task_wdt s_task_wdt; - extern void L3_task_wdt_init(); extern void L3_task_wdt_handle(struct _s_task_wdt *s); diff --git a/source/app/main.c b/source/app/main.c index a61defd..f7eef89 100644 --- a/source/app/main.c +++ b/source/app/main.c @@ -74,7 +74,7 @@ void L0_main_init(void) Lc_delay_ms(700);// 2000--7s ///step: 7>>>>>>>>>寄存器默认初始化>>>>>>>>>>>>> - Lu_register_init(); + L2_register_init(); //L3_flash_write_page0(); #if 0 ///step: 5>>>>>>>>>看门狗>>>>>>>>>>>>> @@ -136,7 +136,11 @@ void main(void) L0_uart0_uc('#'); } } - //串口3 RFID接收 + //看门狗 + L3_task_wdt_handle(&s_task_wdt); + + //串口0,3 RFID接收 + L3_UARTcom0_exp_protocol(&s_uart0_rec); L3_UARTcom3_exp_protocol(&s_uart3_rec); //485轮询 @@ -147,17 +151,17 @@ void main(void) #if 1 //gm35维持连接 L3_task_gm35_core_handle(); + + //解析串口4协议(gsm模块收到的at响应消息+服务器发送消息) L3_UARTcom4_exp_protocol(&s_uart4_at_rec); //tcp发送 L3_task_tcp_handle(&ts_tcp); - //master->slaver发送逻辑控制 + //tcp master->slaver发送逻辑控制 L3_task_tcp_control_handle(&ts_tcp_control); #endif } }//end main - - diff --git a/source/bsp/bsp_config.c b/source/bsp/bsp_config.c index b1e93ae..10bdc53 100644 --- a/source/bsp/bsp_config.c +++ b/source/bsp/bsp_config.c @@ -193,7 +193,7 @@ void L0_cpu_init(void) } //------------------------------串口协议配置 ------------------------------------ -//TS_Handle_PH3 s_uart0_rec; +TS_Handle_PH3 s_uart0_rec; TS_Handle_PH4 s_uart2_rec; TS_Handle_PH3 s_uart3_rec; TS_Handle_0d0a s_uart4_at_rec; @@ -211,15 +211,12 @@ void L1_s2b_PH4_2(unsigned char sbufreg) L1_s2b_PH4(&s_uart2_rec); } -#if 0 //uart0 void L1_s2b_PH3_0(unsigned char sbufreg) { s_uart0_rec.reg = sbufreg; L1_s2b_PH3(&s_uart0_rec); } -#endif - //uart3 void L1_s2b_PH3_3(unsigned char sbufreg) @@ -247,7 +244,7 @@ void L1_s2b_gm35(unsigned char sbufreg) void L1_uart_tpc_config(void) { -#if 0 +#if 1 //uart0 protocol setting... s_uart0_rec.head = 0; s_uart0_rec.ok = 0; @@ -281,7 +278,7 @@ void L1_uart_tpc_config(void) s_uart4_tcp_rec.head_1 = D_CMD_Filter2_fe; s_uart4_tcp_rec.sp = (U8*)&(s_uart4_tcp_rec.ts_ccmodbus); - //Lp0_uart0_fun = L1_s2b_PH3_0; + Lp0_uart0_fun = L1_s2b_PH3_0; Lp0_uart2_fun = L1_s2b_PH4_2; Lp0_uart3_fun = L1_s2b_PH3_3; Lp0_uart4_fun = L1_s2b_gm35;