////////////////////////////////////////////////////////////////////////////// ////// ////// ////// 文 件: UpsDelta.cpp ////// ////// 作 者: Suguobing ////// ////// 创建时间: ////// ////// 说 明: Delta协议 ////// ////// ////// ////// 修改时间:2010-08-24 ////// ////// 修改说明: ////// ////// ////// ////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "CommProcess.h" #include "UpsDelta.h" CUpsDelta::CUpsDelta( char szPath[MAX_PATH], char szIniName[MAX_PATH], int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval ) { #if IS_USE_READMSG_CS InitializeCriticalSection(&m_csReadMsg); #endif MTVERIFY(m_hSemComm = CreateEvent(NULL, TRUE, TRUE, 0)); memset(m_szDelta_STBMsg, 0, sizeof(m_szDelta_STBMsg)); memset(m_szDelta_STIMsg, 0, sizeof(m_szDelta_STIMsg)); memset(m_szDelta_STOMsg, 0, sizeof(m_szDelta_STOMsg)); memset(m_szDelta_STPMsg, 0, sizeof(m_szDelta_STPMsg)); memset(m_szDelta_STAMsg, 0, sizeof(m_szDelta_STAMsg)); m_dwOnlineTick = 0; m_devOnline = TRUE; } CUpsDelta::~CUpsDelta() { #if IS_USE_READMSG_CS DeleteCriticalSection(& m_csReadMsg); #endif MTVERIFY(CloseHandle(m_hSemComm)); CloseComm(); } BOOL CUpsDelta::UpsDeltaOpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval) { BOOL bResult = FALSE; bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval ); return bResult; } int CUpsDelta::SendReadRequest( char szPath[MAX_PATH], char szIniName[MAX_PATH], int nCommPort, int nAddr, char szCmd[MAX_CMD], char szMsg[VAR_MSG], int nReversed1, int nReversed2, int nReversed3, int nReversed4, int nReversed5, float fReversed1, float fReversed2, float fReversed3, char szReversed1[MAX_RESERVED1], char szReversed2[MAX_RESERVED2], char szReversed3[MAX_RESERVED3], char szReversed4[MAX_RESERVED4], char szReversed5[MAX_RESERVED5] ) { int nIndex = 0, nLen = 0; char szSendMsg[UPS_DELTA_SEND_MSG] = {0}; char szType[UPS_TYPE_LENGTH] = {0}; int startBit = 0; int endBit = 0; m_address = nAddr; GetDeltaFromIni(szPath, szIniName, szCmd, szSendMsg, szType, nIndex, nLen, startBit, endBit); CCommProcess *pComm = FindComm(nCommPort); if( pComm == NULL ) return -1; int nRet = -1; if( ( strlen(m_szDelta_STBMsg) == 0 && ( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 ) ) || //获取系统模拟量量化数据(浮点数) ( strlen(m_szDelta_STIMsg) == 0 && ( strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 || strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 ) ) ||//UPS工作状态及传送顺序 ( strlen(m_szDelta_STOMsg) == 0 && ( strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0|| strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 || strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0 ) ) ||//UPS告警内容及传送 ( strlen(m_szDelta_STPMsg) == 0 && ( strcmp(szCmd, "cmd-39") == 0 ||strcmp(szCmd, "cmd-40") == 0 || strcmp(szCmd, "cmd-41") == 0 || strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 || strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 || strcmp(szCmd, "cmd-48") == 0 ) ) ||//获取系统参数(浮点数) ( strlen(m_szDelta_STAMsg) == 0 && ( strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 || strcmp(szCmd, "cmd-51") == 0 || strcmp(szCmd, "cmd-52") == 0 || strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 || strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 || strcmp(szCmd, "cmd-57") == 0 || strcmp(szCmd, "cmd-58") == 0 || strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 || strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 || strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 || strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ) ) || strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 ) { nRet = GetDeviceParam( pComm, szSendMsg, szCmd, szMsg, nIndex, nLen, szType ); if( nRet != 0 ) return nRet; } if( GetTickCount() - m_dwOnlineTick > 60 * 1000 && m_dwOnlineTick > 0 ) { m_devOnline = FALSE; } else if( GetTickCount() - m_dwOnlineTick < 60 * 1000 && m_dwOnlineTick > 0 ) { m_devOnline = TRUE; } if( m_devOnline == FALSE ) { return -1; } nRet = GetDeltaStbMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetDeltaStiMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetDeltaStoMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetDeltaStpMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetDeltaStaMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); LOG4C((LOG_NOTICE, "%s = %s", szCmd, szMsg)); return nRet; } int CUpsDelta::GetDeltaStbMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit) { int nRet = 0; if (strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif CString strSTB = CString(m_szDelta_STBMsg+7); CString strTemp = strSTB; int nTempIndex = -1; for( int i = 0; i < nIndex - 1; i++ ) { nTempIndex = strTemp.Find(";"); strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex); } strTemp = strTemp.Mid(0, nLen); strTemp.TrimLeft("0"); memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() ); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsDelta::GetDeltaStiMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit ) { int nRet = 0; if ( strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 || strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif CString strSTI = CString(m_szDelta_STIMsg+7); CString strTemp = strSTI; int nTempIndex = -1; for( int i = 0; i < nIndex - 1; i++ ) { nTempIndex = strTemp.Find(";"); strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex); } strTemp = strTemp.Mid(0, nLen); strTemp.TrimLeft("0"); memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() ); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsDelta::GetDeltaStoMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit ) { int nRet = 0; if (strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0|| strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 || strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif CString strSTO = CString(m_szDelta_STOMsg+7); CString strTemp = strSTO; int nTempIndex = -1; for( int i = 0; i < nIndex - 1; i++ ) { nTempIndex = strTemp.Find(";"); strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex); } strTemp = strTemp.Mid(0, nLen); strTemp.TrimLeft("0"); memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() ); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsDelta::GetDeltaStpMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit ) { int nRet = 0; if (strcmp(szCmd, "cmd-39") == 0 ||strcmp(szCmd, "cmd-40") == 0 || strcmp(szCmd, "cmd-41") == 0 || strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 || strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 || strcmp(szCmd, "cmd-48") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif CString strSTP = CString(m_szDelta_STPMsg+7); CString strTemp = strSTP; int nTempIndex = -1; for( int i = 0; i < nIndex - 1; i++ ) { nTempIndex = strTemp.Find(";"); strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex); } strTemp = strTemp.Mid(0, nLen); strTemp.TrimLeft("0"); memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() ); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsDelta::GetDeltaStaMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit ) { int nRet = 0; if ( strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 || strcmp(szCmd, "cmd-51") == 0 || strcmp(szCmd, "cmd-52") == 0 || strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 || strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 || strcmp(szCmd, "cmd-57") == 0 || strcmp(szCmd, "cmd-58") == 0 || strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 || strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 || strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 || strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif CString strSTA = CString(m_szDelta_STAMsg+7); CString strTemp = strSTA; int nTempIndex = -1; for( int i = 0; i < nIndex - 1; i++ ) { nTempIndex = strTemp.Find(";"); strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex); } strTemp = strTemp.Mid(0, nLen); strTemp.TrimLeft("0"); memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() ); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsDelta::GetDeviceParam( CCommProcess *pComm, //串口对象指针 char szSendMsg[UPS_DELTA_SEND_MSG], //发送Buffer char szCmd[MAX_CMD], // 命令 char szMsg[VAR_MSG], // 接收Buffer int &nIndex, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szType[TYPE_LENGTH]) // 变量数据类型 { int nRet = -1; nRet = RequestStatus(pComm, szSendMsg); if( nRet != 0 ) { return nRet; // 串口忙 } nRet = ResponseStatus(pComm, szCmd, szMsg, nIndex, nLen, szType); return nRet; } int CUpsDelta::GetDeltaFromIni(char szPath[MAX_PATH], //服务器程序所在目录 char szIniName[MAX_PATH], //配置文件名 char szCmd[MAX_CMD], //命令 char szSanTakSendMsg[MAX_CMD], //发送Buffer char nType[MAX_CMD], int &nIndex, int &nLen, int &startBit, int &endBit) { CHAR szFile[MAX_PATH + 1] = ""; wsprintf(szFile, "%s\\config\\%s", szPath, szIniName); szSanTakSendMsg[0] = '~'; szSanTakSendMsg[1] = '0'; szSanTakSendMsg[2] = '0'; szSanTakSendMsg[3] = 'P'; szSanTakSendMsg[4] = '0'; szSanTakSendMsg[5] = '0'; szSanTakSendMsg[6] = '3'; GetPrivateProfileString(szCmd, "SendCmd", "", szSanTakSendMsg + 7, sizeof(szSanTakSendMsg) - 7, szFile); nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile); nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile); return 0; } int CUpsDelta::RequestStatus(CCommProcess *pComm, char chSendMsg[UPS_DELTA_SEND_MSG] ) { #if DEBUG_DELTA //开关量,用于测试模拟数据 if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 ) { int nDatalen = (int)strlen(chSendMsg); ResetEvent(m_hSemComm); int nResult = pComm->Write((BYTE *)chSendMsg, nDatalen); if (nResult == nDatalen) { } else { SetEvent(m_hSemComm); //LOG4C((LOG_NOTICE, "长度不一")); return EER_CODE_UPSDELTA_COM_REGNUM; } } else { return ERR_CODE_UPSDELTA_COM_BUSY; //串口忙 } #endif return 0; } int CUpsDelta::ResponseStatus( CCommProcess *pComm, char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH] ) { #if DEBUG_DELTA int nReceiveLen = 0; int nProcessLen = 0; int nReadLen = 0; RESPONSE_STRUCT strcutResponse; memset(&strcutResponse, 0, sizeof(RESPONSE_STRUCT)); nReceiveLen = sizeof(RESPONSE_STRUCT); //LOG4C((LOG_NOTICE, "nReceiveLen = %d",nReceiveLen)); char *pBuff = new char[nReceiveLen]; memset(pBuff, 0 , nLen); nReadLen = pComm->Read((BYTE *)pBuff,nReceiveLen); if (nReadLen <= 0) { SetEvent(m_hSemComm); if (pBuff != NULL) { delete [] pBuff; pBuff = NULL; } return ERR_CODE_UPSDELTA_COM_READ_NO_DATA; } SetDeltaStbMsg(szCmd, pBuff); SetDeltaStiMsg(szCmd, pBuff); SetDeltaStoMsg(szCmd, pBuff); SetDeltaStpMsg(szCmd, pBuff); SetDeltaStaMsg(szCmd, pBuff); m_dwOnlineTick = GetTickCount(); // 设置串口等待事件为有信号 SetEvent( m_hSemComm ); if( pBuff != NULL) { delete[] pBuff; pBuff = NULL; } #else SimulationCommData(); #endif return 0; } void CUpsDelta::SetDeltaStbMsg(char szCmd[MAX_CMD], char *pBuff) { if (strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szDelta_STBMsg, pBuff, sizeof(m_szDelta_STBMsg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsDelta::SetDeltaStiMsg(char szCmd[MAX_CMD], char *pBuff) { if ( strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 || strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 || strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szDelta_STIMsg, pBuff, sizeof(m_szDelta_STIMsg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsDelta::SetDeltaStoMsg(char szCmd[MAX_CMD], char *pBuff) { if ( strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 || strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szDelta_STOMsg, pBuff, sizeof(m_szDelta_STOMsg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsDelta::SetDeltaStpMsg(char szCmd[MAX_CMD], char *pBuff) { if ( strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 || strcmp(szCmd, "cmd-41") == 0 || strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 || strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 || strcmp(szCmd, "cmd-48") == 0) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szDelta_STPMsg,pBuff,sizeof(m_szDelta_STPMsg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsDelta::SetDeltaStaMsg(char szCmd[MAX_CMD], char *pBuff) { if ( strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 || strcmp(szCmd, "cmd-51") == 0 || strcmp(szCmd, "cmd-52") == 0 || strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 || strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 || strcmp(szCmd, "cmd-57") == 0 || strcmp(szCmd, "cmd-58") == 0 || strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 || strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 || strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 || strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szDelta_STAMsg,pBuff,sizeof(m_szDelta_STAMsg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsDelta::SimulationCommData(void) { CString strRAT, strSTB, strSTI, strSTO, strSTA; strRAT = "~00D031;220;500;220;;;;;;;;;;;;;;;;;;;"; strSTB = "~00D016;0;0;;;;;;;;100;"; strSTI = "~00D022;3;500;2212;;;;;;;;;;;"; strSTO = "~00D036;500;3;2200;1000;136000;900;;;;;;;;;"; //strSTA = "1;1;1;1;1;1;1;0;1;0;1;1;0;1;1;1;1;1;1;1;"; strSTA = "~00D041;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;0;0;0;"; memcpy(m_szDelta_STAMsg, (char *)(LPCTSTR)strSTA, strSTA.GetLength()); memcpy(m_szDelta_STBMsg, (char *)(LPCTSTR)strSTB, strSTB.GetLength()); memcpy(m_szDelta_STIMsg, (char *)(LPCTSTR)strSTI, strSTI.GetLength()); memcpy(m_szDelta_STOMsg, (char *)(LPCTSTR)strSTO, strSTO.GetLength()); } int CUpsDelta::RequestWrStatus(char szSendMsg[]) { return 0; } int CUpsDelta::ResponseWrStatus(char szSendMsg[]) { return 0; } int CUpsDelta::SendSetReuest( char szPath[MAX_PATH], // 程序所在路径 char szIniName[MAX_PATH], // 配置文件名称 int nCommPort, // 串行端口 int nAddr, // 设备地址 char szCmd[MAX_CMD], // 请求命令 char szMsg[VAR_MSG], // 响应的值 int nReversed1, // 预留整形参数1接口 int nReversed2, // 预留整形参数2接口 int nReversed3, // 预留整形参数3接口 int nReversed4, // 预留整形参数4接口 int nReversed5, // 预留整形参数5接口 float fReversed1, // 预留float参数1接口 float fReversed2, // 预留float参数2接口 float fReversed3, // 预留float参数3接口 char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口 char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口 char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口 char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口 char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口 ) { return 0; } void CUpsDelta::ReturnData(char *szSource, char *szDestion, int nIndex) { char nlen[3] = {0}; nlen[0] = szSource[4]; nlen[1] = szSource[5]; nlen[2] = szSource[6]; int len = atoi(nlen); BOOL bSi = FALSE; int i = 0; int index = 0; if (szSource[7] == 0x3b) { index = 1; } while(i < len) { if (index == nIndex) { int datalen = 0; for (int k = 0;i < len ; k++) { if (szSource[i+7] != 0x3b) szDestion[k] = szSource[i+7]; else break; i++; } break; } if (szSource[i+7] == 0x3b) { int j = 0; for (;i 1) index += 1 ; if (index == nIndex) break; } } if (index == nIndex) { int datalen = 0; for (int k = 0;i < len ; k++) { if (szSource[i+7] != 0x3b) szDestion[k] = szSource[i+7]; else break; i++; } break; } if (szSource[i+7] != 0x3b) { index++; if (index == nIndex) continue; for (;i < len ;i++) if (szSource[i+7] == 0x3b) { --i; bSi = FALSE; break; } } i++; } }