#include "Configuration.h"
#define TB_SERVER_NUM 2
//const u8 SERVER_IP[2][4] = {{122,114,122,174},{39,96,95,56}};
//const u16 SERVER_PORT[2] = {44751,18086};
const u8 SERVER_IP[2][4] = {{47,95,221,93},{39,96,95,56}};
const u16 SERVER_PORT[2] = {18086,18086};
/*
const u8 SERVER_IP[2][4] = {{122,114,122,174},{122,114,122,174}};
const u16 SERVER_PORT[2] = {39129,39129};
const u8 UDPSERVER_IP[2][4] = {{220,180,239,212},{220,180,239,212}};
const u16 UDPSERVER_PORT[2] = {8012,8012};
*/
/*************************************************************
函数名:NB_taskdeal
功能:NB任务处理
输入参数:无
返回:无
作者:scg
时间:2019年2月13日
*************************************************************/
void NB_taskdeal(void)
{
//----------------------------------------------NB模块
if(workdata.NB_SendData_flag!=0)
{
workdata.NB_work_flag = 1;
if(workdata.NB_init_flag == 0)
{
workdata.NB_init_flag = 1;
//--------------------------------------初始化
PWR_NB_ON();
NB_USART_ON();
USART_init();
workdata.PWRon_cnt = 0;
workdata.NB_Ready_flag = 0;
workdata.NB_stop_cnt = 0;
workdata.NB_cmd_flag = 0;
workdata.NB_ipchangnum = 0;
workdata.NB_psm_flag = 0;
workdata.NB_outtimestop_flag = 0;
}
}
else
{
workdata.NB_work_flag = 0;
workdata.NB_init_flag = 0;
}
//--------------------------------------------------------
if(0 != workdata.NB_work_flag)
{
NB_workdeal();
}
else
{
NB_stopdeal();
}
//--------------------------------------------------------
}
/************************************************************
函数名:NB_stopdeal
功能:NB任务模块处理
输入参数:无
返回:无
作者:scg
时间:2019年2月19日
************************************************************/
void NB_stopdeal(void)
{
workdata.PWRon_cnt = 0;
workdata.NB_Ready_flag = 0;
workdata.NB_cmd_flag = 0;
workdata.NB_ack_flag = 0;
workdata.NB_connectstatus_flag = 0;
workdata.NB_nocmd_cnt = 0;
workdata.NB_nocmd_num = 0;
}
void usart_disable(void)
{
GPIO_Init(UART1_TX_PORT, UART1_TX_PIN, GPIO_Mode_Out_PP_Low_Slow);//NB_RXD拉低
GPIO_Init(UART1_RX_PORT, UART1_RX_PIN, GPIO_Mode_Out_PP_Low_Slow);//NB_TXD置高
USART_Cmd(EVAL_COM1, DISABLE);
CLK_PeripheralClockConfig(EVAL_COM1_CLK, DISABLE);
}
/************************************************************
函数名:NB_taskdeal
功能:NB任务模块处理
输入参数:无
返回:无
作者:scg
时间:2019年2月19日
************************************************************/
#define TB_PWONTIME_60S 150 //約1min
#define TB_PWONTIME_40S 130
#define TB_PWONTIME_30S 100
#define TB_PWONTIME_24S 80
#define TB_PWONTIME_15S 50 //300ms*40 = 12s
#define TB_PWONTIME_10S 31 //300ms*30 = 12s
#define TB_PWONTIME_8S 25 //300ms*25 = 7.5S
#define TB_PWONTIME_6S 20 //300ms*20 = 6S
#define TB_PWONTIME_4S 15 //300ms*15 = 4.5S
#define TB_PWONTIME_3S 10
#define TB_PWONTIME_2S 2//8 //300ms*8 = 2.4S
static u8 tempdatabuf[150];
void NB_workdeal(void)
{
//-------------------------------------------------------NB入网
if(0 == workdata.NB_Ready_flag)
{
workdata.NB_nocmd_cnt = 0;
workdata.NB_business_step = 0;
UDP_connecting_deal();
}
else //-------------------------------------------------NB入网后处理
{
NB_task_deal();
}
//---------------------------------------------------------绑定好IP后无应答,需要延迟通信判断
if(workdata.NB_connectstatus_flag==0)
{
//===========================================================超时判断
if(!((0== workdata.NB_Ready_flag)&&(workdata.NB_connecting_step==TB_CONNECTING_PWRON)))//上电时间不计超时
{
workdata.NB_stop_cnt++;
//if(workdata.NB_stop_cnt>=TB_PWONTIME_15S)
if((workdata.NB_connecting_step==TB_CONNECTING_CGATT)||(workdata.NB_Ready_flag!=0))
{
if(workdata.NB_stop_cnt>=TB_PWONTIME_30S)
{
workdata.NB_stop_flag = 1;
workdata.NB_stop_cnt = 0;
workdata.NB_outtimestop_flag = 1;
}
}
else
{
if(workdata.NB_stop_cnt>=TB_PWONTIME_15S)
{
workdata.NB_stop_flag = 1;
workdata.NB_stop_cnt = 0;
workdata.NB_outtimestop_flag = 1;
}
}
}
}
else
{
workdata.NB_connectstatus_flag = 0;
workdata.NB_stop_cnt = 0;
}
//------------------------------------------------
if(workdata.NB_stop_flag)
{
//---------------------------------------------入网失败则关NB供电
if((workdata.NB_error_type != 0)||(!workdata.NB_Ready_flag)||(workdata.NB_outtimestop_flag))
{
workdata.NB_stop_flag = 0;
workdata.NB_connecting_step = TB_CONNECTING_PWRON;
workdata.NB_socketflag = 0;
workdata.NB_SendData_flag = 0;
//NB_cmd_nscol();
PWR_NB_OFF();
}
else
{
if(workdata.NB_psm_flag)
{
workdata.NB_psm_flag = 0;
workdata.NB_stop_flag = 0;
workdata.NB_SendData_flag = 0;
}
else
{
workdata.NB_stop_cnt1++;
//if(workdata.NB_stop_cnt1>=20)
if(workdata.NB_stop_cnt1>=50)
{
workdata.NB_stop_cnt1 = 0;
workdata.NB_outtimestop_flag = 1;
}
}
}
if(workdata.NB_SendData_flag == 0)
{
workdata.NB_init_flag = 0;
workdata.NB_stop_cnt = 0;
workdata.SetupModeflag = 0;
//-------------------------------------------火灾报警情况下,通信失败,则延迟继续通信
if(0 == workdata.comm_ok_flag)
{
if((0 != workdata.Alarm_Smoke_flag)||(0 != workdata.Alarm_Temp_flag)||(0 != workdata.AlarmPRE_Temp_flag ))
{
workdata.NB_conndelay_flag = 1;
}
}
}
}
else
{workdata.NB_stop_cnt1 = 0;}
//------------------------------------------------
}
/************************************************************
函数名:NB_task_deal
功能:NB连接服务器后任务处理
输入参数:无
返回:无
作者:scg
时间:2019年2月19日
************************************************************/
void NB_task_deal(void)
{
static u8 tempcnt1=0,tempcnt2=0;
switch(workdata.NB_business_step)//先发送业务数据
{
case TB_SEND_BUSINESSDATA:
if(0 == workdata.NB_cmd_flag)
{
tempcnt1 = 0;
workdata.NB_CmdWaitRece_flagA = 0;
workdata.NB_cmd_flag = 1;
NB_workdataSend();
}
else
{
tempcnt1++;
//if(tempcnt1>=18)
if(tempcnt1>=25)
{
tempcnt1 = 0;
Usartdata.Recebytenum = 21;
workdata.NB_cmd_flag = 0;
workdata.NB_nocmd_cnt = 0; //等待命令超时计数器清0
workdata.NB_business_step = TB_SEND_RDCMD; //进入命令接收模式
}
}
workdata.NB_CmdWaitRece_flag = 0;
workdata.serverIPflag = 0;
break;
case TB_RECE_WAIT_CMD: //等待是否有指令下达
//-------------------------------------------------检测到有数据到达,延迟发送接收数据指令
if(workdata.NB_CmdWaitRece_
评论0