| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- #include "StdAfx.h"
- #include ".\ups_itrust_adapt.h"
- UPS_iTrust_Adapt::UPS_iTrust_Adapt(char *szPath,char *szIniName,int nCommPort, int nAddr,int nRate, int nDataBit,int nStopBit, int nParity,int nInterval)
- {
- #if IS_USE_READMSG_CS
- InitializeCriticalSection(&m_csReadMsg);
- #endif
- MTVERIFY(m_hSemComm = CreateEvent(NULL, TRUE, TRUE, 0));
- // 读设备;
- memset(m_sz42Msg, 0, sizeof(m_sz42Msg));
- memset(m_sz43Msg, 0, sizeof(m_sz43Msg));
- memset(m_sz44Msg, 0, sizeof(m_sz44Msg));
- memset(m_sz47Msg, 0, sizeof(m_sz47Msg));
- // 写设备;
- memset(m_sz45Msg, 0, sizeof(m_sz45Msg));
- memset(m_sz49Msg, 0, sizeof(m_sz49Msg));
- m_dwOnlineTick = 0;
- m_devOnline = TRUE;
- }
- UPS_iTrust_Adapt::~UPS_iTrust_Adapt(void)
- {
- #if IS_USE_READMSG_CS
- DeleteCriticalSection(& m_csReadMsg);
- #endif
- MTVERIFY(CloseHandle(m_hSemComm));
- CloseComm();
- }
- BOOL UPS_iTrust_Adapt::OpenUPSComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
- {
- BOOL bResult = FALSE;
- LOG4C((LOG_NOTICE,"->OpenUPSComm"));
- bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
- return bResult;
- }
- int UPS_iTrust_Adapt::GetIniInfo(char *szPath,char *szIniName,char *szCmd,char *IniSendCMD, int &IniSendlen, char *nType,int &nIndex,int &nLen)
- {
- CHAR szFile[MAX_PATH + 1] = "";
- wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);
- TRACE("szFile =%s\n",szFile);
- IniSendlen = GetPrivateProfileString(szCmd, "SendCmd", "", IniSendCMD, 10, szFile); // 返回的字符串是以\0结束的;
- GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile);
- nType[strlen(nType)] = '\0';
- nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
- nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
- return 0;
- }
- int UPS_iTrust_Adapt::SendReadRequest(
- char *szPath,
- char *szIniName,
- int nCommPort,
- int nAddr,
- char *szCmd,
- char *szMsg,
- int nReversed1,
- int nReversed2,
- int nReversed3,
- int nReversed4,
- int nReversed5,
- float fReversed1,
- float fReversed2,
- float fReversed3,
- char *szReversed1,
- char *szReversed2,
- char *szReversed3,
- char *szReversed4,
- char *szReversed5 )
- {
- LOG4C((LOG_NOTICE,"->SendReadRequest"));
- CCommProcess *pComm = FindComm(nCommPort);
- if( pComm == NULL ) return -1;
- int nRet(-1);
- int nIndex(0), nLen(0), IniSendlen(0);
- char IniSendCMD[MAX_CMD] = {0}, szDataType[CMD_TYPE] = {0};
- GetIniInfo(szPath,szIniName,szCmd,IniSendCMD,IniSendlen,szDataType,nIndex,nLen);
- if (
-
- (strlen(m_sz42Msg) == 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 || 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_sz43Msg) == 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
- ) )||
- ( strlen(m_sz44Msg) == 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 || 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
- )) ||
- ( strlen(m_sz47Msg) == 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-67") == 0 || strcmp(szCmd, "cmd-68") == 0 || strcmp(szCmd, "cmd-69") == 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-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ||
- strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 || strcmp(szCmd, "cmd-71") == 0 ||
- strcmp(szCmd, "cmd-72") == 0 || strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 ||
- strcmp(szCmd, "cmd-75") == 0 || strcmp(szCmd, "cmd-76") == 0
- ) ) ||
- strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-21") == 0 ||
- strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-52") == 0
- )
- )
- {
- nRet = GetDeviceParam(nAddr ,pComm, IniSendCMD,IniSendlen, szCmd );
- 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;
- }
- LOG4C((LOG_NOTICE,"->GetUPS_42Msg"));
- nRet = GetUPS_42Msg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
- nRet = GetUPS_43Msg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
- nRet = GetUPS_44Msg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
- nRet = GetUPS_47Msg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
- return nRet;
- }
- // 发送写设置;
- int UPS_iTrust_Adapt::SendSetReuest(
- char *szPath,
- char *szIniName,
- int nCommPort,
- int nAddr,
- char *szCmd,
- char *szMsg,
- int nReversed1,
- int nReversed2,
- int nReversed3,
- int nReversed4,
- int nReversed5,
- float fReversed1,
- float fReversed2,
- float fReversed3,
- char *szReversed1,
- char *szReversed2,
- char *szReversed3,
- char *szReversed4,
- char *szReversed5
- )
- {
- return 0;
- }
- int UPS_iTrust_Adapt::GetDeviceParam(int naddr, CCommProcess *pComm,char *IniSendCMD,const int &IniSendlen ,char *szCmd)
- {
- LOG4C((LOG_NOTICE,"->GetDeviceParam"));
- int nRet(-1);
- nRet = Send_ReadDeviceData(naddr, pComm, IniSendCMD, IniSendlen);
- if( nRet != 0 ) {
- return nRet;
- }
- nRet = Recv_ReadDeviceData(naddr, pComm, szCmd);
- return nRet;
- }
- int UPS_iTrust_Adapt::Send_ReadDeviceData(int nAddr,CCommProcess *pComm,const char *IniSendCMD,const int &IniSendlen)
- {
- #if DEBUG_ITRUSTADAPT
- LOG4C((LOG_NOTICE,"->Send_ReadDeviceData"));
- int nSLen = sizeof(SEND_DEVICEDATA);
- SEND_DEVICEDATA SendDeviceData;
- memset(&SendDeviceData, 0, sizeof(SEND_DEVICEDATA));
- SendDeviceData.Start = 0x7E;
-
- SendDeviceData.Version[0] = 0x31;
- SendDeviceData.Version[1] = 0x30;
- SendDeviceData.Address[0] = ByteToAscii( (nAddr >> 4) & 0x0F);
- SendDeviceData.Address[1] = ByteToAscii( nAddr & 0x0F);
- SendDeviceData.Cid1[0] = 0x32;
- SendDeviceData.Cid1[1] = 0x41;
- memcpy(SendDeviceData.Cid2, IniSendCMD, IniSendlen);
- memcpy(SendDeviceData.Length,"0000",4);
- //GetEmersonLength( 0,(char *)SendDeviceData.Length);
- GetEmersonCheck((char *)&SendDeviceData, (char*)SendDeviceData.chkSum);
- // 结束符;
- SendDeviceData.End = 0x0D;
- if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 ) {
- ResetEvent(m_hSemComm);
- int nResult = pComm->Write((BYTE *)&SendDeviceData, nSLen);
- if (nResult != nSLen){
- SetEvent(m_hSemComm);
- return EER_CODE_COM_REGNUM;
- }
- }
- else{
- return ERR_CODE_COM_BUSY;
- }
- #endif
- return 0;
- }
- int UPS_iTrust_Adapt::Recv_ReadDeviceData(int nAddr,CCommProcess *pComm,char *szCmd)
- {
- #if DEBUG_ITRUSTADAPT
- LOG4C((LOG_NOTICE,"->Recv_ReadDeviceData"));
- int nProcessLen(0),nReadLen(0);
- char *pBuff = new char[MAX_RECE_MSG];
- memset(pBuff, 0 , MAX_RECE_MSG);
- nReadLen = pComm->Read((BYTE *)pBuff,MAX_RECE_MSG);
- if (nReadLen <= 0){
- SetEvent(m_hSemComm);
- if (pBuff != NULL) {
- delete [] pBuff;
- pBuff = NULL;
- }
- return ERR_CODE_COM_READ_NO_DATA;
- } //长度校验出错 ;
- CopyUPS_42_Msg(nAddr, szCmd, pBuff);
- CopyUPS_43_Msg(nAddr, szCmd, pBuff);
- CopyUPS_44_Msg(nAddr, szCmd, pBuff);
- CopyUPS_47_Msg(nAddr, szCmd, pBuff);
- m_dwOnlineTick = GetTickCount();
- SetEvent( m_hSemComm );
- if( pBuff != NULL) {
- delete[] pBuff;
- pBuff = NULL;
- }
- #else
- SimulationCommData();
- #endif
- return 0;
- }
- void UPS_iTrust_Adapt::CopyUPS_42_Msg( int naddr, char *szCmd, 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 || 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_sz42Msg, pBuffer, sizeof(m_sz42Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void UPS_iTrust_Adapt::CopyUPS_43_Msg( int naddr, char *szCmd, char *pBuffer)
- {
- 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 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_sz43Msg, pBuffer, sizeof(m_sz43Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void UPS_iTrust_Adapt::CopyUPS_44_Msg( int naddr, char *szCmd, char *pBuffer)
- {
- if ( 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 || 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)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_sz44Msg, pBuffer, sizeof(m_sz44Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void UPS_iTrust_Adapt::CopyUPS_47_Msg( int naddr, char *szCmd, char *pBuffer)
- {
- if ( 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-67") == 0 || strcmp(szCmd, "cmd-68") == 0 || strcmp(szCmd, "cmd-69") == 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-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ||
- strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 || strcmp(szCmd, "cmd-71") == 0 ||
- strcmp(szCmd, "cmd-72") == 0 || strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 ||
- strcmp(szCmd, "cmd-75") == 0 || strcmp(szCmd, "cmd-76") == 0)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_sz47Msg, pBuffer, sizeof(m_sz47Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void UPS_iTrust_Adapt::CopyUPS_45_Msg( int naddr, char *szCmd, char *pBuffer)
- {
- if ( 0)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_sz45Msg, pBuffer, sizeof(m_sz45Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void UPS_iTrust_Adapt::CopyUPS_49_Msg( int naddr, char *szCmd, char *pBuffer)
- {
- if ( 0)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_sz49Msg, pBuffer, sizeof(m_sz49Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- int UPS_iTrust_Adapt::GetUPS_42Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
- {
- 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 || 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_sz42Msg + nIndex, szMsg, nLen);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int UPS_iTrust_Adapt::GetUPS_43Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
- {
- 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 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- DataConversion(szType, m_sz43Msg + nIndex, szMsg, nLen);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int UPS_iTrust_Adapt::GetUPS_44Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
- {
- int nRet(0);
- if (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 || 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 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- DataConversion(szType, m_sz44Msg + nIndex, szMsg, nLen);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int UPS_iTrust_Adapt::GetUPS_47Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
- {
- int nRet(0);
- if (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-67") == 0 || strcmp(szCmd, "cmd-68") == 0 || strcmp(szCmd, "cmd-69") == 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-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ||
- strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 || strcmp(szCmd, "cmd-71") == 0 ||
- strcmp(szCmd, "cmd-72") == 0 || strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 ||
- strcmp(szCmd, "cmd-75") == 0 || strcmp(szCmd, "cmd-76") == 0 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- DataConversion(szType, m_sz47Msg + nIndex, szMsg, nLen);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int UPS_iTrust_Adapt::GetUPS_45Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
- {
- int nRet(0);
- if (0)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- DataConversion(szType, m_sz45Msg + nIndex, szMsg, nLen);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int UPS_iTrust_Adapt::GetUPS_49Msg(int nAddr,char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
- {
- int nRet(0);
- if (0)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- DataConversion(szType, m_sz49Msg + nIndex, szMsg, nLen);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- void UPS_iTrust_Adapt::lowcase2uppcase(BYTE &btSrc)
- {
- if( btSrc >= 'a' && btSrc <= 'z' )
- {
- btSrc = btSrc - 'a' + 'A';
- }
- }
- void UPS_iTrust_Adapt::GetEmersonLength(const int &iLenID, char *szLegth)
- {
- int ilengthchecksum(0);
- int it = iLenID;
- ilengthchecksum = it & 0x00F ; it = iLenID;
- ilengthchecksum += (it &0x0F0) >> 4; it = iLenID;
- ilengthchecksum += (it &0xF00 ) >> 8;
- ilengthchecksum = ilengthchecksum%16;
- ilengthchecksum = ~ilengthchecksum +17;
- int ilength = (ilengthchecksum & 0x000F) << 12 ;
- ilength = ilength | iLenID;
- itoa(ilength,szLegth,16 );
- for (int i(0) ; i < 5 ; i++)
- {
- lowercase2uppercase((BYTE &)szLegth[i]);
- }
- }
- void UPS_iTrust_Adapt::GetEmersonCheck(char *szData, char *szCheck ,int nlen /* = 12 */)
- {
- DWORD dwSum(0);
- for (int i(0); i < nlen; i++)
- {
- dwSum += szData[i+1] ;
- }
- WORD iCompliment = dwSum;
- iCompliment = ~iCompliment;//取反
- iCompliment++;
- itoa(iCompliment, szCheck, 16);
- for (int i(0); i < 5 ; i++)
- {
- lowcase2uppcase((BYTE &)szCheck[i]);
- }
- }
- void UPS_iTrust_Adapt::SimulationCommData(void)
- {
- }
|