// SecUPS.cpp: implementation of the CSecUPS class. //////////////////////////////////////////////////////////////////////////////// ////// ////// ////// 文 件: secups.cpp ////// ////// 作 者: wangjianfeng ////// ////// 创建时间: ////// ////// 说 明: sec协议 ////// ////// ////// ////// 修改时间:2010-06-26 ////// ////// 修改说明:新版本 ////// ////// ////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "CommProcess.h" #include "Global.h" #include "SecUPS.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CSecUPS::CSecUPS( 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 ) ); //CreateEvent()创建或打开一个命名的或无名的事件对象 memset(m_szSEC_ST1Msg, 0, sizeof(m_szSEC_ST1Msg)); memset(m_szSEC_ST2Msg, 0, sizeof(m_szSEC_ST2Msg)); memset(m_szSEC_ST3Msg, 0, sizeof(m_szSEC_ST3Msg)); memset(m_szSEC_ST4Msg, 0, sizeof(m_szSEC_ST4Msg)); memset(m_szSEC_ST5Msg, 0, sizeof(m_szSEC_ST5Msg)); memset(m_szSEC_NOMMsg, 0, sizeof(m_szSEC_NOMMsg)); memset(m_szSEC_ATRMsg, 0, sizeof(m_szSEC_ATRMsg)); } CSecUPS::~CSecUPS() { #if IS_USE_READMSG_CS DeleteCriticalSection( &m_csReadMsg ); #endif MTVERIFY( CloseHandle( m_hSemComm ) ); CloseComm(); } BOOL CSecUPS::UpsSECOpenComm(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 CSecUPS::SendReadRequest( char szPath[MAX_PATH], char szIniName[MAX_PATH], int nCommPort, int nAddr, char szCmd[MAX_CMD], char szRecvMsg[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; char szSendMsg[SEC_SEND_MSG] = {0}; GetSECFromIni(szPath, szIniName, szCmd,szSendMsg, nIndex); CCommProcess *pComm = FindComm(nCommPort); int nRet = -1; if ( (strlen(m_szSEC_ST1Msg) == 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 )) || (strlen(m_szSEC_ST2Msg) == 0 && (strcmp(szCmd, "cmd-9")==0|| strcmp(szCmd, "cmd-10")==0|| strcmp(szCmd, "cmd-11")==0|| strcmp(szCmd, "cmd-12")==0|| strcmp(szCmd, "cmd-13")==0|| strcmp(szCmd, "cmd-14")==0|| strcmp(szCmd, "cmd-15")==0|| strcmp(szCmd, "cmd-16")==0|| strcmp(szCmd, "cmd-17")==0|| strcmp(szCmd, "cmd-18")==0|| strcmp(szCmd, "cmd-19")==0|| strcmp(szCmd, "cmd-20")==0|| strcmp(szCmd, "cmd-21")==0|| strcmp(szCmd, "cmd-22")==0 )) || (strlen(m_szSEC_ST3Msg) == 0 && (strcmp(szCmd, "cmd-23")==0|| strcmp(szCmd, "cmd-24")==0|| strcmp(szCmd, "cmd-25")==0|| strcmp(szCmd, "cmd-26")==0|| strcmp(szCmd, "cmd-27")==0|| strcmp(szCmd, "cmd-28")==0|| strcmp(szCmd, "cmd-29")==0|| strcmp(szCmd, "cmd-30")==0|| strcmp(szCmd, "cmd-31")==0|| strcmp(szCmd, "cmd-32")==0|| strcmp(szCmd, "cmd-33")==0|| strcmp(szCmd, "cmd-34")==0|| strcmp(szCmd, "cmd-35")==0|| strcmp(szCmd, "cmd-36")==0|| strcmp(szCmd, "cmd-37")==0 )) || (strlen(m_szSEC_ST4Msg) == 0 && (strcmp(szCmd, "cmd-38")==0|| strcmp(szCmd, "cmd-39")==0|| strcmp(szCmd, "cmd-40")==0|| strcmp(szCmd, "cmd-41")==0|| strcmp(szCmd, "cmd-42")==0|| strcmp(szCmd, "cmd-43")==0|| strcmp(szCmd, "cmd-44")==0|| strcmp(szCmd, "cmd-45")==0|| strcmp(szCmd, "cmd-46")==0|| strcmp(szCmd, "cmd-47")==0|| strcmp(szCmd, "cmd-48")==0 )) || (strlen(m_szSEC_ST5Msg) == 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 )) || (strlen(m_szSEC_NOMMsg) == 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 )) || (strlen(m_szSEC_ATRMsg) == 0 && (strcmp(szCmd, "cmd-73")==0)) || strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-38") == 0 || strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-73") == 0 ) { nRet = GetDeviceParam( pComm, szSendMsg, szCmd, szRecvMsg,nIndex ); if (nRet != 0) { return nRet; } } nRet = GetSECST1VarMsg(szCmd, szRecvMsg, nIndex); nRet = GetSECST2VarMsg(szCmd, szRecvMsg, nIndex); nRet = GetSECST3VarMsg(szCmd, szRecvMsg, nIndex); nRet = GetSECST4VarMsg(szCmd, szRecvMsg, nIndex); nRet = GetSECST5VarMsg(szCmd, szRecvMsg, nIndex); nRet = GetSECNOMVarMsg(szCmd, szRecvMsg, nIndex); nRet = GetSECATRVarMsg(szCmd, szRecvMsg, nIndex); return nRet; } int CSecUPS::GetDeviceParam( CCommProcess *pComm, //串口对象指针 char szSendMsg[SEC_SEND_MSG], //发送Buffer char szCmd[MAX_CMD], // 命令 char szRecvMsg[VAR_MSG], // 接收Buffer int &nIndex) // 变量数据类型 { int nRet = -1; nRet = RequestReadStatus(pComm, szSendMsg); if( nRet != 0 ) { return nRet; // 串口忙 } nRet = ResponseReadStatus(pComm, szCmd, szRecvMsg, nIndex); return nRet; } void CSecUPS::ReturnData(char *szSource, char *szDestion, int nIndex) { char nlen[3] = {0}; nlen[0] = szSource[2]; nlen[1] = szSource[3]; nlen[2] = szSource[4]; int len = atoi(nlen); BOOL bSi = FALSE; int i = 0; int index = 0; if (szSource[5] == 0x2c) { index = 1; } while(i < len) { if (index == nIndex) { int datalen = 0; for (int k = 0;i < len ; k++) { if (szSource[i+5] != 0x2C) szDestion[k] = szSource[i+5]; else break; i++; } break; } if (szSource[i+5] == 0x2C) { int j = 0; for (;i 1) index += 1 ; if (index == nIndex) break; } } if (index == nIndex) { int datalen = 0; for (int k = 0;i < len ; k++) { if (szSource[i+5] != 0x2C) szDestion[k] = szSource[i+5]; else break; i++; } break; } if (szSource[i+5] != 0x2C) { index++; if (index == nIndex) continue; for (;i < len ;i++) if (szSource[i+5] == 0x2C) { --i; bSi = FALSE; break; } } i++; } } int CSecUPS::GetSECST1VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex) { 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 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif ReturnData(m_szSEC_ST1Msg, szRecvMsg, nIndex); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CSecUPS::GetSECST2VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex) { int nRet = 0; if( strcmp(szCmd, "cmd-9")==0|| strcmp(szCmd, "cmd-10")==0|| strcmp(szCmd, "cmd-11")==0|| strcmp(szCmd, "cmd-12")==0|| strcmp(szCmd, "cmd-13")==0|| strcmp(szCmd, "cmd-14")==0|| strcmp(szCmd, "cmd-15")==0|| strcmp(szCmd, "cmd-16")==0|| strcmp(szCmd, "cmd-17")==0|| strcmp(szCmd, "cmd-18")==0|| strcmp(szCmd, "cmd-19")==0|| strcmp(szCmd, "cmd-20")==0|| strcmp(szCmd, "cmd-21")==0|| strcmp(szCmd, "cmd-22")==0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif ReturnData(m_szSEC_ST2Msg, szRecvMsg, nIndex); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CSecUPS::GetSECST3VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex) { 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|| 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) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif ReturnData(m_szSEC_ST3Msg, szRecvMsg, nIndex); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CSecUPS::GetSECST4VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex) { int nRet = 0; if( strcmp(szCmd, "cmd-38")==0|| strcmp(szCmd, "cmd-39")==0|| strcmp(szCmd, "cmd-40")==0|| strcmp(szCmd, "cmd-41")==0|| strcmp(szCmd, "cmd-42")==0|| strcmp(szCmd, "cmd-43")==0|| strcmp(szCmd, "cmd-44")==0|| strcmp(szCmd, "cmd-45")==0|| strcmp(szCmd, "cmd-46")==0|| strcmp(szCmd, "cmd-47")==0|| strcmp(szCmd, "cmd-48")==0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif ReturnData(m_szSEC_ST4Msg, szRecvMsg, nIndex); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CSecUPS::GetSECST5VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex) { 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 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif ReturnData(m_szSEC_ST5Msg, szRecvMsg, nIndex); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CSecUPS::GetSECNOMVarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex) { int nRet = 0; if(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 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif ReturnData(m_szSEC_NOMMsg, szRecvMsg, nIndex); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } int CSecUPS::GetSECATRVarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex) { int nRet = 0; if(strcmp(szCmd, "cmd-73")==0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif ReturnData(m_szSEC_ATRMsg, szRecvMsg, nIndex); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif nRet = 0; } return nRet; } // 发送设置设备参数请求 int CSecUPS::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接口 ) { int nIndex = 0; char szSendMsg[SEC_SEND_MSG] = {0}; GetSECFromIni(szPath, szIniName, szCmd,szSendMsg, nIndex); CCommProcess *pComm = FindComm(nCommPort); int nRet = -1; //if( (strlen(m_szSEC_ATRMsg) == 0 && strcmp(szCmd, "cmd-73")==0) || (strlen(m_szSEC_NOMMsg) == 0 &&(strcmp(szCmd, "cmd-72")) )) //{ // nRet = RequestWriteStatus(pComm, szSendMsg); // if( nRet != 0 ) // { // return nRet; // 串口忙 // } // nRet = ResponseWriteStatus(pComm, szCmd, szRecvMsg, nIndex); //} return nRet; } //int CSecUPS::RequestWriteStatus( CCommProcess *pComm,char szSendMsg[SEC_SEND_MSG] ) //{ //#if DEBUG_SEC // // int iLen = sizeof(POTOCOLPARAM_STRUCT); // char chLength[4] = {0}; // char chChkSum[5] = {0}; // // POTOCOLPARAM_STRUCT RequestPara; // // memset( &RequestPara, 0, iLen ); // // RequestPara.SendHead = 0x5E; // // RequestPara.SendType = 0x53; // RequestPara.SendLength[0] = 0x30; // RequestPara.SendLength[1] = 0x30; // RequestPara.SendLength[2] = 0x33; // // memcpy(RequestPara.SendData, szSendMsg, 3); // // //WaitForSingObject();等待有信号; // if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口 // { // //求得数组字符实际长度; // int nDataLen = (int)strlen(szSendMsg); // // //ResetEvent()设置无信号状态 // ResetEvent( m_hSemComm ); // // int nResult = pComm->Write((unsigned char *)&RequestPara, nDataLen); // if( nResult == nDataLen ) // { // } // else // { // //SetEvent设置有信号; // SetEvent( m_hSemComm ); // // //返回 错误值; // return EER_CODE_COM_REGNUM; // } // } // else // { // //如果m_hSemCom无信号,返回错误; // return ERR_CODE_COM_BUSY; // } //#endif // return 0; //} // //int CSecUPS::ResponseWriteStatus( CCommProcess *pComm,char szCmd[MAX_CMD], char szRecvMsg[SEC_SEND_MSG],int &nIndex ) //{ // return 0; //} int CSecUPS::ResponseReadStatus( CCommProcess *pComm, char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex) { #if DEBUG_SEC //这个整型没用到; int nProcessLen = 0; POTOCOLPARAM_STRUCT structResponse; memset( &structResponse, 0, sizeof(POTOCOLPARAM_STRUCT) ); int nReceiveLen = 0; nReceiveLen = sizeof(POTOCOLPARAM_STRUCT); char *pBuffer = new char[ nReceiveLen ]; memset(pBuffer, 0, nReceiveLen); int nReadLen = 0; nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen);//pBuffer整串协议 数据 if( nReadLen <= 0) { // 串口没有读到数据 TRACE("串口没有读到数据!\r\n"); SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } return ERR_CODE_COM_READ_NO_DATA; } SetSECST1VarMsg( szCmd, pBuffer); SetSECST2VarMsg( szCmd, pBuffer); SetSECST3VarMsg( szCmd, pBuffer); SetSECST4VarMsg( szCmd, pBuffer); SetSECST5VarMsg( szCmd, pBuffer); SetSECNOMVarMsg( szCmd, pBuffer); SetSECATRVarMsg( szCmd, pBuffer); SetEvent( m_hSemComm ); if( pBuffer != NULL) { delete[] pBuffer; pBuffer = NULL; } #else SimulationCommData(); #endif return 0; } int CSecUPS::RequestReadStatus(CCommProcess *pComm,char szSendMsg[SEC_SEND_MSG]) { #if DEBUG_SEC int iLen = sizeof(POTOCOLPARAM_STRUCT); char chLength[4] = {0}; char chChkSum[5] = {0}; POTOCOLPARAM_STRUCT RequestPara; memset( &RequestPara, 0, iLen ); RequestPara.SendHead = 0x5E; RequestPara.SendType = 0x50; RequestPara.SendLength[0] = 0x30; RequestPara.SendLength[1] = 0x30; RequestPara.SendLength[2] = 0x33; memcpy(RequestPara.SendData, szSendMsg, 3); //WaitForSingObject();等待有信号; if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口 { //求得数组字符实际长度; int nDataLen = (int)strlen(szSendMsg); //ResetEvent()设置无信号状态 ResetEvent( m_hSemComm ); int nResult = pComm->Write((unsigned char *)&RequestPara, nDataLen); if( nResult == nDataLen ) { } else { //SetEvent设置有信号; SetEvent( m_hSemComm ); //返回 错误值; return EER_CODE_COM_REGNUM; } } else { //如果m_hSemCom无信号,返回错误; return ERR_CODE_COM_BUSY; } #endif return 0; } void CSecUPS::SetSECST1VarMsg(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 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szSEC_ST1Msg, pBuff, sizeof(m_szSEC_ST1Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CSecUPS::SetSECST2VarMsg(char szCmd[MAX_CMD], char *pBuff) { if( strcmp(szCmd, "cmd-9")==0|| strcmp(szCmd, "cmd-10")==0|| strcmp(szCmd, "cmd-11")==0|| strcmp(szCmd, "cmd-12")==0|| strcmp(szCmd, "cmd-13")==0|| strcmp(szCmd, "cmd-14")==0|| strcmp(szCmd, "cmd-15")==0|| strcmp(szCmd, "cmd-16")==0|| strcmp(szCmd, "cmd-17")==0|| strcmp(szCmd, "cmd-18")==0|| strcmp(szCmd, "cmd-19")==0|| strcmp(szCmd, "cmd-20")==0|| strcmp(szCmd, "cmd-21")==0|| strcmp(szCmd, "cmd-22")==0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szSEC_ST2Msg, pBuff, sizeof(m_szSEC_ST2Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CSecUPS::SetSECST3VarMsg(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|| 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 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szSEC_ST3Msg, pBuff, sizeof(m_szSEC_ST3Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CSecUPS::SetSECST4VarMsg(char szCmd[MAX_CMD], char *pBuff) { if( strcmp(szCmd, "cmd-38")==0|| strcmp(szCmd, "cmd-39")==0|| strcmp(szCmd, "cmd-40")==0|| strcmp(szCmd, "cmd-41")==0|| strcmp(szCmd, "cmd-42")==0|| strcmp(szCmd, "cmd-43")==0|| strcmp(szCmd, "cmd-44")==0|| strcmp(szCmd, "cmd-45")==0|| strcmp(szCmd, "cmd-46")==0|| strcmp(szCmd, "cmd-47")==0|| strcmp(szCmd, "cmd-48")==0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szSEC_ST4Msg, pBuff, sizeof(m_szSEC_ST4Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CSecUPS::SetSECST5VarMsg(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 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szSEC_ST5Msg, pBuff, sizeof(m_szSEC_ST5Msg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CSecUPS::SetSECNOMVarMsg(char szCmd[MAX_CMD], char *pBuff) { if( 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 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szSEC_NOMMsg, pBuff, sizeof(m_szSEC_NOMMsg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } void CSecUPS::SetSECATRVarMsg(char szCmd[MAX_CMD], char *pBuff) { if( strcmp(szCmd, "cmd-73")==0 ) { #if IS_USE_READMSG_CS EnterCriticalSection( &m_csReadMsg ); #endif memcpy(m_szSEC_ATRMsg, pBuff, sizeof(m_szSEC_ATRMsg)); #if IS_USE_READMSG_CS LeaveCriticalSection(&m_csReadMsg); #endif } } int CSecUPS::GetSECFromIni( char szPath[MAX_PATH], //服务器程序所在目录 char szIniName[MAX_PATH], //配置文件名 char szCmd[MAX_CMD], //命令 char szSendMsg[MAX_CMD], //发送Buffer int &nIndex ) { CHAR szFile[MAX_PATH + 1] = ""; wsprintf(szFile, "%s\\config\\%s", szPath, szIniName); GetPrivateProfileString(szCmd, "SenCmd", "", szSendMsg, 10, szFile); szSendMsg[strlen(szSendMsg)] = '\0'; nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile); return 0; } void CSecUPS::SimulationCommData(void) { strcpy(m_szSEC_ST1Msg,"^D015,0,,,10,90,,,35"); strcpy(m_szSEC_ST2Msg,"^D007,,,1180"); strcpy(m_szSEC_ST3Msg,"^D007,,,1200"); strcpy(m_szSEC_ST4Msg,""); strcpy(m_szSEC_ST5Msg,"^D013,,,1,,,,,,,,0"); strcpy(m_szSEC_NOMMsg,""); strcpy(m_szSEC_ATRMsg,""); }