| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737 |
- //////////////////////////////////////////////////////////////////////////////
- ////// //////
- ////// 文 件: UpsDelta.cpp //////
- ////// 作 者: Suguobing //////
- ////// 创建时间: //////
- ////// 说 明: Delta协议 //////
- ////// //////
- ////// 修改时间:2010-08-24 //////
- ////// 修改说明: //////
- ////// //////
- //////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "CommProcess.h"
- #include "UpsDelta.h"
- CUpsDelta::CUpsDelta( 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_szDelta_STBMsg, 0, sizeof(m_szDelta_STBMsg));
- memset(m_szDelta_STIMsg, 0, sizeof(m_szDelta_STIMsg));
- memset(m_szDelta_STOMsg, 0, sizeof(m_szDelta_STOMsg));
- memset(m_szDelta_STPMsg, 0, sizeof(m_szDelta_STPMsg));
- memset(m_szDelta_STAMsg, 0, sizeof(m_szDelta_STAMsg));
- m_dwOnlineTick = 0;
- m_devOnline = TRUE;
- }
- CUpsDelta::~CUpsDelta()
- {
- #if IS_USE_READMSG_CS
- DeleteCriticalSection(& m_csReadMsg);
- #endif
- MTVERIFY(CloseHandle(m_hSemComm));
- CloseComm();
- }
- BOOL CUpsDelta::UpsDeltaOpenComm(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 CUpsDelta::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_DELTA_SEND_MSG] = {0};
- char szType[UPS_TYPE_LENGTH] = {0};
- int startBit = 0;
- int endBit = 0;
- m_address = nAddr;
- GetDeltaFromIni(szPath, szIniName, szCmd, szSendMsg, szType, nIndex, nLen, startBit, endBit);
- CCommProcess *pComm = FindComm(nCommPort);
- if( pComm == NULL ) return -1;
- int nRet = -1;
- if( ( strlen(m_szDelta_STBMsg) == 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
- ) )
- || //获取系统模拟量量化数据(浮点数)
- ( strlen(m_szDelta_STIMsg) == 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
- ) )
- ||//UPS工作状态及传送顺序
- ( strlen(m_szDelta_STOMsg) == 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
- ) )
- ||//UPS告警内容及传送
- ( strlen(m_szDelta_STPMsg) == 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
- ) )
- ||//获取系统参数(浮点数)
- ( strlen(m_szDelta_STAMsg) == 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-67") == 0 || strcmp(szCmd, "cmd-68") == 0
- ) )
- ||
- strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 ||
- strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-24") == 0 ||
- strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-39") == 0 ||
- strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 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 = GetDeltaStbMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetDeltaStiMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetDeltaStoMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetDeltaStpMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetDeltaStaMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- LOG4C((LOG_NOTICE, "%s = %s", szCmd, szMsg));
- return nRet;
- }
- int CUpsDelta::GetDeltaStbMsg(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)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- CString strSTB = CString(m_szDelta_STBMsg+7);
- CString strTemp = strSTB;
- int nTempIndex = -1;
- for( int i = 0; i < nIndex - 1; i++ )
- {
- nTempIndex = strTemp.Find(";");
- strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex);
- }
- strTemp = strTemp.Mid(0, nLen);
- strTemp.TrimLeft("0");
- memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() );
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUpsDelta::GetDeltaStiMsg(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-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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- CString strSTI = CString(m_szDelta_STIMsg+7);
- CString strTemp = strSTI;
- int nTempIndex = -1;
- for( int i = 0; i < nIndex - 1; i++ )
- {
- nTempIndex = strTemp.Find(";");
- strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex);
- }
- strTemp = strTemp.Mid(0, nLen);
- strTemp.TrimLeft("0");
- memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() );
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUpsDelta::GetDeltaStoMsg(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-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)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- CString strSTO = CString(m_szDelta_STOMsg+7);
- CString strTemp = strSTO;
- int nTempIndex = -1;
- for( int i = 0; i < nIndex - 1; i++ )
- {
- nTempIndex = strTemp.Find(";");
- strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex);
- }
- strTemp = strTemp.Mid(0, nLen);
- strTemp.TrimLeft("0");
- memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() );
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUpsDelta::GetDeltaStpMsg(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-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 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- CString strSTP = CString(m_szDelta_STPMsg+7);
- CString strTemp = strSTP;
- int nTempIndex = -1;
- for( int i = 0; i < nIndex - 1; i++ )
- {
- nTempIndex = strTemp.Find(";");
- strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex);
- }
- strTemp = strTemp.Mid(0, nLen);
- strTemp.TrimLeft("0");
- memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() );
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUpsDelta::GetDeltaStaMsg(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-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-67") == 0 || strcmp(szCmd, "cmd-68") == 0)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- CString strSTA = CString(m_szDelta_STAMsg+7);
- CString strTemp = strSTA;
- int nTempIndex = -1;
- for( int i = 0; i < nIndex - 1; i++ )
- {
- nTempIndex = strTemp.Find(";");
- strTemp = strTemp.Mid(nTempIndex + 1, strTemp.GetLength() - nTempIndex);
- }
- strTemp = strTemp.Mid(0, nLen);
- strTemp.TrimLeft("0");
- memcpy( szMsg, (char *)(LPCTSTR)strTemp, strTemp.GetLength() );
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUpsDelta::GetDeviceParam(
- CCommProcess *pComm, //串口对象指针
- char szSendMsg[UPS_DELTA_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 CUpsDelta::GetDeltaFromIni(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);
- szSanTakSendMsg[0] = '~';
- szSanTakSendMsg[1] = '0';
- szSanTakSendMsg[2] = '0';
- szSanTakSendMsg[3] = 'P';
- szSanTakSendMsg[4] = '0';
- szSanTakSendMsg[5] = '0';
- szSanTakSendMsg[6] = '3';
- GetPrivateProfileString(szCmd, "SendCmd", "", szSanTakSendMsg + 7, sizeof(szSanTakSendMsg) - 7, szFile);
- nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
- nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
- return 0;
- }
- int CUpsDelta::RequestStatus(CCommProcess *pComm, char chSendMsg[UPS_DELTA_SEND_MSG] )
- {
- #if DEBUG_DELTA //开关量,用于测试模拟数据
- if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 )
- {
- int nDatalen = (int)strlen(chSendMsg);
- ResetEvent(m_hSemComm);
- int nResult = pComm->Write((BYTE *)chSendMsg, nDatalen);
- if (nResult == nDatalen)
- {
- }
- else
- {
- SetEvent(m_hSemComm);
- //LOG4C((LOG_NOTICE, "长度不一"));
- return EER_CODE_UPSDELTA_COM_REGNUM;
- }
- }
- else
- {
- return ERR_CODE_UPSDELTA_COM_BUSY; //串口忙
- }
- #endif
- return 0;
- }
- int CUpsDelta::ResponseStatus(
- CCommProcess *pComm,
- char szCmd[MAX_CMD],
- char szMsg[VAR_MSG],
- int &nIndex,
- int &nLen,
- char szType[TYPE_LENGTH]
- )
- {
- #if DEBUG_DELTA
- int nReceiveLen = 0;
- int nProcessLen = 0;
- int nReadLen = 0;
- RESPONSE_STRUCT strcutResponse;
- memset(&strcutResponse, 0, sizeof(RESPONSE_STRUCT));
- nReceiveLen = sizeof(RESPONSE_STRUCT);
- //LOG4C((LOG_NOTICE, "nReceiveLen = %d",nReceiveLen));
- 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_UPSDELTA_COM_READ_NO_DATA;
- }
-
- SetDeltaStbMsg(szCmd, pBuff);
- SetDeltaStiMsg(szCmd, pBuff);
- SetDeltaStoMsg(szCmd, pBuff);
- SetDeltaStpMsg(szCmd, pBuff);
- SetDeltaStaMsg(szCmd, pBuff);
- m_dwOnlineTick = GetTickCount();
- // 设置串口等待事件为有信号
- SetEvent( m_hSemComm );
- if( pBuff != NULL)
- {
- delete[] pBuff;
- pBuff = NULL;
- }
- #else
- SimulationCommData();
- #endif
- return 0;
- }
- void CUpsDelta::SetDeltaStbMsg(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 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_szDelta_STBMsg, pBuff, sizeof(m_szDelta_STBMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUpsDelta::SetDeltaStiMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_szDelta_STIMsg, pBuff, sizeof(m_szDelta_STIMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUpsDelta::SetDeltaStoMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( 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 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_szDelta_STOMsg, pBuff, sizeof(m_szDelta_STOMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUpsDelta::SetDeltaStpMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( 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)
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_szDelta_STPMsg,pBuff,sizeof(m_szDelta_STPMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUpsDelta::SetDeltaStaMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( 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-67") == 0 || strcmp(szCmd, "cmd-68") == 0 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection(&m_csReadMsg);
- #endif
- memcpy(m_szDelta_STAMsg,pBuff,sizeof(m_szDelta_STAMsg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUpsDelta::SimulationCommData(void)
- {
- CString strRAT, strSTB, strSTI, strSTO, strSTA;
- strRAT = "~00D031;220;500;220;;;;;;;;;;;;;;;;;;;";
- strSTB = "~00D016;0;0;;;;;;;;100;";
- strSTI = "~00D022;3;500;2212;;;;;;;;;;;";
- strSTO = "~00D036;500;3;2200;1000;136000;900;;;;;;;;;";
- //strSTA = "1;1;1;1;1;1;1;0;1;0;1;1;0;1;1;1;1;1;1;1;";
- strSTA = "~00D041;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;0;0;0;";
- memcpy(m_szDelta_STAMsg, (char *)(LPCTSTR)strSTA, strSTA.GetLength());
- memcpy(m_szDelta_STBMsg, (char *)(LPCTSTR)strSTB, strSTB.GetLength());
- memcpy(m_szDelta_STIMsg, (char *)(LPCTSTR)strSTI, strSTI.GetLength());
- memcpy(m_szDelta_STOMsg, (char *)(LPCTSTR)strSTO, strSTO.GetLength());
- }
- int CUpsDelta::RequestWrStatus(char szSendMsg[])
- {
- return 0;
- }
- int CUpsDelta::ResponseWrStatus(char szSendMsg[])
- {
- return 0;
- }
- int CUpsDelta::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;
- }
- void CUpsDelta::ReturnData(char *szSource, char *szDestion, int nIndex)
- {
- char nlen[3] = {0};
- nlen[0] = szSource[4];
- nlen[1] = szSource[5];
- nlen[2] = szSource[6];
- int len = atoi(nlen);
- BOOL bSi = FALSE;
- int i = 0;
- int index = 0;
- if (szSource[7] == 0x3b)
- {
- index = 1;
- }
- while(i < len)
- {
- if (index == nIndex)
- {
- int datalen = 0;
- for (int k = 0;i < len ; k++)
- {
- if (szSource[i+7] != 0x3b)
- szDestion[k] = szSource[i+7];
- else
- break;
- i++;
- }
- break;
- }
- if (szSource[i+7] == 0x3b)
- {
- int j = 0;
- for (;i<len;i++)
- {
- if (szSource[i+7] != 0x3b)
- break;
- j++;
- if (j > 1)
- index += 1 ;
- if (index == nIndex)
- break;
- }
- }
-
- if (index == nIndex)
- {
- int datalen = 0;
- for (int k = 0;i < len ; k++)
- {
- if (szSource[i+7] != 0x3b)
- szDestion[k] = szSource[i+7];
- else
- break;
- i++;
- }
- break;
- }
- if (szSource[i+7] != 0x3b)
- {
- index++;
- if (index == nIndex)
- continue;
- for (;i < len ;i++)
- if (szSource[i+7] == 0x3b)
- {
- --i;
- bSi = FALSE;
- break;
- }
- }
- i++;
- }
- }
|