| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180 |
- //////////////////////////////////////////////////////////////////////////////
- ////// //////
- ////// 文 件: UpsLink.cpp //////
- ////// 作 者: Suguobing //////
- ////// 创建时间: //////
- ////// 说 明: UPSLink协议 //////
- ////// //////
- ////// 修改时间:2010-05-10 //////
- ////// 修改说明:MostDevice新版本 //////
- ////// //////
- //////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "UpsLink.h"
- #include "CommProcess.h"
- CUpsLink::CUpsLink(
- char szPath[MAX_PATH],
- char szIniName[MAX_PATH],
- int nCommPort, int nAddr,
- int nRate, int nDataBit,
- int nStopBit, int nParity,
- int nInterval )
- {
- InitializeCriticalSection(&m_csReadFinished);
- InitializeCriticalSection(&m_csWrFinished);
- MTVERIFY(m_hSemComm = CreateEvent(NULL, TRUE, TRUE, 0));
- memset(m_szLink_XMsg, 0, sizeof(m_szLink_XMsg));
- memset(m_szLink_X1Msg, 0, sizeof(m_szLink_X1Msg));
- memset(m_szLink_X2Msg, 0, sizeof(m_szLink_X2Msg));
- memset(m_szLink_GMsg, 0, sizeof(m_szLink_GMsg));
- memset(m_szLink_gMsg, 0, sizeof(m_szLink_gMsg));
- memset(m_szLink_fMsg, 0, sizeof(m_szLink_fMsg));
- memset(m_szLink_9Msg, 0, sizeof(m_szLink_9Msg));
- memset(m_szLink_QMsg, 0, sizeof(m_szLink_QMsg));
- memset(m_szLink_X3Msg, 0, sizeof(m_szLink_X3Msg));
- memset(m_szLink_8Msg, 0, sizeof(m_szLink_8Msg));
- memset(m_szLink_jMsg, 0, sizeof(m_szLink_jMsg));
- memset(m_szLink_X5Msg, 0, sizeof(m_szLink_X5Msg));
- memset(m_szLink_X6Msg, 0, sizeof(m_szLink_X6Msg));
- memset(m_szLink_BMsg, 0, sizeof(m_szLink_BMsg));
- memset(m_szLink_CMsg, 0, sizeof(m_szLink_CMsg));
- memset(m_szLink_LMsg, 0, sizeof(m_szLink_LMsg));
- memset(m_szLink_MMsg, 0, sizeof(m_szLink_MMsg));
- memset(m_szLink_NMsg, 0, sizeof(m_szLink_NMsg));
- memset(m_szLink_OMsg, 0, sizeof(m_szLink_OMsg));
- memset(m_szLink_PMsg, 0, sizeof(m_szLink_PMsg));
- memset(m_szLink_tMsg, 0, sizeof(m_szLink_tMsg));
- memset(m_szLink_hMsg, 0, sizeof(m_szLink_hMsg));
- memset(m_szLink_XJMsg, 0, sizeof(m_szLink_XJMsg));
- memset(m_szLink_X7Msg, 0, sizeof(m_szLink_X7Msg));
- memset(m_szLink_X8Msg, 0, sizeof(m_szLink_X8Msg));
- m_devOnline = TRUE;
- m_dwOnlineTick = 0;
- }
- CUpsLink::~CUpsLink()
- {
- DeleteCriticalSection(& m_csReadFinished);
- DeleteCriticalSection(&m_csWrFinished);
- MTVERIFY(CloseHandle(m_hSemComm));
- CloseComm();
- }
- BOOL CUpsLink::UpsUpLinkOpenComm(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 CUpsLink::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_UHK_SEND_MSG] = {0};
- char szType[UPS_TYPE_LENGTH] = {0};
- int startBit = 0;
- int endBit = 0;
- GetUpLinkFromIni(szPath, szIniName, szCmd, szSendMsg, szType, nIndex, nLen,startBit,endBit);
- CCommProcess *pComm = FindComm(nCommPort);
- if( pComm == NULL ) return -1;
- int nRet = -1;
- if( strlen(m_szLink_XMsg) == 0 || //获取系统模拟量量化数据(浮点数)
- strlen(m_szLink_X1Msg) == 0 || //UPS工作状态及传送顺序
- strlen(m_szLink_X2Msg) == 0 || //UPS告警内容及传送
- strlen(m_szLink_GMsg) == 0 || //获取系统参数(浮点数)
- strlen(m_szLink_gMsg) == 0 || //获取监测模块
- strlen(m_szLink_fMsg) == 0 || //获取监测模块
- strlen(m_szLink_9Msg) == 0 ||
- strlen(m_szLink_QMsg) == 0 ||
- strlen(m_szLink_X3Msg) == 0 ||
- strlen(m_szLink_8Msg) == 0 ||
- strlen(m_szLink_jMsg) == 0 ||
- strlen(m_szLink_X5Msg) == 0 ||
- strlen(m_szLink_X6Msg) == 0 ||
- strlen(m_szLink_BMsg) == 0 ||
- strlen(m_szLink_CMsg) == 0 ||
- strlen(m_szLink_XFMsg) == 0 ||
- strlen(m_szLink_LMsg) == 0 ||
- strlen(m_szLink_MMsg) == 0 ||
- strlen(m_szLink_NMsg) == 0 ||
- strlen(m_szLink_OMsg) == 0 ||
- strlen(m_szLink_PMsg) == 0 ||
- strlen(m_szLink_tMsg) == 0 ||
- strlen(m_szLink_hMsg) == 0 ||
- strlen(m_szLink_XJMsg) == 0 ||
- strlen(m_szLink_X7Msg) == 0 ||
- strlen(m_szLink_X8Msg) == 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-15") == 0 ||
- strcmp(szCmd, "cmd-23") == 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-52") == 0 ||
- strcmp(szCmd, "cmd-53") == 0 )
- {
- int 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 = GetUpLinkXVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkX1VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkX2VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkGVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkgVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkfVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLink9VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkQVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkX3VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLink8VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkjVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkX5VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkX6VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkBVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkCVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkXFVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkLVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkMVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkNVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkOVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkPVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinktVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkhVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkXJVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkX7VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- nRet = GetUpLinkX8VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
- return nRet;
- }
- int CUpsLink::GetUpLinkXVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit)
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-1") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(pSource, m_szLink_XMsg + nIndex, nLen);
- //ConfirmChar(pSource,szMsg,szType,nLen, startBit, endBit);
- DataConversion(pSource, szMsg, szType, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkX1VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-2") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(pSource, m_szLink_X1Msg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkX2VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-3") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(pSource, m_szLink_X2Msg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkGVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-4") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(pSource, m_szLink_GMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkgVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-5") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(pSource, m_szLink_gMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkfVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-6") == 0 )
- {
- memcpy(pSource, m_szLink_fMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- TRACE("szMsg = %s",szMsg);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLink9VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-7") == 0 )
- {
- memcpy(pSource, m_szLink_9Msg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkQVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (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 )
- {
- memcpy(pSource, m_szLink_QMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkX3VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- 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 )
- {
- TRACE("EnterCriticalSection9 nIndex = %d,nLen = %d\n",nIndex,nLen);
- TRACE("EnterCriticalSection9 m_szLink_X3Msg =%s\n",m_szLink_X3Msg);
- memcpy(pSource, m_szLink_X3Msg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- TRACE("szMsg = %s",szMsg);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLink8VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (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 )
- {
- memcpy(pSource, m_szLink_8Msg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkjVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-31") == 0 )
- {
- memcpy(pSource, m_szLink_jMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkX5VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-32") == 0 )
- {
- memcpy(pSource, m_szLink_X5Msg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkX6VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-33") == 0 )
- {
- memcpy(pSource, m_szLink_X6Msg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkBVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-34") == 0 )
- {
- memcpy(pSource, m_szLink_BMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkCVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-35") == 0 )
- {
- memcpy(pSource, m_szLink_CMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkXFVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-36") == 0 )
- {
- memcpy(pSource, m_szLink_XFMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkLVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-37") == 0 )
- {
- memcpy(pSource, m_szLink_LMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkMVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-38") == 0 )
- {
- memcpy(pSource, m_szLink_MMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkNVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-39") == 0 )
- {
- memcpy(pSource, m_szLink_NMsg + nIndex, nLen);
- DataConversion(pSource, szMsg, szType, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkOVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-40") == 0 )
- {
- memcpy(pSource, m_szLink_OMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkPVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-41") == 0 )
- {
- memcpy(pSource, m_szLink_PMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinktVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-42") == 0 )
- {
- memcpy(pSource, m_szLink_tMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkhVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-43") == 0 )
- {
- memcpy(pSource, m_szLink_hMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkXJVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (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 )
- {
- memcpy(pSource, m_szLink_XJMsg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkX7VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-52") == 0)
- {
- memcpy(pSource, m_szLink_X7Msg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetUpLinkX8VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
- {
- char *pSource = new char [nLen];
- int nRet = 0;
- if (strcmp(szCmd, "cmd-53") == 0)
- {
- memcpy(pSource, m_szLink_X8Msg + nIndex, nLen);
- DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
- LeaveCriticalSection(&m_csWrFinished);
- nRet = 0;
- }
- delete [] pSource;
- return nRet;
- }
- int CUpsLink::GetDeviceParam(CCommProcess *pComm, //串口对象指针
- char szSendMsg[UPS_UHK_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 CUpsLink::GetUpLinkFromIni(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);
- GetPrivateProfileString(szCmd, "SendCmd", "", szSanTakSendMsg, sizeof(szSanTakSendMsg), szFile);
- GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile);
- nType[strlen(nType)] = '\0';
- nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
- nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
- if (strcmp(nType,"BIT") == 0)
- {
- startBit = GetPrivateProfileInt(szCmd, "StaBit", 0, szFile);
- endBit = GetPrivateProfileInt(szCmd, "Endbit", 0 ,szFile);
- }
- return 0;
- }
- int CUpsLink::RequestStatus(CCommProcess *pComm, char chSendMsg[UPS_UHK_SEND_MSG] )
- {
- #if DEBUG_LINK //开关量,用于测试模拟数据
- if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 )
- {
- int nDatalen = (int)strlen(chSendMsg);
- ResetEvent(m_hSemComm);
- int nResult = pComm->Write((unsigned char *)chSendMsg, nDatalen);
- if (nResult == nDatalen)
- {
- }
- else
- {
- SetEvent(m_hSemComm);
- return EER_CODE_UPSKEHUA_COM_REGNUM;
- }
- }
- else
- {
- return ERR_CODE_UPSKEHUA_COM_BUSY; //串口忙
- }
- #endif
- return 0;
- }
- int CUpsLink::ResponseStatus(
- CCommProcess *pComm,
- char szCmd[MAX_CMD],
- char szMsg[VAR_MSG],
- int &nIndex,
- int &nLen,
- char szType[TYPE_LENGTH] )
-
- {
- #if DEBUG_LINK
- int nReceiveLen = 0;
- int nProcessLen = 0;
- int nReadLen = 0;
-
- char pBuff[20] = {0};
- memset(pBuff, 0 , nLen);
- nReadLen = pComm->Read((BYTE *)pBuff,nReceiveLen);
- if (nReadLen <= 0)
- {
- SetEvent(m_hSemComm);
-
- return ERR_CODE_UPSKEHUA_COM_READ_NO_DATA;
- }
- SetUpLinkXVarMsg(szCmd, pBuff);
- SetUpLinkX1VarMsg(szCmd, pBuff);
- SetUpLinkX2VarMsg(szCmd, pBuff);
- SetUpLinkGVarMsg(szCmd, pBuff);
- SetUpLinkgVarMsg(szCmd, pBuff);
- SetUpLinkfVarMsg(szCmd, pBuff);
- SetUpLink9VarMsg(szCmd, pBuff);
- SetUpLinkQVarMsg(szCmd, pBuff);
- SetUpLinkX3VarMsg(szCmd, pBuff);
- SetUpLink8VarMsg(szCmd, pBuff);
- SetUpLinkjVarMsg(szCmd, pBuff);
- SetUpLinkX5VarMsg(szCmd, pBuff);
- SetUpLinkX6VarMsg(szCmd, pBuff);
- SetUpLinkBVarMsg(szCmd, pBuff);
- SetUpLinkCVarMsg(szCmd, pBuff);
- SetUpLinkXFVarMsg(szCmd, pBuff);
- SetUpLinkLVarMsg(szCmd, pBuff);
- SetUpLinkMVarMsg(szCmd, pBuff);
- SetUpLinkNVarMsg(szCmd, pBuff);
- SetUpLinkOVarMsg(szCmd, pBuff);
- SetUpLinkPVarMsg(szCmd, pBuff);
- SetUpLinktVarMsg(szCmd, pBuff);
- SetUpLinkhVarMsg(szCmd, pBuff);
- SetUpLinkXJVarMsg(szCmd, pBuff);
- SetUpLinkX7VarMsg(szCmd, pBuff);
- SetUpLinkX8VarMsg(szCmd, pBuff);
- m_dwOnlineTick[nAddr - 1] = GetTickCount();
- // 设置串口等待事件为有信号
- SetEvent( m_hSemComm );
- #else
- SimulationCommData();
- #endif
- return 0;
- }
- void CUpsLink::SetUpLinkXVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if (strcmp(szCmd, "cmd-1") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_XMsg, pBuff, sizeof(m_szLink_XMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkX1VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-2") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_X1Msg,pBuff,sizeof(m_szLink_X1Msg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkX2VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-3") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_X2Msg,pBuff,sizeof(m_szLink_X2Msg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkGVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-4") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_GMsg,pBuff,sizeof(m_szLink_GMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkgVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-5") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_GMsg,pBuff,sizeof(m_szLink_GMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkfVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-6") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_fMsg,pBuff,sizeof(m_szLink_fMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLink9VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-7") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_9Msg,pBuff,sizeof(m_szLink_9Msg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkQVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( 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 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_QMsg,pBuff,sizeof(m_szLink_QMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkX3VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- 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 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_X3Msg,pBuff,sizeof(m_szLink_X3Msg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLink8VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( 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 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_8Msg,pBuff,sizeof(m_szLink_8Msg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkjVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-31") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_jMsg,pBuff,sizeof(m_szLink_jMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkX5VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-32") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_X5Msg,pBuff,sizeof(m_szLink_X5Msg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkX6VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-33") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_X6Msg,pBuff,sizeof(m_szLink_X6Msg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkBVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-34") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_BMsg,pBuff,sizeof(m_szLink_BMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkCVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-35") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_CMsg,pBuff,sizeof(m_szLink_CMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkXFVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-36") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_XFMsg,pBuff,sizeof(m_szLink_XFMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkLVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-37") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_LMsg,pBuff,sizeof(m_szLink_LMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkMVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-38") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_MMsg,pBuff,sizeof(m_szLink_MMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkNVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-39") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_NMsg,pBuff,sizeof(m_szLink_NMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkOVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-40") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_OMsg,pBuff,sizeof(m_szLink_OMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkPVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-41") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_PMsg,pBuff,sizeof(m_szLink_PMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinktVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-42") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_tMsg,pBuff,sizeof(m_szLink_tMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkhVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-43") == 0 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_hMsg,pBuff,sizeof(m_szLink_hMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkXJVarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( 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 )
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_XJMsg,pBuff,sizeof(m_szLink_XJMsg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkX7VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-52") == 0)
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_X7Msg,pBuff,sizeof(m_szLink_X7Msg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SetUpLinkX8VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if ( strcmp(szCmd, "cmd-53") == 0)
- {
- EnterCriticalSection(&m_csWrFinished);
- memcpy(m_szLink_X8Msg,pBuff,sizeof(m_szLink_X8Msg));
- LeaveCriticalSection(&m_csWrFinished);
- }
- }
- void CUpsLink::SimulationCommData(void)
- {
- m_szLink_XMsg[0] = 0x34; //X
- m_szLink_XMsg[1] = 0x66; //X
- m_szLink_XMsg[2] = 0x34; //X
- m_szLink_XMsg[3] = 0x62; //X
- m_szLink_X1Msg[0] = 0x33; //$>
- m_szLink_X1Msg[1] = 0x30; //$>
- m_szLink_X1Msg[2] = 0x33; //$>
- m_szLink_X1Msg[3] = 0x30; //$>
- m_szLink_X1Msg[4] = 0x33; //$>
- m_szLink_X1Msg[5] = 0x32; //$>
- m_szLink_X1Msg[6] = 0x33; //$>
- m_szLink_X1Msg[7] = 0x32; //$>
-
- m_szLink_X2Msg[0] = 0x33; //$>
- m_szLink_X2Msg[1] = 0x30; //$>
- m_szLink_X2Msg[2] = 0x33; //$>
- m_szLink_X2Msg[3] = 0x30; //$>
- m_szLink_X2Msg[4] = 0x33; //$>
- m_szLink_X2Msg[5] = 0x32; //$>
- m_szLink_X2Msg[6] = 0x33; //$>
- m_szLink_X2Msg[7] = 0x32; //$>
-
- m_szLink_GMsg[0] = 0x35; //G
- m_szLink_GMsg[1] = 0x32;
- m_szLink_gMsg[0] = 0x33; //$>
- m_szLink_gMsg[1] = 0x30; //$>
- m_szLink_gMsg[2] = 0x33; //$>
- m_szLink_gMsg[3] = 0x32; //$>
- m_szLink_gMsg[4] = 0x33; //$>
- m_szLink_gMsg[5] = 0x32; //$>
- m_szLink_gMsg[6] = 0x33; //$>
- m_szLink_gMsg[7] = 0x30; //$>
- }
- int CUpsLink::UpRequestWrStatus(char szSendMsg[])
- {
- return 0;
- }
- int CUpsLink::UpResponseWrStatus(char szSendMsg[])
- {
- return 0;
- }
- int CUpsLink::StrLower(char *pSource, char *pDest)
- {
- int length, i;
- length = (int)strlen(pSource);
- for (i = 0; i < length; i++) {
- if ((pSource[i] >= 'A') && (pSource[i] <= 'Z')){
- pDest[i] = _tolower(pSource[i]);
- }
- else
- pDest[i] = pSource[i];
- }
- return 0;
- }
- int CUpsLink::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;
- }
|