////////////////////////////////////////////////////////////////////////////// ////// ////// ////// 文 件: Tmaster.cpp ////// ////// 作 者: Wangjianfeng ////// ////// 创建时间: ////// ////// 说 明: Tmaster约顿空调协议 ////// ////// ////// ////// 修改时间:2011-07-23 ////// ////// 修改说明:数据转换 ////// ////// ////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "CommProcess.h" #include "Global.h" #include ".\tmaster.h" CTmaster::CTmaster( 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 ) ); //CreateEvent()创建或打开一个命名的或无名的事件对象 for(int i = 0;i < MAX_ADDR;i++) { memset(m_szE0Msg[i], 0, sizeof(m_szE0Msg[i])); memset(m_szSend49Msg[i], 0, sizeof(m_szSend49Msg[i])); memset(m_szSend45Msg[i], 0, sizeof(m_szSend45Msg[i])); m_devOnline[i] = TRUE; m_dwOnlineTick[i] = 0; } } CTmaster::~CTmaster() { #if IS_USE_READMSG_CS DeleteCriticalSection( &m_csReadMsg ); #endif MTVERIFY( CloseHandle( m_hSemComm ) ); CloseComm(); } int CTmaster::GetULFromIni( char szPath[MAX_PATH], //服务器程序所在目录 char szIniName[MAX_PATH], //配置文件名 char szCmd[MAX_CMD], //命令 char szSendMsg[MAX_CMD], //发送Buffer char nType[MAX_CMD], int &nIndex, int &nLen, int &startbit, int &endbit, char szLength[5], int &nCDT) { CHAR szFile[MAX_PATH + 1] = ""; wsprintf(szFile, "%s\\config\\%s", szPath, szIniName); GetPrivateProfileString(szCmd, "SendCmd", "", szSendMsg, 10, szFile); szSendMsg[strlen(szSendMsg)] = '\0'; GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile); nType[strlen(nType)] = '\0'; nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile); nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile); startbit = GetPrivateProfileInt(szCmd, "startbit", 0, szFile); endbit = GetPrivateProfileInt(szCmd, "endbit", 0, szFile); GetPrivateProfileString(szCmd, "LENGTH", "", szLength, 10, szFile); szLength[strlen(szLength)] = '\0'; nCDT = GetPrivateProfileInt(szCmd, "CDT", 0, szFile); return 0; } BOOL CTmaster::AirTmasterOpenComm(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 CTmaster::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; int startbit = 0,endbit = 0; char szSendMsg[_VAR_MSG] = {0}; char szType[TYPE_LENGTH] = {0}; char szLength[5] = {0}; int nCDT = 0; GetULFromIni(szPath, szIniName, szCmd,szSendMsg, szType, nIndex, nLen,startbit,endbit,szLength,nCDT); CCommProcess *pComm = FindComm(nCommPort); if( pComm == NULL ) return -1; int nRet = -1; if ( (strlen(m_szE0Msg[nAddr-1]) ==0 && ( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 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 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 )) || strcmp(szCmd, "cmd-1") == 0 ) { nRet = GetDeviceParam( nAddr,pComm, szSendMsg, szCmd, szMsg, nIndex, nLen, szType,startbit,endbit ); 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 = GetE0VarMsg(szCmd, szMsg, nAddr, nIndex, nLen, szType,startbit,endbit); LOG4C((LOG_NOTICE, "szCmd = %s, szMsg = %s ,nIndex = %d , startbit = %d, endbit = %d ,return nRet = %d", szCmd, szMsg,nIndex,startbit,endbit, nRet)); return nRet; } int CTmaster::GetDeviceParam( int nAddr, CCommProcess *pComm, // 串口对象指针 char szSendMsg[MAX_INFO], // 发送Buffer char szCmd[MAX_CMD], // 命令 char szRecvMsg[VAR_MSG], // 接收Buffer int &nIndex, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szType[TYPE_LENGTH], // 变量数据类型 int &startbit, int &endbit ) { int nRet = -1; nRet = RequestReadStatus(nAddr,pComm, szSendMsg); if( nRet != 0 ) { return nRet; // 串口忙 } nRet = ResponseReadStatus(pComm, szCmd, szRecvMsg, nAddr, nIndex, nLen, szType,startbit,endbit); return nRet; } int CTmaster::ResponseReadStatus( CCommProcess *pComm, char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int nAddr, int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startbit, int &endbit) { #if ___DEBUG REPONSEPARAM structResponse; memset( &structResponse, 0, sizeof(REPONSEPARAM) ); int nReceiveLen = 0; nReceiveLen = sizeof(REPONSEPARAM); char *pBuffer = new char[ nReceiveLen ]; memset(pBuffer, 0, nLen); int nReadLen = 0; nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen); if (!CheckLength(pBuffer)) { SetEvent(m_hSemComm); if (pBuffer !=NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_AIRTMASTER_COM_LRC_LOST; //长度校验出错 } if (!ChkSumCheck(pBuffer,nReadLen)) { SetEvent(m_hSemComm); if (pBuffer !=NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_AIRTMASTER_COM_LRC_LOST; //校验码校验出错 } int nRet = RtnCheck(pBuffer, nReadLen); if (nRet != 0) { SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return nRet; //RTN校验出错 } if( nReadLen <= 0) { // 串口没有读到数据 TRACE("串口没有读到数据!\r\n"); SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_AIRTMASTER_COM_READ_NO_DATA; } SetE0VarMsg( nAddr,szCmd, pBuffer); m_dwOnlineTick[nAddr-1] = GetTickCount(); SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } #else SimulationCommData(); LOG4C((LOG_NOTICE,"%s",m_szE0Msg[0])); #endif return 0; } int CTmaster::RequestReadStatus(int nAddr,CCommProcess *pComm,char chSendMsg[_VAR_MSG]) { #if ___DEBUG char chLength[4] = {0}; char chChkSum[5] = {0}; REQUESTPARAM RequestPara; int iLen = sizeof(RequestPara); memset( &RequestPara, 0, iLen ); //起始位; RequestPara.RequestChild.bySoi = 0x7E; //通讯协议版本; RequestPara.RequestChild.byVer[0] = 0x32; RequestPara.RequestChild.byVer[1] = 0x30; //设备地址描述; RequestPara.RequestChild.byAdr[0] = ByteToAscii((nAddr >> 4) & 0x0f); RequestPara.RequestChild.byAdr[1] = ByteToAscii(nAddr & 0x0f); //Cid1 RequestPara.RequestChild.byCid1[0] = 0x36; RequestPara.RequestChild.byCid1[1] = 0x30; //Cid2 memcpy(RequestPara.RequestChild.byCid2, chSendMsg, 2); RequestPara.RequestChild.byLength[0] = 0x30; RequestPara.RequestChild.byLength[1] = 0x30; RequestPara.RequestChild.byLength[2] = 0x30; RequestPara.RequestChild.byLength[3] = 0x30; int nLen = sizeof(RequestPara.byCheckSum) -1; //校验码; BYTE *pDataBuf = new BYTE[ iLen - nLen]; memset(pDataBuf, 0, iLen -nLen ); memcpy(pDataBuf, &RequestPara, iLen - nLen); GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.byCheckSum) - 2 ); delete []pDataBuf; pDataBuf = NULL; RequestPara.byCheckSum[0] = chChkSum[0]; RequestPara.byCheckSum[1] = chChkSum[1]; RequestPara.byCheckSum[2] = chChkSum[2]; RequestPara.byCheckSum[3] = chChkSum[3]; //结束符 RequestPara.byEoi = 0x0D; //WaitForSingObject();等待有信号; if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口 { //求得数组字符实际长度; int nDataLen = (int)sizeof(RequestPara); //ResetEvent()设置无信号状态 ResetEvent( m_hSemComm ); int nResult = pComm->Write((BYTE *)&RequestPara, nDataLen); if( nResult != nDataLen ) { //SetEvent设置有信号; SetEvent( m_hSemComm ); //返回 错误值; return EER_CODE_AIRTMASTER_COM_REGNUM; } } else { //如果m_hSemCom无信号,返回错误; return ERR_CODE_AIRTMASTER_COM_BUSY; } #endif return 0; } int CTmaster::GetE0VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int nAddr, 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-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 || strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif DataConversion(szType, m_szE0Msg[nAddr-1] + nIndex, szRecvMsg, nLen,startbit,endbit ); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } // 发送设置设备参数请求 int CTmaster::SendSetReuest( char szPath[MAX_PATH], // 程序所在路径 char szIniName[MAX_PATH], // 配置文件名称 int nCommPort, // 串行端口 int nAddr, // 设备地址 char szCmd[MAX_CMD], // 请求命令 char szSetMsg[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接口 ) { int nIndex = 0, nLen = 0; int startbit = 0,endbit = 0; char szSendCmd[_VAR_MSG] = {0}; char szType[TYPE_LENGTH] = {0}; char szLength[5] = {0}; int nCDT = 0; GetULFromIni( szPath, szIniName, szCmd, szSendCmd, //ini SendCmd命令; szType, //ini Type键值; nIndex, nLen, startbit, endbit, szLength, // ini LENGTH; nCDT); // int CDT; CCommProcess *pComm = FindComm(nCommPort); if( pComm == NULL ) return -1; int nRet = -1; if ( strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 || //-25空调开机;-26空调关机; 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 ) { nRet = SetDeviceParam( nAddr,pComm, szSendCmd, szCmd, szSetMsg/*输入设备的设置值*/, szLength, nCDT ); 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; // } return nRet; } // 设置传入设备的值; int CTmaster::SetDeviceParam( int nAddr, CCommProcess *pComm, //串口对象指针 char szSendCmd[_VAR_MSG], //发送Buffer char szCmd[MAX_CMD], // 命令 char szSetMsg[VAR_MSG], // 接收Buffer char szLength[5], // 变量索引,针对接收Buffer而言 int &nCDT // 变量长度 ) { LOG4C((LOG_NOTICE,"nAddr = %d,szSendCmd = %s,szCmd = %s,szSetMsg = %s,szLength = %s,nCDT = %d",nAddr,szSendCmd,szCmd,szSetMsg,szLength,nCDT)); int nRet = -1; nRet = RequestWriteStatus(pComm, nAddr, szCmd, szSendCmd, szSetMsg, szLength, nCDT); if( nRet != 0 ) { return nRet; // 串口忙 } nRet = ResponseWriteStatus(pComm, nAddr); return nRet; } // 写优先,设置事件为无信号; int CTmaster::RequestWriteStatus( CCommProcess *pComm,int nAddr,char szCmd[MAX_CMD],char szSendCmd[VAR_MSG] ,char szSetMsg[VAR_MSG],char szLength[5], int &nCDT) { char chLength[4] = {0}; char chChkSum[5] = {0}; char szSendBuf[100] = {0}; #if 1 int nDataLen = 0; szSendBuf[0] = 0x7E; szSendBuf[1] = 0x32; szSendBuf[2] = 0x30; szSendBuf[3] = ByteToAscii((nAddr >> 4) & 0x0f); szSendBuf[4] = ByteToAscii(nAddr & 0x0f); szSendBuf[5] = 0x36; szSendBuf[6] = 0x30; memcpy(&szSendBuf[7], szSendCmd, 2); memcpy(&szSendBuf[9],szLength,4); if (strcmp(szCmd,"cmd-25") == 0) { memcpy(&szSendBuf[13],szSetMsg,2); GetCheckSum((char *)szSendBuf + 1, chChkSum, 14 ); memcpy(&szSendBuf[15],chChkSum,4); szSendBuf[19] = 0x0D; nDataLen = 20; } else { szSendBuf[13] = ByteToAscii((nCDT >> 4) & 0x0f); szSendBuf[14] = ByteToAscii(nCDT & 0x0f); memcpy(&szSendBuf[15],szSetMsg,4); GetCheckSum((char *)szSendBuf + 1, chChkSum, 17 ); memcpy(&szSendBuf[19],chChkSum,4); szSendBuf[23] = 0x0D; nDataLen = 24; } LOG4C_HEX_DUMP((LOG_NOTICE, szSendBuf, nDataLen)); ResetEvent( m_hSemComm );//设置为无信号(写设备优先级高); int iResult = pComm->Write((BYTE *)&szSendBuf, nDataLen); if (iResult == nDataLen) { SetEvent( m_hSemComm );//设置为有信号; return 0; } else { SetEvent( m_hSemComm );//设置为有信号; return EER_CODE_AIRTMASTER_COM_WRITE_DATA; } #endif #if 0 WRITEPARAM RequestPara; int iLen = sizeof(RequestPara); memset( &RequestPara, 0, iLen ); //起始位; RequestPara.ReposeChild.bySoi = 0x7E; //通讯协议版本; RequestPara.ReposeChild.byVer[0] = 0x32; RequestPara.ReposeChild.byVer[1] = 0x30; //设备地址描述; RequestPara.ReposeChild.byAdr[0] = ByteToAscii((nAddr >> 4) & 0x0f); RequestPara.ReposeChild.byAdr[1] = ByteToAscii(nAddr & 0x0f); //Cid1 RequestPara.ReposeChild.byCid1[0] = 0x36; RequestPara.ReposeChild.byCid1[1] = 0x30; //Cid2 memcpy(RequestPara.ReposeChild.byCid2, szSendCmd, 2); //Length; memcpy(RequestPara.ReposeChild.byLength,szLength,4); if (strcmp(szCmd,"cmd-25") == 0) { memcpy(RequestPara.ReposeChild.byInfo,szSetMsg,strlen(szSetMsg)); } else { char szSet[10] ={0}; szSet[0] = nCDT; memcpy(&szSet[1],szSetMsg,strlen(szSetMsg)); memcpy(RequestPara.ReposeChild.byInfo,szSet,strlen(szSet)); } int nLen = sizeof(RequestPara.byCheckSum) -1; //校验码; BYTE *pDataBuf = new BYTE[ iLen - nLen]; memset(pDataBuf, 0, iLen -nLen ); memcpy(pDataBuf, &RequestPara, iLen - nLen); GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.byCheckSum) - 2 ); delete []pDataBuf; pDataBuf = NULL; RequestPara.byCheckSum[0] = chChkSum[0]; RequestPara.byCheckSum[1] = chChkSum[1]; RequestPara.byCheckSum[2] = chChkSum[2]; RequestPara.byCheckSum[3] = chChkSum[3]; //结束符 RequestPara.byEoi = 0x0D; ResetEvent( m_hSemComm );//设置为无信号(写设备优先级高); int nDataLen = (int)sizeof(RequestPara); //WriteMessage写命令入串口,返回实际写入的字节数; int iResult = pComm->Write((BYTE *)&RequestPara, nDataLen); if (iResult == nDataLen) { SetEvent( m_hSemComm );//设置为有信号; return 0; } else { SetEvent( m_hSemComm );//设置为有信号; return EER_CODE_AIRTMASTER_COM_WRITE_DATA; } #endif return 0; } int CTmaster::ResponseWriteStatus( CCommProcess *pComm,int nAddr) { char chBuf[30] = {0}; //读取请求写入的命令; int iReadLen = pComm->Read((BYTE *)chBuf, sizeof(chBuf)); if( iReadLen <= 0) // 串口没有读到数据 { SetEvent( m_hSemComm ); return ERR_CODE_AIRTMASTER_COM_READ_NO_DATA; } SetEvent( m_hSemComm ); if (chBuf[7] == 0x00 && chBuf[8] == 0x00)//RTN =00H 成功接收; { return 0; } else return ERR_CODE_AIRTMASTER_COM_INVALIDRES; return 0; } void CTmaster::SetE0VarMsg(int nAddr, 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-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|| strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szE0Msg[nAddr-1], pBuff, sizeof(m_szE0Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } UINT CTmaster::GetCheckSum(char *pBuf, char chDest[5], int len) { LOG4C((LOG_NOTICE,"pBuf = %s, len = %d",pBuf,len)); WORD iSum = 0;; for(int i=0; i