| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171 |
- //////////////////////////////////////////////////////////////////////////////
- ////// //////
- ////// 文 件: UL33.cpp //////
- ////// 作 者: wangjianfeng //////
- ////// 创建时间: //////
- ////// 说 明: UL33协议 //////
- ////// //////
- ////// 修改时间:2010-05-11 //////
- ////// 修改说明:新版本 //////
- ////// //////
- //////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "CommProcess.h"
- #include "Global.h"
- #include "UL33.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CUL33::CUL33(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 ) ); //CreateEvent()创建或打开一个命名的或无名的事件对象
-
- memset(m_szUL33_41Msg, 0, sizeof(m_szUL33_41Msg));
- memset(m_szUL33_43Msg, 0, sizeof(m_szUL33_43Msg));
- memset(m_szUL33_44Msg, 0, sizeof(m_szUL33_44Msg));
-
- memset(m_szUL33_C0Msg, 0, sizeof(m_szUL33_C0Msg));
- memset(m_szUL33_C1Msg, 0, sizeof(m_szUL33_C1Msg));
- memset(m_szUL33_C2Msg, 0, sizeof(m_szUL33_C2Msg));
- memset(m_szUL33_C3Msg, 0, sizeof(m_szUL33_C3Msg));
- memset(m_szUL33_C4Msg, 0, sizeof(m_szUL33_C4Msg));
- memset(m_szUL33_C7Msg, 0, sizeof(m_szUL33_C7Msg));
- memset(m_szUL33_C8Msg, 0, sizeof(m_szUL33_C8Msg));
- m_devOnline = TRUE;
- m_dwOnlineTick = 0;
- }
- CUL33::~CUL33()
- {
- #if IS_USE_READMSG_CS
- DeleteCriticalSection( &m_csReadMsg );
- #endif
- MTVERIFY( CloseHandle( m_hSemComm ) );
- CloseComm();
- }
- BOOL CUL33::UpsULOpenComm(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 CUL33::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[UL33_SEND_MSG] = {0};
- char szType[TYPE_LENGTH] = {0};
- GetULFromIni(szPath, szIniName, szCmd,szSendMsg, szType, nIndex, nLen);
- CCommProcess *pComm = FindComm(nCommPort);
- if( pComm == NULL ) return -1;
- int nRet = -1;
- if (
- (strlen(m_szUL33_41Msg) ==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 || strcmp(szCmd, "cmd-11") == 0
- ) )
- ||
- (strlen(m_szUL33_C0Msg) ==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
- ) )
- ||
- (strlen(m_szUL33_C1Msg) ==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
- ) )
- ||
- (strlen(m_szUL33_C2Msg) ==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
- ) )
- ||
- (strlen(m_szUL33_C3Msg) ==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
- ) )
- ||
- (strlen(m_szUL33_43Msg) ==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
- ) )
- ||
- (strlen(m_szUL33_44Msg) ==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
- ) )
- ||
- (strlen(m_szUL33_C7Msg) ==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-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-77") == 0 || strcmp(szCmd, "cmd-78") == 0 ||
- strcmp(szCmd, "cmd-79") == 0 || strcmp(szCmd, "cmd-80") == 0 ||
- strcmp(szCmd, "cmd-81") == 0 || strcmp(szCmd, "cmd-82") == 0 ||
- strcmp(szCmd, "cmd-83") == 0 || strcmp(szCmd, "cmd-84") == 0 ||
- strcmp(szCmd, "cmd-85") == 0 || strcmp(szCmd, "cmd-86") == 0 ||
- strcmp(szCmd, "cmd-87") == 0 || strcmp(szCmd, "cmd-88") == 0
- ) )
- ||
- (strlen(m_szUL33_C8Msg) ==0 &&
- (
- strcmp(szCmd, "cmd-89") == 0 || strcmp(szCmd, "cmd-90") == 0 ||
- strcmp(szCmd, "cmd-91") == 0 || strcmp(szCmd, "cmd-92") == 0 ||
- strcmp(szCmd, "cmd-93") == 0 || strcmp(szCmd, "cmd-94") == 0 ||
- strcmp(szCmd, "cmd-95") == 0 || strcmp(szCmd, "cmd-96") == 0 ||
- strcmp(szCmd, "cmd-97") == 0 || strcmp(szCmd, "cmd-98") == 0
- ) )
- ||
- (strlen(m_szUL33_C4Msg) == 0 &&
- (
- strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ||
- strcmp(szCmd, "cmd-41") == 0
- ))
- ||
- strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-12") == 0 ||
- strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-27") == 0 ||
- strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-39") == 0 ||
- strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-53") == 0 ||
- strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-89") == 0
- )
- {
- nRet = GetDeviceParam( nAddr,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 = GetULQ41VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetULQ43VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetULQ44VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetULQC0VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetULQC1VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetULQC2VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetULQC3VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetULQC4VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetULQC7VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- nRet = GetULQC8VarMsg(szCmd, szMsg, nIndex, nLen, szType);
- LOG4C((LOG_NOTICE,"nRet = %d,cmd = %s,值 = %s",nRet,szCmd,szMsg));
- return nRet;
- }
- int CUL33::GetDeviceParam(
- int nAddr,
- CCommProcess *pComm, //串口对象指针
- char szSendMsg[UL33_SEND_MSG], //发送Buffer
- char szCmd[MAX_CMD], // 命令
- char szRecvMsg[VAR_MSG], // 接收Buffer
- int &nIndex, // 变量索引,针对接收Buffer而言
- int &nLen, // 变量长度
- char szType[TYPE_LENGTH]) // 变量数据类型
- {
- int nRet = -1;
- nRet = RequestReadStatus(nAddr,pComm, szSendMsg);
- if( nRet != 0 )
- {
- return nRet; // 串口忙
- }
- nRet = ResponseReadStatus(pComm, szCmd, szRecvMsg, nIndex, nLen, szType);
- return nRet;
- }
- int CUL33::GetULQ41VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- 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-5") == 0 || strcmp(szCmd, "cmd-6") == 0 ||
- strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 ||
- strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 ||
- strcmp(szCmd, "cmd-11") == 0
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- DataConversion(szType, m_szUL33_41Msg + nIndex, szRecvMsg, nLen,0,0 );
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUL33::GetULQC0VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- int nRet = 0;
- if(
- 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 )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- DataConversion(szType, m_szUL33_C0Msg + nIndex, szRecvMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUL33::GetULQC1VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- int nRet = 0;
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- DataConversion(szType, m_szUL33_C1Msg + nIndex, szRecvMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUL33::GetULQC2VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- int nRet = 0;
-
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- DataConversion(szType, m_szUL33_C2Msg + nIndex, szRecvMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUL33::GetULQC3VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- int nRet = 0;
- if( 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
- DataConversion(szType, m_szUL33_C3Msg + nIndex, szRecvMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUL33::GetULQ43VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- int nRet = 0;
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- DataConversion(szType, m_szUL33_43Msg + nIndex, szRecvMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUL33::GetULQ44VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- int nRet = 0;
- if( 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- DataConversion(szType, m_szUL33_44Msg + nIndex, szRecvMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUL33::GetULQC7VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- int nRet = 0;
- if(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-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-77") == 0 || strcmp(szCmd, "cmd-78") == 0 ||
- strcmp(szCmd, "cmd-79") == 0 || strcmp(szCmd, "cmd-80") == 0 ||
- strcmp(szCmd, "cmd-81") == 0 || strcmp(szCmd, "cmd-82") == 0 ||
- strcmp(szCmd, "cmd-83") == 0 || strcmp(szCmd, "cmd-84") == 0 ||
- strcmp(szCmd, "cmd-85") == 0 || strcmp(szCmd, "cmd-86") == 0 ||
- strcmp(szCmd, "cmd-87") == 0 || strcmp(szCmd, "cmd-88") == 0
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- DataConversion(szType,m_szUL33_C7Msg + nIndex, szRecvMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUL33::GetULQC8VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- int nRet = 0;
- if(
- strcmp(szCmd, "cmd-89") == 0 || strcmp(szCmd, "cmd-90") == 0 ||
- strcmp(szCmd, "cmd-91") == 0 || strcmp(szCmd, "cmd-92") == 0 ||
- strcmp(szCmd, "cmd-93") == 0 || strcmp(szCmd, "cmd-94") == 0 ||
- strcmp(szCmd, "cmd-95") == 0 || strcmp(szCmd, "cmd-96") == 0 ||
- strcmp(szCmd, "cmd-97") == 0 || strcmp(szCmd, "cmd-98") == 0
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- DataConversion(szType, m_szUL33_C8Msg + nIndex, szRecvMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- int CUL33::GetULQC4VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
- {
- int nRet = 0;
- if(
- strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ||
- strcmp(szCmd, "cmd-41") == 0
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- DataConversion(szType, m_szUL33_C4Msg + nIndex, szRecvMsg, nLen, 0, 0);
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- nRet = 0;
- }
- return nRet;
- }
- // 发送设置设备参数请求
- int CUL33::SendSetReuest(
- char szPath[MAX_PATH], // 程序所在路径
- char szIniName[MAX_PATH], // 配置文件名称
- int nCommPort, // 串行端口
- int nAddr, // 设备地址
- char szCmd[MAX_CMD], // 请求命令
- char szRecvMsg[VAR_MSG], // 响应的值
- int nReversed1, // 预留整形参数1接口
- int nReversed2, // 预留整形参数2接口
- int nReversed3, // 预留整形参数3接口
- int nReversed4, // 预留整形参数4接口
- int nReversed5, // 预留整形参数5接口
- float fReversed1, // 预留float参数1接口
- float fReversed2, // 预留float参数2接口
- float fReversed3, // 预留float参数3接口
- char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
- char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
- char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
- char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
- char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
- )
- {
- return 0;
- }
- int CUL33::ResponseReadStatus( CCommProcess *pComm,
- char szCmd[MAX_CMD],
- char szRecvMsg[VAR_MSG],
- int &nIndex,
- int &nLen,
- char szType[TYPE_LENGTH] )
- {
- #if DEBUG_UL33
- //LOG4C((LOG_NOTICE,"->0"));
- RESPONSE_STRUCT structResponse;
- memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) );
- int nReceiveLen = 0;
- nReceiveLen = sizeof(RESPONSE_STRUCT);
- char *pBuffer = new char[ nReceiveLen ];
- memset(pBuffer, 0, nLen);
- int nReadLen = 0;
- nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen);
- if (!CheckLength(pBuffer))
- {
- SetEvent(m_hSemComm);
- if (pBuffer !=NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- LOG4C((LOG_NOTICE,"->长度校验出错"));
- return ERR_CODE_UL33_COM_CHKSUM_LOST; //长度校验出错
- }
- if (!ChkSumCheck(pBuffer,nReadLen))
- {
- SetEvent(m_hSemComm);
- if (pBuffer !=NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- LOG4C((LOG_NOTICE,"->校验码校验出错"));
- return ERR_CODE_UL33_COM_CHKSUM_LOST; //校验码校验出错
- }
- int nRet = RtnCheck(pBuffer, nReadLen);
- if (nRet != 0)
- {
- SetEvent( m_hSemComm );
- if( pBuffer != NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- LOG4C((LOG_NOTICE,"->RTN校验出错"));
- return nRet; //RTN校验出错
- }
- if( nReadLen <= 0)
- {
- // 串口没有读到数据
- SetEvent( m_hSemComm );
- if( pBuffer != NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- LOG4C((LOG_NOTICE,"->串口没有读到数据"));
- return ERR_CODE_UL33_COM_READ_NO_DATA;
- }
-
- SetULQ41VarMsg( szCmd, pBuffer);
- SetULQ43VarMsg( szCmd, pBuffer);
- SetULQ44VarMsg( szCmd, pBuffer);
- SetULQC0VarMsg( szCmd, pBuffer);
- SetULQC1VarMsg( szCmd, pBuffer);
- SetULQC2VarMsg( szCmd, pBuffer);
- SetULQC3VarMsg( szCmd, pBuffer);
- SetULQC4VarMsg( szCmd, pBuffer);
- SetULQC7VarMsg( szCmd, pBuffer);
- SetULQC8VarMsg( szCmd, pBuffer);
- m_dwOnlineTick = GetTickCount();
- SetEvent( m_hSemComm );
- if( pBuffer != NULL)
- {
- delete[] pBuffer;
- pBuffer = NULL;
- }
- #else
- SimulationCommData();
- #endif
- return 0;
- }
- int CUL33::RequestReadStatus(int nAddr,CCommProcess *pComm,char chSendMsg[UL33_SEND_MSG])
- {
- #if DEBUG_UL33
- #if 0
- char chLength[4] = {0};
- char chChkSum[5] = {0};
- REQUESTPARAM RequestPara;
- int iLen = sizeof(RequestPara);
- memset( &RequestPara, 0, iLen );
- //起始位
- RequestPara.RequestChild.bySoi = 0x7E;
- //通讯协议版本
- RequestPara.RequestChild.byVer[0] = 0x31;
- RequestPara.RequestChild.byVer[1] = 0x37;
- //设备地址描述
- RequestPara.RequestChild.byAdr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
- RequestPara.RequestChild.byAdr[1] = ByteToAscii(nAddr & 0x0f);
- //Cid1
- RequestPara.RequestChild.byCid1[0] = 0x32;
- RequestPara.RequestChild.byCid1[1] = 0x41;
- //Cid2
- memcpy(RequestPara.RequestChild.byCid2, chSendMsg, 2);
- RequestPara.RequestChild.byLength[0] = 0x45;
- RequestPara.RequestChild.byLength[1] = 0x30;
- RequestPara.RequestChild.byLength[2] = 0x30;
- RequestPara.RequestChild.byLength[3] = 0x32;
- //Info
- RequestPara.RequestChild.byInfo[0] = 0x30;
- RequestPara.RequestChild.byInfo[1] = 0x31;
- int nLen = sizeof(RequestPara.byCheckSum) -1;
- //校验码
- BYTE *pDataBuf = new BYTE[ iLen - nLen];
- memset(pDataBuf, 0, iLen -nLen );
- memcpy(pDataBuf, &RequestPara, iLen - nLen);
- GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.byCheckSum) - 2 );
- delete []pDataBuf;
- pDataBuf = NULL;
- RequestPara.byCheckSum[0] = chChkSum[0];
- RequestPara.byCheckSum[1] = chChkSum[1];
- RequestPara.byCheckSum[2] = chChkSum[2];
- RequestPara.byCheckSum[3] = chChkSum[3];
- //结束符
- RequestPara.byEoi = 0x0D;
- //LOG4C((LOG_NOTICE,"sendmsg = %s",(char*)RequestPara));
- //WaitForSingObject();等待有信号;
- if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口
- {
- //求得数组字符实际长度;
- int nDataLen = (int)sizeof(RequestPara);
- //ResetEvent()设置无信号状态
- ResetEvent( m_hSemComm );
- int nResult = pComm->Write((BYTE *)&RequestPara, nDataLen);
- if( nResult != nDataLen )
- {
- //SetEvent设置有信号;
- SetEvent( m_hSemComm );
- //返回 错误值;
- return EER_CODE_UL33_COM_REGNUM;
- }
- }
- else
- {
- //如果m_hSemCom无信号,返回错误;
- return ERR_CODE_UL33_COM_BUSY;
- }
- #endif
- BYTE szSendMSG[32] = {0};
- // 对数组进行赋值;
- szSendMSG[0] = 0x7E;
- szSendMSG[1] = 0x31;
- szSendMSG[2] = 0x37;
- szSendMSG[3] = ByteToAscii( (nAddr >> 4) & 0x0F);
- szSendMSG[4] = ByteToAscii( nAddr & 0x0F);
- szSendMSG[5] = 0x32;
- szSendMSG[6] = 0x41;
- memcpy(szSendMSG + 7, chSendMsg, 2);
- // 进行lengcheck判断;
- if ( nAddr == 4 )
- {
- BYTE szCheck[5] = {0};
- memcpy(szSendMSG + 9, "E002", 4); // LENID;
- memcpy(szSendMSG + 13, "01", 2); // DATAF;
- GetEmersonCheck((char *)szSendMSG, (char*)szCheck);
- memcpy(szSendMSG + 15,szCheck,4);
- szSendMSG[strlen((char*)szSendMSG)] = 0x0D;
- }
- else if ( nAddr == 3)
- {
- BYTE szCheck[5] = {0};
- memcpy(szSendMSG + 9, "E002", 4); // LENID;
- memcpy(szSendMSG + 13, "02", 2); // DATAF;
- GetEmersonCheck((char *)szSendMSG, (char*)szCheck);
- memcpy(szSendMSG + 15,szCheck,4);
- szSendMSG[strlen((char*)szSendMSG)] = 0x0D;
- }
- int iLen = strlen((char*)szSendMSG);
- if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 ) {
- ResetEvent(m_hSemComm);
- int nResult = pComm->Write(szSendMSG, iLen);
- if (nResult != iLen){
- SetEvent(m_hSemComm);
- return EER_CODE_UL33_COM_REGNUM;
- }
- }
- else{
- return ERR_CODE_UL33_COM_BUSY;
- }
-
- LOG4C((LOG_NOTICE,"发送命令=%s",szSendMSG));
- #endif
- return 0;
- }
- void CUL33::GetEmersonCheck(char *szData, char *szCheck ,int nlen /* = 12 */)
- {
- DWORD dwSum(0);
- nlen = strlen(szData);
- 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 CUL33::lowcase2uppcase(BYTE &btSrc)
- {
- if( btSrc >= 'a' && btSrc <= 'z' )
- {
- btSrc = btSrc - 'a' + 'A';
- }
- }
- void CUL33::SetULQ41VarMsg(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-5") == 0 || strcmp(szCmd, "cmd-6") == 0 ||
- strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 ||
- strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 ||
- strcmp(szCmd, "cmd-11") == 0
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szUL33_41Msg, pBuff, sizeof(m_szUL33_41Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUL33::SetULQC0VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szUL33_C0Msg, pBuff, sizeof(m_szUL33_C0Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUL33::SetULQC1VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if( 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szUL33_C1Msg, pBuff, sizeof(m_szUL33_C1Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUL33::SetULQC2VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if( 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szUL33_C2Msg, pBuff, sizeof(m_szUL33_C2Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUL33::SetULQC3VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if(
- 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_szUL33_C3Msg, pBuff, sizeof(m_szUL33_C3Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUL33::SetULQ43VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szUL33_43Msg, pBuff, sizeof(m_szUL33_43Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUL33::SetULQ44VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if(
- 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
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szUL33_44Msg, pBuff, sizeof(m_szUL33_44Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUL33::SetULQC7VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if(
- 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-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-77") == 0 || strcmp(szCmd, "cmd-78") == 0 ||
- strcmp(szCmd, "cmd-79") == 0 || strcmp(szCmd, "cmd-80") == 0 ||
- strcmp(szCmd, "cmd-81") == 0 || strcmp(szCmd, "cmd-82") == 0 ||
- strcmp(szCmd, "cmd-83") == 0 || strcmp(szCmd, "cmd-84") == 0 ||
- strcmp(szCmd, "cmd-85") == 0 || strcmp(szCmd, "cmd-86") == 0 ||
- strcmp(szCmd, "cmd-87") == 0 || strcmp(szCmd, "cmd-88") == 0
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szUL33_C7Msg, pBuff, sizeof(m_szUL33_C7Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUL33::SetULQC8VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if(
- strcmp(szCmd, "cmd-89") == 0 || strcmp(szCmd, "cmd-90") == 0 ||
- strcmp(szCmd, "cmd-91") == 0 || strcmp(szCmd, "cmd-92") == 0 ||
- strcmp(szCmd, "cmd-93") == 0 || strcmp(szCmd, "cmd-94") == 0 ||
- strcmp(szCmd, "cmd-95") == 0 || strcmp(szCmd, "cmd-96") == 0 ||
- strcmp(szCmd, "cmd-97") == 0 || strcmp(szCmd, "cmd-98") == 0
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szUL33_C8Msg, pBuff, sizeof(m_szUL33_C8Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- void CUL33::SetULQC4VarMsg(char szCmd[MAX_CMD], char *pBuff)
- {
- if(
- strcmp(szCmd, "cmd-39") == 0 ||
- strcmp(szCmd, "cmd-40") == 0 ||
- strcmp(szCmd, "cmd-41") == 0
- )
- {
- #if IS_USE_READMSG_CS
- EnterCriticalSection( &m_csReadMsg );
- #endif
- memcpy(m_szUL33_C4Msg, pBuff, sizeof(m_szUL33_C4Msg));
- #if IS_USE_READMSG_CS
- LeaveCriticalSection(&m_csReadMsg);
- #endif
- }
- }
- UINT CUL33::GetCheckSum(char *pBuf, char chDest[5], int len)
- {
- WORD iSum = 0;;
- for(int i=0; i<len; i++)//求和
- {
- iSum += pBuf[i];
- }
- WORD iCompliment = iSum;
- iCompliment = ~iCompliment;//取反
- iCompliment++;
- itoa(iCompliment, chDest, 16);
- chDest[0] = lowercase2uppercase(chDest[0]);
- chDest[1] = lowercase2uppercase(chDest[1]);
- chDest[2] = lowercase2uppercase(chDest[2]);
- chDest[3] = lowercase2uppercase(chDest[3]);
- return atoi(chDest);
- }
- //
- //BOOL CUL33::LengthCheck(char szRecvdMsg[VAR_MSG])
- //{
- //
- // WORD len ,index , lenID;
- // len = 4;
- // index = 9;
- // char ch[4];
- //
- // for (int i=0;i<len;i++)
- // {
- // ch[i] = szRecvdMsg[index+i];
- // }
- //
- // lenID = AsciiToBYTE(ch[1]) + AsciiToBYTE(ch[2]) + AsciiToBYTE(ch[3]);
- // lenID = lenID%16;
- // lenID = ~lenID + 1;
- // lenID = lenID & 15;
- //
- // if (AsciiToBYTE(ch[0]) == lenID)
- // {
- // return TRUE;
- // }
- // else
- // {
- // return FALSE;
- // }
- //}
- //BOOL CUL33::ChkSumCheck(char szSendMsg[],int len)
- //{
- // char *buffer = new char[5];
- //
- // memset(buffer,0,sizeof(buffer));
- //
- // unsigned int nData = 0;
- // unsigned int nDataLen = 0;
- //
- // for (int i = 1; i < len-5; i++)
- // {
- // nData += szSendMsg[i];
- // }
- //
- // nData = ~nData +1;
- //
- // nData = nData << 16;
- // itoa(nData,buffer,16);
- //
- // int j = 0;
- // for (i = len-5; i <len -1,j < 4; i++,j++)
- // {
- // if(lowercase2uppercase(buffer[j]) != szSendMsg[i])
- // {
- // return FALSE;
- // }
- // }
- //
- // return TRUE;
- //}
- WORD CUL33::RtnCheck(char szRecvdMsg[],int len)
- {
- char ch[2] = {0};
- ch[0] = szRecvdMsg[7];
- ch[1] = szRecvdMsg[8];
- if (atoi(ch) == 0)
- {
- return ERR_CODE_RTN_NATURAL;
- }
- else if (atoi(ch) ==1)
- {
- return ERR_CODE_RTN_VER_ERROR;
- }
- else if (atoi(ch) ==2)
- {
- return ERR_CODE_RTN_CHKSUM_ERROR;
- }
- else if (atoi(ch) ==3)
- {
- return ERR_CODE_RTN_LCHKSUM_ERROR;
- }
- else if (atoi(ch) ==4)
- {
- return ERR_CODE_RTN_CID_ERROR;
- }
- else if (atoi(ch) ==5)
- {
- return ERR_CODE_RTN_COMMAND_FORMAT;
- }
- else if (atoi(ch) ==6)
- {
- return ERR_CODE_RTN_INVALID_DATA;
- }
- else if (atoi(ch) ==16)
- {
- return ERR_CODE_RTN_INVALID_LIMIT;
- }
- else if (atoi(ch) ==17)
- {
- return ERR_CODE_RTN_OPERATE_FAIL;
- }
- else if (atoi(ch) ==18)
- {
- return ERR_CODE_RTN_EQUIT_FAIL;
- }
- return -1;
- }
- int CUL33::GetULFromIni(
- char szPath[MAX_PATH], //服务器程序所在目录
- char szIniName[MAX_PATH], //配置文件名
- char szCmd[MAX_CMD], //命令
- char szSendMsg[MAX_CMD], //发送Buffer
- char nType[MAX_CMD],
- int &nIndex,
- int &nLen
- )
- {
- CHAR szFile[MAX_PATH + 1] = "";
- wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);
- GetPrivateProfileString(szCmd, "SendCmd", "", szSendMsg, 10, szFile);
- szSendMsg[strlen(szSendMsg)] = '\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;
- }
- void CUL33::SimulationCommData(void)
- {
- }
|