📄 main.cpp.bak
字号:
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include <bios.h>
#include "readini.h"
#include "etr_ppp.h"
#include "gprs.h"
#include "tcpclnt.h"
#include "rs232x3.h"
#include "etr232i.h"
#include "wdt.h"
#include "sms_ring.h"
#include "GPRSPROC.H"
#include "tmrisr.h"
#include "cmdproc.h"
#include "downcmd.h"
#include "fileio.h"
#include "macrodef.h"
#include "taskproc.h"
//////////////////////////for keypad
#include "keymenu.h"
extern KPState KeyPassState;
#define PPPCONNTIMEOUTCNT 12000 //以10MS为最小时间单位
#define TCPCONNTIMEOUTCNT 6000 //以10MS为最小时间单位
int ComIdx, BaudIdx, HeartBeat, TalkTime;
struct SERVER_ID Svr_ID;
int TaskFlg = WaitingActive;
unsigned char MalFunctionflg=0; //故障报警标志
unsigned char ReportRFTimeoutCnt=0; //采集器上报降雨量超时计数;
unsigned char ReportWLTimeoutCnt=0; //采集器上报水位超时计数;
char RFRegTimeBuff[3][6]={{0},{0},{0}};
char WLRegTimeBuff[3][6]={{0},{0},{0}};
extern RAINFALLDATA OutRainfallregdata;
extern WATERLEVELDATA OutWaterLevelregdata;
extern char AlarmTimeBuff[6];
extern int ARTimeUnit; //add by wuhuan 2006.7.22
extern char ReadHistroyDataFlg;
extern unsigned char RHDCMDTmpBuf[30];
extern unsigned char WhoSendRHDCMD;
extern int Ivtime[2]; ////水位和降雨量采集间隔时间
unsigned char ManualWLBuff[50];
unsigned char ManualRFBuff[50];
extern char InitWaterLevel[6];
extern unsigned int ReportRFTimeoutFlg;
extern unsigned int ReportWLTimeoutFlg;
int SysInit( ); // 系统初始化函数定义
int SysExit( ); // 系统退出处理
void flashchar(char inchar);
char flashc[9]={'\0','\0','\0','\0','\0','\0','\0','\0','\0'};
PPPGPRSState PPPState;
TCP_STATE GetTCPState;
int main( )
{
int tempmin = 999;
int i, j=0, Rs485DataLen=0, CmdStrLen;
unsigned char Rs485DataBuf[200];
unsigned char CmdDataBuf[200];
unsigned char waterlevelbuff[3][6]={{0},{0},{0}}; //元素个数增加到6个 modify by wuhuan 200.6.8
unsigned char rainfallbuff[3][6]={{0},{0},{0}}; //元素个数增加到6个 modify by wuhuan 200.6.8
char CurrentWL[50];
char CurrentRf[50];
struct time Currenttime;
struct date Currentdate;
unsigned char CurrentClock[30];
char Currentstat[30];
///////////////////////////////////////
//计算数据采集一次所花的时间
unsigned long timecnt=0;
clock_t start, end;
start = clock();
/////////////////////////////////////////
unsigned char SystemState = State_GatherData ;
printf( "\nHDTS V1.21 startup...\n" );
SysInit( ); // 首先进行初始化
sprintf(CurrentRf,"\nNo New Rf Data \n");
sprintf(CurrentWL,"\nNo New Wl Data \n");
for( ; ; )
{
ReloadWDTLong( );
KeyPadOperation( );
if(SysExitState!=RUNMODE) break; ///////////////////退出主程序
end = clock( );
if( (end-start) >= 18 )
{
getdate( &Currentdate ); //取系统的时间
gettime( &Currenttime );
sprintf(CurrentClock,"\n %4d/%d/%d\n %d:%d:%d\n",Currentdate.da_year,Currentdate.da_mon,Currentdate.da_day,Currenttime.ti_hour,Currenttime.ti_min,Currenttime.ti_sec);
if (TaskFlg==WaitingActive) flashchar('|');
else if(TaskFlg==PPPConneting)
{
if( GetTCPState!=TCPOPEN ) flashchar('>');
else flashchar('*');
}
else if(TaskFlg==NeedInitUART) flashchar('^');
else if(TaskFlg==FTPdownload) flashchar('!');
else if(TaskFlg==MANUALDATA) flashchar('+');
else flashchar('?');
sprintf(Currentstat,"\n %s",flashc);
if(GetKPState==LOCK) printf("\nGetKPSt=%d\n",GetKPState);
if ((timecnt>=19)&&(GetKPState==LOCK)) KeyPassState=SHOW;
if (KeyPassState==SHOW)
{
printf("%s",CurrentRf);
printf("%s",CurrentWL);
printf("%s",CurrentClock);
printf("%s",Currentstat);
timecnt=0;
}
start = end;
if (GetKPState==LOCK) timecnt++;
///////////////////////////////////////
if(Currenttime.ti_min!=tempmin)
{
tempmin=Currenttime.ti_min;
if((Currenttime.ti_min%Ivtime[0])==0)
{
strcpy(RFRegTimeBuff[1],RFRegTimeBuff[0]);
GetSystemTime(RFRegTimeBuff[0]);
}
if((Currenttime.ti_min%Ivtime[1])==0)
{
strcpy(WLRegTimeBuff[1],WLRegTimeBuff[0]);
GetSystemTime(WLRegTimeBuff[0]);
}
}
}
switch(SystemState)
{
case State_GatherData:
Rs485DataLen = GetDataFromCOM( ComIdx, Rs485DataBuf, 100 );
if(Rs485DataLen>0)
{
j++;
if(GetKPState==LOCK) printf("\nRs485DataLen%d = %d\n", j,Rs485DataLen);
SystemState = State_DownFrameProc; //收到数据转解析过程
}
else SystemState = State_IfMalfunAlarm; //没有收到数据判断采集器是否通信异常
break;
case State_DownFrameProc: //解析采集器发送的数据
i = DownFrame_Master_Proc( Rs485DataBuf, rainfallbuff, waterlevelbuff );
if(i==1) SystemState = State_SaveAutoData;
else SystemState = State_IfMalfunAlarm;
break;
case State_SaveAutoData: //正确解析数据后保存数据
if(Rs485DataBuf[3]==0x01) //降雨量数据
{
if(Rs485DataBuf[5]==0x83) //自报数据
{
if( ReportRFTimeoutCnt<1)
{
SaveRainfallData( "Rain.dat", rainfallbuff[0], RFRegTimeBuff[0], Ivtime[0],'Z');
}
else
{
SaveRainfallData( "Rain.dat", rainfallbuff[1], RFRegTimeBuff[1], Ivtime[0],'Z');
SaveRainfallData( "Rain.dat", rainfallbuff[0], RFRegTimeBuff[0], Ivtime[0],'Z');
}
sprintf(CurrentRf,"\nRainF = %.1fmm\n", atof(rainfallbuff[0])/10 );
TimerCnt_485hasRFdata=0;
ReportRFTimeoutCnt = 0;
ReportRFTimeoutFlg = 0;
if((Currenttime.ti_min%Ivtime[0])!=0||Currenttime.ti_sec > 20)
Send_SyschroTime_to_GatherMachine( );
}
else if(Rs485DataBuf[5]==0x88) //加报数据
{
GetSystemTime(OutRainfallregdata.time);
SaveRainfallData( "Rain.dat", rainfallbuff[0], OutRainfallregdata.time, ARTimeUnit,'J');
sprintf(CurrentRf,"\nAlmRF = %.1fmm\n", atof(rainfallbuff[0])/10 );
}
SystemState = State_IfReport485Data;
}
else if(Rs485DataBuf[3]==0x02) //水位数据
{
if(Rs485DataBuf[5]==0x82) //水位召测
{
GetSystemTime(OutWaterLevelregdata.time);
sprintf(CurrentWL,"\nWater = %.2fm\n", atof(waterlevelbuff[0])/100 );
}
else if(Rs485DataBuf[5]==0x83) //水位自报
{
if( ReportWLTimeoutCnt<1 )
{
SaveWaterLevelData( "Water.dat", waterlevelbuff[0], WLRegTimeBuff[0], 'Z');
}
else
{
SaveWaterLevelData( "Water.dat", waterlevelbuff[1], WLRegTimeBuff[1], 'Z');
SaveWaterLevelData( "Water.dat", waterlevelbuff[0], WLRegTimeBuff[0], 'Z');
}
sprintf(CurrentWL,"\nWater = %.2fm\n", atof(waterlevelbuff[0])/100 );
TimerCnt_485hasWLdata=0;
ReportWLTimeoutCnt = 0;
ReportWLTimeoutFlg = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -