📄 dataanalyse.cpp
字号:
//通知窗体发生告警
iLevel = GetLevel(lSeconds);
if (port.AlarmState == PORT_WARNING)
{
m_port.AlarmLevel = iLevel;
m_port.value = 0;
}else
{
m_port.AlarmLevel = 0;
m_port.value = 0;
}
if (iLevel != 0)
{
SendMessage(m_pWnd->m_hWnd,WM_STATUS_CHANGE,(WPARAM)(&m_port),(LPARAM)port.AlarmState);
}
}else
{
//告警级别划分
if (port.AlarmState == PORT_WARNING)
{
iLevel = GetLevel(lSeconds);
if (iLevel > m_port.AlarmLevel)
{
m_port.AlarmLevel = iLevel;
SendMessage(m_pWnd->m_hWnd,WM_STATUS_CHANGE,(WPARAM)(&m_port),(LPARAM)port.AlarmState);
}
//if (lSeconds > 10 && lSeconds <= 120 && m_port.AlarmLevel == 1)
//{
// m_port.AlarmLevel = 2;
// SendMessage(m_pWnd->m_hWnd,WM_STATUS_CHANGE,(WPARAM)(&m_port),(LPARAM)port.AlarmState);
//}else if (lSeconds > 120 && lSeconds <= 600 && m_port.AlarmLevel == 2)
//{
// m_port.AlarmLevel = 3;
// SendMessage(m_pWnd->m_hWnd,WM_STATUS_CHANGE,(WPARAM)(&m_port),(LPARAM)port.AlarmState);
//}else if (lSeconds > 600 && m_port.AlarmLevel == 3)
//{
// m_port.AlarmLevel = 4;
// SendMessage(m_pWnd->m_hWnd,WM_STATUS_CHANGE,(WPARAM)(&m_port),(LPARAM)port.AlarmState);
//}
}
}
pMonitor->m_EquipState.SetAt(i,m_port);
break;
}
}
return 0;
}
int CDataAnalyse::ACmd4DH(CInfoFrame frame,CEquipmentPort port)
{
CString strTip ;
UCHAR* ucpTemp ;
int nYear,nLen ;
try
{
nLen = frame.nRLen ;
if( nLen < 30 )
{
strTip.Format("异常:设备 %s 获取监测模块时间 响应命令 格式出错",frame.InPack.ADR ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return -1 ;
}
ucpTemp = frame.InPack.INFO ;
nYear = 0 ;
nYear = ( *ucpTemp << 8 ) | *(ucpTemp + 1) ;//取得年份
CTime tmTime;
tmTime = CTime(nYear,*(ucpTemp+2),*(ucpTemp+3),*(ucpTemp+4),*(ucpTemp+5),*(ucpTemp+6));
strTip.Format("设备地址 %s 的时间是%s\r\n",frame.InPack.ADR,tmTime.Format("%Y-%m-%d %H:%M:%S")) ;
//增加WEB端日期回复功能
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return 0 ;
}
catch(_com_error e)
{
strTip.Format( "异常:执行MDF响应命令ACmd4DH发生异常:%s ",(LPCSTR)e.Description() ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return -1 ;
}
}
int CDataAnalyse::ACmd4EH(CInfoFrame frame,CEquipmentPort port)
{
int nLen ;
CString strTip ;
CAdoDB cAdo ;
try
{
//cAdo.InitDB() ;
nLen = frame.nRLen;
if( nLen < 16 )
{
strTip.Format("异常:设备 %s 设置监测模块时间 响应命令 格式出错",frame.InPack.ADR ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return -1 ;
}
strTip = "设备时间设置成功\r\n" ;
//theApp.DebugShow(strTip) ;
return 0 ;
}
catch(_com_error e)
{
strTip.Format( "异常:执行MDF响应命令ACmd4EH发生异常:%s ",(LPCSTR)e.Description() ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return -1 ;
}
}
int CDataAnalyse::ACmd4FH(CInfoFrame frame,CEquipmentPort port)
{
int nLen ;
UCHAR ucCover ;
CString strTip ;
CAdoDB cAdo ;
try
{
nLen = frame.nRLen; ;
if( nLen != 18 )
{
strTip.Format("异常:设备 %s 获取监测模块 通讯协议 响应命令 格式出错 ",frame.InPack.ADR ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return -1 ;
}
ucCover = frame.InPack.VER & 0x0F ;
if(ucCover > 0x09)
strTip.Format("协议版本号:%d.1%d \r\n", frame.InPack.VER >> 4 , ucCover-0x0A) ;
else
strTip.Format("协议版本号:%d.0%d \r\n", frame.InPack.VER >> 4 , ucCover ) ;
return 0 ;
}
catch(_com_error e)
{
strTip.Format( "异常:执行MDF响应命令ACmd4FH发生异常:%s ",(LPCSTR)e.Description() ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return -1 ;
}
return -1;
}
int CDataAnalyse::ACmd50H(CInfoFrame frame,CEquipmentPort port)
{
int nLen ;
CString strTip ;
try
{
nLen = frame.nRLen ;
if( nLen < 16 )
{
strTip.Format("异常:设备 %s 获取监测模块 地址 响应命令 格式出错 ",frame.InPack.ADR ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return -1 ;
}
strTip.Format("设备地址为:%x%x\r\n", frame.InPack.ADR >> 4 , frame.InPack.ADR & 0x0F) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return 0 ;
}
catch(_com_error e)
{
CString strTip ;
strTip.Format( "异常:执行MDF响应命令ACmd50H发生异常:%s ",(LPCSTR)e.Description() ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return -1 ;
}
}
int CDataAnalyse::ACmd51H(CInfoFrame frame,CEquipmentPort port)
{
char acEQ[10];
char acComp[20] ;
char* pTemp ;
UCHAR ucCover ;
int i,nLen ;
CString strTip ;
CString strTemp1,strTemp2 ;
CAdoDB cAdo ;
try
{
//cAdo.InitDB() ;
nLen = frame.nRLen ;
if( nLen < 80 )
{
strTip.Format("异常:设备 %s 获取监厂家信息 响应命令 格式出错 ",frame.InPack.ADR ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTip) ;
return -1 ;
}
memset(acEQ,0,sizeof(acEQ)) ;
memset(acComp,0,sizeof(acComp)) ;
pTemp = (char*)frame.InPack.INFO ;
i = strlen( pTemp ) ;
memcpy(acEQ,pTemp,i) ;
acEQ[i] = '\0' ;
strTemp1 = acEQ ;
strTemp2 = "采集器名称:" + strTemp1 ;
ucCover = *(frame.InPack.INFO+11) ;
if(ucCover > 0x09)
strTemp1.Format("厂家软件版本:%d.1%d ", *(frame.InPack.INFO+10),ucCover-0x0A) ;
else
strTemp1.Format("厂家软件版本:%d.0%d ", *(frame.InPack.INFO+10),ucCover) ;
strTemp2 += strTemp1 ;
pTemp += 12 ;
i = strlen(pTemp) ;
memcpy( acComp, pTemp , i) ;
acComp[i] = '\0' ;
strTemp1 = acComp ;
strTemp2 += "厂家名称:" + strTemp1 ;
//-测试-
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTemp1) ;
return 0 ;
}
catch(_com_error e)
{
strTip.Format( "异常:执行MDF响应命令ACmd51H发生异常:%s ",(LPCSTR)e.Description() ) ;
if (theApp.m_Baseinfo.SaveLog == 1 )
m_pAdoDB->WriteLog(strTemp1) ;
return -1 ;
}
}
int CDataAnalyse::ACmd60H(CInfoFrame frame,CEquipmentPort port)
{
int nLen ;
CString strTip ;
CAdoDB cAdo ;
//try
//{
// //cAdo.InitDB() ;
// nLen = pItem->strBuf.GetLength() ;
// if( nLen < 16 )
// {
// strTip.Format("异常:设备 %s 初始化响应命令格式出错 %s ",pItem->pEQ->strName,pItem->strBuf) ;
// theApp.DebugShow(strTip) ;
// cAdo.WriteLog(strTip) ;
// return -1 ;
// }
// if( pItem->pEQ->nTimeOut >= CONFIRM_TIME )
// {
// pItem->pEQ->nTimeOut = 0 ;
// strTip.Format("系统:设备 %s 通讯恢复正常",pItem->pEQ->strName) ;
// theApp.DebugShow(strTip) ;
// cAdo.WriteLog(strTip) ;
// }
// strTip.Format("系统:设备 %s 初始化 成功",pItem->pEQ->strName) ;
// theApp.DebugShow(strTip) ;
// cAdo.WriteLog(strTip) ;
// pItem->pEQ->unCommState = 1 ;//设置设备为已初始化状态
// pItem->pEQ->nTimeOut = 0 ;//超时复位
// return 0 ;
//}
//catch(_com_error e)
//{
// strTip.Format( "异常:执行MDF响应命令ACmd60H发生异常:%s ",(LPCSTR)e.Description() ) ;
// cAdo.WriteLog(strTip) ;
return -1 ;
//}
}
int CDataAnalyse::GetLevel(int iSecond)
{
CString strSQL,strTable,strTip,strField,strValue,strRange1,strRange2 ; //SQL语句
int iLevel = 0;
_variant_t var;
_RecordsetPtr pRsPtr ;
pRsPtr.CreateInstance(__uuidof(Recordset));
int iPos = theApp.m_Baseinfo.AlarmRange.Find('-');
if (iPos < 0)
return(0);
strRange1 = theApp.m_Baseinfo.AlarmRange.Left(iPos);
strRange2 = theApp.m_Baseinfo.AlarmRange.Mid(iPos + 1);
strSQL.Format("Select * From CMTAlarmLevel Where fCarrent1 =%s and fCarrent2 = %s and fSecond1 <=%d and fSecond2 > %d " ,\
strRange1,strRange2,iSecond,iSecond );
int iResult = m_pAdoDB->ReadDB(strSQL,pRsPtr,strTip);
if(iResult == 0)
{
if (!pRsPtr->adoEOF)
{
m_pAdoDB->GetFieldValue("fAlarmLevel",pRsPtr,iLevel);
}else
{
if (iSecond > 9 && iSecond <= 20 )
{
iLevel = 1;
}else if (iSecond > 20 && iSecond <= 350 )
{
iLevel = 2;
}else if (iSecond > 350 && iSecond <= 600 )
{
iLevel = 3;
}else if (iSecond > 600 )
{
iLevel = 4;
}
}
pRsPtr->Close();
}
return iLevel;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -