#include "stdafx.h" #include "UpsNxr.h" #include "CommProcess.h" CUPSNxr::CUPSNxr(char *szPath,char *szIniName,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 ) ); //创建或打开一个命名的或无名的事件对象 for( int i = 0; i < MAX_ADDR; i++ ) { memset(m_szNxr_41Msg[i], 0, sizeof(m_szNxr_41Msg[i])); memset(m_szNxr_43Msg[i], 0, sizeof(m_szNxr_43Msg[i])); memset(m_szNxr_44Msg[i], 0, sizeof(m_szNxr_44Msg[i])); memset(m_szNxr_E1Msg[i], 0, sizeof(m_szNxr_E1Msg[i])); memset(m_szNxr_E2Msg[i], 0, sizeof(m_szNxr_E2Msg[i])); memset(m_szNxr_E3Msg[i], 0, sizeof(m_szNxr_E3Msg[i])); memset(m_szNxr_E7Msg[i], 0, sizeof(m_szNxr_E7Msg[i])); m_devOnline[i] = TRUE; m_dwOnlineTick[i] = 0; } } CUPSNxr::~CUPSNxr() { #if IS_USE_READMSG_CS DeleteCriticalSection( &m_csReadMsg ); #endif MTVERIFY( CloseHandle( m_hSemComm ) ); CloseComm(); } BOOL CUPSNxr::NxrOpenComm(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 ); //LOG4C((LOG_NOTICE," CUPSNxr::NxrOpenComm")); return bResult; } int CUPSNxr::SendReadRequest( char *szPath, char *szIniName, int nCommPort, int nAddr, char *szCmd, char *szMsg, int nReversed1, int nReversed2, int nReversed3, int nReversed4, int nReversed5, float fReversed1, float fReversed2, float fReversed3, char *szReversed1, char *szReversed2, char *szReversed3, char *szReversed4, char *szReversed5 ) { CCommProcess *pComm = FindComm(nCommPort); if( pComm == NULL ) return -1; int nRet = -1; int nIndex(0), nLen(0), IniSendlen(0),iSBit(0), iEBit(0); char IniSendCMD[MAX_CMD] = {0}, szDataType[CMD_TYPE] = {0}; GetIniInfo(szPath,szIniName,szCmd,IniSendCMD,IniSendlen,szDataType,nIndex,nLen,iSBit,iEBit); int iCmd = atoi(szCmd + 4); if( (strlen(m_szNxr_41Msg[nAddr - 1]) == 0 && (iCmd >= 1 && iCmd <=15)) || iCmd == 1 || //获取系统模拟量量化数据(浮点数) ( strlen(m_szNxr_43Msg[nAddr - 1]) == 0 && (iCmd >= 16 && iCmd <=40)) || iCmd == 16 || //获取开关输入状态 ( strlen(m_szNxr_44Msg[nAddr - 1]) == 0 && (iCmd >= 41 && iCmd <=127)) || iCmd == 41 || //报警量 (strlen(m_szNxr_E1Msg[nAddr - 1]) == 0 && (iCmd >= 128 && iCmd <=143)) || iCmd == 130 || //E1获取自定义模拟量量化数据1(浮点数,厂家扩展模拟量1) (strlen(m_szNxr_E2Msg[nAddr - 1]) == 0 && (iCmd >= 144 && iCmd <=163)) || iCmd == 146 || //获取自定义模拟量量化数据2(浮点数,厂家扩展模拟量2) (strlen(m_szNxr_E3Msg[nAddr - 1]) == 0 && (iCmd >= 164 && iCmd <=173)) || iCmd == 164 || //获取自定义模拟量量化数据3(浮点数,厂家扩展模拟量3) (strlen(m_szNxr_E7Msg[nAddr - 1]) == 0 && (iCmd >= 174 && iCmd <=183)) || iCmd == 176 //获取自定义模拟量量化数据4(浮点数,厂家扩展模拟量4) ) { nRet = GetDeviceParam( nAddr,pComm,szCmd,IniSendCMD,IniSendlen ); if( nRet != 0 ) return nRet; } if( GetTickCount() - m_dwOnlineTick[nAddr - 1] > 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 ) m_devOnline[nAddr - 1] = FALSE; else if( GetTickCount() - m_dwOnlineTick[nAddr - 1] < 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 ) m_devOnline[nAddr - 1] = TRUE; if( m_devOnline[nAddr - 1] == FALSE ) return -1; nRet = GetNxr_41VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType, iSBit, iEBit); nRet = GetNxr_43VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType, iSBit, iEBit); nRet = GetNxr_44VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType, iSBit, iEBit); nRet = GetNxr_E1VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType, iSBit, iEBit); nRet = GetNxr_E2VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType, iSBit, iEBit); nRet = GetNxr_E3VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType, iSBit, iEBit); nRet = GetNxr_E7VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType, iSBit, iEBit); // if (iCmd == 43) // LOG4C((LOG_NOTICE, "%s = %s", szCmd, szMsg)); return nRet; } int CUPSNxr::GetDeviceParam(int nAddr,CCommProcess *pComm,char *szCmd,char *IniSendCMD, const int &IniSendlen) { int nRet = -1; nRet = Send_ReadDeviceData(nAddr,pComm,szCmd,IniSendCMD,IniSendlen); if( nRet != 0 ) { LOG4C((LOG_NOTICE,"RequestStatus::Error")); return nRet; } nRet = Recv_ReadDeviceData(nAddr,pComm,szCmd); return nRet; } int CUPSNxr::Send_ReadDeviceData(int nAddr,CCommProcess *pComm,char *szCmd, const char *IniSendCMD,const int &IniSendlen) { int nRet = -1; #if DEBUG_NXR char chLength[4] = {0}; char chChkSum[5] = {0}; if ((strcmp(IniSendCMD, "43") == 0) || (strcmp(IniSendCMD, "44") == 0) || (strcmp(IniSendCMD, "E3") == 0)) { int iLen = sizeof(REQUESTNOCOMMD); REQUESTNOCOMMD RequestPara; memset( &RequestPara, 0, iLen ); //起始位 RequestPara.Start = 0x7E; //通讯协议版本 RequestPara.Version[0] = 0x31; RequestPara.Version[1] = 0x30; //RequestPara.Version[1] = 0x32; //设备地址描述 RequestPara.Address[0] = ByteToAscii((nAddr>>4) & 0x0f); RequestPara.Address[1] = ByteToAscii(nAddr & 0x0f); //Cid1 RequestPara.Cid1[0] = 0x32; RequestPara.Cid1[1] = 0x41; //Cid2 memcpy(RequestPara.Cid2, IniSendCMD, 2); RequestPara.Lenth[1] = 0x30; RequestPara.Lenth[2] = 0x30; RequestPara.Lenth[3] = 0x30; RequestPara.Lenth[0] = ByteToAscii(GetLengthSum(RequestPara.Lenth)); BYTE *pDataBuf = new BYTE[ iLen - sizeof(RequestPara.chkSum) - 1 ]; memset(pDataBuf, 0, iLen - sizeof(RequestPara.chkSum) - 1 ); memcpy(pDataBuf, &RequestPara, iLen - sizeof(RequestPara.chkSum) - 1 ); GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.chkSum) - 2 ); RequestPara.chkSum[0] = chChkSum[0]; RequestPara.chkSum[1] = chChkSum[1]; RequestPara.chkSum[2] = chChkSum[2]; RequestPara.chkSum[3] = chChkSum[3]; //结束符 RequestPara.End = 0x0D; if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口 { int nDataLen = (int)sizeof(RequestPara); ResetEvent( m_hSemComm ); int nResult = pComm->Write((BYTE *)&RequestPara, nDataLen); if( nResult == nDataLen ) { } else { delete []pDataBuf; SetEvent( m_hSemComm ); return EER_CODE_NXR_COM_WRITE_DATA; } } else { //LOG4C((LOG_NOTICE, "m_hSemComm no single")); delete []pDataBuf; return ERR_CODE_NXR_COM_BUSY; } delete[]pDataBuf; } else if ((strcmp(IniSendCMD, "41") == 0) || (strcmp(IniSendCMD, "E1") == 0) || (strcmp(IniSendCMD, "E2") == 0) ) { int iLen = sizeof(REQUESTTWOCOMMD); REQUESTTWOCOMMD RequestPara; memset( &RequestPara, 0, iLen ); //起始位 RequestPara.Start = 0x7E; //通讯协议版本 RequestPara.Version[0] = 0x31; RequestPara.Version[1] = 0x30; //设备地址描述 RequestPara.Address[0] = ByteToAscii((nAddr>>4) & 0x0f); RequestPara.Address[1] = ByteToAscii(nAddr & 0x0f); //Cid1 RequestPara.Cid1[0] = 0x32; RequestPara.Cid1[1] = 0x41; //Cid2 memcpy(RequestPara.Cid2, IniSendCMD, 2); RequestPara.Lenth[1] = 0x30; RequestPara.Lenth[2] = 0x30; RequestPara.Lenth[3] = 0x32; RequestPara.Lenth[0] = ByteToAscii(GetLengthSum(RequestPara.Lenth)); RequestPara.GroupInfo[0] = 0x30; RequestPara.GroupInfo[1] = 0x30; BYTE *pDataBuf = new BYTE[ iLen - sizeof(RequestPara.chkSum) - 1 ]; memset(pDataBuf, 0, iLen - sizeof(RequestPara.chkSum) - 1 ); memcpy(pDataBuf, &RequestPara, iLen - sizeof(RequestPara.chkSum) - 1 ); GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.chkSum) - 2 ); RequestPara.chkSum[0] = chChkSum[0]; RequestPara.chkSum[1] = chChkSum[1]; RequestPara.chkSum[2] = chChkSum[2]; RequestPara.chkSum[3] = chChkSum[3]; //结束符 RequestPara.End = 0x0D; //LOG4C_HEX_DUMP((LOG_NOTICE, (char *)&RequestPara, sizeof(RequestPara))); if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口 { int nDataLen = (int)sizeof(RequestPara); ResetEvent( m_hSemComm ); int nResult = pComm->Write((BYTE *)&RequestPara, nDataLen); if( nResult == nDataLen ) { } else { delete []pDataBuf; SetEvent( m_hSemComm ); return EER_CODE_NXR_COM_WRITE_DATA; } } else { //LOG4C((LOG_NOTICE, "m_hSemComm no single")); delete []pDataBuf; return ERR_CODE_NXR_COM_BUSY; } delete[]pDataBuf; } else if (strcmp(IniSendCMD, "E7") == 0) { int iLen = sizeof(REQUESTFOURCOMMD); REQUESTFOURCOMMD RequestPara; memset( &RequestPara, 0, iLen ); //起始位 RequestPara.Start = 0x7E; //通讯协议版本 RequestPara.Version[0] = 0x31; RequestPara.Version[1] = 0x30; //设备地址描述 RequestPara.Address[0] = ByteToAscii((nAddr>>4) & 0x0f); RequestPara.Address[1] = ByteToAscii(nAddr & 0x0f); //Cid1 RequestPara.Cid1[0] = 0x32; RequestPara.Cid1[1] = 0x41; //Cid2 memcpy(RequestPara.Cid2, IniSendCMD, 2); RequestPara.Lenth[1] = 0x30; RequestPara.Lenth[2] = 0x30; RequestPara.Lenth[3] = 0x34; RequestPara.Lenth[0] = ByteToAscii(GetLengthSum(RequestPara.Lenth)); RequestPara.GroupInfo[0] = 0x30; RequestPara.GroupInfo[1] = 0x31; RequestPara.GroupInfo[2] = 0x30; RequestPara.GroupInfo[3] = 0x30; BYTE *pDataBuf = new BYTE[ iLen - sizeof(RequestPara.chkSum) - 1 ]; memset(pDataBuf, 0, iLen - sizeof(RequestPara.chkSum) - 1 ); memcpy(pDataBuf, &RequestPara, iLen - sizeof(RequestPara.chkSum) - 1 ); GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.chkSum) - 2 ); RequestPara.chkSum[0] = chChkSum[0]; RequestPara.chkSum[1] = chChkSum[1]; RequestPara.chkSum[2] = chChkSum[2]; RequestPara.chkSum[3] = chChkSum[3]; //结束符 RequestPara.End = 0x0D; //LOG4C_HEX_DUMP((LOG_NOTICE, (char *)&RequestPara, sizeof(RequestPara))); if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口 { int nDataLen = (int)sizeof(RequestPara); ResetEvent( m_hSemComm ); int nResult = pComm->Write((BYTE *)&RequestPara, nDataLen); if( nResult == nDataLen ) { } else { delete []pDataBuf; SetEvent( m_hSemComm ); return EER_CODE_NXR_COM_WRITE_DATA; } } else { //LOG4C((LOG_NOTICE, "m_hSemComm no single")); delete []pDataBuf; return ERR_CODE_NXR_COM_BUSY; } delete[]pDataBuf; } #endif return 0; } int CUPSNxr::Recv_ReadDeviceData(int nAddr,CCommProcess *pComm,char *szCmd) { #if DEBUG_NXR int nReceiveLen = 0; int nProcessLen = 0; int nReadLen = 0; RESPONSE_STRUCT structResponse; memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) ); nReceiveLen = sizeof(RESPONSE_STRUCT); char *pBuffer = new char[ nReceiveLen ]; memset(pBuffer, 0, nReceiveLen); nReadLen = pComm->Read((BYTE *)pBuffer,nReceiveLen); //if ( strcmp(szCmd, "cmd-41") == 0) //{ // LOG4C((LOG_NOTICE,"UPS-Nxr : %s",pBuffer)); //} if( nReadLen <= 0) { SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_NXR_COM_READ_NO_DATA; } if (LengthCheck(pBuffer) != 0) { SetEvent(m_hSemComm); if (pBuffer != NULL) { delete [] pBuffer; pBuffer = NULL; } return ERR_CODE_RTN_LCHKSUM_ERROR; } if (!ChkSumCheck(pBuffer, nReadLen)) { SetEvent(m_hSemComm); if (pBuffer != NULL) { delete [] pBuffer; pBuffer = NULL; } return ERR_CODE_RTN_CHKSUM_ERROR; //校验码校验出错 } if (RtnCheck(pBuffer) != 0) { SetEvent(m_hSemComm); if (pBuffer != NULL) { delete [] pBuffer; pBuffer = NULL; } return ERR_CODE_RTN_CHKSUM_RTN_ERROR; //RTN校验出错 } SetNxr_41VarMsg(nAddr, szCmd, pBuffer); SetNxr_43VarMsg(nAddr, szCmd, pBuffer); SetNxr_44VarMsg(nAddr, szCmd, pBuffer); SetNxr_E1VarMsg(nAddr, szCmd, pBuffer); SetNxr_E2VarMsg(nAddr, szCmd, pBuffer); SetNxr_E3VarMsg(nAddr, szCmd, pBuffer); SetNxr_E7VarMsg(nAddr, szCmd, pBuffer); m_dwOnlineTick[nAddr - 1] = GetTickCount(); // 设置串口等待事件为有信号 SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } #else SimulationCommData(nAddr); #endif return 0; } int CUPSNxr::GetNxr_41VarMsg(int nAddr,char *szCmd,char *szMsg,int &nIndex,int &nLen,char *szType,int iSBit,int iEBit) { int nRet = 0; int iCmd = atoi(szCmd + 4); if( iCmd >= 1 && iCmd <= 15) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif DataConversion(szType, m_szNxr_41Msg[nAddr - 1] + nIndex, szMsg, nLen, iSBit, iEBit); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUPSNxr::GetNxr_43VarMsg(int nAddr,char *szCmd,char *szMsg,int &nIndex,int &nLen,char *szType,int iSBit,int iEBit) { int nRet = 0; int iCmd = atoi(szCmd + 4); if( iCmd >= 16 && iCmd <= 40) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif DataConversion(szType, m_szNxr_43Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUPSNxr::GetNxr_44VarMsg(int nAddr,char *szCmd,char *szMsg,int &nIndex,int &nLen,char *szType,int iSBit,int iEBit) { int nRet = 0; int iCmd = atoi(szCmd + 4); if( iCmd >= 41 && iCmd <= 127) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif DataConversion(szType, m_szNxr_44Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUPSNxr::GetNxr_E1VarMsg(int nAddr,char *szCmd,char *szMsg,int &nIndex,int &nLen,char *szType,int iSBit,int iEBit) { int nRet = 0; int iCmd = atoi(szCmd + 4); if( iCmd >= 128 && iCmd <= 143) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif DataConversion(szType, m_szNxr_E1Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUPSNxr::GetNxr_E2VarMsg(int nAddr,char *szCmd,char *szMsg,int &nIndex,int &nLen,char *szType,int iSBit,int iEBit) { int nRet = 0; int iCmd = atoi(szCmd + 4); if( iCmd >= 144 && iCmd <= 163) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif DataConversion(szType, m_szNxr_E2Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUPSNxr::GetNxr_E3VarMsg(int nAddr,char *szCmd,char *szMsg,int &nIndex,int &nLen,char *szType,int iSBit,int iEBit) { int nRet = 0; int iCmd = atoi(szCmd + 4); if( iCmd >= 164 && iCmd <= 173) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif DataConversion(szType, m_szNxr_E3Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUPSNxr::GetNxr_E7VarMsg(int nAddr,char *szCmd,char *szMsg,int &nIndex,int &nLen,char *szType,int iSBit,int iEBit) { int nRet = 0; int iCmd = atoi(szCmd + 4); if( iCmd >= 174 && iCmd <= 183) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif DataConversion(szType, m_szNxr_E7Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } void CUPSNxr::SetNxr_41VarMsg( int nAddr, char *szCmd, char *pBuffer) { int iCmd = atoi(szCmd + 4); if( iCmd >= 1 && iCmd <= 15) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szNxr_41Msg[nAddr - 1], pBuffer, sizeof(m_szNxr_41Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUPSNxr::SetNxr_43VarMsg( int nAddr, char *szCmd, char *pBuffer) { int iCmd = atoi(szCmd + 4); if( iCmd >= 16 && iCmd <= 40) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szNxr_43Msg[nAddr - 1], pBuffer, sizeof(m_szNxr_43Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUPSNxr::SetNxr_44VarMsg( int nAddr, char *szCmd, char *pBuffer) { int iCmd = atoi(szCmd + 4); if( iCmd >= 41 && iCmd <= 127) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif //memcpy(m_szNxr_44Msg[nAddr - 1], pBuffer + 10, sizeof(m_szNxr_44Msg[nAddr - 1])); //Z.t国贸时的UPS处理; memcpy(m_szNxr_44Msg[nAddr - 1], pBuffer , sizeof(m_szNxr_44Msg[nAddr - 1])); //Z.t思明公安局有时的UPS处理; #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUPSNxr::SetNxr_E1VarMsg( int nAddr, char *szCmd, char *pBuffer) { int iCmd = atoi(szCmd + 4); if( iCmd >= 128 && iCmd <= 143) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szNxr_E1Msg[nAddr - 1], pBuffer, sizeof(m_szNxr_E1Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUPSNxr::SetNxr_E2VarMsg( int nAddr, char *szCmd, char *pBuffer) { int iCmd = atoi(szCmd + 4); if( iCmd >= 144 && iCmd <= 163) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szNxr_E2Msg[nAddr - 1], pBuffer, sizeof(m_szNxr_E2Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUPSNxr::SetNxr_E3VarMsg( int nAddr, char *szCmd, char *pBuffer) { int iCmd = atoi(szCmd + 4); if( iCmd >= 164 && iCmd <= 173) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szNxr_E3Msg[nAddr - 1], pBuffer, sizeof(m_szNxr_E3Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUPSNxr::SetNxr_E7VarMsg( int nAddr, char *szCmd, char *pBuffer) { int iCmd = atoi(szCmd + 4); if( iCmd >= 174 && iCmd <= 183) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szNxr_E7Msg[nAddr - 1], pBuffer, sizeof(m_szNxr_E7Msg[nAddr - 1])); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } WORD CUPSNxr::RtnCheck(char Msg[VAR_MSG]) { char buffer[3] = {0}; int j = 0; for (int i = 7; i < 9; i++) { buffer[j++] = Msg[i]; } buffer[j] = '\0'; if (strcmp(buffer,"00") == 0) { return 0; } else if (strcmp(buffer,"01") == 0) { return ERR_CODE_RTN_VER_ERROR; } else if (strcmp(buffer,"02") == 0) { return ERR_CODE_RTN_CHKSUM_ERROR; } else if (strcmp(buffer,"03") == 0) { return ERR_CODE_RTN_LCHKSUM_ERROR; } else if (strcmp(buffer,"04") == 0) { return ERR_CODE_RTN_CID_ERROR; } else if (strcmp(buffer,"05") == 0) { return ERR_CODE_RTN_COMMAND_FORMAT; } else if (strcmp(buffer,"06") == 0) { return ERR_CODE_RTN_INVALID_LIMIT; } else if (strcmp(buffer,"10") == 0) { return ERR_CODE_RTN_OPERATE_FAIL; } return 0; } UINT CUPSNxr::GetCheckSum(char *pBuf, char chDest[5], int len) { WORD iSum = 0; for(int i=0; i