////////////////////////////////////////////////////////////////////////////// ////// ////// ////// 文 件: UpsUH31.cpp ////// ////// 作 者: Suguobing ////// ////// 创建时间: ////// ////// 说 明: UH31协议 ////// ////// ////// ////// 修改时间:2010-05-10 ////// ////// 修改说明:数据转换 ////// ////// ////// ////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "CommProcess.h" #include "UpsUH31.h" //UINT CUpsUhk31::ConfirmChar(char *pSource,char *pDes, char *pType,int len)//ASCII转换为字符串 //{ // char *nbuf = new char[len]; // memset(nbuf, 0, len); // char nbuf1[30] = {0}; // char nchar; // char nchar1; // char nchar2; // char nchar3; // // for (int i = 0; i< len; i++) // { // nbuf[i] = (char)AsciiToBYTE(pSource[i]); // } // // if (strcmp(pType, "DDWORD") == 0) // { // int j = 0; // for (int i = 0; i < len; i++) // { // nbuf1[j] = nbuf[i]<<4 | nbuf[i+1]; // j++; // i+=2; // } // strcpy(pDes, nbuf1); // // } // // if (strcmp(pType, "UNIT") == 0) // { // nchar = nbuf[0]<<4 | nbuf[1]; // nchar1 = nbuf[2]<<4 | nbuf[3]; // nchar2 = nbuf[4]<<4 | nbuf[5]; // nchar3 = nbuf[6]<<4 | nbuf[6]; // // if ((nchar == 0) && (nchar1 == 0) && (nchar2 == 0) && (nchar3 == 0)) // { // sprintf(pDes, "0"); // } // else // { // sprintf(pDes, "%c%c%c%c",nchar, nchar1, nchar2, nchar3); // } // } // // if (strcmp(pType,"BYTE") == 0) // { // nchar = (nbuf[0]<<4) | nbuf[1]; // if (nchar == 0) // { // sprintf(pDes,"0"); // } // else // { // sprintf(pDes,"%c",nchar); // } // } // if (strcmp(pType, "WORD") == 0) // { // nchar = nbuf[0]<<4 | nbuf[1]; // nchar1 = nbuf[2]<<4 | nbuf[3]; // if ((nchar == 0) && (nchar1 == 0)) // { // sprintf(pDes,"0"); // } // else // { // sprintf(pDes,"%c%c",nchar,nchar1); // // } // // } // if (strcmp(pType,"FLOAT") == 0) // { // for (int i = 0; i < len; i++) // { // nbuf[i] = (char)AsciiToBYTE(pSource[i]); // } // // Test data; // // data.ch[0] = (nbuf[0]<<4) | nbuf[1]; // data.ch[1] = (nbuf[2]<<4) | nbuf[3]; // data.ch[2] = (nbuf[4]<<4) | nbuf[5]; // data.ch[3] = (nbuf[6]<<4) | nbuf[7]; // // sprintf(pDes,"%f",data.ff); // } // // delete [] nbuf; // return 0; //} CUpsUhk31::CUpsUhk31( 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); //InitializeCriticalSection(&m_csReadMsg); #endif MTVERIFY(m_hSemComm = CreateEvent(NULL, TRUE, TRUE, 0)); memset(m_szUhk_Q41Msg, 0, sizeof(m_szUhk_Q41Msg)); memset(m_szUhk_Q43Msg, 0, sizeof(m_szUhk_Q43Msg)); memset(m_szUhk_Q44Msg, 0, sizeof(m_szUhk_Q44Msg)); memset(m_szUhk_Q45Msg, 0, sizeof(m_szUhk_Q45Msg)); memset(m_szUhk_Q46Msg, 0, sizeof(m_szUhk_Q46Msg)); memset(m_szUhk_Q48Msg, 0, sizeof(m_szUhk_Q48Msg));//设定系统参数 memset(m_szUhk_Q4FMsg, 0, sizeof(m_szUhk_Q4FMsg)); memset(m_szUhk_Q50Msg, 0, sizeof(m_szUhk_Q50Msg)); m_dwOnlineTick = 0; m_devOnline = TRUE; //OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval ); } CUpsUhk31::~CUpsUhk31() { #if IS_USE_READMSG_CS DeleteCriticalSection(& m_csReadMsg); #endif MTVERIFY(CloseHandle(m_hSemComm)); CloseComm(); } BOOL CUpsUhk31::UpsUhkOpenComm(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 CUpsUhk31::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_UHK_SEND_MSG] = {0}; char szType[UPS_TYPE_LENGTH] = {0}; int startBit = 0; int endBit = 0; m_address = nAddr; GetUhkFromIni(szPath, szIniName, szCmd, szSendMsg, szType, nIndex, nLen, startBit, endBit); CCommProcess *pComm = FindComm(nCommPort); if( pComm == NULL ) return -1; int nRet = -1; if( ( strlen(m_szUhk_Q41Msg) == 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 || 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) ) || //获取系统模拟量量化数据(浮点数) ( strlen(m_szUhk_Q43Msg) == 0 && (strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0 ) )||//UPS工作状态及传送顺序 ( strlen(m_szUhk_Q44Msg) == 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 || 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 ) ) ||//UPS告警内容及传送 ( strlen(m_szUhk_Q45Msg) == 0 && (strcmp(szCmd, "cmd-73") == 0 ) ) ||//获取系统参数(浮点数) ( strlen(m_szUhk_Q46Msg) == 0 && ( strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 || strcmp(szCmd, "cmd-48") == 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 ) ) ||//获取监测模块 ( strlen(m_szUhk_Q4FMsg) == 0 && (strcmp(szCmd, "cmd-74") == 0 ) ) ||//获取通信协议版本号 ( strlen(m_szUhk_Q50Msg) == 0 && (strcmp(szCmd, "cmd-75") == 0 ) ) || //获取设备地址 strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 || strcmp(szCmd, "cmd-75") == 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 = GetUhkQ41VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetUhkQ43VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetUhkQ44VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetUhkQ45VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetUhkQ46VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetUhkQ4FVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); nRet = GetUhkQ50VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit); return nRet; } int CUpsUhk31::GetUhkQ41VarMsg(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 || 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) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif DataConversion(szType, m_szUhk_Q41Msg + nIndex, szMsg, nLen, startBit, endBit); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsUhk31::GetUhkQ43VarMsg(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-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif DataConversion(szType, m_szUhk_Q43Msg + nIndex, szMsg, nLen, startBit, endBit); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsUhk31::GetUhkQ44VarMsg(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-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 || 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 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif DataConversion(szType, m_szUhk_Q44Msg + nIndex, szMsg, nLen, startBit, endBit); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsUhk31::GetUhkQ45VarMsg(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-73") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif DataConversion(szType, m_szUhk_Q45Msg + nIndex, szMsg, nLen, startBit, endBit); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsUhk31::GetUhkQ46VarMsg(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-46") == 0 || strcmp(szCmd, "cmd-47") == 0 || strcmp(szCmd, "cmd-48") == 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 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif DataConversion(szType, m_szUhk_Q45Msg + nIndex, szMsg, nLen, startBit, endBit); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsUhk31::GetUhkQ4FVarMsg(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-74") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif DataConversion(szType, m_szUhk_Q4FMsg + nIndex, szMsg, nLen, startBit, endBit); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsUhk31::GetUhkQ50VarMsg(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-75") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif DataConversion(szType, m_szUhk_Q50Msg + nIndex, szMsg, nLen, startBit, endBit); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CUpsUhk31::GetDeviceParam( CCommProcess *pComm, //串口对象指针 char szSendMsg[UPS_UHK_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 CUpsUhk31::GetUhkFromIni(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); TRACE("szFile =%s\n",szFile); GetPrivateProfileString(szCmd, "SendCmd", "", szSanTakSendMsg, 10, szFile); szSanTakSendMsg[strlen(szSanTakSendMsg)] = '\0'; GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile); nType[strlen(nType)] = '\0'; nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile); nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile); TRACE("GetUhkFromIniszPath=%s\nszIniName=%s\nszCmd=%s\nzSanTakSendMsg=%s\nsType=%s\nnIndex=%d\nnLen = %d\n", szPath,szIniName,szCmd,szSanTakSendMsg,nType,nIndex,nLen); return 0; } int CUpsUhk31::RequestStatus(CCommProcess *pComm, char chSendMsg[UPS_UHK_SEND_MSG] ) { #if DEBUG_UHK //开关量,用于测试模拟数据 REQUEST_STRUCT structResuest; int nLen = sizeof(REQUEST_STRUCT); char chkSumBuf[5] ={0}; char addBuf[UPS_TYPE_LENGTH] = {0}; memset(&structResuest,0,nLen); // structResuest.headMes.Start = 0x7E; // structResuest.headMes.Version[0] = 0x32; structResuest.headMes.Version[1] = 0x31; // sprintf(addBuf, "%x",m_address); structResuest.headMes.Address[0] = ByteToAscii((m_address >> 4) & 0x0f); structResuest.headMes.Address[1] = ByteToAscii(m_address & 0x0f); // structResuest.headMes.Cid1[0] = 0x32; structResuest.headMes.Cid1[1] = 0x41; structResuest.headMes.Cid2[0] = ByteToAscii(chSendMsg[0] & 0x0f); structResuest.headMes.Cid2[1] = ByteToAscii(chSendMsg[1] & 0x0f); structResuest.headMes.Lenth[0] = 0x30; structResuest.headMes.Lenth[1] = 0x30; structResuest.headMes.Lenth[2] = 0x30; structResuest.headMes.Lenth[3] = 0x30; BYTE *pDatabuf = new BYTE[nLen - sizeof(structResuest.chkSum) - 1]; memset(pDatabuf,0,nLen - sizeof(structResuest.chkSum) - 1); memcpy(pDatabuf,&structResuest,nLen - sizeof(structResuest.chkSum) - 1); GetCheckSum((char *)pDatabuf + 1, chkSumBuf, nLen - sizeof(structResuest.chkSum) - 2); structResuest.chkSum[0] = chkSumBuf[0]; structResuest.chkSum[1] = chkSumBuf[1]; structResuest.chkSum[2] = chkSumBuf[2]; structResuest.chkSum[3] = chkSumBuf[3]; structResuest.End = 0x0D; TRACE("headMes.Start= %c\nversion=%s\ncid1=%s\ncid2=%s\nlength=%s\nchksum=%s\n\n", structResuest.headMes.Start,structResuest.headMes.Version, structResuest.headMes.Address,structResuest.headMes.Cid1, structResuest.headMes.Cid2,structResuest.headMes.Lenth,structResuest.chkSum,structResuest.End); if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 ) { int nDatalen = (int)sizeof(structResuest); ResetEvent(m_hSemComm); int nResult = pComm->Write((BYTE *)&structResuest, nDatalen); if (nResult == nDatalen) { } else { delete [] pDatabuf; SetEvent(m_hSemComm); return EER_CODE_UPSKEHUA_COM_REGNUM; } } else { delete [] pDatabuf; return ERR_CODE_UPSKEHUA_COM_BUSY; //串口忙 } delete [] pDatabuf; #endif TRACE("resquest return 0"); return 0; } int CUpsUhk31::ResponseStatus( CCommProcess *pComm, char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH] ) { #if DEBUG_UHK int nReceiveLen = 0; int nProcessLen = 0; int nReadLen = 0; RESPONSE_STRUCT strcutResponse; memset(&strcutResponse, 0, sizeof(RESPONSE_STRUCT)); nReceiveLen = sizeof(RESPONSE_STRUCT); 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_UPSKEHUA_COM_READ_NO_DATA; } //长度校验出错 if (LengthCheck(pBuff) != 0) { SetEvent(m_hSemComm); TRACE("长度校验出错"); if (pBuff != NULL) { delete [] pBuff; pBuff = NULL; } return ERR_CODE_RTN_LCHKSUM_ERROR; } //int TempLen = strlen(pBuff); if (!ChkSumCheck(pBuff, nReadLen)) { TRACE("校验码校验出错"); SetEvent(m_hSemComm); if (pBuff != NULL) { delete [] pBuff; pBuff = NULL; } return ERR_CODE_RTN_CHKSUM_ERROR; //校验码校验出错 } if (CheckRtn(pBuff, nReadLen) != 0) { TRACE("RTN校验出错"); if (pBuff != NULL) { delete [] pBuff; pBuff = NULL; } return ERR_CODE_RTN_CHKSUM_RTN_ERROR; //RTN校验出错 } SetUhkQ41VarMsg(szCmd, pBuff); SetUhkQ43VarMsg(szCmd, pBuff); SetUhkQ44VarMsg(szCmd, pBuff); SetUhkQ45VarMsg(szCmd, pBuff); SetUhkQ46VarMsg(szCmd, pBuff); SetUhkQ4FVarMsg(szCmd, pBuff); SetUhkQ50VarMsg(szCmd, pBuff); m_dwOnlineTick = GetTickCount(); // 设置串口等待事件为有信号 SetEvent( m_hSemComm ); if( pBuff != NULL) { delete[] pBuff; pBuff = NULL; } #else SimulationCommData(); #endif return 0; } void CUpsUhk31::SetUhkQ41VarMsg(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 || 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) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szUhk_Q41Msg, pBuff, sizeof(m_szUhk_Q41Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsUhk31::SetUhkQ43VarMsg(char szCmd[MAX_CMD], char *pBuff) { if ( strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || strcmp(szCmd, "cmd-27") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szUhk_Q43Msg,pBuff,sizeof(m_szUhk_Q43Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsUhk31::SetUhkQ44VarMsg(char szCmd[MAX_CMD], char *pBuff) { if ( 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 || 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 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szUhk_Q44Msg,pBuff,sizeof(m_szUhk_Q44Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsUhk31::SetUhkQ45VarMsg(char szCmd[MAX_CMD], char *pBuff) { if ( strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-73") == 0) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szUhk_Q45Msg,pBuff,sizeof(m_szUhk_Q45Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsUhk31::SetUhkQ46VarMsg(char szCmd[MAX_CMD], char *pBuff) { if ( strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 || strcmp(szCmd, "cmd-48") == 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 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szUhk_Q46Msg,pBuff,sizeof(m_szUhk_Q46Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsUhk31::SetUhkQ4FVarMsg(char szCmd[MAX_CMD], char *pBuff) { if (strcmp(szCmd, "cmd-74") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szUhk_Q4FMsg,pBuff,sizeof(m_szUhk_Q4FMsg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsUhk31::SetUhkQ50VarMsg(char szCmd[MAX_CMD], char *pBuff) { if (strcmp(szCmd, "cmd-75") == 0) { #if IS_USE_READMSG_CS EnterCriticalSection(&m_csReadMsg); #endif memcpy(m_szUhk_Q50Msg,pBuff,sizeof(m_szUhk_Q50Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CUpsUhk31::SimulationCommData(void) { /*获取模拟量量化数据浮点数*/ TRACE("UhkResponseStatus赋值\n"); // 7E 32 31 30 30 32 41 30 30 37 // 30 39 30 30 30 36 36 36 36 36 // 44 34 33 36 36 36 36 36 44 34 // 33 36 36 36 36 37 30 34 33 36 // 36 36 36 35 43 34 33 20 20 20 // 20 20 20 20 20 20 20 20 20 20 // 20 20 20 43 44 43 43 34 43 34 // 30 20 20 20 20 20 20 20 20 20 // 20 20 20 20 20 20 20 39 41 31 // 39 38 36 34 33 37 42 31 34 34 // 38 34 32 30 30 30 30 30 36 37 // 42 31 34 34 38 34 32 30 30 30 // 30 30 30 34 31 30 30 30 30 43 // 38 34 32 34 38 45 31 44 41 34 // 31 36 36 45 36 36 41 34 33 30 // 30 38 30 38 36 34 33 45 31 46 // 30 0D m_szUhk_Q41Msg[0] = 0x7E; m_szUhk_Q41Msg[1] = 0x32; m_szUhk_Q41Msg[2] = 0x31; m_szUhk_Q41Msg[3] = 0x30; m_szUhk_Q41Msg[4] = 0x30; m_szUhk_Q41Msg[5] = 0x32; m_szUhk_Q41Msg[6] = 0x41; m_szUhk_Q41Msg[7] = 0x30; m_szUhk_Q41Msg[8] = 0x30; m_szUhk_Q41Msg[9] = 0x37; m_szUhk_Q41Msg[10] = 0x30; m_szUhk_Q41Msg[11] = 0x39; m_szUhk_Q41Msg[12] = 0x30; m_szUhk_Q41Msg[13] = 0x30; m_szUhk_Q41Msg[14] = 0x30; m_szUhk_Q41Msg[15] = 0x36; m_szUhk_Q41Msg[16] = 0x36; m_szUhk_Q41Msg[17] = 0x36; m_szUhk_Q41Msg[18] = 0x36; m_szUhk_Q41Msg[19] = 0x36; //44 34 33 36 36 36 36 36 44 34 m_szUhk_Q41Msg[20] = 0x44; m_szUhk_Q41Msg[21] = 0x34; m_szUhk_Q41Msg[22] = 0x33; m_szUhk_Q41Msg[23] = 0x36; m_szUhk_Q41Msg[24] = 0x36; m_szUhk_Q41Msg[25] = 0x36; m_szUhk_Q41Msg[26] = 0x36; m_szUhk_Q41Msg[27] = 0x36; m_szUhk_Q41Msg[28] = 0x44; m_szUhk_Q41Msg[29] = 0x34; //33 36 36 36 36 37 30 34 33 36 m_szUhk_Q41Msg[30] = 0x33; m_szUhk_Q41Msg[31] = 0x36; m_szUhk_Q41Msg[32] = 0x36; m_szUhk_Q41Msg[33] = 0x36; m_szUhk_Q41Msg[34] = 0x36; m_szUhk_Q41Msg[35] = 0x37; m_szUhk_Q41Msg[36] = 0x30; m_szUhk_Q41Msg[37] = 0x34; m_szUhk_Q41Msg[38] = 0x33; m_szUhk_Q41Msg[39] = 0x36; //36 36 36 35 43 34 33 20 20 20 m_szUhk_Q41Msg[40] = 0x36; m_szUhk_Q41Msg[41] = 0x36; m_szUhk_Q41Msg[42] = 0x36; m_szUhk_Q41Msg[43] = 0x35; m_szUhk_Q41Msg[44] = 0x43; m_szUhk_Q41Msg[45] = 0x34; m_szUhk_Q41Msg[46] = 0x33; m_szUhk_Q41Msg[47] = 0x20; m_szUhk_Q41Msg[48] = 0x20; m_szUhk_Q41Msg[49] = 0x20; //20 20 20 20 20 20 20 20 20 20 m_szUhk_Q41Msg[50] = 0x20; m_szUhk_Q41Msg[51] = 0x20; m_szUhk_Q41Msg[52] = 0x20; m_szUhk_Q41Msg[53] = 0x20; m_szUhk_Q41Msg[54] = 0x20; m_szUhk_Q41Msg[55] = 0x20; m_szUhk_Q41Msg[56] = 0x20; m_szUhk_Q41Msg[57] = 0x20; m_szUhk_Q41Msg[58] = 0x20; m_szUhk_Q41Msg[59] = 0x20; //20 20 20 30 30 30 30 36 30 34 m_szUhk_Q41Msg[60] = 0x20; m_szUhk_Q41Msg[61] = 0x20; m_szUhk_Q41Msg[62] = 0x20; m_szUhk_Q41Msg[63] = 0x30; m_szUhk_Q41Msg[64] = 0x30; m_szUhk_Q41Msg[65] = 0x30; m_szUhk_Q41Msg[66] = 0x30; m_szUhk_Q41Msg[67] = 0x36; m_szUhk_Q41Msg[68] = 0x30; m_szUhk_Q41Msg[69] = 0x34; // 30 20 20 20 20 20 20 20 20 20 m_szUhk_Q41Msg[70] = 0x30; m_szUhk_Q41Msg[71] = 0x20; m_szUhk_Q41Msg[72] = 0x20; m_szUhk_Q41Msg[73] = 0x20; m_szUhk_Q41Msg[74] = 0x20; m_szUhk_Q41Msg[75] = 0x20; m_szUhk_Q41Msg[76] = 0x20; m_szUhk_Q41Msg[77] = 0x20; m_szUhk_Q41Msg[78] = 0x20; m_szUhk_Q41Msg[79] = 0x20; //20 20 20 20 20 20 20 39 41 31 m_szUhk_Q41Msg[80] = 0x20; m_szUhk_Q41Msg[81] = 0x20; m_szUhk_Q41Msg[82] = 0x20; m_szUhk_Q41Msg[83] = 0x20; m_szUhk_Q41Msg[84] = 0x20; m_szUhk_Q41Msg[85] = 0x20; m_szUhk_Q41Msg[86] = 0x20; m_szUhk_Q41Msg[87] = 0x39; m_szUhk_Q41Msg[88] = 0x41; m_szUhk_Q41Msg[89] = 0x31; //39 38 36 34 33 33 44 31 34 34 m_szUhk_Q41Msg[90] = 0x39; m_szUhk_Q41Msg[91] = 0x38; m_szUhk_Q41Msg[92] = 0x36; m_szUhk_Q41Msg[93] = 0x34; m_szUhk_Q41Msg[94] = 0x33; m_szUhk_Q41Msg[95] = 0x33; m_szUhk_Q41Msg[96] = 0x44; m_szUhk_Q41Msg[97] = 0x30; m_szUhk_Q41Msg[98] = 0x41; m_szUhk_Q41Msg[99] = 0x34; //38 34 32 30 30 30 30 30 36 37 m_szUhk_Q41Msg[100] = 0x38; m_szUhk_Q41Msg[101] = 0x34; m_szUhk_Q41Msg[102] = 0x32; m_szUhk_Q41Msg[103] = 0x30; m_szUhk_Q41Msg[104] = 0x30; m_szUhk_Q41Msg[105] = 0x30; m_szUhk_Q41Msg[106] = 0x30; m_szUhk_Q41Msg[107] = 0x30; m_szUhk_Q41Msg[108] = 0x36; m_szUhk_Q41Msg[109] = 0x37; // 42 31 34 34 38 34 32 30 30 30 m_szUhk_Q41Msg[110] = 0x42; m_szUhk_Q41Msg[111] = 0x31; m_szUhk_Q41Msg[112] = 0x34; m_szUhk_Q41Msg[113] = 0x34; m_szUhk_Q41Msg[114] = 0x38; m_szUhk_Q41Msg[115] = 0x34; m_szUhk_Q41Msg[116] = 0x32; m_szUhk_Q41Msg[117] = 0x30; m_szUhk_Q41Msg[118] = 0x30; m_szUhk_Q41Msg[119] = 0x30; //30 30 30 34 31 30 30 30 30 43 m_szUhk_Q41Msg[120] = 0X30; m_szUhk_Q41Msg[121] = 0x30; m_szUhk_Q41Msg[122] = 0x30; m_szUhk_Q41Msg[123] = 0x34; m_szUhk_Q41Msg[124] = 0x31; m_szUhk_Q41Msg[125] = 0x30; m_szUhk_Q41Msg[126] = 0x30; m_szUhk_Q41Msg[127] = 0x30; m_szUhk_Q41Msg[128] = 0x30; m_szUhk_Q41Msg[129] = 0x43; //38 34 32 34 38 45 31 44 41 34 m_szUhk_Q41Msg[130] = 0x38; m_szUhk_Q41Msg[131] = 0x34; m_szUhk_Q41Msg[132] = 0x32; m_szUhk_Q41Msg[133] = 0x34; m_szUhk_Q41Msg[134] = 0x38; m_szUhk_Q41Msg[135] = 0x45; m_szUhk_Q41Msg[136] = 0x31; m_szUhk_Q41Msg[137] = 0x44; m_szUhk_Q41Msg[138] = 0x41; m_szUhk_Q41Msg[139] = 0x34; //31 36 36 45 36 36 41 34 33 30 m_szUhk_Q41Msg[140] = 0x31; m_szUhk_Q41Msg[141] = 0x39; m_szUhk_Q41Msg[142] = 0x41; m_szUhk_Q41Msg[143] = 0x39; m_szUhk_Q41Msg[144] = 0x39; m_szUhk_Q41Msg[145] = 0x36; m_szUhk_Q41Msg[146] = 0x42; m_szUhk_Q41Msg[147] = 0x34; m_szUhk_Q41Msg[148] = 0x33; m_szUhk_Q41Msg[149] = 0x36; //30 38 30 38 36 34 33 45 31 46 m_szUhk_Q41Msg[150] = 0x36; m_szUhk_Q41Msg[151] = 0x36; m_szUhk_Q41Msg[152] = 0x36; m_szUhk_Q41Msg[153] = 0x38; m_szUhk_Q41Msg[154] = 0x36; m_szUhk_Q41Msg[155] = 0x34; m_szUhk_Q41Msg[156] = 0x33; m_szUhk_Q41Msg[157] = 0x45; m_szUhk_Q41Msg[158] = 0x31; m_szUhk_Q41Msg[159] = 0x46; //30 0D m_szUhk_Q41Msg[160] = 0x30; m_szUhk_Q41Msg[161] = 0x0D; //7E 32 31 30 30 32 41 30 30 46 //30 31 30 30 30 30 31 30 35 45 //31 45 32 45 32 45 34 45 38 46 //41 31 33 0D /*获取开关量输入状态*/ // 7E 32 31 30 30 32 41 30 30 46 m_szUhk_Q43Msg[0] = 0x7E; m_szUhk_Q43Msg[1] = 0x32; m_szUhk_Q43Msg[2] = 0x31; m_szUhk_Q43Msg[3] = 0x30; m_szUhk_Q43Msg[4] = 0x30; m_szUhk_Q43Msg[5] = 0x32; m_szUhk_Q43Msg[6] = 0x41; m_szUhk_Q43Msg[7] = 0x30; m_szUhk_Q43Msg[8] = 0x30; m_szUhk_Q43Msg[9] = 0x46; // 30 31 30 30 30 30 31 30 35 45 m_szUhk_Q43Msg[10] = 0x30; m_szUhk_Q43Msg[11] = 0x31; m_szUhk_Q43Msg[12] = 0x30; m_szUhk_Q43Msg[13] = 0x30; m_szUhk_Q43Msg[14] = 0x30; m_szUhk_Q43Msg[15] = 0x30; m_szUhk_Q43Msg[16] = 0x31; m_szUhk_Q43Msg[17] = 0x30; m_szUhk_Q43Msg[18] = 0x35; m_szUhk_Q43Msg[19] = 0x45; // 31 45 32 45 32 45 34 45 38 46 m_szUhk_Q43Msg[20] = 0x31; m_szUhk_Q43Msg[21] = 0x45; m_szUhk_Q43Msg[22] = 0x32; m_szUhk_Q43Msg[23] = 0x45; m_szUhk_Q43Msg[24] = 0x32; m_szUhk_Q43Msg[25] = 0x45; m_szUhk_Q43Msg[26] = 0x34; m_szUhk_Q43Msg[27] = 0x45; m_szUhk_Q43Msg[28] = 0x38; m_szUhk_Q43Msg[29] = 0x46; // 41 31 33 0D m_szUhk_Q43Msg[30] = 0x41; m_szUhk_Q43Msg[31] = 0x31; m_szUhk_Q43Msg[32] = 0x33; m_szUhk_Q43Msg[33] = 0x0D; /*获取告警状态*/ // 7E 32 31 30 30 32 41 30 30 38 // 30 32 36 30 30 30 30 30 30 30 // 30 30 30 30 30 30 30 30 30 30 // 41 30 30 30 30 30 30 30 30 30 // 30 30 30 30 30 30 30 30 30 30 // 30 46 36 36 39 0D m_szUhk_Q44Msg[0] = 0x7E; m_szUhk_Q44Msg[1] = 0x32; m_szUhk_Q44Msg[2] = 0x31; m_szUhk_Q44Msg[3] = 0x30; m_szUhk_Q44Msg[4] = 0x30; m_szUhk_Q44Msg[5] = 0x32; m_szUhk_Q44Msg[6] = 0x41; m_szUhk_Q44Msg[7] = 0x30; m_szUhk_Q44Msg[8] = 0x30; m_szUhk_Q44Msg[9] = 0x38; // 30 32 36 30 30 30 30 30 30 30 m_szUhk_Q44Msg[10] = 0x30; m_szUhk_Q44Msg[11] = 0x32; m_szUhk_Q44Msg[12] = 0x36; m_szUhk_Q44Msg[13] = 0x30; m_szUhk_Q44Msg[14] = 0x30; m_szUhk_Q44Msg[15] = 0x30; m_szUhk_Q44Msg[16] = 0x30; m_szUhk_Q44Msg[17] = 0x30; m_szUhk_Q44Msg[18] = 0x30; m_szUhk_Q44Msg[19] = 0x30; // 30 30 30 30 30 30 30 30 30 30 m_szUhk_Q44Msg[20] = 0x30; m_szUhk_Q44Msg[21] = 0x30; m_szUhk_Q44Msg[22] = 0x30; m_szUhk_Q44Msg[23] = 0x30; m_szUhk_Q44Msg[24] = 0x30; m_szUhk_Q44Msg[25] = 0x30; m_szUhk_Q44Msg[26] = 0x30; m_szUhk_Q44Msg[27] = 0x30; m_szUhk_Q44Msg[28] = 0x30; m_szUhk_Q44Msg[29] = 0x30; // 41 30 30 30 30 30 30 30 30 30 m_szUhk_Q44Msg[30] = 0x41; m_szUhk_Q44Msg[31] = 0x30; m_szUhk_Q44Msg[32] = 0x30; m_szUhk_Q44Msg[33] = 0x30; m_szUhk_Q44Msg[34] = 0x30; m_szUhk_Q44Msg[35] = 0x30; m_szUhk_Q44Msg[36] = 0x30; m_szUhk_Q44Msg[37] = 0x30; m_szUhk_Q44Msg[38] = 0x30; m_szUhk_Q44Msg[39] = 0x30; // 30 30 30 30 30 30 30 30 30 30 m_szUhk_Q44Msg[40] = 0x30; m_szUhk_Q44Msg[41] = 0x30; m_szUhk_Q44Msg[42] = 0x30; m_szUhk_Q44Msg[43] = 0x30; m_szUhk_Q44Msg[44] = 0x30; m_szUhk_Q44Msg[45] = 0x30; m_szUhk_Q44Msg[46] = 0x30; m_szUhk_Q44Msg[47] = 0x30; m_szUhk_Q44Msg[48] = 0x30; m_szUhk_Q44Msg[49] = 0x30; // 30 46 36 36 39 0D m_szUhk_Q44Msg[50] = 0x30; m_szUhk_Q44Msg[51] = 0x46; m_szUhk_Q44Msg[52] = 0x36; m_szUhk_Q44Msg[53] = 0x36; m_szUhk_Q44Msg[54] = 0x39; m_szUhk_Q44Msg[55] = 0x0D; /*获取系统参数*/ // 7E 32 31 30 30 32 41 30 30 30 m_szUhk_Q46Msg[0] = 0x7E; m_szUhk_Q46Msg[1] = 0x32; m_szUhk_Q46Msg[2] = 0x31; m_szUhk_Q46Msg[3] = 0x30; m_szUhk_Q46Msg[4] = 0x30; m_szUhk_Q46Msg[5] = 0x32; m_szUhk_Q46Msg[6] = 0x41; m_szUhk_Q46Msg[7] = 0x30; m_szUhk_Q46Msg[8] = 0x30; m_szUhk_Q46Msg[9] = 0x30; // 30 36 41 20 20 20 20 20 20 20 m_szUhk_Q46Msg[10] = 0x30; m_szUhk_Q46Msg[11] = 0x36; m_szUhk_Q46Msg[12] = 0x41; m_szUhk_Q46Msg[13] = 0x20; m_szUhk_Q46Msg[14] = 0X20; m_szUhk_Q46Msg[15] = 0x20; m_szUhk_Q46Msg[16] = 0x20; m_szUhk_Q46Msg[17] = 0x20; m_szUhk_Q46Msg[18] = 0x20; m_szUhk_Q46Msg[19] = 0x20; // 20 20 20 20 20 20 20 20 20 20 m_szUhk_Q46Msg[20] = 0x20; m_szUhk_Q46Msg[21] = 0x20; m_szUhk_Q46Msg[22] = 0x20; m_szUhk_Q46Msg[23] = 0x20; m_szUhk_Q46Msg[24] = 0x20; m_szUhk_Q46Msg[25] = 0x20; m_szUhk_Q46Msg[26] = 0x20; m_szUhk_Q46Msg[27] = 0x20; m_szUhk_Q46Msg[28] = 0x20; m_szUhk_Q46Msg[29] = 0x20; // 20 20 20 20 20 20 20 20 20 20 m_szUhk_Q46Msg[30] = 0x20; m_szUhk_Q46Msg[31] = 0x20; m_szUhk_Q46Msg[32] = 0x20; m_szUhk_Q46Msg[33] = 0x20; m_szUhk_Q46Msg[34] = 0x20; m_szUhk_Q46Msg[35] = 0x20; m_szUhk_Q46Msg[36] = 0x20; m_szUhk_Q46Msg[37] = 0x20; m_szUhk_Q46Msg[38] = 0x20; m_szUhk_Q46Msg[39] = 0x20; // 20 20 20 20 20 30 39 30 30 30 m_szUhk_Q46Msg[40] = 0x20; m_szUhk_Q46Msg[41] = 0x20; m_szUhk_Q46Msg[42] = 0x20; m_szUhk_Q46Msg[43] = 0x20; m_szUhk_Q46Msg[44] = 0x20; m_szUhk_Q46Msg[45] = 0x30; m_szUhk_Q46Msg[46] = 0x39; m_szUhk_Q46Msg[47] = 0x30; m_szUhk_Q46Msg[48] = 0x30; m_szUhk_Q46Msg[49] = 0x30; // 30 41 30 34 30 30 30 30 30 46 m_szUhk_Q46Msg[50] = 0x30; m_szUhk_Q46Msg[51] = 0x41; m_szUhk_Q46Msg[52] = 0x30; m_szUhk_Q46Msg[53] = 0x34; m_szUhk_Q46Msg[54] = 0x30; m_szUhk_Q46Msg[55] = 0x30; m_szUhk_Q46Msg[56] = 0x30; m_szUhk_Q46Msg[57] = 0x30; m_szUhk_Q46Msg[58] = 0x30; m_szUhk_Q46Msg[59] = 0x46; // 30 34 32 30 30 30 30 32 30 34 m_szUhk_Q46Msg[60] = 0x30; m_szUhk_Q46Msg[61] = 0x34; m_szUhk_Q46Msg[62] = 0x32; m_szUhk_Q46Msg[63] = 0x30; m_szUhk_Q46Msg[64] = 0x30; m_szUhk_Q46Msg[65] = 0x30; m_szUhk_Q46Msg[66] = 0x30; m_szUhk_Q46Msg[67] = 0x32; m_szUhk_Q46Msg[68] = 0x30; m_szUhk_Q46Msg[69] = 0x34; // 31 30 30 30 30 30 30 34 30 30 m_szUhk_Q46Msg[70] = 0x31; m_szUhk_Q46Msg[71] = 0x30; m_szUhk_Q46Msg[72] = 0x30; m_szUhk_Q46Msg[73] = 0x30; m_szUhk_Q46Msg[74] = 0x30; m_szUhk_Q46Msg[75] = 0x30; m_szUhk_Q46Msg[76] = 0x30; m_szUhk_Q46Msg[77] = 0x34; m_szUhk_Q46Msg[78] = 0x30; m_szUhk_Q46Msg[79] = 0x30; // 30 30 30 30 30 34 30 30 30 30 m_szUhk_Q46Msg[80] = 0x30; m_szUhk_Q46Msg[81] = 0x30; m_szUhk_Q46Msg[82] = 0x30; m_szUhk_Q46Msg[83] = 0x30; m_szUhk_Q46Msg[84] = 0x30; m_szUhk_Q46Msg[85] = 0x34; m_szUhk_Q46Msg[86] = 0x30; m_szUhk_Q46Msg[87] = 0x30; m_szUhk_Q46Msg[88] = 0x30; m_szUhk_Q46Msg[89] = 0x30; // 30 38 30 33 46 30 30 30 30 45 m_szUhk_Q46Msg[90] = 0x30; m_szUhk_Q46Msg[91] = 0x38; m_szUhk_Q46Msg[92] = 0x30; m_szUhk_Q46Msg[93] = 0x33; m_szUhk_Q46Msg[94] = 0x46; m_szUhk_Q46Msg[95] = 0x30; m_szUhk_Q46Msg[96] = 0x30; m_szUhk_Q46Msg[97] = 0x30; m_szUhk_Q46Msg[98] = 0x30; m_szUhk_Q46Msg[99] = 0x45; // 30 34 30 30 30 30 30 38 30 33 m_szUhk_Q46Msg[100] = 0x30; m_szUhk_Q46Msg[101] = 0x34; m_szUhk_Q46Msg[102] = 0x30; m_szUhk_Q46Msg[103] = 0x30; m_szUhk_Q46Msg[104] = 0x30; m_szUhk_Q46Msg[105] = 0x30; m_szUhk_Q46Msg[106] = 0x30; m_szUhk_Q46Msg[107] = 0x38; m_szUhk_Q46Msg[108] = 0x30; m_szUhk_Q46Msg[109] = 0x33; // 46 30 30 30 30 38 30 34 30 45 m_szUhk_Q46Msg[110] = 0x46; m_szUhk_Q46Msg[111] = 0x30; m_szUhk_Q46Msg[112] = 0x30; m_szUhk_Q46Msg[113] = 0x30; m_szUhk_Q46Msg[114] = 0x30; m_szUhk_Q46Msg[115] = 0x38; m_szUhk_Q46Msg[116] = 0x30; m_szUhk_Q46Msg[117] = 0x34; m_szUhk_Q46Msg[118] = 0x30; m_szUhk_Q46Msg[119] = 0x45; // 42 30 33 0D m_szUhk_Q46Msg[120] = 0x42; m_szUhk_Q46Msg[121] = 0x30; m_szUhk_Q46Msg[122] = 0x33; m_szUhk_Q46Msg[123] = 0x0D; } int CUpsUhk31::LengthCheck(char szSendMsg[]) { int len = (int)strlen(szSendMsg); char buffer[5] = {0}; int j = 0; for (int i = 9; i< 13; i++) { buffer[j++] = szSendMsg[i]; //取出检验位 } buffer[j] ='0'; if(!ValiateLength(buffer)) // 相加模十六取反加一 { return ERR_CODE_RTN_LCHKSUM_ERROR; } /*转换为十六进制*/ return 0; } BOOL CUpsUhk31::CheckCHKSUM(char szSendMsg[]) { int j = 0; char buf1[5] = {0}; char buf2[5] = {0}; char szbuf[5] = {0}; char chDest[5] = {0}; unsigned short nData = 0; int len = (int)strlen(szSendMsg); char *buffer = new char [len-2]; memset(buffer,0,sizeof(buffer)); for (int i = 1; i < len-5; i++) { buffer[j++] = szSendMsg[i]; } buffer[j] = '\0'; for (j = 0; j < buffer[j] != '\0'; j ++) { nData += AsciiToBYTE(buffer[j]); //十进制相加 } nData = ~nData +1; //取反加1 (有问题) nData %= 65536; //转换为16进制 sprintf(buf2,"%x",nData); StrLower(buf2,chDest); j = 0; for (int i = len-5; i < len -1; i++) { buf1[j++] = szSendMsg[i]; } buf1[j] = '\0'; StrLower(buf1,szbuf); if (strcmp(szbuf,chDest) == 0) { delete [] buffer; return TRUE; } delete [] buffer; return FALSE; } BOOL CUpsUhk31::CheckRtn(char szMsg[], int len) { //int len = (int)strlen(szMsg); char buffer[3] = {0}; int j = 0; for (int i = 7; i < 9; i++) { buffer[j++] = szMsg[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,"E0") == 0) { return ERR_CODE_RTN_OPERATE_FAIL; } else if (strcmp(buffer,"E1") == 0) { return ERR_CODE_RTN_EQUIT_FAIL; } else if (strcmp(buffer,"E3")==0 || strcmp(buffer,"E4")==0 ) { return ERR_CODE_RTN_KEEP; } else if (strcmp(buffer, "E5")==0 || strcmp(buffer, "E6") == 0 || strcmp(buffer, "E7") == 0 || strcmp(buffer, "E8") == 0 || strcmp(buffer, "E9") == 0 ) { return ERR_CODE_RTN_WATCH; } else if (strcmp(buffer,"EA") == 0 || strcmp(buffer, "EB") == 0 || strcmp(buffer, "EC") == 0 || strcmp(buffer, "ED") == 0 || strcmp(buffer, "EE") == 0 || strcmp(buffer, "EF") == 0 ) { return ERR_CODE_RTN_ELECTICAL_SOURCE; } return -1; } int CUpsUhk31::UhkRequestWrStatus(char szSendMsg[]) { return 0; } int CUpsUhk31::UhkResponseWrStatus(char szSendMsg[]) { return 0; } int CUpsUhk31::StrLower(char *pSource, char *pDest) { int length, i; length = (int)strlen(pSource); for (i = 0; i < length; i++) { if ((pSource[i] >= 'A') && (pSource[i] <= 'Z')){ pDest[i] = _tolower(pSource[i]); } else pDest[i] = pSource[i]; } return 0; } BOOL CUpsUhk31::ValiateLength(char szChar[]) { unsigned int nData = 0; unsigned int nData1 =0; unsigned short nDataLength = 0; unsigned short nChar1; nChar1 =AsciiToBYTE(szChar[1]) + AsciiToBYTE(szChar[2]) + AsciiToBYTE(szChar[3]); nChar1 = (~nChar1) + 1; nChar1 %=16; nDataLength = AsciiToBYTE(szChar[0]); if (nDataLength != nChar1) { return FALSE; } return TRUE; } int CUpsUhk31::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; } UINT CUpsUhk31::GetCheckSum(char *pBuf, char chDest[5], int len) { WORD iSum = 0; //unsigned char chCompliment[2] = {0}; for(int i=0; i