// Emerson_CM.cpp: implementation of the Emerson_CM class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "CommProcess.h" #include "Global.h" #include "Emerson_CM.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// Emerson_CM::Emerson_CM(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()创建或打开一个命名的或无名的事件对象 memset(m_emerson_ControlMsg, 0, sizeof(m_emerson_ControlMsg)); memset(m_emerson_QeuryMsg, 0, sizeof(m_emerson_QeuryMsg)); } Emerson_CM::~Emerson_CM() { #if IS_USE_READMSG_CS DeleteCriticalSection( &m_csReadMsg ); #endif MTVERIFY( CloseHandle( m_hSemComm ) ); CloseComm(); } BOOL Emerson_CM::AirEmersonOpenComm(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 Emerson_CM::SendReadRequest( char szPath[MAX_PATH], // 程序所在路径 char szIniName[MAX_PATH], // 配置文件名称 int nCommPort, // 串行端口 int nAddr, // 设备地址 char szCmd[MAX_CMD], // 请求命令 char szRecvMsg[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 LBCount = 0; int SendCmd = 0; int Function = 0; int Index = 0; int nLen = 0; char Dtype[10] = {0}; int startbit =0; int endbit = 0; GetFromIni(szPath, szIniName, szCmd, SendCmd,Function, LBCount,Index,nLen,Dtype,startbit,endbit); CCommProcess *pComm = FindComm(nCommPort); if( pComm == NULL ) return -1; int nRet = -1; /*if( strlen((char *)m_emerson_QeuryMsg) == 0 && ( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 ) ||*/ if((strlen((char *)m_emerson_QeuryMsg) == 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-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 || strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 || strcmp(szCmd, "cmd-41") == 0 ))||(strcmp(szCmd, "cmd-4"))||strcmp(szCmd, "cmd-41") ) { GetDeviceParam( pComm,nAddr,szCmd,SendCmd,Function,LBCount,Index,nLen, Dtype,startbit,endbit,szRecvMsg); } //nRet = GetEmersonContrlVarMsg(szCmd, szRecvMsg, Index, nLen, Dtype,startbit,endbit); nRet = GetEmersonEnquiryVarMsg(szCmd, szRecvMsg, Index, nLen, Dtype,startbit,endbit); return nRet; } // 发送设置设备参数请求 int Emerson_CM::SendSetReuest( char szPath[MAX_PATH], // 程序所在路径 char szIniName[MAX_PATH], // 配置文件名称 int nCommPort, // 串行端口 int nAddr, // 设备地址 char szCmd[MAX_CMD], // 请求命令 char szRecvMsg[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 LBCount = 0; int SendCmd = 0; int Function = 0; int Index = 0; int nLen = 0; char Dtype[10] = {0}; int startbit =0; int endbit = 0; GetFromIni(szPath, szIniName, szCmd, SendCmd,Function, LBCount,Index,nLen,Dtype,startbit,endbit); CCommProcess *pComm = FindComm(nCommPort); if( pComm == NULL ) return -1; if( strlen((char *)m_emerson_ControlMsg) == 0 || strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 ) { GetDeviceParam( pComm,nAddr,szCmd,SendCmd,Function,LBCount,Index,nLen, Dtype,startbit,endbit,szRecvMsg); } // nRet = GetEmersonContrlVarMsg(szCmd, szRecvMsg, Index, nLen, Dtype,startbit,endbit); return 0; } int Emerson_CM::RequestReadStatus(CCommProcess *pComm,int SendCmd,int Function,int LBCount,int addr) { #if DEBUG_EMERSON int iLen = sizeof(REQUESTPARAM); REQUESTPARAM RequestPara; memset( &RequestPara, 0, iLen ); RequestPara.UnitId = (addr - 1) ^ 0xf0;// RequestPara.ControlId = Function; RequestPara.Len = LBCount; RequestPara.Request = SendCmd; RequestPara.Chksum = (RequestPara.UnitId + RequestPara.ControlId + RequestPara.Len + RequestPara.Request) & 0xff; //WaitForSingObject();等待有信号; if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口 { //ResetEvent()设置无信号状态 ResetEvent( m_hSemComm ); int nResult = pComm->Write((unsigned char *)&RequestPara, iLen); if( nResult != iLen ) { //SetEvent设置有信号; SetEvent( m_hSemComm ); //返回 错误值; return EER_CODE_AIREMERSONCM_COM_REGNUM; } } else { //如果m_hSemCom无信号,返回错误; return ERR_CODE_AIREMERSONCM_COM_BUSY; } #endif return 0; } int Emerson_CM::ResponseReadStatus( CCommProcess *pComm, // 串口对象 char szCmd[MAX_CMD], // 命令 int &SendCmd, // 控制码 int &Function, // 功能码 int &LBCount // 变量类型长度 ) { #if DEBUG_EMERSON int nReceiveLen = sizeof(RESPONSE_STRUCT); //if (0x05 == SendCmd) //{ // nReceiveLen = 29; //} //else if (0x11 == SendCmd) //{ // nReceiveLen = 4; //} char *pBuffer = new char[nReceiveLen]; memset(pBuffer, 0, nReceiveLen); int nReadLen = 0; nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen);//pBuffer整串协议 数据 if (!ChkSumCheck(pBuffer,SendCmd)) { SetEvent(m_hSemComm); if (pBuffer !=NULL) { delete[] pBuffer; pBuffer = NULL; } return FALSE; //校验码校验出错 } if( nReadLen <= 0) { // 串口没有读到数据 TRACE("串口没有读到数据!\r\n"); SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_AIREMERSONCM_COM_READ_NO_DATA; } //SetEmersonContrlVarMsg(szCmd, pBuffer); SetEmersonEnquiryVarMsg(szCmd, pBuffer); // 设置串口等待事件为有信号 SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } #else SimulationCommData(); #endif return 0; } int Emerson_CM::RequestWriteStatus( CCommProcess *pComm,int Function ,int SendCmd,int LBCount,int nAddr ) { REQUESTPARAM requsetparam; int nDataLen = sizeof(REQUESTPARAM); memset(&requsetparam,0,nDataLen); requsetparam.UnitId = (nAddr-1) ^ 0xf0; //机组-in requsetparam.ControlId = SendCmd; //0x11//控制 requsetparam.Len = LBCount; //后续数 requsetparam.Request = Function; //szcmd//功能码-in requsetparam.Chksum = (requsetparam.UnitId + requsetparam.ControlId + requsetparam.Len + requsetparam.Request) & 0xff; //校验 ResetEvent( m_hSemComm );//设置为无信号 //WriteMessage写命令入串口,返回实际写入的字节数; int iResult = pComm->Write((BYTE *)&requsetparam, nDataLen); if (iResult == nDataLen) { SetEvent( m_hSemComm );//设置为有信号; return 0; } else { SetEvent( m_hSemComm );//设置为有信号; return EER_CODE_AIREMERSONCM_COM_WRITE_DATA; } } int Emerson_CM::ResponseWriteStatus(CCommProcess *pComm) { char chBuf[30] = {0}; //char chBuf = 0; //读取请求写入的命令; int iReadLen = pComm->Read((BYTE *)chBuf, sizeof(chBuf)); if( iReadLen <= 0) // 串口没有读到数据 { SetEvent( m_hSemComm ); return ERR_CODE_AIREMERSONCM_COM_READ_NO_DATA; } SetEvent( m_hSemComm ); //char *ack = (char *)&chBuf; if (chBuf[1] == 0x06)//ack字符 成功接收; { return 0; } else return ERR_CODE_AIREMERSONCM_COM_INVALIDRES; } int Emerson_CM::GetFromIni( char szPath[MAX_PATH], //服务器程序所在目录 char szIniName[MAX_PATH], //配置文件名 char szCmd[MAX_CMD], //功能码 int &SendCmd, int &Function, int &LBCount, int &Index, int &nLen, char Dtype[10], int &startbit, int &endbit ) { CHAR szFile[MAX_PATH + 1] = ""; wsprintf(szFile, "%s\\config\\%s", szPath, szIniName); TRACE("szFile =%s\n",szFile); SendCmd = GetPrivateProfileInt(szCmd,"SendCmd",0,szFile); Function = GetPrivateProfileInt(szCmd,"Function",0,szFile); LBCount = GetPrivateProfileInt(szCmd,"LBCount",0,szFile); Index = GetPrivateProfileInt(szCmd,"Index",0,szFile); nLen = GetPrivateProfileInt(szCmd,"nLen",0,szFile); DWORD ks = GetPrivateProfileString(szCmd, "Type" , "" , Dtype ,10, szFile); Dtype[strlen(Dtype)] = '\0'; //GetPrivateProfileString(szCmd, "SendCmd", "", szSanTakSendMsg, sizeof(szSanTakSendMsg), szFile); startbit = GetPrivateProfileInt(szCmd,"startbit",0,szFile); endbit = GetPrivateProfileInt(szCmd,"endbit",0,szFile); return 0; } int Emerson_CM::GetDeviceParam( CCommProcess *pComm, //串口对象指针 int nAddr, // 设备地址 char szCmd[MAX_CMD], //功能码 int &SendCmd, // int &Function, // int &LBCount, // int &Index, // int &nLen, // char Dtype[10], // int &startbit, // int &endbit, // char szRecvMsg[VAR_MSG] // 接收Buffer ) { int nRet = -1; if(SendCmd == 0x05) { nRet = RequestReadStatus(pComm, SendCmd, Function, LBCount, nAddr); if( nRet != 0 ) { return nRet; // 串口忙 } nRet = ResponseReadStatus( pComm, szCmd,SendCmd,Function, LBCount); } else if (SendCmd = 0x11) { nRet = RequestWriteStatus(pComm, SendCmd, Function, LBCount, nAddr); if( nRet != 0 ) { return nRet; // 串口忙 } nRet = ResponseWriteStatus(pComm); } return nRet; } // //int Emerson_CM::GetEmersonContrlVarMsg( char szCmd[MAX_CMD], // 命令 // char szRecvMsg[VAR_MSG], // 接收Buffer // int &Index, // 变量索引,针对接收Buffer而言 // int &nLen, // 变量长度 // char szSendCmd[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*/ // ) // { //#if IS_USE_READMSG_CS // EnterCriticalSection( &m_csReadMsg ); //#endif // memcpy(szRecvMsg, m_emerson_ControlMsg + Index, nLen);//命令对应的需要的数据szRecvMsg; //#if IS_USE_READMSG_CS // LeaveCriticalSection(&m_csReadMsg); //#endif // // nRet = 0; // } // // return nRet; //} int Emerson_CM::GetEmersonEnquiryVarMsg(char szCmd[MAX_CMD], // 命令 char szRecvMsg[VAR_MSG], // 接收Buffer int &Index, // 变量索引,针对接收Buffer而言 int &nLen, // 变量长度 char szSendCmd[TYPE_LENGTH] , int &startbit, int &endbit) // 变量数据类型 { int nRet = 0; if( //strcmp(szCmd, "cmd-4") == 0 ||//无bit; //strcmp(szCmd, "cmd-5") == 0 || //无bit; strcmp(szCmd, "cmd-6") == 0 || //strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 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 || //冷水,4位; //strcmp(szCmd, "cmd-22") == 0 ||//无bit; //strcmp(szCmd, "cmd-23") == 0 ||//无bit; strcmp(szCmd, "cmd-24") == 0 ||//无bit; 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 || //strcmp(szCmd, "cmd-39") == 0 //双bit; //strcmp(szCmd, "cmd-40") == 0 ||//无bit; //strcmp(szCmd, "cmd-41") == 0 ||//无bit; //strcmp(szCmd, "cmd-42") == 0//无bit; ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(szRecvMsg, m_emerson_QeuryMsg + Index,nLen);//命令对应的需要的数据szRecvMsg; GetBitStatu(szRecvMsg,startbit,endbit); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } if ( strcmp(szCmd, "cmd-4") == 0 //温度设定 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(szRecvMsg, m_emerson_QeuryMsg + Index,nLen);//命令对应的需要的数据szRecvMsg; int Temp = 17 + (szRecvMsg[0] & 0xf0)/16; sprintf(szRecvMsg,"%d",Temp); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } if ( strcmp(szCmd, "cmd-5") == 0 //湿度设定 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(szRecvMsg, m_emerson_QeuryMsg + Index,nLen);//命令对应的需要的数据szRecvMsg; int Hum = 42 + (szRecvMsg[0] & 0x0f) * 2; sprintf(szRecvMsg,"%d",Hum); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } if( strcmp(szCmd, "cmd-22") == 0 ||//BCD温度 无bit; strcmp(szCmd, "cmd-23") == 0 //BCD湿度 无bit; ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(szRecvMsg, m_emerson_QeuryMsg + Index,nLen);//命令对应的需要的数据szRecvMsg; BCDtofloat(szRecvMsg); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } // if ( // strcmp(szCmd, "cmd-40") == 0 ||//not bit SendCmd // strcmp(szCmd, "cmd-41") == 0 || // strcmp(szCmd, "cmd-42") == 0 // ) // { //#if IS_USE_READMSG_CS // EnterCriticalSection( &m_csReadMsg ); //#endif // memcpy(szRecvMsg, m_emerson_QeuryMsg + Index,nLen);//命令对应的需要的数据szRecvMsg; //#if IS_USE_READMSG_CS // LeaveCriticalSection(&m_csReadMsg); //#endif // } return nRet; } //void Emerson_CM::SetEmersonContrlVarMsg( char szCmd[MAX_CMD], char *pBuffer) //{ // if( strcmp(szCmd, "cmd-1") == 0 || // strcmp(szCmd, "cmd-2") == 0 /*|| // strcmp(szCmd, "cmd-3") == 0 */ // ) // { //#if IS_USE_READMSG_CS // EnterCriticalSection( &m_csReadMsg ); //#endif // memcpy(m_emerson_ControlMsg, pBuffer, sizeof(m_emerson_ControlMsg)); //#if IS_USE_READMSG_CS // LeaveCriticalSection(&m_csReadMsg); //#endif // } //} void Emerson_CM::SetEmersonEnquiryVarMsg( char szCmd[MAX_CMD], char *pBuffer) { if (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-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 || strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 || strcmp(szCmd, "cmd-41") == 0 */ ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_emerson_QeuryMsg, pBuffer, sizeof(m_emerson_QeuryMsg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } BOOL Emerson_CM::ChkSumCheck(char szSendMsg[],int SendCmd/*,int nReadLen*/) { //int len = (int)strlen(szSendMsg); unsigned int nData = 0; switch (SendCmd) { case 0x05: for (int i = 0;i < 28;i++) { nData += szSendMsg[i]; } nData = nData & 0xff; if (nData != szSendMsg[i]) { return FALSE; } break; case 0x11: for(i = 0;i < 4;i++) { nData +=szSendMsg[i]; } nData = nData & 0xff; if (nData != szSendMsg[i]) { return FALSE; } break; default: break; } return TRUE; } void Emerson_CM:: GetBitStatu( char *bytValue,int startbit,int endbit) { int ByteBit = 0; char tempbyte[8] = {0}; //int Len = sizeof(bytValue); if (startbit == endbit) { switch(startbit) { case 0: ByteBit = bytValue[0] & 0x01; break; case 1: ByteBit = (bytValue[0] & 0x02) / 0x02 ; break; case 2: ByteBit = (bytValue[0] & 0x04) / 0x04 ; break; case 3: ByteBit = (bytValue[0] & 0x08) / 0x08 ; break; case 4: ByteBit = (bytValue[0] & 0x10) / 0x10 ; break; case 5: ByteBit = (bytValue[0] & 0x20) / 0x20 ; break; case 6: ByteBit = (bytValue[0] & 0x40) / 0x40 ; break; case 7: ByteBit = (bytValue[0] & 0x80) / 0x80; break; } _snprintf(bytValue,sizeof(bytValue),"%d",ByteBit); //itoa(ByteBit,&bytValue,10); } else { int tempbit = startbit; int TiLen = endbit - startbit; for (int i = 0; i < TiLen;i++) { tempbit = tempbit + i; switch(tempbit) { case 0: ByteBit = bytValue[0] & 0x01; break; case 1: ByteBit = (bytValue[0] & 0x02) / 0x02 ; break; case 2: ByteBit = (bytValue[0] & 0x04) / 0x04 ; break; case 3: ByteBit = (bytValue[0] & 0x08) / 0x08 ; break; case 4: ByteBit = (bytValue[0] & 0x10) / 0x10 ; break; case 5: ByteBit = (bytValue[0] & 0x20) / 0x20 ; break; case 6: ByteBit = (bytValue[0] & 0x40) / 0x40 ; break; case 7: ByteBit = (bytValue[0] & 0x80) / 0x80; break; } _snprintf(tempbyte+i,sizeof(tempbyte),"%d",ByteBit); //itoa(ByteBit,&bytValue,10); } bytValue = tempbyte; } } void Emerson_CM::BCDtofloat(char szRecvbuffer[VAR_MSG]) { int Lvalue; char BufferLd[4] = {0}; char BufferHd[4] = {0}; //int Len = sizeof(szRecvbuffer)-1; Lvalue = (((szRecvbuffer[0] & 15) + ((szRecvbuffer[0] >> 4)*10))); itoa(Lvalue,BufferHd,10); Lvalue = (((szRecvbuffer[1] & 15) + ((szRecvbuffer[1] >> 4)*10))); itoa(Lvalue,BufferLd,10); strcat(BufferHd,BufferLd); int temp_int = atoi(BufferHd); //float temp_flo = temp_int * 0.01; _snprintf(szRecvbuffer,sizeof(szRecvbuffer),"%d",temp_int); //szRecvbuffer[3] = 0; } void Emerson_CM::SimulationCommData() { // m_emerson_ControlMsg[0] = 0xF0; m_emerson_ControlMsg[1] = 0x06; m_emerson_ControlMsg[2] = 0x01; m_emerson_ControlMsg[3] = 0xF7; // m_emerson_QeuryMsg[0] =0xF0; m_emerson_QeuryMsg[1] =0x06; m_emerson_QeuryMsg[2] =0x1A; m_emerson_QeuryMsg[3] =0x00; m_emerson_QeuryMsg[4] =0x02; m_emerson_QeuryMsg[5] =0x05; m_emerson_QeuryMsg[6] =0x05; m_emerson_QeuryMsg[7] =0x67; m_emerson_QeuryMsg[8] =0xFF; m_emerson_QeuryMsg[9] =0xF7; m_emerson_QeuryMsg[10]=0xFF; m_emerson_QeuryMsg[11]=0x36; m_emerson_QeuryMsg[12]=0x00; m_emerson_QeuryMsg[13]=0x08; m_emerson_QeuryMsg[14]=0x00; m_emerson_QeuryMsg[15]=0x00; m_emerson_QeuryMsg[16]=0xE7; m_emerson_QeuryMsg[17]=0x88; m_emerson_QeuryMsg[18]=0x00; m_emerson_QeuryMsg[19]=0x14; m_emerson_QeuryMsg[20]=0x01; m_emerson_QeuryMsg[21]=0x01; m_emerson_QeuryMsg[22]=0x04; m_emerson_QeuryMsg[23]=0x70; m_emerson_QeuryMsg[24]=0x05; m_emerson_QeuryMsg[25]=0xEC; m_emerson_QeuryMsg[26]=0x0A; m_emerson_QeuryMsg[27]=0xA2; m_emerson_QeuryMsg[28]=0x4C; }