| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- /*************************************************
- /* Copyright (C), 2010-2011,StoneU. Co., Ltd.
- /* File name: ups_newave.cpp
- /* Author: Zero.t
- /* Version: Ver1.0.0.1
- /* Date: 2011-8-30
- /* Description: Conceptpower系列UPS,具体型号未知;本类首次使用在项目::K客户现场文件\b北京\M美思装饰\大众汽车金融;
- /* Others: UPS协议类,不做控制设备操作;
- /* Function List: ###
- /* History:
- 1.Date: ###
- Author: ###
- Modification: ###
- *************************************************/
- #include "StdAfx.h"
- #include "CommProcess.h"
- #include ".\ups_newave.h"
- Cups_newave::Cups_newave(
- 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_szAlarmMsg, 0, sizeof(m_szAlarmMsg));
- memset(m_szStatuMsg, 0, sizeof(m_szStatuMsg));
- memset(m_szValueMsg, 0, sizeof(m_szValueMsg));
- m_dwOnlineTick = 0;
- m_devOnline = TRUE;
- }
- Cups_newave::~Cups_newave(void)
- {
- #if IS_USE_READMSG_CS
- DeleteCriticalSection(& m_csReadMsg);
- #endif
- MTVERIFY(CloseHandle(m_hSemComm));
- CloseComm();
- }
- BOOL Cups_newave::upsAveOpenComm(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 Cups_newave::GetParamFromIni( char szPath[MAX_PATH], char szIniName[MAX_PATH],char szCmd[MAX_CMD],char szSanTakSendMsg[MAX_CMD],
- char nType[MAX_CMD], int &nIndex, int &nLen ,int &StaBit, 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)] = 0x0D;
- GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile);
- nType[strlen(nType)] = '\0';
- nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
- nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
- StaBit = GetPrivateProfileInt(szCmd,"StaBit",0,szFile);
- EndBit = GetPrivateProfileInt(szCmd,"EndBit",0,szFile);
- return 0;
- }
- int Cups_newave::SendQueryMsg( CCommProcess *pComm,int nAddr)
- {
- #if NEWAVE_DEBUG //开关量,用于测试模拟数据
- __QueryMsg str_Query;
- int nLen = sizeof(__QueryMsg);
- memset(&str_Query,0,nLen);
-
- str_Query.msg_head = 0x3E;
- str_Query.msg_addr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
- str_Query.msg_addr[1] = ByteToAscii(nAddr & 0x0f);
- str_Query.msg_type = 0x51;
- str_Query.msg_length[0] = 0x30;
- str_Query.msg_length[1] = 0x30;
- str_Query.msg_length[3] = 0x34;
- memcpy(str_Query.msg_check,"0186",4);
- if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 )
- {
- int nDatalen = (int)sizeof(str_Query);
- ResetEvent(m_hSemComm);
- int nResult = pComm->Write((BYTE *)&str_Query, nDatalen);
- //LOG4C_HEX_DUMP((LOG_NOTICE, chSendMsg, 3));
- //LOG4C((LOG_NOTICE, "CSanTak::RequestStatus chSendMsg = %s, nResult = %d, nDatalen = %d", chSendMsg,nResult, nDatalen));
- if (nResult == nDatalen)
- {
- }
- else
- {
- SetEvent(m_hSemComm);
- return EER_CODE_NEWAVE_COM_REGNUM;
- }
- }
- else
- {
- return ERR_CODE_NEWAVE_COM_BUSY; //串口忙
- }
- #endif
- return 0;
- }
- int Cups_newave::QueryResponeMsg(CCommProcess *pComm,int nAddr)
- {
- #if NEWAVE_DEBUG //开关量,用于测试模拟数据
- int ireallen = 0;
- __ResponeQuery str_record;
- int ireadlen = sizeof(str_record);
- char *pBuffer = new char[ireadlen];
- memset(pBuffer,0,ireadlen);
- ireallen = pComm->Read((BYTE *)pBuffer,ireadlen);
- if (ireallen <= 0)
- {
- SetEvent(m_hSemComm);
- if (pBuffer != NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
-
- return ERR_CODE_NEWAVE_COM_READ_NO_DATA;
- }
- char ch_record = 0;
- ch_record = pBuffer[4];
- m_dwOnlineTick = GetTickCount();
- // 设置串口等待事件为有信号
- SetEvent( m_hSemComm );
- if( pBuffer != NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- #endif
- return 0;
- }
- int Cups_newave::SendReadRequest(
- char szPath[MAX_PATH],
- char szIniName[MAX_PATH],
- int nCommPort,
- int nAddr,
- char szCmd[MAX_CMD],
- char szRecMsg[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 StaBit = 0, EndBit = 0;
- char szSendCmd[MAX_SENDCMD] = {0};
- char szType[CMD_TYPE] = {0};
- m_address = nAddr;
- GetParamFromIni(szPath, szIniName, szCmd, szSendCmd, szType, nIndex, nLen ,StaBit, EndBit);
- CCommProcess *pComm = FindComm(nCommPort);
- if( pComm == NULL ) return -1;
- int nRet = -1;
- if(
- ( strlen(m_szValueMsg) == 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-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
- ))||
- (strlen(m_szStatuMsg) == 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
- ))||
- (strlen(m_szAlarmMsg) == 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 || 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 ||
- 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-1") == 0 || strcmp(szCmd,"cmd-15") == 0 || strcmp(szCmd,"cmd-39") == 0
- )
- {
- nRet = GetDeviceParam(nAddr, pComm, szSendCmd, szCmd, szRecMsg, 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 = GetValueMsg(szCmd, szRecMsg, nIndex, nLen, szType);
- nRet = GetStatuMsg(szCmd, szRecMsg, nIndex, nLen, StaBit, EndBit, szType);
- nRet = GetAlarmMsg(szCmd, szRecMsg, nIndex, nLen, StaBit, EndBit, szType);
- //LOG4C_HEX_DUMP((LOG_NOTICE, szMsg, sizeof(szMsg)));
- LOG4C((LOG_NOTICE, "%s=%d", szCmd, atoi(szRecMsg)));
- return nRet;
- }
- int Cups_newave::GetDeviceParam(
- int nAddr,
- CCommProcess *pComm, // 串口对象指针
- char szSendCmd[MAX_SEND_MSG], // 发送Buffer
- char szCmd[MAX_CMD], // 命令
- char szMsg[VAR_MSG], // 接收Buffer
- int &nIndex, // 变量索引,针对接收Buffer而言
- int &nLen, // 变量长度
- char szType[CMD_TYPE] // 变量数据类型
- )
- {
- int nRet = -1;
- nRet = RequestStatus(nAddr, pComm, szSendCmd);
- if( nRet != 0 )
- {
- return nRet;
- }
- nRet = ResponseStatus(nAddr, pComm, szCmd, szMsg, nIndex, nLen, szType);
- return nRet;
- }
- int Cups_newave::RequestStatus(int nAddr, CCommProcess *pComm,const char szSendCmd[MAX_SEND_MSG] )
- {
- #if NEWAVE_DEBUG //开关量,用于测试模拟数据
- int sum = 0;
- __GetMsg str_GetMsg;
- int nLen = sizeof(str_GetMsg);
- memset(&str_GetMsg,0,nLen);
- str_GetMsg.msg_head = 0x3E;
- str_GetMsg.msg_addr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
- str_GetMsg.msg_addr[1] = ByteToAscii(nAddr & 0x0f);
- str_GetMsg.msg_type = 0x47;
- str_GetMsg.msg_length[0] = 0x30;
- str_GetMsg.msg_length[1] = 0x30;
- str_GetMsg.msg_length[2] = 0x38;
- memcpy(str_GetMsg.msg_record,szSendCmd,4);
- {
- sum += str_GetMsg.msg_head;
- sum += str_GetMsg.msg_addr[0];
- sum += str_GetMsg.msg_addr[1];
- sum += str_GetMsg.msg_type;
- sum += str_GetMsg.msg_length[0];
- sum += str_GetMsg.msg_length[1];
- sum += str_GetMsg.msg_length[2];
- sum += str_GetMsg.msg_record[0];
- sum += str_GetMsg.msg_record[1];
- sum += str_GetMsg.msg_record[2];
- sum += str_GetMsg.msg_record[3];
- }
- CString strSum;
- strSum.Format("%00004X",sum);
- int nstrlen = strSum.GetLength();
- if (nstrlen > 4)
- {
- return -1;
- }
- for (int i = 0 ; i < nstrlen; i++)
- {
- str_GetMsg.msg_check[i] = strSum.GetAt(i);
- }
- if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 )
- {
- int nDatalen = (int)sizeof(str_GetMsg);
- ResetEvent(m_hSemComm);
- int nResult = pComm->Write((BYTE *)&str_GetMsg, nDatalen);
- //LOG4C_HEX_DUMP((LOG_NOTICE, chSendMsg, 3));
- //LOG4C((LOG_NOTICE, "CSanTak::RequestStatus chSendMsg = %s, nResult = %d, nDatalen = %d", chSendMsg,nResult, nDatalen));
- if (nResult == nDatalen)
- {
- }
- else
- {
- SetEvent(m_hSemComm);
- return EER_CODE_NEWAVE_COM_REGNUM;
- }
- }
- else
- {
- return ERR_CODE_NEWAVE_COM_BUSY; //串口忙
- }
- #endif
- return 0;
- }
- int Cups_newave::ResponseStatus(int nAddr,CCommProcess *pComm, char szCmd[MAX_CMD],
- char szMsg[VAR_MSG],int &nIndex, int &nLen, char szType[CMD_TYPE])
- {
- #if NEWAVE_DEBUG
- int nReceiveLen = 650;
- int nProcessLen = 0;
- int nReadLen = 0;
- char *pBuff = new char[nReceiveLen];
- memset(pBuff, 0 , nReceiveLen);
- nReadLen = pComm->Read((BYTE *)pBuff,nReceiveLen);
- //LOG4C((LOG_NOTICE, "CSanTak::ResponseStatus pBuff = %s, nReadLen = %d, nReceiveLen = %d", pBuff, nReadLen, nReceiveLen));
- if (nReadLen <= 0)
- {
- SetEvent(m_hSemComm);
- if (pBuff != NULL)
- {
- delete [] pBuff;
- pBuff = NULL;
- }
- return ERR_CODE_NEWAVE_COM_READ_NO_DATA;
- }
- //长度校验出错
- SetValueMsg(szCmd, pBuff);
- SetStatuMsg(szCmd, pBuff);
- SetAlarmMsg(szCmd, pBuff);
- m_dwOnlineTick = GetTickCount();
- // 设置串口等待事件为有信号
- SetEvent( m_hSemComm );
- if( pBuff != NULL)
- {
- delete[] pBuff;
- pBuff = NULL;
- }
- #else
- SimulationCommData();
- #endif
- return 0;
- }
- // 长度为2;
- void Cups_newave::DataProcess(const char *szSour, char *szDest,int &StaBit, int &EndBit)
- {
- char tmp_Sour[3] = {0};
- memcpy(tmp_Sour,szSour,2);
- int sum = (AsciiToBYTE(tmp_Sour[0]))*16 + AsciiToBYTE(tmp_Sour[1]);
- int ByteBit = 0;
- switch(StaBit)
- {
- #if 1
- case 7:
- ByteBit = sum & 0x01;
- break;
- case 6:
- ByteBit = (sum & 0x02) / 0x02 ;
- break;
- case 5:
- ByteBit = (sum & 0x04) / 0x04 ;
- break;
- case 4:
- ByteBit = (sum & 0x08) / 0x08 ;
- break;
- case 3:
- ByteBit = (sum & 0x10) / 0x10 ;
- break;
- case 2:
- ByteBit = (sum & 0x20) / 0x20 ;
- break;
- case 1:
- ByteBit = (sum & 0x40) / 0x40 ;
- break;
- case 0:
- ByteBit = (sum & 0x80) / 0x80;
- break;
- #else
- case 0:
- ByteBit = sum & 0x01;
- break;
- case 1:
- ByteBit = (sum & 0x02) / 0x02 ;
- break;
- case 2:
- ByteBit = (sum & 0x04) / 0x04 ;
- break;
- case 3:
- ByteBit = (sum & 0x08) / 0x08 ;
- break;
- case 4:
- ByteBit = (sum & 0x10) / 0x10 ;
- break;
- case 5:
- ByteBit = (sum & 0x20) / 0x20 ;
- break;
- case 6:
- ByteBit = (sum & 0x40) / 0x40 ;
- break;
- case 7:
- ByteBit = (sum & 0x80) / 0x80;
- break;
- #endif
- }
- szDest[0] = ByteBit + 48;
- }
- void Cups_newave::BitDataProcess(const char *szSour, char *szRecv, int &iSourLen,int &StaBit)
- {
- CString strBit = ""; // 存放位串字符;
- int ByteBit = 0;
- char *tmp_Sour = new char[iSourLen+1];
- memcpy(tmp_Sour,szSour,iSourLen);
- for (int i = 0; i < iSourLen; i+=2)
- {
- char szDest[9] = {0}; // 目标数据;
- int sum = (AsciiToBYTE(tmp_Sour[i]))*16 + AsciiToBYTE(tmp_Sour[i+1]);
- for(int j = 0; j < 8; j ++)
- {
- switch(j)
- {
- case 7:
- ByteBit = sum & 0x01;
- break;
- case 6:
- ByteBit = (sum & 0x02) / 0x02 ;
- break;
- case 5:
- ByteBit = (sum & 0x04) / 0x04 ;
- break;
- case 4:
- ByteBit = (sum & 0x08) / 0x08 ;
- break;
- case 3:
- ByteBit = (sum & 0x10) / 0x10 ;
- break;
- case 2:
- ByteBit = (sum & 0x20) / 0x20 ;
- break;
- case 1:
- ByteBit = (sum & 0x40) / 0x40 ;
- break;
- case 0:
- ByteBit = (sum & 0x80) / 0x80;
- break;
- }
- szDest[j] = ByteBit + 48;
- }
- strBit += szDest;
- }
-
- strBit = strBit.MakeReverse();
- szRecv[0] = strBit.GetAt(StaBit);
- if (tmp_Sour != NULL)
- {
- delete[] tmp_Sour;
- tmp_Sour = NULL;
- }
- }
- int Cups_newave::GetValueMsg(char szCmd[MAX_CMD],char szRecMsg[VAR_MSG],int &nIndex, int &nLen, char szTp[CMD_TYPE])
- {
- 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-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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- DataConversion(szTp, m_szValueMsg + nIndex, szRecMsg, nLen);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int Cups_newave::GetStatuMsg(char szCmd[MAX_CMD],char szRecMsg[VAR_MSG],int &nIndex, int &nLen, int &StaBit, int &EndBit, char szTp[CMD_TYPE])
- {
- int nRet = 0;
- if (
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- //DataProcess(m_szStatuMsg + nIndex, szRecMsg ,StaBit, EndBit);
- BitDataProcess(m_szStatuMsg + nIndex,szRecMsg,nLen,StaBit);
- LOG4C((LOG_NOTICE, "%s Bit[%d] = %s", szCmd,StaBit ,szRecMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int Cups_newave::GetAlarmMsg(char szCmd[MAX_CMD],char szRecMsg[VAR_MSG],int &nIndex, int &nLen, int &StaBit, int &EndBit, char szTp[CMD_TYPE])
- {
- int nRet = 0;
- if (
- 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 || 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 ||
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- //DataProcess(m_szAlarmMsg + nIndex, szRecMsg ,StaBit, EndBit);
- BitDataProcess(m_szAlarmMsg + nIndex,szRecMsg,nLen,StaBit);
- LOG4C((LOG_NOTICE, "%s Bit[%d] = %s", szCmd,StaBit ,szRecMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- void Cups_newave::SetValueMsg(char szCmd[MAX_CMD], char *pBuffer)
- {
- 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-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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_szValueMsg, pBuffer, sizeof(m_szValueMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void Cups_newave::SetStatuMsg(char szCmd[MAX_CMD], char *pBuffer)
- {
- if (
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_szStatuMsg, pBuffer, sizeof(m_szStatuMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void Cups_newave::SetAlarmMsg(char szCmd[MAX_CMD], char *pBuffer)
- {
- if (
- 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 || 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 ||
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_szAlarmMsg, pBuffer, sizeof(m_szAlarmMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void Cups_newave::SimulationCommData()
- {
- memcpy(m_szValueMsg, ">01A0575999,100,2277,2278,2289,2204,2197,2199,3,7,4,12,23,150BDF", sizeof(">01A0575999,100,2277,2278,2289,2204,2197,2199,3,7,4,12,23,150BDF"));
- memcpy(m_szStatuMsg, ">01A012C0C291B3033A", sizeof(">01A012C0C291B3033A"));
- memcpy(m_szAlarmMsg, ">01A018808080808080800451", sizeof(">01A018808080808080800451"));
- }
|