📄 ptcmdf.cpp
字号:
// PtcMDF.cpp: implementation of the CPtcMDF class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "mdf.h"
#include "PtcMDF.h"
#include "MDFDlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern CMDFApp theApp ;
//##ModelId=44B6F8840128
CPtcMDF::CPtcMDF()
{
}
//##ModelId=44B6F8840129
CPtcMDF::~CPtcMDF()
{
}
//##ModelId=44B6F8840119
int CPtcMDF::Transact(sCommItem *pItem)
{
if( pItem->InPack.CID2 > 0x10 && pItem->InPack.CID2 < 0xE0 )
{
//Order(pItem) ; //处理来自于MDF的命令包暂缺
}
else
{
Answer(pItem) ; //处理来自于MDF的响应包
}
return 0 ;
}
//##ModelId=44B6F884010B
int CPtcMDF::FindCmd(UCHAR ucCmd , CString &strName)
{
int nResult = 0 ;
switch( ucCmd )
{
case 0x00 :
strName = "响应包" ;
break ;
case 0x44 :
strName = "获取监测模块告警" ;
break ;
case 0x4d :
strName = "获取检测模块时间" ;
break ;
case 0x4e :
strName = "设定检测模块时间" ;
break ;
case 0x4f :
strName = "获取通信协议版本号" ;
break ;
case 0x50 :
strName = "获取设备地址" ;
break ;
case 0x51 :
strName = "获取设备厂家信息" ;
break ;
case 0x55 :
strName = "程序测试用码(获取命令格式)" ;
break ;
case 0x58 :
strName = "系统复位启动" ;
break ;
case 0x60 :
strName = "初始化检测模块" ;
break ;
case 0xe0 :
strName = "设备告警上传" ;
break ;
default :
strName = "未知命令" ;
nResult = -1 ;
break ;
}
return nResult ;
}
//##ModelId=44B6F8840109
//对各响应包的处理,分析其结果并进行处理
int CPtcMDF::Answer(sCommItem *pItem)
{
CString strTemp1,strTemp2 ;
CString strTime,strError,strTip ;
CList<sCmd,sCmd> *pCmdList ;
sCmd f_Cmd ;
CAdoDB cAdo ;
//BOOL bTest ;
/*
try
{
if( pItem->pEQ == NULL )
return -1 ;
//bTest = cAdo.InitDB() ;
//非法响应命令将不做处理
pCmdList = (CList<sCmd,sCmd> *)pItem->pEQ->pCmdList ;
if( pCmdList->IsEmpty() )//非法响应包
{
strTip.Format("非法响应包:%s 不处理",pItem->strBuf) ;
theApp.DebugShow(strTip) ;
//写响应包记录
strTime = CTime::GetCurrentTime().Format ( "%Y-%m-%d %H:%M:%S" ) ; //获取当前时间
cAdo.WriteCommRd(strTime,CRDR_ERROR,CRDT_MODULE,pItem->pEQ->strName,"未知",pItem->strBuf,pItem->strSource,"非法监测模块数据包被丢弃不处理") ;
return -1 ;
}
else//正确响应包
{
f_Cmd = pCmdList->GetHead() ;
if( pItem->InPack.CID2 == 0x00 )//正确响应包处理
{
switch( f_Cmd.ucCmd )
{
case 0x44 ://*** 获取告警响应包处理 ***
ACmd44H( pItem ) ;
break ;
case 0x4D :
ACmd4DH( pItem ) ;
break ;
case 0x4E :
ACmd4EH( pItem ) ;
break ;
case 0x50 :
ACmd50H( pItem ) ;
break ;
case 0x51 :
ACmd51H( pItem ) ;
break ;
case 0X60 :
ACmd60H( pItem ) ;
break ;
default :
break ;
}
strTip.Format("收到数据包:%s \r\n",pItem->strBuf) ;
theApp.DebugShow(strTip) ;
//写通讯记录(正常响应)命令包
strTemp1 = theApp.m_pComm->m_pProtocol->GetCmdNote(pItem->pEQ,f_Cmd.ucCmd) ;
cAdo.WriteCommRd(f_Cmd.strTime,CRDR_NORMAL,CRDT_HOST,"监测中心",strTemp1,f_Cmd.strPack,theApp.m_pComm->m_sHostIp.strIp,"收到正确响应包返回") ;
//清除命令队列里已响应的命令
theApp.m_pComm->m_pEQPool->SubCommand(pItem->pEQ) ; //删除设备通讯命令
//写响应包记录
strTime = CTime::GetCurrentTime().Format( "%Y-%m-%d %H:%M:%S" ) ; //获取当前时间
cAdo.WriteCommRd(strTime,CRDR_NORMAL,CRDT_MODULE,pItem->pEQ->strName,strTemp1,pItem->strBuf,pItem->strSource,"命令成功执行") ;
return 0 ;
}
else if( pItem->InPack.CID2 > 0x00 && pItem->InPack.CID2 < 0x10 ) //出错数据包处理
{
strTip.Format("%s 通讯返回出错数据 %s ",pItem->pEQ->strName,pItem->strBuf) ;
theApp.DebugShow(strTip) ;
//写通讯记录(异常响应)命令包
strTemp1 = theApp.m_pComm->m_pProtocol->GetCmdNote(pItem->pEQ,f_Cmd.ucCmd) ;
cAdo.WriteCommRd(f_Cmd.strTime,CRDR_EXCEPT,CRDT_HOST,"监测中心",strTemp1,pItem->pEQ->strScanPack,theApp.m_pComm->m_sHostIp.strIp,"收到出错响应包返回") ;
//清除命令队列里已响应的命令
theApp.m_pComm->m_pEQPool->SubCommand(pItem->pEQ) ; //删除设备通讯命令
//写响应包记录
strTime = CTime::GetCurrentTime().Format ( "%Y-%m-%d %H:%M:%S" ) ; //获取当前时间
cAdo.WriteCommRd(strTime,CRDR_EXCEPT,CRDT_MODULE,pItem->pEQ->strName,strTemp1,pItem->strBuf,pItem->strSource,"命令成功执行") ;
if( pItem->pEQ->nFault < CONFIRM_TIME )
{
//错误响应包重发
strTip = "重发监测中心命令包:" ;
theApp.DebugShow(strTip) ;
//轮询和初始化将不做重发
if( pItem->InPack.CID2 != 0x44 && pItem->InPack.CID2 != 0x60)
theApp.m_pComm->SendData(f_Cmd.strPack,pItem->pEQ,f_Cmd.ucCmd) ;
pItem->pEQ->nFault++ ; //出错增加
return 0 ;
}
else
{
pItem->pEQ->nFault = 0 ;
//pItem->pEQ->unCommState = 3
strTime = CTime::GetCurrentTime().Format ( "%Y-%m-%d %H:%M:%S" ) ; //获取当前时间
strTip.Format("异常:监测中心 向 %s 发送数据包:%s 发生通讯故障(%d次错误响应)",pItem->pEQ->strName,pItem->strBuf,CONFIRM_TIME) ;
//pItem->pEQ->unCommState = 0 ;
theApp.DebugShow(strTip) ;
cAdo.WriteLog(strTip) ;//写异常记录
if( theApp.m_pComm->m_bIsDebug )
{
//##通讯故障处理
((CMDFDlg*)theApp.m_pMainWnd)->m_UI.m_DebugDlg.SetCommState(pItem->pEQ->nNo,3) ;
}
return 1 ;
}
}
}
return 0 ;
}
catch(_com_error e)
{
strTip.Format("异常:CPtcMDF::Answer 发生异常:%s",(LPCSTR)e.Description()) ;
theApp.Show(strTip) ;
return -1 ;
}
*/
return -1;
}
//##ModelId=44B6F88400FD
int CPtcMDF::ACmd44H(sCommItem *pItem)
{
////#加入出错异常处理
//CAdoDB cAdo ;
//UCHAR ucCover ;
//int i,j,nSWAlarm,nSIAlarm,nWrite ;
//int nPort,nState,nLen;
//CString strAlarmL,strValue ;
//CString strTemp ;
//CString strTime ;
//CString strStep ;
//CString strAlarm ;
//CString strError ;
//CString strTip ;
//CString strPort ;
//sSVMPort* pPort ;
////BOOL bTest ;
////bTest = FALSE ;
//try
//{
// //bTest = cAdo.InitDB() ;
// nLen = pItem->strBuf.GetLength() ;
//
// if( nLen < 56 )//以40个告警位来判断
// {
// strTip.Format("异常:设备 %s 返回状态数据包:%s 错误格式",pItem->pEQ->strName,pItem->strBuf) ;
// theApp.DebugShow(strTip) ;
// cAdo.WriteLog(strTip) ;
// return -1 ;
// }
// nSWAlarm = 0 ; //0 -- 正常 , 1 -- 告警
// nSIAlarm = 0 ;
// nWrite = 0 ; //0 -- 不写 , 1 -- 写入
//
// strTemp = "\r\n**********************************************\r\n" ;
// strStep.Format( "%s来源:%s\r\n\r\n",strTemp,pItem->pEQ->strName) ;
// if(pItem->pEQ != NULL )
// pItem->pEQ->nTimeOut = 0 ;
// for( i=0 ; i < 3 ; i++ ) //开关量列告警 3字节 16路告警 1字节8路 外接告警
// {
// for( j = 0 , ucCover = 0x01 ; j < 8 ; j++ )
// {
// nPort = i*8+j+1 ;
// //*****是否为已存在端口*****
// pPort = theApp.m_pComm->m_pEQPool->FindEQPort(pItem->pEQ,nPort) ;
// //*****是否存在告警******
// nState = pItem->InPack.INFO[i] & ucCover ;
// if( nState && pPort == NULL )
// {
// //未知端口告警
// strAlarm.Format("异常:设备:%s 未知端口:%d 发生告警\r\n",pItem->pEQ->strName,nPort) ;
// strTip = strStep + strAlarm +strTemp ;
// nSIAlarm = 1 ;
// cAdo.WriteLog(strAlarm) ;
// }
// else if( pPort != NULL ) //对已设置端口进行操作
// {
// if( nState )//设备处告警状态
// {
// strAlarm.Format("系统:告警位置:%s-%s-%s-%s 设备名:%s 类型:%s 告警列:%s 接入描述:%s", pPort->strSVDCity ,pPort->strSVDArea, pPort->strSVDAddr,pPort->strSVDPlace,pPort->strSVDName,pPort->strSVDType,pPort->strSpotSort,pPort->strSpotNote) ;
// strTip = strStep + strAlarm + strTemp ;
// nSWAlarm = 1 ;
// //##写端口数据暂为开关量赋值
// if( pPort->dValue != 1.000 )
// {
// pPort->dValue = 1.000 ;
// cAdo.WriteCheckData(pItem->pEQ->nID,pPort->strPortSort,pPort->nSVDID,pPort->strSpotSort,1.000) ;
// }
// theApp.DebugShow(strTip) ;
// if( pPort->nState == PORT_NORMAL ) //端口原处于正常状态
// {
// if ( pPort->nACount >= ALARM_LIMIT )//告警次数累加
// {
// pPort->nState = PORT_WARNING ; //发生告警
// pItem->pEQ->unEQState = 1 ; //设备处于告警状态。
//
// cAdo.WriteLog(strAlarm) ;
// // 写告警信息表
// strTime = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S") ;
// cAdo.WriteAlarm( pItem->pEQ->nID,PORT_SWITCH,pPort->strPortSort,pItem->pEQ->strIDAddr,pItem->pEQ->strName,pPort->nSVDID,pPort->strSpotSort,1,strTime,"","",1,1.00,"") ;
// //短信告警
// if( theApp.m_pComm->m_bIsMsgOpen && theApp.m_pComm->m_pCommPool->m_GSM.GetGsmRun())
// theApp.m_pComm->AddGsmMsg(strAlarm) ;//增加一条短信报警
// //电话语音
// if( theApp.m_pComm->m_bIsVoiceOpen && theApp.m_pComm->m_pCommPool->m_GSM.GetGsmRun())
// {
// theApp.TestWriteLog("程序:电话语音功能位为真") ;
// if( theApp.m_pComm->m_bIsDebug )
// theApp.m_pComm->AddGsmVoice(pItem->pEQ->strName,pItem->pEQ->strIDAddr,nPort,((CMDFDlg*)theApp.m_pMainWnd)->m_UI.m_DebugDlg.m_hWnd) ;
// else
// theApp.m_pComm->AddGsmVoice(pItem->pEQ->strName,pItem->pEQ->strIDAddr,nPort,theApp.m_pMainWnd->m_hWnd) ;
// }
// }
// else
// {
// pPort->nACount++ ;
// }
// }
// else
// {
// strTip.Format("告警信息表已存在设备告警,但尚未处理\r\n") ;
// theApp.DebugShow(strTip) ;
// //theApp.OutPut(strTip) ;
// pPort->nACount = ALARM_LIMIT ;
// }
// }
// else//设备正常无告警
// {
// //##写端口数据暂为开关量赋值
// //strTip.Format("程序:端口%s原处于正常状态",pPort->strPortSort) ;
// //theApp.OutPut(strTip) ;
// if( pPort->dValue != 0.000 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -