📄 process.cpp
字号:
/////////////////////////////////////////////////////////////////////
// Process.cpp
#include "stdafx.h"
#include "fert2000.h"
#include "process.h"
#include "math.h"
extern bool bStopFlag;
extern CHANNEL Channels[MAX_CHANNEL_NUM];
extern RTU Rtus[MAX_RTU_NUM];
extern SYSTEMCOUNT SystemCount;
//extern CDatabase Database;
extern BYTE DebugCommand[0x23];//当前调试的命令数组
extern char DebugRtuNo;
extern EVENT Events;
extern RecSendThread RecSendThread1;
extern long ProgramStartTime;
extern NetProcess NetProcess1;
extern char YKEchoFlag[MAX_RTU_NUM];
extern BYTE YKEcho[MAX_RTU_NUM][6];//?
extern BYTE YKReserved[24];//?
extern unsigned char TBCH0[];
extern CFert2000App theApp;
extern BYTE GpsSendBuf[100];
extern BYTE GpsRecBuf[100];
extern BYTE SwitchSendBuf[100];
extern BYTE SwitchRecBuf[100];
//////////////////////////////////////////////////////////////////////
void Process()
{
static int iProcCount = -1;
while(1)
{
Sleep(200);
if (bStopFlag)
{
SetEvent(RecSendThread1.g_EventEndCDTProtocolProcess);
return;
}
if (iProcCount++ > 10000) iProcCount = 0;
for (int i=0;i<SystemCount.ChNum; i++)
{
if (!Channels[i].Flag) continue;
if (NetProcess1.ThisNodeId != NetProcess1.mainfertid/* && Channels[i].WorkType != 1*/)
{
if (theApp.ComFileFlag[i] == true)
theApp.CloseChannel (i);
continue;
}
else
{
if (Channels[i].bReInit == true)
{
Channels[i].bReInit = false;
theApp.CloseChannel (i);
Sleep(1000);
}
if (theApp.ComFileFlag[i] == false)
theApp.InitChannel (i,4);
}
if (Channels[i].WorkType == 0 || Channels[i].WorkType == 1)//前置机,旁听
{
switch(Channels[i].Protocol)
{
case 0://CDT91
CDT(i);
break;
case 1://SC1801
SC1801(i);
break;
case 2://即CDT85规约
CDT85(i);
break;
case 3://即CDT85规约变种,在此针对长沙局桐梓坡
CDT85(i);
break;
case 6:
DCF_5(i);
break;
case 7:
break;
default:
break;
}
}
else if (Channels[i].WorkType == 2)//模拟RTU
{
switch(Channels[i].Protocol)
{
case 4://CDT ZF
CDTZF(i);
break;
case 5://SC1801 ZF
SC1801ZF(i);
break;
}
}
else if (Channels[i].WorkType == 3)//Gps
{
if (iProcCount % 50 == 0)//10秒处理一次GPS
GpsProc(i);
}
else if (Channels[i].WorkType == 4)//you xian channel switch
{
if (iProcCount % 10 == 0)//2秒处理一次通道切换
ChannelSwitch(i);
}
else if (Channels[i].WorkType == 5)//channel test
{
ChannelTest(i);
}
else if (Channels[i].WorkType == 6)//hua yuan channel switch
{
if(iProcCount%10==0)//2秒处理一次通道切换
{
SwitchSendBuf[0]=0x01;
SwitchSendBuf[1]=0x01;
SwitchSendBuf[2]=0xff;
MoxaBufWrite(i,(char *)&SwitchSendBuf[2],1);
}
}
}
}
}
void ChannelEvent(BYTE RtuNo,char Flag)
{//通道事项 Flag: (0 未用 1 故障 2 恢复正常 -1 保持正常)
FERTEVENT Event;
SYSTEMTIME CurTime;
GetLocalTime(&CurTime);
CTime Systime = CTime::GetCurrentTime();
if((Events.EventNum+1)==Events.EventSendNum)
{
Beep(1200,500);
return;
}
Event.ms = CurTime.wMilliseconds % 100;
Event.hundms = CurTime.wMilliseconds / 100;
Event.seconds = (BYTE)CurTime.wSecond;
Event.minute = (BYTE)CurTime.wMinute;
Event.hour = (BYTE)CurTime.wHour;
Event.day = (BYTE)CurTime.wDay;
Event.month = (BYTE)CurTime.wMonth;
Event.year = CurTime.wYear;
Event.Recms = CurTime.wMilliseconds % 100;
Event.Rechundms = CurTime.wMilliseconds/100;
Event.Recseconds = (BYTE)CurTime.wSecond;
Event.Recminute = (BYTE)CurTime.wMinute;
Event.Rechour = (BYTE)CurTime.wHour;
Event.Recday = (BYTE)CurTime.wDay;
Event.rtuno = RtuNo;
Event.yxno = Rtus[RtuNo].RtuChNo;
Event.cause = 2;
// Event.state = 1<<Flag;
if (Flag == 0)
Event.state = 0;
else if (Flag == 1)
Event.state = 1;
else if (Flag == 2)
Event.state = 2;
else if (Flag == -1)
Event.state = 255;
FERTEVENT *CurEventP = Events.EventBuf + Events.EventNum;
memcpy(CurEventP,&Event,sizeof(FERTEVENT));
if(++Events.EventNum>=MAX_EVENT_NUM)
Events.EventNum=0;
}
void YxEvent(int RtuNo,int YxNo,BYTE State)//生成变位遥信Event
{
FERTEVENT Event;
SYSTEMTIME CurTime;
GetLocalTime(&CurTime);
if((Events.EventNum+1)==Events.EventSendNum)
{
Beep(1200,500);
return;
}
Event.ms = CurTime.wMilliseconds % 100;
Event.hundms = CurTime.wMilliseconds / 100;
Event.seconds = (BYTE)CurTime.wSecond;
Event.minute = (BYTE)CurTime.wMinute;
Event.hour = (BYTE)CurTime.wHour;
Event.day = (BYTE)CurTime.wDay;
Event.month = (BYTE)CurTime.wMonth;
Event.year = CurTime.wYear;
Event.Recms = CurTime.wMilliseconds % 100;
Event.Rechundms = CurTime.wMilliseconds/100;
Event.Recseconds = (BYTE)CurTime.wSecond;
Event.Recminute = (BYTE)CurTime.wMinute;
Event.Rechour = (BYTE)CurTime.wHour;
Event.Recday = (BYTE)CurTime.wDay;
Event.rtuno = RtuNo;
Event.yxno = YxNo;
Event.cause = 1;
Event.type = 0;
Event.state = State;
FERTEVENT *CurEventP = Events.EventBuf + Events.EventNum;
memcpy(CurEventP,&Event,sizeof(FERTEVENT));
if(++Events.EventNum>=MAX_EVENT_NUM)
Events.EventNum=0;
}
int SetNtRegValue(LPCTSTR lpszSection,LPCTSTR lpszEntry,void *nValue,int WriteSize)
{
ASSERT(lpszSection != NULL);
ASSERT(lpszEntry != NULL);
{
HKEY hSecKey = GetNtSectionKey(lpszSection);
if (hSecKey == NULL)
return FALSE;
LONG lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_NONE,
(LPBYTE)nValue, WriteSize);
RegCloseKey(hSecKey);
return (lResult == ERROR_SUCCESS);
}
}
HKEY GetNtSectionKey(LPCTSTR lpszSection)
{
ASSERT(lpszSection != NULL);
HKEY hSectionKey = NULL;
HKEY hAppKey=HKEY_CURRENT_USER;
if (hAppKey == NULL)
return NULL;
DWORD dw;
RegCreateKeyEx(hAppKey, lpszSection, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&hSectionKey, &dw);
RegCloseKey(hAppKey);
return hSectionKey;
}
int QueryNtRegValue(LPCTSTR lpszSection, LPCTSTR lpszEntry,LPBYTE lpData,int QuerySize)
{
HKEY hResult;
DWORD dwCount=sizeof(DWORD);
dwCount=QuerySize;
if(ERROR_SUCCESS!=RegOpenKey(HKEY_CURRENT_USER,lpszSection,&hResult))
{
return false;
}
RegQueryValueEx(hResult,lpszEntry,0,0,lpData,&dwCount);
RegCloseKey(hResult);
return true;
}
bool QueryPassword(CString *UserName,CString *Password,bool *bAdministrator)
{//return
BYTE UserNum;
char SqrUserName[7],UserData[41];
CString ReUserName,UserPassword;
QueryNtRegValue("FenlSys\\","UserNum",&UserNum,1);
for (int i=1;i<=UserNum;i++)
{
sprintf(SqrUserName,"User%02d",i);
QueryNtRegValue("FenlSys\\",(LPCTSTR)SqrUserName,(BYTE*)UserData,41);
ReUserName = UserData;
if (ReUserName == *UserName)
{
if (!Password) return true;
QueryNtRegValue("FenlSys\\",(LPCTSTR)SqrUserName,(BYTE *)UserData,41);
UserPassword = &UserData[20];
if (UserPassword == *Password)
{
*bAdministrator = (UserData[40])?true:false;
return true;
}
else
return false;
}
}
return false;
}
bool DelNtRegValue(LPCTSTR lpszSection, LPCTSTR lpszEntry)
{
HKEY hResult;
if(ERROR_SUCCESS!=RegOpenKey(HKEY_CURRENT_USER,lpszSection,&hResult))
{
return false;
}
RegDeleteValue(hResult,lpszEntry);
return true;
}
bool Start = true;
void GpsProc(int ChNo)
{
unsigned char TxBuf[8],RxBuf[24];
SYSTEMTIME stgps;
SYSTEMTIME stlocal;
float freq ;
TxBuf[0] = 'D';
TxBuf[1] = 0x0a;
BYTE Temp[1024];
MoxaBufRead(ChNo,Temp,1024);
GpsSendBuf[0] = 1;
GpsSendBuf[1] = 2;
GpsSendBuf[2] = 'D';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -