/**************************************************************************** * @source : VMSSThread.cpp * @description : VMS Server Socket Thread **************************************************************************** * DATE AUTHOR DESCRIPTION * -------------------------------------------------------------------------- * 2012/03/09 CYM [100] First Cut * ****************************************************************************/ //--------------------------------------------------------------------------- #include "AppGlobalF.h" #include "VMSSThread.h" #include "VMSCThread.h" #include "FrmSysLogF.h" #include "FrmVmsInfoF.h" #include "FrmVmsLogF.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- // Important: Methods and properties of objects in VCL can only be // used in a method called using Synchronize, for example: // // Synchronize(&UpdateCaption); // // where UpdateCaption could look like: // // void __fastcall TVMSSThread::UpdateCaption() // { // Form1->Caption = "Updated in a thread"; // } //--------------------------------------------------------------------------- #define VMSID FVmsObj->VmsId __fastcall TVMSSThread::TVMSSThread(TServerSocketThread* ServerSocketThread, TCustomIpClient* ClientSocket, int Tag, bool *ActiveIndicator) : TClientSocketThread(ServerSocketThread) { try { FDupClose = false; m_InitFlag = false; FVmsObj = (TVmsCtlr*)Tag; FLogFile = FVmsObj->FSLog; ThreadActiveIndicator = ActiveIndicator; *ThreadActiveIndicator = true; FVmsObj->ConnectTm = Now().DateTimeString(); // Á¤º¸ ÃʱâÈ­ ServerInitMem(); ServerInitInfo(); pClientSocket = ClientSocket; pClientSocket->BlockMode = bmBlocking; pClientSocket->OnError = TcpServerClientError; pClientSocket->OnDisconnect = TcpServerDisconnect; m_InitFlag = true; Priority = tpNormal; FreeOnTerminate = true; Resume(); } catch(Exception &e) { SERROR("Thread Init Error"); Terminate(); } } //--------------------------------------------------------------------------- __fastcall TVMSSThread::~TVMSSThread() { try { Close(); SAFE_DELETE(pClientSocket); } catch(Exception &e) { } *ThreadActiveIndicator = false; } //--------------------------------------------------------------------------- void __fastcall TVMSSThread::Close(void) { try { FVmsObj->DisconnectTm = Now().DateTimeString(); FVmsObj->Server.Status == process_fail; if (pClientSocket) { //if (pClientSocket->Connected) { pClientSocket->Close(); //Sleep(3000); } } } catch(Exception &e) { } } //--------------------------------------------------------------------------- void __fastcall TVMSSThread::TcpServerClientError(TObject *Sender, int SocketError) { LPVOID lpMsgBuf = NULL; try { try { FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, //GetLastError(), //MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language SocketError, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); char *pData = (char*)lpMsgBuf; if (strlen(pData) > 2) { pData[strlen(pData)-2] = 0x00; pData[strlen(pData)-1] = 0x00; } SERROR("SocketError: (%d: %s)", SocketError, pData); } __finally { if (lpMsgBuf) LocalFree(lpMsgBuf); lpMsgBuf = NULL; } } catch(Exception &e) { } Close(); } //--------------------------------------------------------------------------- bool __fastcall TVMSSThread::SocketActivity(bool &AError) { bool Error, ReadReady, WriteReady, ExcepFlag; ReadReady = false; AError = false; if (!pClientSocket) return ReadReady; try { Error = pClientSocket->Select(&ReadReady, &WriteReady, &ExcepFlag, 0); if ((Error == false))// || (ExcepFlag == true)) //exception flag == o.o.b(out of band data receive) { AError = true; ReadReady = false; } } catch(Exception &e) { AError = true; ReadReady = false; } return ReadReady; } //--------------------------------------------------------------------------- bool __fastcall TVMSSThread::SocketActivity() { bool bResult = false; bool Error, ReadReady, WriteReady, ExcepFlag; if (!pClientSocket) return bResult; try { Error = pClientSocket->Select(&ReadReady, &WriteReady, &ExcepFlag, 0); if ((Error == false) || (ReadReady == true) || (ExcepFlag == true)) { bResult = true; } } catch(Exception &e) { } return bResult; } //--------------------------------------------------------------------------- void __fastcall TVMSSThread::TcpServerDisconnect(TObject *Sender) { //SINFO("Client Disconnect"); if (!APP_EXIT) { SINFO("Client Disconnect: %s %s", pClientSocket->RemoteHost.c_str(), pClientSocket->RemotePort.c_str()); } Close(); } //--------------------------------------------------------------------------- void __fastcall TVMSSThread::Execute() { BYTE buffer[DEFAULT_TCP_PACKET_MAX_SIZE]; int nError; int nResult; bool bError; int nReadLen; unsigned long nRecvLen; FErrLine = 0; SINFO("Thread start"); try { while (!Terminated && !m_InitFlag); //NameThreadForDebugging(m_strName); FVmsObj->Server.Status = process_run; POST_MSG(MAINHANDLE, WM_VMS_THREAD, WM_VMS_SERVER_STTS, (int)FVmsObj); try { CheckClientThread(true); //TODO m_Server.State = ST_SECTION; while (!Terminated && pClientSocket->Connected && !FDupClose) { try { bError = false; if (pClientSocket->WaitForData(100) || SocketActivity()) { bError = false; nRecvLen = 0; #if 0 nResult = ioctlsocket(pClientSocket->Handle, FIONREAD, &nRecvLen); if (nResult != 0) { Close(); } if (nRecvLen > 0) #endif { memset(buffer, 0, sizeof(buffer)); nReadLen = pClientSocket->ReceiveBuf(buffer, sizeof(buffer)); if (nReadLen > 0) { if ((nResult = RecvPacket(buffer, nReadLen)) != SYS_ERR_NONE) { ProcErrorState(TRUE, nResult); } } else { bError = true; } #if 0 if ((int)nRecvLen != nReadLen) { SERROR("Receive data size false: %d, %d", nRecvLen, nReadLen); } #endif } } if (bError) { SERROR("Socket Error[Closed]...."); nError = -3; Close(); } else { CheckClientThread(true); ServerStateMachine(); } if (g_AppCfg.bThrExit) { nError = 0; SINFO("Thread exit catched...."); Close(); } } catch(Exception &e) { SERROR("Thread execute exception: %s, Line: %d", AnsiString(e.Message).c_str(), FErrLine); nError = -2; Close(); } } SERROR("Term: %d, Conn: %d, Dup: %d, Err: %d, Line: %d", Terminated, pClientSocket->Connected, FDupClose, nError, FErrLine); } __finally { Close(); Terminate(); } } catch(Exception &e) { SERROR("Thread execute error: %s", AnsiString(e.Message).c_str()); Terminate(); } ServerTerminate(); } //--------------------------------------------------------------------------- // VMS Á¦¾î±â¿ÍÀÇ »óÅÂÁ¤º¸ Åë½ÅÀ» ´ã´çÇÒ Å¬¶óÀÌ¾ðÆ® ½º·¹µå¸¦ üũÇÑ´Ù. bool __fastcall TVMSSThread::CheckClientThread(bool ARun) { if (FVmsObj->Client.UseFlag != bit_enable) return false; if (ARun) { if ((FVmsObj->Client.pThread == NULL) && (FVmsObj->Client.ActiveIndicator == false)) { TVMSCThread *pVMSCThread = new TVMSCThread(true, (int)FVmsObj, &FVmsObj->Client.ActiveIndicator); FVmsObj->Client.pThread = pVMSCThread; if (FVmsObj->Client.pThread == NULL) { FVmsObj->Client.Status = process_fail; } else { FVmsObj->Client.wTimer = Now(); } LINFO("Client Thread create: %d", FVmsObj->Client.pThread == NULL ? 0 : 1); } } return true; } //--------------------------------------------------------------------------- void __fastcall TVMSSThread::ServerTerminate(void) { try { FVmsObj->Server.Status = process_fail; if (!APP_EXIT) { POST_MSG(MAINHANDLE, WM_VMS_THREAD, WM_VMS_SERVER_STTS, (int)FVmsObj); SINFO("Thread stop"); } } catch(Exception &e) { } } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::ServerInitMem(void) { return S_SUCC; } //--------------------------------------------------------------------------- void __fastcall TVMSSThread::ServerInitInfo(void) { m_RxLen = 0; m_rTimer = Now(); m_WatchDogTimer = Now(); m_strName = "VMSS" + FVmsObj->VmsId; FWatchDogTime = g_AppCfg.comm.nWatchDogTime; m_pVmsFormList = FVmsObj->pForms; m_Server.VmsId = FVmsObj->VmsId; m_Server.Addr = FVmsObj->LocalNo; m_Server.IpAddress = FVmsObj->IpAddress; m_Server.Port = VMS_DEFAULT_PORT; m_Server.TimeOut = g_AppCfg.comm.nCmdTimeOut; m_Server.CycleTime = g_AppCfg.comm.nPollingTime; m_pState = &FVmsObj->RSTATE; //TODO m_Server.State = ST_IDLE; //m_Server.State = ST_INITIATE; m_Server.sTimer = Now(); m_Server.iRetry = VMS_MAX_RETRY_COUNT; m_Server.cTimer = Now(); m_Server.LocalCenterId = ""; m_Server.CenterId = ""; m_Server.LocalDomainNm = g_AppCfg.comm.sLocalDomain; m_Server.DomainNm = FVmsObj->VmsId; m_Server.UserName = g_AppCfg.comm.sLoginUser; m_Server.UserPasswd = g_AppCfg.comm.sLoginPswd; m_Server.MaxHeartbeatTime = VMS_MAX_HEARTBEAT_TIME; m_Server.DatagramSize = VMS_MAX_DATAGRAM_SIZE; m_DataPacketNumber = 0; m_FrEDConfirmPacketNumber = 0; m_LoginFlag = false; m_PublishSerialNbr = 0; m_Registered.GeneralStatus = false; m_Registered.ModuleStatus = false; m_Registered.PowerStatus = false; m_Registered.ScreenDataStatusMessage = false; m_Registered.RealTimeDisplayMessage = false; #if 0 //VMS°¡ Á¢¼ÓÇÏ´Â °æ¿ì »ý¼ºµÇ¾î ÀÖ´Â ¸Þ½ÃÁö¸¦ ¹Ù·Î º¸³»µµ·Ï Ç÷¡±× ¼³Á¤ AnsiString sSvcDate = Now().FormatString("yyyymmddhhnnss"); if (sSvcDate == FVmsObj->CTLMODE->SvcDate) { Sleep(1000); sSvcDate = Now().FormatString("yyyymmddhhnnss"); } FVmsObj->CTLMODE->Enable = object_enable; FVmsObj->CTLMODE->SvcDate = sSvcDate; FVmsObj->CTLMODE->SaveFlag = false; FVmsObj->CTLMODE->Result = false; #endif LINFO("ServerInitInfo ok"); } //--------------------------------------------------------------------------- void __fastcall TVMSSThread::LOG_WriteTime(Time_t *pTime) { FErrLine = 29; if (!pTime) return; if (pTime->time_Year_qty) { LDEBUG("time_Year_qty: %d", *pTime->time_Year_qty); } if (pTime->time_Month_qty) { LDEBUG("time_Month_qty: %d", *pTime->time_Month_qty); } if (pTime->time_Day_qty) { LDEBUG("time_Day_qty: %d", *pTime->time_Day_qty); } LDEBUG("time_Hour_qty : %d", pTime->time_Hour_qty); LDEBUG("time_Minute_qty: %d", pTime->time_Minute_qty); LDEBUG("time_Second_qty: %d", pTime->time_Second_qty); switch(pTime->time_SecondFractions_zz.present) { case time_SecondFractions_PR_deci_seconds: LDEBUG("deci_seconds: %d", pTime->time_SecondFractions_zz.choice.deci_seconds); break; case time_SecondFractions_PR_centi_seconds: LDEBUG("centi_seconds: %d", pTime->time_SecondFractions_zz.choice.centi_seconds); break; case time_SecondFractions_PR_milliseconds: LDEBUG("milliseconds: %d", pTime->time_SecondFractions_zz.choice.milliseconds); break; default: LDEBUG("Unknown time_SecondFractions %d", pTime->time_SecondFractions_zz.present); break; } if (pTime->time_Timezone) { LDEBUG("timezone_Hour_qty: %d", pTime->time_Timezone->timezone_Hour_qty); LDEBUG("time_Minute_qty: %d", pTime->time_Timezone->time_Minute_qty); } } /*--------------------------------------------------------------------------*/ /* * * arguments * void * return * void */ void __fastcall TVMSSThread::ClientResponse(int error) { #ifdef CENTERCOMM BYTE ErrCode; int sResult; int Flag; bool bSave = false; switch(error) { case SYS_ERR_NONE: break; case SYS_ERR_OTHER: ErrCode = INT_ERROR_OTHER; break; case SYS_ERR_INTERNAL: ErrCode = INT_ERROR_SYSTEM; break; case SYS_ERR_MEMORY: ErrCode = INT_ERROR_SYSTEM; break; case SYS_ERR_DATABASE: ErrCode = INT_ERROR_SYSTEM; break; case SYS_ERR_RESET: ErrCode = INT_ERROR_SYSTEM; break; case SYS_ERR_START: ErrCode = INT_ERROR_SYSTEM; break; case SYS_ERR_OFFLINE: ErrCode = INT_ERROR_OFFLINE; break; case SYS_ERR_NO_RES: ErrCode = INT_ERROR_NO_RESPONSE; break; case SYS_ERR_ACCESS: ErrCode = INT_ERROR_PROCESS; break; case SYS_ERR_INVALID: ErrCode = INT_ERROR_OTHER; break; case SYS_ERR_UNKNOWN: ErrCode = INT_ERROR_UNKNOWN_CODE; break; case SYS_ERR_WRITE_LENGTH: ErrCode = INT_ERROR_OTHER; break; case SYS_ERR_PACKET_SIZE_LARGE: ErrCode = INT_ERROR_OTHER; break; case SYS_ERR_INVALID_TAG: ErrCode = INT_ERROR_OTHER; break; case SYS_ERR_CRC: ErrCode = INT_ERROR_OTHER; break; case SYS_ERR_LENGTH: ErrCode = INT_ERROR_LENGTH; break; case SYS_ERR_ADDRESS: ErrCode = INT_ERROR_ADDRESS; break; case SYS_ERR_HEADER_OPTIONS: ErrCode = INT_ERROR_HEADER; break; case SYS_ERR_UNKNOWN_COMMAND: ErrCode = INT_ERROR_UNKNOWN_OPCODE; break; case SYS_ERR_RECEIVE_TIMEOUT: ErrCode = INT_ERROR_OTHER; break; case SYS_ERR_DATA_SIZE: ErrCode = INT_ERROR_DISCORD; break; case SYS_ERR_MISMATCH: ErrCode = INT_ERROR_OTHER; break; case SYS_ERR_INVALID_PARA: ErrCode = INT_ERROR_INVALID_DATA; break; case SYS_ERR_MOVEMENT: ErrCode = INT_ERROR_MOVEMENT; break; case SYS_ERR_UNAUTHORIZED: ErrCode = INT_ERROR_UNAUTHORIZED; break; default: ErrCode = INT_ERROR_OTHER; break; } switch (m_Req.OpCode) { case INT_OP_VMS_POWER_CTL: /* 0x0303 VMS Åë½Å ¼­¹ö, VMS Àü±¤ÆÇ On/Off Á¦¾î */ if (error == SYS_ERR_NONE) { Flag = SEND_ACK; m_Set.Data.Control.Result = CTL_RESULT_SUCC; } else { Flag = SEND_NACK; } bSave = true; break; case INT_OP_VMS_PARA_SET: /* 0x0308 VMS Åë½Å ¼­¹ö, VMS ȯ°æ¼³Á¤Á¤º¸ Àü¼Û */ if (error == SYS_ERR_NONE) { Flag = SEND_ACK; bSave = true; } else { Flag = SEND_NACK; } break; case INT_OP_VMS_RESET: /* 0x0309 VMS Åë½Å ¼­¹ö, VMS Á¦¾î±â ¸®¼Â Àü¼Û */ if (error == SYS_ERR_NONE) { Flag = SEND_ACK; m_Set.Data.Control.Result = CTL_RESULT_SUCC; } else { Flag = SEND_NACK; } bSave = true; break; default: Flag = SEND_NONE; break; } if (bSave == true) { if ((sResult = SendDbThreadDataMessage(WM_DATA_SAVE, (void *)&m_Set, sizeof(m_Set))) != SYS_ERR_NONE) { } } if (Flag == SEND_ACK) { INT_ACK_RES Ack; memset(&Ack, 0x00, sizeof(Ack)); Ack.OPCode.Type = INT_TYPE(m_Req.OpCode); Ack.OPCode.Kind = INT_KIND(m_Req.OpCode); Ack.MsgSeq = m_Req.MsgSeq; if ((sResult = AckRes(&Ack, m_Req.ProcessID)) != UDP_ERR_NONE) { } } else if (Flag == SEND_NACK) { INT_NACK_RES Nack; memset(&Nack, 0x00, sizeof(Nack)); Nack.OPCode.Type = INT_TYPE(m_Req.OpCode); Nack.OPCode.Kind = INT_KIND(m_Req.OpCode); Nack.MsgSeq = m_Req.MsgSeq; Nack.ErrCode = ErrCode; if ((sResult = NackRes(&Nack, m_Req.ProcessID)) != UDP_ERR_NONE) { } } #endif } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::SendDbThreadMessage(UINT Msg, int wParam, int lParam) { int result; result = SYS_ERR_OTHER; if (g_SysInfo->State.CommThreadID != NULL) { if (PostThreadMessage(g_SysInfo->State.CommThreadID, Msg, (WPARAM)wParam, (LPARAM)lParam)){ result = SYS_ERR_NONE; }else{ result = SYS_ERR_INTERNAL; } } return result; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::SendDbThreadDataMessage(UINT Msg, void *pData, int iLen) { int nResult; char *p; nResult = VERR_OTHER; if (g_SysInfo->State.CommThreadID != NULL) { p = new char[iLen]; if (p != NULL) { try { memcpy(p, pData, iLen); if (PostThreadMessage(g_SysInfo->State.CommThreadID, Msg, (WPARAM)p, NULL)) { nResult = VERR_NONE; Sleep(50); } else { nResult = VERR_INTERNAL; } } __finally { if (nResult != VERR_NONE) { delete []p; } } } else { nResult = VERR_MEMORY_ALLOC; } } return nResult; } //--------------------------------------------------------------------------- /* * ÇѱÛÀ» UTF8 ¹®ÀÚ¿­·Î º¯È¯ * arguments * void * return * void */ int __fastcall TVMSSThread::Hangul2UTF8String(char *pIn, char *pOut, int outSize) { FErrLine = 1; int result; UTF8String uStr; result = 0; memset(pOut, 0x00, outSize); if (!pIn) { SERROR("Hangul2UTF8String In Data is NULL"); return result; } try { uStr = UTF8Encode(WideString(pIn)); if (uStr.Length() > outSize) { return -1; } memcpy(pOut, uStr.c_str(), uStr.Length()); } catch(Exception &e) { SERROR("Hangul2UTF8String exception: [%s], %s", pIn, AnsiString(e.Message).c_str()); } return result; } //--------------------------------------------------------------------------- /* * UTF8¸¦ ÇÑ±Û ¹®ÀÚ¿­·Î º¯È¯ * arguments * void * return * void */ int __fastcall TVMSSThread::UTF8String2Hangul(char *pIn, char *pOut, int outSize) { FErrLine = 2; int result; AnsiString AnsiStr; result = 0; memset(pOut, 0x00, outSize); if (!pIn) { SERROR("UTF8String2Hangul In Data is NULL"); return result; } try { AnsiStr = (AnsiString)UTF8Decode(UTF8String(pIn)); if (AnsiStr.Length() > outSize) { return -1; } memcpy(pOut, AnsiStr.c_str(), AnsiStr.Length()); } catch(Exception &e) { SERROR("UTF8String2Hangul exception: [%s], %s", pIn, AnsiString(e.Message).c_str()); } return result; } /*--------------------------------------------------------------------------*/ /* * ÆÐŶ ¼ö½Å * arguments * void * return * void */ int __fastcall TVMSSThread::RecvPacket(void *Data, int Len) { FErrLine = 3; int result; ssize_t stat; ssize_t length; DatexDataPacket_t *pMsg = 0; /* Type to decode */ asn_dec_rval_t rval; /* Decoder return value */ long version; WORD crc; result = SYS_ERR_NONE; if (Len > 0) { LogData("RECV", (char*)Data, Len); } if (m_RxLen) { if ((m_RxLen + Len) > SERVER_MAX_PACKET_SIZE) m_RxLen = 0; memcpy(m_RxBuff + m_RxLen, Data, Len); m_RxLen += Len; } else { memcpy(m_RxBuff, Data, Len); m_RxLen = Len; m_rTimer = Now(); } while (m_RxLen >= VMS_MIN_PACKET_SIZE) { stat = ASN1C_BerReadLength(m_RxBuff, m_RxLen, &length); if ((stat != RC_OK) || (length > VMS_MAX_PACKET_SIZE)) { result = SYS_ERR_INVALID_TAGANDLEN; break; } LINFO("Recv: state[%d], length[%d/%d]", stat, length, m_RxLen); if (length > m_RxLen) { break; } /* Decode */ #if 0 rval = ber_decode(0, &asn_DEF_DatexDataPacket, (void **)&pMsg, m_RxBuff, m_RxLen); #else rval = ber_decode(0, &asn_DEF_DatexDataPacket, (void **)&pMsg, m_RxBuff, length); #endif switch(rval.code) { case RC_OK: if ((rval.consumed == 0) || (pMsg == 0)) { result = SYS_ERR_DATEXDATAPACKET_DECODE; break; } asn_INTEGER2long(&pMsg->datex_Version_number, &version); if (version != datex_Version_number_version1) { LERROR("SYS_ERR_INVALID_VERSION_NUMBER: %d/%d", version, datex_Version_number_version1); result = SYS_ERR_INVALID_VERSION_NUMBER; break; } #if 1 crc = ASN1C_MakeCrc16((void *)pMsg->datex_Data.buf, pMsg->datex_Data.size); if (pMsg->datex_Crc_nbr.size != 2 || pMsg->datex_Crc_nbr.buf[0] != HIBYTE(crc) || pMsg->datex_Crc_nbr.buf[1] != LOBYTE(crc)) { result = ASN_ERR_CRC; break; } #endif /* ÆÐŶ ó¸® */ result = ProcessRecvPacket((BYTE *)pMsg->datex_Data.buf, pMsg->datex_Data.size); if (result != SYS_ERR_NONE) { SERROR("Receive Packet Error : %d", result); } break; case RC_WMORE: case RC_FAIL: default: result = SYS_ERR_DATEXDATAPACKET_DECODE; break; } if (pMsg) { ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg); pMsg = 0; } if (result != SYS_ERR_NONE) { m_RxLen = 0; break; } m_RxLen -= length; if (m_RxLen < 0) m_RxLen = 0; if (m_RxLen > 0) { memcpy(m_RxBuff, m_RxBuff + length, m_RxLen); } } /* end while */ return result; } //--------------------------------------------------------------------------- /* * ¼ö½Å ÆÐŶ ó¸® * arguments * void * return * void */ int __fastcall TVMSSThread::ProcessRecvPacket(BYTE *pBuffer, int Len) { FErrLine = 4; int result, iResult; C2CAuthenticatedMessage_t *pMsg = 0; /* Type to decode */ asn_dec_rval_t rval; /* Decoder return value */ BYTE cmd; BYTE pdu; COMMAND_ARGUMENT arg; long DataPacket_number; result = SYS_ERR_OTHER; /* Decode */ rval = ber_decode(0, &asn_DEF_C2CAuthenticatedMessage, (void **)&pMsg, pBuffer, Len); switch(rval.code) { case RC_OK: { if ((rval.consumed == 0) || (pMsg == 0)) { LERROR("SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE"); result = SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE; break; } /* °øÅëºÎºÐ */ if (pMsg->datex_AuthenticationInfo_text.size != 1 || /* pMsg->datex_DataPacket_number < 0 || */ /* pMsg->datex_DataPacket_number > 4294967295 || */ /* pMsg->datex_DataPacketPriority_number < 0 || */ pMsg->datex_DataPacketPriority_number > 10) { LERROR("SYS_ERR_C2CAUTHENTICATEDMESSAGE: %d/%d", pMsg->datex_AuthenticationInfo_text.size, pMsg->datex_DataPacketPriority_number); result = SYS_ERR_C2CAUTHENTICATEDMESSAGE; break; } asn_INTEGER2long(&pMsg->datex_DataPacket_number, &DataPacket_number); pdu = pMsg->pdu.present; cmd = pMsg->datex_AuthenticationInfo_text.buf[0]; #if 1 if ((m_LoginFlag == false) && (pdu != PDUs_PR_login)) { LWARN("SYS_ERR_NOT_LOGIN"); m_Server.State = ST_SECTION; result = SYS_ERR_NOT_LOGIN; //break; } #endif #if 0 HeaderOptions_t *options; /* Header Options */ options = &pMsg->options; if (options->datex_OriginAddress_location->size == 0 || options->datex_DestinationAddress_location->size == 0) { result = SYS_ERR_HEADER_OPTIONS; break; } // m_Server.CenterId = NULL // m_Server.LocalCenterId = NULL // datex_OriginAddress_location = VM10000002 // datex_DestinationAddress_location = 00000000 if (memcmp(options->datex_OriginAddress_location->buf, m_Server.CenterId.c_str(), options->datex_OriginAddress_location->size) || memcmp(options->datex_DestinationAddress_location->buf, m_Server.LocalCenterId.c_str(), options->datex_DestinationAddress_location->size)) { result = SYS_ERR_ADDRESS; break; } #endif /* options->datex_Origin_text */ /* options->datex_Sender_text */ /* options->datex_SenderAddress_location */ /* options->datex_Destination_text */ /* options->datex_Cost->amount_Currency_code */ /* options->datex_Cost->amount_Factor_quantity */ /* options->datex_Cost->amount_Quantity_quantity */ /* options->datex_DataPacket_time->time_Year_qty */ /* options->datex_DataPacket_time->time_Month_qty */ /* options->datex_DataPacket_time->time_Day_qty */ /* options->datex_DataPacket_time->time_Hour_qty */ /* options->datex_DataPacket_time->time_Minute_qty */ /* options->datex_DataPacket_time->time_Second_qty */ /* options->datex_DataPacket_time->time_SecondFractions->present */ /* options->datex_DataPacket_time->time_SecondFractions->choice.milliseconds */ /* options->datex_DataPacket_time->time_Timezone->timezone_Hour_qty */ /* options->datex_DataPacket_time->time_Timezone->time_Minute_qty */ switch(pdu) { case PDUs_PR_NOTHING: //FOR YONGIN LINFO("<<< PDUs_PR_NOTHING ¼ö½Åxxxxx"); result = SYS_ERR_NONE; break; case PDUs_PR_datex_Initiate_null: //FOR YONGIN LINFO("<<< PDUs_PR_datex_Initiate_null ¼ö½Å"); result = SYS_ERR_NONE; break; case PDUs_PR_login: /* ¼­¹ö¿¡ Á¢¼ÓÇϱâ À§ÇÑ Å¬¶óÀ̾ðÆ®ÀÇ ·Î±×ÀÎ µ¥ÀÌÅÍ ÆÐŶ */ LINFO("<<< PDUs_PR_login ¼ö½Å"); result = PacketLogin(&pMsg->pdu.choice.login, DataPacket_number); if (result == SYS_ERR_NONE) { m_LoginFlag = true; m_Server.State = ST_SECTION; } else { LERROR("PacketLogin result Error: %d", result); } break; case PDUs_PR_fred: /* ¼­¹ö¿Í Ŭ¶óÀ̾ðÆ®ÀÇ ¿¬°áÀ» À¯ÁöÇϱâ À§ÇÑ È®ÀÎ µ¥ÀÌÅÍ ÆÐŶ */ { long fred; asn_INTEGER2long(&pMsg->pdu.choice.fred, &fred); result = SYS_ERR_NONE; LINFO("<<< PDUs_PR_fred ¼ö½Å: %u", fred); { //TODO m_LoginFlag = true; //m_Server.State = ST_SECTION; } m_WatchDogTimer = Now(); } if (m_FrEDConfirmPacketNumber > 65535) m_FrEDConfirmPacketNumber = 0; arg.FrED = m_FrEDConfirmPacketNumber++; if ((iResult = ProcessCommand(AI_FrED, &arg)) != SYS_ERR_NONE) { LERROR("AI_FrED Command failed: %d", iResult); } break; case PDUs_PR_terminate: /* ¿¬°áÀ» Á¾·áÇϰíÀÚ ÇÒ ¶§, ¼­¹ö¿¡¼­ Ŭ¶óÀÌ¾ðÆ®¿¡ ¿äûÇÏ´Â µ¥ÀÌÅÍ ÆÐŶ */ { //¿©±â´Â µé¾î¿À¸é ¾È‰Î(¼­¹ö ¸ðµâ¿¡¼­ º¸³»´Â ¸Þ½ÃÁöÀÓ) LINFO("<<< PDUs_PR_terminate ¼ö½Åxxxxx"); result = SYS_ERR_NONE; #if 0 try { long terminate; asn_INTEGER2long(&pMsg->pdu.choice.terminate, &terminate); result = SYS_ERR_NONE; LINFO("<<< PDUs_PR_terminate ¼ö½Å %u", terminate); } catch(Exception &e) {} #endif } break; case PDUs_PR_logout: /* Á¢¼ÓÀ» Á¾·áÇϱâ À§ÇÑ Å¬¶óÀ̾ðÆ®ÀÇ ·Î±×¾Æ¿ô µ¥ÀÌÅÍ ÆÐŶ */ { long logout; asn_INTEGER2long(&pMsg->pdu.choice.logout, &logout); result = SYS_ERR_NONE; LINFO("<<< PDUs_PR_logout ¼ö½Å %d", logout); } arg.FrED = m_FrEDConfirmPacketNumber++; if ((iResult = ProcessCommand(AI_FrED, &arg)) != SYS_ERR_NONE) { LERROR("Logout FrED Command failed: %d", iResult); } m_Server.State = ST_CLOSE; result = SYS_ERR_NONE; break; case PDUs_PR_subscripiton: /* Ŭ¶óÀÌ¾ðÆ®°¡ ¼­¹ö¿¡ Á¤º¸¸¦ ¿äûÇÒ °æ¿ì ¼Û½ÅÇÏ´Â µ¥ÀÌÅÍ ÆÐŶ */ { LINFO("<<< PDUs_PR_subscripiton ¼ö½Å"); result = PacketSubscription(&pMsg->pdu.choice.subscripiton); bool bSubscript = false; int Message_id = 0; if (result == SYS_ERR_NONE) { long Serial_nbr; asn_INTEGER2long(&pMsg->pdu.choice.subscripiton.datexSubscribe_Serial_nbr, &Serial_nbr); arg.Accept.nbr = DataPacket_number; if (pMsg->pdu.choice.subscripiton.datexSubscribe_Type.present == SubscriptionType_PR_subscription) { if (pMsg->pdu.choice.subscripiton.datexSubscribe_Type.choice.subscription.datexSubscribe_Mode.present == SubscriptionMode_PR_single) { arg.Accept.type = datexAccept_Type_PR_single_subscription; } else { /* SubscriptionMode_PR_event_driven, SubscriptionMode_PR_periodic */ arg.Accept.type = datexAccept_Type_PR_registered_subscription; arg.Accept.sub = Serial_nbr; Subscription_t *pSubscripiton = &pMsg->pdu.choice.subscripiton; SubscriptionData_t *pData = &pSubscripiton->datexSubscribe_Type.choice.subscription; if ((Message_id = ASN1C_GetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id)) != -1) { //bSubscript = true; switch(Message_id) { case OBJ_RealTimeDisplay: /* ½Ç½Ã°£Á¤º¸Ç¥Ãâ */ arg.Accept.nbr = 4; arg.Accept.sub = 1; break; case OBJ_ScheduledDisplay: /* °èȹµÈÁ¤º¸Ç¥Ãâ */ arg.Accept.nbr = 5; arg.Accept.sub = 2; break; case OBJ_DownloadGraphicData: /* ±×·¡Çȵ¥ÀÌÅÍ ´Ù¿î·Îµå */ arg.Accept.nbr = 6; arg.Accept.sub = 3; break; case OBJ_StatusControl: /* »óÅÂÁ¦¾î */ arg.Accept.nbr = 7; arg.Accept.sub = 4; break; case OBJ_StatusSetting: /* »óż³Á¤ */ arg.Accept.nbr = 8; arg.Accept.sub = 5; break; } } } } else { /* SubscriptionType_PR_datexSubscribe_CancelReason_cd */ arg.Accept.type = datexAccept_Type_PR_registered_subscription; arg.Accept.sub = Serial_nbr; } if (bSubscript) { SendSubscriptionAccept(Message_id); } else { if ((iResult = ProcessCommand(AI_Accept, &arg)) != SYS_ERR_NONE) { SERROR("Subscription Accept Command failed: %d", iResult); } } } else { int ErrCode; switch(result) { case SYS_ERR_SUBSCRIPTION_MODE_VALUE: ErrCode = datexReject_Subscription_cd_invalid_mode; break; case SYS_ERR_SUBSCRIPTION_FORMAT_VALUE: ErrCode = datexReject_Subscription_cd_publishFormatNotSupported; break; case SYS_ERR_UNKNOWN_MESSAGE_ID: ErrCode = datexReject_Subscription_cd_unknowSubscriptionMsgId; break; case SYS_ERR_MESSAGE_DECODE: ErrCode = datexReject_Subscription_cd_invalidSubscriptionContent; break; case SYS_ERR_SUBSCRIPTION_STATUS_VALUE: case SYS_ERR_SUBSCRIPTION_TYPE: default: ErrCode = datexReject_Subscription_cd_other; } /* datexReject_Subscription_cd_unknownSubscriptionNbr */ /* datexReject_Subscription_cd_invalidTimes */ /* datexReject_Subscription_cd_frequencyTooSmall */ /* datexReject_Subscription_cd_frequencyTooLarge */ /* datexReject_Subscription_cd_invalidSubscriptionMsgId */ arg.Reject.nbr = DataPacket_number; arg.Reject.type = RejectType_PR_datexReject_Subscription_cd; arg.Reject.code = ErrCode; if((iResult = ProcessCommand(AI_Reject, &arg)) != SYS_ERR_NONE) { SERROR("Subscription Reject Command failed: %d", iResult); } } } break; case PDUs_PR_publication: // FOR YONGIN LINFO("<<< PDUs_PR_publication ¼ö½Å"); switch(cmd) { case AI_GeneralStatusMessage: LINFO(" *** AI_GeneralStatusMessage ¼ö½Å"); break; case AI_PowerStatusMessage: LINFO(" *** AI_PowerStatusMessage ¼ö½Å"); break; case AI_ModuleStatusMessage: LINFO(" *** AI_ModuleStatusMessage ¼ö½Å"); break; case AI_DotStatusMessage: LINFO(" *** AI_DotStatusMessage ¼ö½Å"); break; case AI_ScreenStatusMessage: LINFO(" *** AI_ScreenStatusMessage ¼ö½Å"); break; case AI_DisplayingDataMessage:LINFO(" *** AI_DisplayingDataMessage ¼ö½Å"); break; default: LINFO(" *** PDUs_PR_publication Unknown ¼ö½Å: %d", cmd); break; } result = RecvPacketPublication(&pMsg->pdu.choice.publication); if (result == SYS_ERR_NONE) { #if 0 m_WatchDogTimer = Now(); arg.Accept = DataPacket_number; if((iResult = ProcessCommand(AI_Accept, &arg)) != SYS_ERR_NONE) { SERROR("Publication Accept Command failed: %d", iResult); } #endif } else { int ErrCode; switch(result) { case SYS_ERR_DATEXPUBLISH_FORMAT: ErrCode = datexReject_Publication_cd_invalidPublishFormat; break; case SYS_ERR_UNKNOWN_MESSAGE_ID: ErrCode = datexReject_Publication_cd_unknownPublicationMsgId; break; case SYS_ERR_DATEXPUBLISH_TYPE: ErrCode = datexReject_Publication_cd_invalidPublicationMsgContent; break; case SYS_ERR_MESSAGE_DECODE: ErrCode = datexReject_Publication_cd_invalidPublicationMsgContent; break; default: ErrCode = datexReject_Publication_cd_other; } /* datexReject_Publication_cd_unknownSubscription */ /* datexReject_Publication_cd_unknownPublicationNbr */ /* datexReject_Publication_cd_invalidPublicationMsgId */ /* datexReject_Publication_cd_repeatedPublicationNbr */ #if 0 arg.Reject.nbr = DataPacket_number; arg.Reject.code = ErrCode; if ((iResult = ProcessCommand(AI_Reject, &arg)) != SYS_ERR_NONE) { SERROR("Publication Reject Command %d", iResult); } #endif } result = SYS_ERR_NONE; break; case PDUs_PR_transfer_done: LINFO("<<< PDUs_PR_transfer_done ¼ö½Å"); { AnsiString sFormImgId = ""; TransferDone_t *pTrans = &pMsg->pdu.choice.transfer_done; long lv; asn_INTEGER2long(&pTrans->datexTransferDone_Publication_nbr, &lv); LDEBUG("datexTransferDone_Publication_nbr: %u", lv); sFormImgId.printf("%.*s", pTrans->datexTransferDone_FileName_txt.size, pTrans->datexTransferDone_FileName_txt.buf); LDEBUG(" datexTransferDone_FileName_txt: %s", sFormImgId.c_str()); LDEBUG(" datexTransferDone_Sucess_bool: %d", pTrans->datexTransferDone_Sucess_bool); result = RecvFormDownResult(sFormImgId); if (result != SYS_ERR_NONE) { LERROR("RecvFormDownResult result Error: %d", result); } } break; case PDUs_PR_accept: /* Ŭ¶óÀ̾ðÆ®ÀÇ ¿äû¿¡ ´ëÇÑ ¼ö¿ë */ LINFO("<<< PDUs_PR_accept ¼ö½Å"); result = PacketAccept(&pMsg->pdu.choice.accept); if (result != SYS_ERR_NONE) { LERROR("PDUs_PR_accept result Error: %d", result); } break; case PDUs_PR_reject: /* Ŭ¶óÀ̾ðÆ®ÀÇ ¿äû¿¡ ´ëÇÑ °ÅºÎ */ LINFO("<<< PDUs_PR_reject ¼ö½Å"); result = PacketReject(&pMsg->pdu.choice.reject); if (result != SYS_ERR_NONE) { LERROR("PacketReject result Error: %d", result); } break; default: LINFO("<<< Unknown PDUs ¼ö½Å: pdu(%d), cmd(%d)", pdu, cmd); result = SYS_ERR_UNKNOWN_COMMAND; break; }/* end switch */ } break; case RC_WMORE: case RC_FAIL: default: result = SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE; break; }/* end switch */ if (pMsg) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); } if ((result == SYS_ERR_NONE) && (cmd != AI_Reject)) { m_Server.iRetry = VMS_MAX_RETRY_COUNT; } if (pdu == PDUs_PR_login) { if (FVmsObj->FSymbolDownload) { if (FVmsObj->FIsOldProtocol && !FVmsObj->FBmpDownload) { DownloadSymbolImage(); } } } return result; } //--------------------------------------------------------------------------- /* * ¼ö½Å ÆÐŶ ó¸® * arguments * void * return * void */ int __fastcall TVMSSThread::RecvPacketPublication(Publication_t *pPublication) { FErrLine = 47; int result; PublicationData_t *pData; int i; result = SYS_ERR_OTHER; /* pPublication->datexPublish_Guaranteed_bool */ switch(pPublication->datexPublish_Format.present) { case Publish_Format_PR_datexPublish_Data: for(i = 0; i < pPublication->datexPublish_Format.choice.datexPublish_Data.list.count; i++) { pData = (PublicationData_t *)pPublication->datexPublish_Format.choice.datexPublish_Data.list.array[i]; if ((result = RecvPacketPublicationData(pData)) != SYS_ERR_NONE) { break; } } break; case Publish_Format_PR_datexPublish_FileName_txt: result = SYS_ERR_NONE; break; default: result = SYS_ERR_DATEXPUBLISH_FORMAT; break; }/* end switch */ return result; } //--------------------------------------------------------------------------- /* * ¼ö½Å ÆÐŶ ó¸® * arguments * void * return * void */ int __fastcall TVMSSThread::RecvPacketPublicationData(PublicationData_t *pData) { FErrLine = 48; int result; int Message_id; int i; result = SYS_ERR_OTHER; /* pData->datexPublish_SubscribeSerial_nbr */ /* pData->datexPublish_Serial_nbr */ /* pData->datexPublish_LatePublicationFlag */ #if 0 { long lv; asn_INTEGER2long(&pData->datexPublish_SubscribeSerial_nbr, &lv); LDEBUG("datexPublish_SubscribeSerial_nbr: %u", lv); asn_INTEGER2long(&pData->datexPublish_Serial_nbr, &lv); LDEBUG(" datexPublish_Serial_nbr: %u", lv); LDEBUG("datexPublish_LatePublicationFlag: %d", pData->datexPublish_LatePublicationFlag); } #endif switch(pData->datexPublish_Type.present) { case PublicationType_PR_datexPublication_Management_cd: result = SYS_ERR_NONE; break; case PublicationType_PR_datexPublish_Data: #if 0 { int arcs[10]; int count, j; count = OBJECT_IDENTIFIER_get_arcs(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id, arcs, sizeof(int), 10); LDEBUG("endApplication_Message_id: %d", count); for (j = 0; j < count && j < 10; j++) { LDEBUG("[%d]: %d", j, arcs[j]); } } #endif if ((Message_id = ASN1C_GetObjId(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id)) == -1) { return SYS_ERR_UNKNOWN_MESSAGE_ID; } /* pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg */ switch(Message_id) { case OBJ_GeneralStatus: /* ±âº»»óÅÂÁ¤º¸ */ { GeneralStatusMessage_t *pGS; MessageBodyGeneralStatusMessage_t *pMsg = 0; /* Type to decode */ /* Decode */ if (ANY_to_type(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg, &asn_DEF_MessageBodyGeneralStatusMessage, (void **)&pMsg) == ASN_ERR_NONE) { for(i = 0; i < pMsg->list.count; i++) { pGS = (GeneralStatusMessage_t *)pMsg->list.array[i]; SaveStateData(pGS); } LINFO("GeneralStatus Publication Recv %d OK", pMsg->list.count); result = VERR_NONE; } else { result = SYS_ERR_MESSAGE_DECODE; } if(pMsg) { ASN1C_Free(&asn_DEF_MessageBodyGeneralStatusMessage, pMsg); } //FGenState = true; } break; case OBJ_PowerStatus: /* Àü¿ø»óÅÂÁ¤º¸ */ { PowerStatusMessage_t *pMS; MessageBodyPowerStatusMessage_t *pMsg = 0; /* Type to decode */ long PowerQty; int numbits, bit; /* Decode */ if (ANY_to_type(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg, &asn_DEF_MessageBodyPowerStatusMessage, (void **)&pMsg) == ASN_ERR_NONE) { for(i = 0; i < pMsg->list.count; i++) { pMS = (PowerStatusMessage_t *)pMsg->list.array[i]; asn_INTEGER2long(&pMS->power_Qty, &PowerQty); numbits = DATEX_NUMBITS(pMS->power_Status); LDEBUG("Power Module Count: %d, %d", PowerQty, numbits); if (PowerQty != numbits) { PowerQty = numbits;//¾ç»ê°Å´Â ´Ù¸£°Ô ³ªÅ¸³² } if (numbits >= INT_VMS_MAX_POWER) { numbits = INT_VMS_MAX_POWER; PowerQty = numbits; LERROR("Power size overflow: %d, %d", numbits, INT_VMS_MAX_POWER); } if (PowerQty == numbits) { #if 0 memset((char*)m_pState->PowerStatus, 0x00, sizeof(m_pState->PowerStatus)); for (bit = 0; bit < numbits; bit++) { int nOnOff = ASN1C_CheckBitString(&pMS->power_Status, bit); if (nOnOff == bit_enable) { VComm_SetBitString((char*)m_pState->PowerStatus, bit); } } m_pState->PowerCount = PowerQty; #endif } #if 0 { LDEBUG(" module_PowerQty: %d", PowerQty); AnsiString sModule = ""; for (int v = 0; v < PowerQty; v++) { int nM = VComm_GetBitString((char*)m_pState->PowerStatus, v); sModule += String(nM); } LDEBUG("%s", sModule.c_str()); } #endif }/* end for */ result = VERR_NONE; } else { result = SYS_ERR_MESSAGE_DECODE; }/* end if */ if(pMsg) { ASN1C_Free(&asn_DEF_MessageBodyPowerStatusMessage, pMsg); } //FPowState = true; } break; case OBJ_ModuleStatus: /* ¸ðµâ»óÅÂÁ¤º¸ */ { ModuleStatusMessage_t *pMS; MessageBodyModuleStatusMessage_t *pMsg = 0; /* Type to decode */ long Horizontal, Vertical; int numbits, bit; BYTE ModuleState; /* Decode */ if (ANY_to_type(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg, &asn_DEF_MessageBodyModuleStatusMessage, (void **)&pMsg) == ASN_ERR_NONE) { for(i = 0; i < pMsg->list.count; i++) { pMS = (ModuleStatusMessage_t *)pMsg->list.array[i]; asn_INTEGER2long(&pMS->module_HorizontalQty, &Horizontal); asn_INTEGER2long(&pMS->module_VerticalQty, &Vertical); numbits = DATEX_NUMBITS(pMS->module_Status); if (numbits >= INT_VMS_MAX_MODULE) { numbits = INT_VMS_MAX_MODULE; LERROR("Module size overflow: %d, %d", numbits, INT_VMS_MAX_MODULE); } #if 0 memset((char*)m_pState->ModuleStatus, 0x00, sizeof(m_pState->ModuleStatus)); if ((Horizontal * Vertical) == numbits) { ModuleState = vms_normal; for (bit = 0; bit < numbits; bit++) { int nOnOff = ASN1C_CheckBitString(&pMS->module_Status, bit); if (nOnOff == bit_disable) { ModuleState = vms_error; } else { VComm_SetBitString((char*)m_pState->ModuleStatus, bit); } } if ((m_pState != NULL) && (numbits < INT_VMS_MAX_MODULE)) { m_pState->ModuleHorizontal = Horizontal; m_pState->ModuleVertical = Vertical; } } else { ModuleState = vms_unknown; m_pState->ModuleHorizontal = 0; m_pState->ModuleVertical = 0; } m_pState->ModuleState = ModuleState; if (FLogFile->FLogCfg.Debug) { LDEBUG(" module_VerticalQty x HorizontalQty(Cnt): %d x %d (%d)", Vertical, Horizontal, numbits); //LDEBUG(" module_HorizontalQty: %d", Horizontal); //LDEBUG("module_Status numbits: %d", numbits); for (int v = 0, bit=0; v < Vertical; v++) { AnsiString sModule = ""; for(int h = 0; h < Horizontal; h++) { int nM = VComm_GetBitString((char*)m_pState->ModuleStatus, v*h); sModule += String(nM); } LDEBUG("%d, %s", v, sModule.c_str()); } } #endif }/* end for */ result = SYS_ERR_NONE; } else { result = SYS_ERR_MESSAGE_DECODE; }/* end if */ if(pMsg) { ASN1C_Free(&asn_DEF_MessageBodyModuleStatusMessage, pMsg); } //FModState = true; } break; case OBJ_DotStatus: /* µµÆ®»óÅÂÁ¤º¸ */ result = SYS_ERR_NONE; break; case OBJ_ScreenStatus: /* Ç¥Ãâ»óÅÂÁ¤º¸ */ result = SYS_ERR_NONE; break; case OBJ_DisplayingData: /* Ç¥ÃâÁ¤º¸ */ result = SYS_ERR_NONE; break; default: result = SYS_ERR_UNKNOWN_MESSAGE_ID; break; }/* end switch */ #if 0 if (FGenState && FModState && FPowState) { FGenState = FModState = FPowState = false; POST_MSG(MAINHANDLE, WM_VMS_THREAD, WM_VMS_STATE_STTS, (int)FVmsObj); } #endif break; default: result = SYS_ERR_DATEXPUBLISH_TYPE; break; } return result; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::SaveStateData(GeneralStatusMessage_t *pGS) { FErrLine = 42; int result; long lv; result = SYS_ERR_OTHER; // if (m_pState == NULL) return result; // m_pState->Cpsw.Enable = bit_enable; // m_pState->CollectDate = Now().FormatString("yyyymmddhhnnss"); #if 0 asn_INTEGER2long(&pGS->door_StatusCode, &lv); switch(lv) { case door_StatusCode_closed: m_pState->DoorStatus = vms_close; break; case door_StatusCode_open : m_pState->DoorStatus = vms_open; break; default : m_pState->DoorStatus = vms_unknown; break; } LDEBUG(" door_StatusCode: %u, %d", lv, m_pState->DoorStatus); asn_INTEGER2long(&pGS->modulePower_StatusCode, &lv); m_pState->ModulePowerStatus = lv; switch(lv) { case modulePower_StatusCode_off: m_pState->ModulePowerStatus = vms_off; break; case modulePower_StatusCode_on : m_pState->ModulePowerStatus = vms_on; break; default : m_pState->ModulePowerStatus = vms_unknown; break; } LDEBUG("modulePower_StatusCode: %u, %d", lv, m_pState->ModulePowerStatus); asn_INTEGER2long(&pGS->body_TemperatureQty, &lv); m_pState->BodyTemp = lv; LDEBUG(" body_TemperatureQty: %u, %d", lv, m_pState->BodyTemp); asn_INTEGER2long(&pGS->luminance_StatusQty, &lv); m_pState->LuminanceStatus = lv; LDEBUG(" luminance_StatusQty: %u, %d", lv, m_pState->LuminanceStatus); asn_INTEGER2long(&pGS->fan_StatusCode, &lv); m_pState->FanStatus = lv; switch(lv) { case fan_StatusCode_off: m_pState->FanStatus = vms_off; break; case fan_StatusCode_on : m_pState->FanStatus = vms_on; break; default : m_pState->FanStatus = vms_unknown; break; } LDEBUG(" fan_StatusCode: %u, %d", lv, m_pState->FanStatus); asn_INTEGER2long(&pGS->heater_StatusCode, &lv); m_pState->HeaterStatus = lv; switch(lv) { case heater_StatusCode_off: m_pState->HeaterStatus = vms_off; break; case heater_StatusCode_on : m_pState->HeaterStatus = vms_on; break; default : m_pState->HeaterStatus = vms_unknown; break; } LDEBUG(" heater_StatusCode: %u, %d", lv, m_pState->HeaterStatus); result = SYS_ERR_NONE; { if (pGS->externalLight_StatusCode) { asn_INTEGER2long(pGS->externalLight_StatusCode, &lv); m_pState->ExternalLightStatus = lv; LDEBUG("externalLight_StatusCode: %u", lv); } if (pGS->alarmLight_StatusCode) { asn_INTEGER2long(pGS->alarmLight_StatusCode, &lv); m_pState->AlarmLightStatus = lv; LDEBUG("alarmLight_StatusCode: %u", lv); } if (pGS->speaker_StatusCode) { asn_INTEGER2long(pGS->speaker_StatusCode, &lv); m_pState->SpeakerStatus = lv; LDEBUG("speaker_StatusCode: %u", lv); } if (pGS->controller_CurrentTime) { sprintf((char*)m_pState->ControllerCurrentTime, ".*s", pGS->controller_CurrentTime->size, pGS->controller_CurrentTime->buf); LDEBUG("controller_CurrentTime: %.*s", pGS->controller_CurrentTime->size, pGS->controller_CurrentTime->buf); } asn_INTEGER2long(&pGS->scheduledmessage_OperatingTime, &lv); m_pState->ScheduledMessageOperatingTime = lv; LDEBUG("scheduledmessage_OperatingTime: %u", lv); asn_INTEGER2long(&pGS->module_OperatingTemperatureQty, &lv); m_pState->ModuleOperatingTemperature = lv; LDEBUG("module_OperatingTemperatureQty: %u", lv); asn_INTEGER2long(&pGS->fan_OperatingTemperatureQty, &lv); m_pState->FanOperatingTemperature = lv; LDEBUG(" fan_OperatingTemperatureQty: %u", lv); asn_INTEGER2long(&pGS->heater_OperatingTemperatureQty, &lv); m_pState->HeaterOperatingTemperature = lv; LDEBUG("heater_OperatingTemperatureQty: %u", lv); if (pGS->externalLight_OperatingLuminanceQty) { asn_INTEGER2long(pGS->externalLight_OperatingLuminanceQty, &lv); m_pState->ExternalLightOperatingLuminance = lv; LDEBUG("externalLight_OperatingLuminanceQty: %u", lv); } //¾Æ·¡Á¸ÀçÇÔ if (pGS->module_BasicFailureRate) { asn_INTEGER2long(pGS->module_BasicFailureRate, &lv); m_pState->ModuleBasicFailureRate = lv; LDEBUG(" module_BasicFailureRate: %u", lv); } if (pGS->maximum_RetryQty) { asn_INTEGER2long(pGS->maximum_RetryQty, &lv); m_pState->MaximumRetry = lv; LDEBUG("maximum_RetryQty: %u", lv); } if (pGS->response_TimeOutQty) { asn_INTEGER2long(pGS->response_TimeOutQty, &lv); m_pState->ResponseTimeOut = lv; LDEBUG("response_TimeOutQty: %u", lv); } if (pGS->blinking_CycleTime) { asn_INTEGER2long(pGS->blinking_CycleTime, &lv); m_pState->BlinkingCycleTime = lv; LDEBUG("blinking_CycleTime: %u", lv); } } #endif return result; } //--------------------------------------------------------------------------- /* * ¼ö½Å ÆÐŶ ó¸® * arguments * void * return * void */ int __fastcall TVMSSThread::PacketLogin(Login_t *pLogin, DWORD nbr) { FErrLine = 5; int result, iResult; int ErrCode; COMMAND_ARGUMENT arg; result = SYS_ERR_NONE; ErrCode = datexReject_Login_cd_other; #if 0 { long lv; int arcs[10]; int count, i, j; OBJECT_IDENTIFIER_t *pOid; LDEBUG(" datex_Sender_txt : %s", pLogin->datex_Sender_txt.buf); LDEBUG(" datex_Destinatin_txt : %s", pLogin->datex_Destinatin_txt.buf); LDEBUG(" datexLogin_UserName_txt : %s", pLogin->datexLogin_UserName_txt.buf); LDEBUG(" datexLogin_Password_txt : %s", pLogin->datexLogin_Password_txt.buf); /* for (i = 0; i < pLogin->datexLogin_EncodingRules_id_zz.list.count; i++) { LDEBUG(" datexLogin_EncodingRules_id: [%d]", i); pOid = (OBJECT_IDENTIFIER_t *)pLogin->datexLogin_EncodingRules_id_zz.list.array[i]; count = OBJECT_IDENTIFIER_get_arcs(pOid, arcs, sizeof(int), 10); for (j = 0; j < count && j < 10; j++) { LDEBUG("[%d]: %d", j, arcs[j]); } } */ LDEBUG("datexLogin_HearteatDurationMax_qty : %d", pLogin->datexLogin_HearteatDurationMax_qty); LDEBUG(" datexLogin_ResponseTimeOut_qty : %d", pLogin->datexLogin_ResponseTimeOut_qty); asn_INTEGER2long(&pLogin->datexLogin_Initiator_cd, &lv); LDEBUG(" datexLogin_Initiator_cd : %d", lv); LDEBUG(" datexLogin_DatagramSize_qty : %d", pLogin->datexLogin_DatagramSize_qty); } #endif // m_Server.DomainNm = VMS ID // m_Server.LocalDomainNm = 00000000 if (memcmp(pLogin->datex_Sender_txt.buf, m_Server.DomainNm.c_str(), m_Server.DomainNm.Length()) || memcmp(pLogin->datex_Destinatin_txt.buf, m_Server.LocalDomainNm.c_str(), m_Server.LocalDomainNm.Length())) { LERROR("Login: Domain(%s - %s)", m_Server.DomainNm.c_str(), pLogin->datex_Sender_txt.buf); LERROR("Login: Destnation(%s - %s)", m_Server.LocalDomainNm.c_str(), pLogin->datex_Destinatin_txt.buf); if (LOGIN_CHECK) { result = SYS_ERR_MISMATCH_DESTINATION_TEXT; ErrCode = datexReject_Login_cd_unknownDomainName; } } // m_Server.UserName = 00000000 // m_Server.UserPasswd = 00000000 if (memcmp(pLogin->datexLogin_UserName_txt.buf, m_Server.UserName.c_str(), m_Server.UserName.Length()) || memcmp(pLogin->datexLogin_Password_txt.buf, m_Server.UserPasswd.c_str(), m_Server.UserPasswd.Length())) { LERROR("Login: UserName(%s - %s)", m_Server.UserName.c_str(), pLogin->datexLogin_UserName_txt.buf); LERROR("Login: Password(%s - %s)", m_Server.UserPasswd.c_str(), pLogin->datexLogin_Password_txt.buf); if (LOGIN_CHECK) { result = SYS_ERR_DATEXLOGIN_VALUE; ErrCode = datexReject_Login_cd_invalidNamePassword; } } if (pLogin->datexLogin_HearteatDurationMax_qty < 10) { LERROR("HearteatDurationMax: [Require >= 10] ==> %d", pLogin->datexLogin_HearteatDurationMax_qty); if (LOGIN_CHECK) { result = SYS_ERR_DATEXLOGIN_VALUE; ErrCode = datexReject_Login_cd_heartbeatTooSmall; } else pLogin->datexLogin_HearteatDurationMax_qty = 10; } if (pLogin->datexLogin_HearteatDurationMax_qty > 1000) { LERROR("HearteatDurationMax_qty: [Require <= 1000] ==> %d", pLogin->datexLogin_HearteatDurationMax_qty); if (LOGIN_CHECK) { result = SYS_ERR_DATEXLOGIN_VALUE; ErrCode = datexReject_Login_cd_heartbeatTooLarge; } else pLogin->datexLogin_HearteatDurationMax_qty = 1000; } if (pLogin->datexLogin_HearteatDurationMax_qty > FWatchDogTime) { FWatchDogTime = pLogin->datexLogin_HearteatDurationMax_qty + 5; } if (pLogin->datexLogin_ResponseTimeOut_qty < 3) { LERROR("ResponseTimeOut_qty: [Require >= 3] ==> %d", pLogin->datexLogin_ResponseTimeOut_qty); if (LOGIN_CHECK) { result = SYS_ERR_DATEXLOGIN_VALUE; ErrCode = datexReject_Login_cd_timeoutTooSmall; } else pLogin->datexLogin_ResponseTimeOut_qty = 3; } if (pLogin->datexLogin_ResponseTimeOut_qty > 120) { LERROR("ResponseTimeOut_qty: [Require <= 120] ==> %d", pLogin->datexLogin_ResponseTimeOut_qty); if (LOGIN_CHECK) { result = SYS_ERR_DATEXLOGIN_VALUE; ErrCode = datexReject_Login_cd_timeoutTooLarge; } else pLogin->datexLogin_ResponseTimeOut_qty = 120; } #if 0 if ((pLogin->datexLogin_Initiator_cd != datexLogin_Initiator_cd_clientInitiated) && (pLogin->datexLogin_Initiator_cd != datexLogin_Initiator_cd_serverInitiated)) { result = SYS_ERR_DATEXLOGIN_VALUE; ErrCode = datexReject_Login_cd_other; } if ((pLogin->datexLogin_DatagramSize_qty < 0) || (pLogin->datexLogin_DatagramSize_qty > 65535)) { result = SYS_ERR_DATEXLOGIN_VALUE; ErrCode = datexReject_Login_cd_other; } #endif if (result == SYS_ERR_NONE) { m_Server.MaxHeartbeatTime = pLogin->datexLogin_HearteatDurationMax_qty; m_Server.TimeOut = pLogin->datexLogin_ResponseTimeOut_qty; m_Server.DatagramSize = pLogin->datexLogin_DatagramSize_qty; arg.Accept.nbr = nbr; arg.Accept.type = datexAccept_Type_PR_logIn; if((iResult = ProcessCommand(AI_Accept, &arg)) != SYS_ERR_NONE) { SERROR("Login Accept Command failed: %d", iResult); } } else { arg.Reject.nbr = nbr; arg.Reject.type = RejectType_PR_datexReject_Login_cd; arg.Reject.code = ErrCode; if((iResult = ProcessCommand(AI_Reject, &arg)) != SYS_ERR_NONE) { SERROR("Login Reject Command failed: %d", iResult); } } return result; } //--------------------------------------------------------------------------- /* * ¼ö½Å ÆÐŶ ó¸® * arguments * void * return * void */ int __fastcall TVMSSThread::PacketSubscription(Subscription_t *pSubscripiton) { FErrLine = 6; int result; SubscriptionData_t *pData; long Serial_nbr; long Status; long PublishFormat; int flag; int Message_id; result = SYS_ERR_OTHER; #if 0 { long lv; asn_INTEGER2long(&pSubscripiton->datexSubscribe_Serial_nbr, &lv); LDEBUG("datexSubscribe_Serial_nbr: %u", lv); LDEBUG("datexSubscribe_Type: %d", pSubscripiton->datexSubscribe_Type.present); switch(pSubscripiton->datexSubscribe_Type.present) { case SubscriptionType_PR_subscription: pData = &pSubscripiton->datexSubscribe_Type.choice.subscription; LDEBUG("datexSubscribe_Persistent_bool: %d", pData->datexSubscribe_Persistent_bool); asn_INTEGER2long(&pData->datexSubscribe_Status_cd, &lv); LDEBUG("datexSubscribe_Status_cd: %d", lv); LDEBUG("datexSubscribe_Mode: %d", pData->datexSubscribe_Mode.present); switch(pData->datexSubscribe_Mode.present){ case SubscriptionMode_PR_single: break; case SubscriptionMode_PR_event_driven: case SubscriptionMode_PR_periodic: { Registered_t *pRegistered; int numbits, bit; if(pData->datexSubscribe_Mode.present == SubscriptionMode_PR_event_driven){ pRegistered = &pData->datexSubscribe_Mode.choice.event_driven; }else{ pRegistered = &pData->datexSubscribe_Mode.choice.periodic; } LDEBUG("Registered: %d", pRegistered->present); switch(pRegistered->present) { case Registered_PR_continuous: LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.continuous.datexRegistered_UpdateDelay_qty); if(pRegistered->choice.continuous.datexRegistered_StartTime){ LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_StartTime); } if(pRegistered->choice.continuous.datexRegistered_EndTime){ LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_EndTime); } break; case Registered_PR_daily: LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.daily.datexRegistered_UpdateDelay_qty); numbits = DATEX_NUMBITS(pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd); LDEBUG("datexRegistered_DaysOfWeek_cd numbits: %d", numbits); for (bit = 0; bit < numbits; bit++) { LDEBUG("[%d]: %d", bit, ASN1C_CheckBitString(&pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd, bit)); } if (pRegistered->choice.daily.datexRegistered_StartDate) { LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartDate); } if (pRegistered->choice.daily.datexRegistered_EndDate) { LOG_WriteTime(pRegistered->choice.daily.datexRegistered_EndDate); } if (pRegistered->choice.daily.datexRegistered_StartTime) { LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartTime); } if (pRegistered->choice.daily.datexRegistered_Duration_qty) { LDEBUG("datexRegistered_Duration_qty: %u", *pRegistered->choice.daily.datexRegistered_Duration_qty); } break; default: LDEBUG("Unknown Registered %d", pRegistered->present); break; }/* end swtich */ } break; default : LDEBUG("Unknown datexSubscribe_Mode %d", pData->datexSubscribe_Mode.present); break; }/* end switch */ asn_INTEGER2long(&pData->datexSubscribe_PublishFormat_cd, &lv); LDEBUG("datexSubscribe_PublishFormat_cd: %d", lv); LDEBUG("datexSubscription_Priority_nbr: %d", pData->datexSubscription_Priority_nbr); LDEBUG("datexSubscribe_Guarantee_bool: %d", pData->datexSubscribe_Guarantee_bool); break; case SubscriptionType_PR_datexSubscribe_CancelReason_cd: LDEBUG("datexSubscribe_CancelReason_cd: %d", pSubscripiton->datexSubscribe_Type.choice.datexSubscribe_CancelReason_cd); break; default: LDEBUG("Unknown datexSubscribe_Type %d", pSubscripiton->datexSubscribe_Type.present); break; }/* end switch */ } #endif asn_INTEGER2long(&pSubscripiton->datexSubscribe_Serial_nbr, &Serial_nbr); switch(pSubscripiton->datexSubscribe_Type.present) { case SubscriptionType_PR_subscription: pData = &pSubscripiton->datexSubscribe_Type.choice.subscription; /* pData->datexSubscribe_Persistent_bool */ asn_INTEGER2long(&pData->datexSubscribe_Status_cd, &Status); switch(Status){ case datexSubscribe_Status_cd_new: break; case datexSubscribe_Status_cd_update: break; default: return SYS_ERR_SUBSCRIPTION_STATUS_VALUE; } switch(pData->datexSubscribe_Mode.present){ case SubscriptionMode_PR_single: flag = SubscriptionMode_PR_single; break; case SubscriptionMode_PR_event_driven: flag = SubscriptionMode_PR_event_driven; /* pData->datexSubscribe_Mode.choice.event_driven */ break; case SubscriptionMode_PR_periodic: flag = SubscriptionMode_PR_periodic; /* pData->datexSubscribe_Mode.choice.periodic */ break; default: return SYS_ERR_SUBSCRIPTION_MODE_VALUE; } asn_INTEGER2long(&pData->datexSubscribe_PublishFormat_cd, &PublishFormat); switch(PublishFormat) { #if 0 case datexSubscribe_PublishFormat_cd_other: break; case datexSubscribe_PublishFormat_cd_ftp: break; case datexSubscribe_PublishFormat_cd_tftp: break; #endif case datexSubscribe_PublishFormat_cd_dataPacket: break; default: return SYS_ERR_SUBSCRIPTION_FORMAT_VALUE; } /* pData->datexSubscription_Priority_nbr */ /* pData->datexSubscribe_Guarantee_bool */ if ((Message_id = ASN1C_GetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id)) == -1) { return SYS_ERR_UNKNOWN_MESSAGE_ID; } switch(Message_id) { case OBJ_RealTimeDisplay: /* ½Ç½Ã°£Á¤º¸Ç¥Ãâ */ { LINFO(" *** OBJ_RealTimeDisplay ¼ö½Å"); result = SYS_ERR_NONE; } break; case OBJ_ScheduledDisplay: /* °èȹµÈÁ¤º¸Ç¥Ãâ */ LINFO(" *** OBJ_ScheduledDisplay ¼ö½Å"); result = SYS_ERR_NONE; break; case OBJ_DownloadGraphicData: /* ±×·¡Çȵ¥ÀÌÅÍ ´Ù¿î·Îµå */ LINFO(" *** OBJ_DownloadGraphicData ¼ö½Å"); result = SYS_ERR_NONE; break; case OBJ_StatusControl: /* »óÅÂÁ¦¾î */ LINFO(" *** OBJ_StatusControl ¼ö½Å"); result = SYS_ERR_NONE; break; case OBJ_StatusSetting: /* »óż³Á¤ */ LINFO(" *** OBJ_StatusSetting ¼ö½Å"); result = SYS_ERR_NONE; break; //FOR YONGIN case OBJ_GeneralStatus:// = 6, /* ±âº»»óÅÂÁ¤º¸ */ LINFO(" *** OBJ_GeneralStatus ¼ö½Å"); result = SYS_ERR_NONE; break; case OBJ_PowerStatus:// = 7, /* Àü¿ø»óÅÂÁ¤º¸ */ LINFO(" *** OBJ_PowerStatus ¼ö½Å"); result = SYS_ERR_NONE; break; case OBJ_ModuleStatus:// = 8, /* ¸ðµâ»óÅÂÁ¤º¸ */ LINFO(" *** OBJ_ModuleStatus ¼ö½Å"); result = SYS_ERR_NONE; break; case OBJ_DotStatus:// = 9, /* µµÆ®»óÅÂÁ¤º¸ */ LINFO(" *** OBJ_DotStatus ¼ö½Å"); result = SYS_ERR_NONE; break; case OBJ_ScreenStatus:// = 10, /* Ç¥Ãâ»óÅÂÁ¤º¸ */ LINFO(" *** OBJ_ScreenStatus ¼ö½Å"); result = SYS_ERR_NONE; break; case OBJ_DisplayingData:// = 11 /* Ç¥ÃâÁ¤º¸ */ LINFO(" *** OBJ_DisplayingData ¼ö½Å"); result = SYS_ERR_NONE; break; //END YONGIN default: SERROR(" *** Unknown Subscription message: %d ¼ö½Å", Message_id); result = SYS_ERR_UNKNOWN_MESSAGE_ID; break; } break; case SubscriptionType_PR_datexSubscribe_CancelReason_cd: result = SYS_ERR_NONE; break; default: SERROR(" *** Unknown Subscription Recv: %d", pSubscripiton->datexSubscribe_Type.present); result = SYS_ERR_SUBSCRIPTION_TYPE; break; }/* end switch */ return result; } //--------------------------------------------------------------------------- /* * ¼ö½Å ÆÐŶ ó¸® * arguments * void * return * void */ int __fastcall TVMSSThread::PacketAccept(Accept_t *pAccept) { FErrLine = 7; int result, sResult; long nbr; result = VERR_OTHER; asn_INTEGER2long(&pAccept->datexAccept_Packet_nbr, &nbr); switch(pAccept->datexAccept_Type.present) { /* case datexAccept_Type_PR_logIn: break; case datexAccept_Type_PR_single_subscription: break; case datexAccept_Type_PR_registered_subscription: break; */ case datexAccept_Type_PR_publication: #if 0 if ((m_Server.State != ST_LOCAL_WAIT) && (m_Server.State != ST_CLIENT_WAIT)) { result = SYS_ERR_MISMATCH; break; } #endif /* if (nbr == (long)FSvrCtl.DataPacketNumber) */ { if (FSvrCtl.obj == OBJ_RealTimeDisplay) { m_pVmsFormList->Lock(); try { TVmsForm *pVmsForm = m_pVmsFormList->GetItem(FSvrCtl.Idx); if (pVmsForm) { pVmsForm->SvcRes = true; } else { // } } __finally { m_pVmsFormList->UnLock(); } } else if (FSvrCtl.obj == OBJ_ScheduledDisplay) { SAVE_STRUCT ProvideSave; memset(&ProvideSave, 0x00, sizeof(ProvideSave)); ProvideSave.Type = save_provide; ProvideSave.Count = 1; ProvideSave.pObj[0] = (void*)FVmsObj; FVmsObj->CTLMODE->Enable = object_disable; FVmsObj->CTLMODE->SvcDate = Now().FormatString("yyyymmddhhnnss"); FVmsObj->CTLMODE->SaveFlag = true; FVmsObj->CTLMODE->Result = true; if ((sResult = SendDbThreadDataMessage(WM_PROVIDE_SAVE, &ProvideSave, sizeof(ProvideSave))) != VERR_NONE) { SERROR("SendDbThreadDataMessage Error %d", sResult); } } else if (FSvrCtl.obj == OBJ_DownloadGraphicData) { FVmsObj->DOWNLOAD->Unit[FSvrCtl.Idx].SendEndDate = Now().FormatString("yyyymmddhhnnss"); FVmsObj->DOWNLOAD->Unit[FSvrCtl.Idx].SendStep = send_complete; FVmsObj->DOWNLOAD->Unit[FSvrCtl.Idx].SendResult = vms_download_succ; if ((FSvrCtl.Idx + 1) == FVmsObj->DOWNLOAD->Count) { SAVE_STRUCT DownLoadSave; memset(&DownLoadSave, 0x00, sizeof(DownLoadSave)); DownLoadSave.Type = save_download; DownLoadSave.Count = 1; DownLoadSave.pObj[0] = (void*)FVmsObj; FVmsObj->DOWNLOAD->Enable = object_disable; FVmsObj->DOWNLOAD->SaveFlag = true; if ((sResult = SendDbThreadDataMessage(WM_PROVIDE_SAVE, &DownLoadSave, sizeof(DownLoadSave))) != VERR_NONE) { SERROR("SendDbThreadDataMessage Error %d", sResult); } } } }/* end if */ SetServerState(SET_SERVER_SUCC); result = SYS_ERR_NONE; LINFO(" *** Accept_Type_PR_publication: %u", nbr); break; default: result = SYS_ERR_ACCEPT_TYPE; SERROR(" *** Unknown Accept_Type: %u, %d", nbr, pAccept->datexAccept_Type.present); break; } return result; } //--------------------------------------------------------------------------- /* * ¼ö½Å ÆÐŶ ó¸® * arguments * void * return * void */ int __fastcall TVMSSThread::PacketReject(Reject_t *pReject) { FErrLine = 8; int result; long nbr; long ErrCode; result = SYS_ERR_OTHER; asn_INTEGER2long(&pReject->datexReject_Packet_nbr, &nbr); switch(pReject->datexReject_Type.present){ /* case RejectType_PR_datexReject_Login_cd: asn_INTEGER2long(&pReject->datexReject_Type.choice.datexReject_Login_cd, &ErrCode); break; case RejectType_PR_datexReject_Subscription_cd: asn_INTEGER2long(&pReject->datexReject_Type.choice.datexReject_Subscription_cd, &ErrCode); break; */ case RejectType_PR_datexReject_Publication_cd: asn_INTEGER2long(&pReject->datexReject_Type.choice.datexReject_Publication_cd, &ErrCode); if ((m_Server.State != ST_LOCAL_WAIT) && (m_Server.State != ST_CLIENT_WAIT)) { result = SYS_ERR_MISMATCH; break; } SetServerState(SET_SERVER_FAIL); result = SYS_ERR_NONE; break; default: ErrCode = -1; break; } /* pReject->datexReject_AlternateRequest */ LINFO("Reject ¼ö½Å[%d %d %d]", nbr, pReject->datexReject_Type.present, ErrCode); return result; } //--------------------------------------------------------------------------- /* * ÆÐŶ ¼Û½Å * arguments * void * return * void */ int __fastcall TVMSSThread::SendPacket(void *Data, int Len, BYTE cmd) { FErrLine = 9; int result; DatexDataPacket_t *pMsg; /* Type to encode */ asn_enc_rval_t er; /* Encoder return value */ BYTE MsgBuf[SERVER_MSG_BUF_SIZE]; WORD crc; int eLen, wLen; result = SYS_ERR_OTHER; pMsg = (DatexDataPacket_t *)ASN1C_Alloc(sizeof(DatexDataPacket_t)); if(pMsg == NULL) { return SYS_ERR_INTERNAL; } if(asn_long2INTEGER(&pMsg->datex_Version_number, datex_Version_number_version1) != ASN_ERR_NONE){ ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg); return -1; } if(OCTET_STRING_fromBuf(&pMsg->datex_Data, (char *)Data, Len) != ASN_ERR_NONE){ ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg); return -2; } crc = ASN1C_MakeCrc16(Data, Len); crc = CommUtil_WordSwap(crc); if (OCTET_STRING_fromBuf(&pMsg->datex_Crc_nbr, (char *)&crc, sizeof(crc)) != ASN_ERR_NONE) { ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg); return -3; } /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_DatexDataPacket, pMsg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_DATEXDATAPACKET_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; wLen = pClientSocket->SendBuf(MsgBuf, eLen); LINFO("Send: %d/%d, cmd: %02X", eLen, wLen, cmd); if (eLen == wLen) { --m_Server.iRetry; m_Server.cTimer = Now(); result = SYS_ERR_NONE; LogData("SEND", (char*)MsgBuf, eLen); } else { LERROR("TCP_Write(%d %d)", eLen, wLen); result = SYS_ERR_WRITE_LENGTH; LogData("SEND Fail", (char*)MsgBuf, eLen); } } ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg); return result; } //--------------------------------------------------------------------------- int UTF8String_fromBuf(UTF8String_t *st, const char *str, int len) { UTF8String uStr; uStr = UTF8Encode(WideString(str, len)); return OCTET_STRING_fromBuf(st, uStr.c_str(), uStr.Length()); } //--------------------------------------------------------------------------- /* * ÀÔ·Â ÆÄ¶ó¹ÌÅÍ¿¡ µû¶ó ¸í·ÉÀ» Àü¼ÛÇÑ´Ù. * arguments * void * return * void */ int __fastcall TVMSSThread::ProcessCommand(BYTE cmd, COMMAND_ARGUMENT *arg) { FErrLine = 10; C2CAuthenticatedMessage_t *pMsg; /* Type to encode */ asn_enc_rval_t er; /* Encoder return value */ BYTE MsgBuf[SERVER_MSG_BUF_SIZE]; int eLen; int result; Word year, month, day; Word hour, min, sec, msec; result = SYS_ERR_OTHER; Now().DecodeDate(&year, &month, &day); Now().DecodeTime(&hour, &min, &sec, &msec); pMsg = (C2CAuthenticatedMessage_t *)ASN1C_Alloc(sizeof(C2CAuthenticatedMessage_t)); if (pMsg == NULL) { return SYS_ERR_INTERNAL; } /* °øÅëºÎºÐ */ if (OCTET_STRING_fromBuf(&pMsg->datex_AuthenticationInfo_text, (char *)&cmd, sizeof(cmd)) != ASN_ERR_NONE) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -1; } if (asn_long2INTEGER(&pMsg->datex_DataPacket_number, m_DataPacketNumber++) != ASN_ERR_NONE) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -2; } pMsg->datex_DataPacketPriority_number = 0; /* Header Options */ /* pMsg->options.datex_Origin_text */ pMsg->options.datex_OriginAddress_location = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t)); if (pMsg->options.datex_OriginAddress_location == NULL) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -3; } //if (OCTET_STRING_fromString(pMsg->options.datex_OriginAddress_location, m_Server.LocalCenterId.c_str()) != ASN_ERR_NONE) if (OCTET_STRING_fromString(pMsg->options.datex_OriginAddress_location, m_Server.LocalDomainNm.c_str()) != ASN_ERR_NONE) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -4; } /* pMsg->options.datex_Sender_text */ /* pMsg->options.datex_SenderAddress_location */ /* pMsg->options.datex_Destination_text */ #if 1 pMsg->options.datex_SenderAddress_location = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t)); if (pMsg->options.datex_SenderAddress_location == NULL) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -5; } if (OCTET_STRING_fromString(pMsg->options.datex_SenderAddress_location, m_Server.LocalDomainNm.c_str()) != ASN_ERR_NONE) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -6; } #endif pMsg->options.datex_DestinationAddress_location = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t)); if (pMsg->options.datex_DestinationAddress_location == NULL) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -5; } //if (OCTET_STRING_fromString(pMsg->options.datex_DestinationAddress_location, m_Server.CenterId.c_str()) != ASN_ERR_NONE) if (OCTET_STRING_fromString(pMsg->options.datex_DestinationAddress_location, m_Server.DomainNm.c_str()) != ASN_ERR_NONE) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -6; } /* pMsg->options.datex_Cost->amount_Currency_code */ /* pMsg->options.datex_Cost->amount_Factor_quantity */ /* pMsg->options.datex_Cost->amount_Quantity_quantity */ pMsg->options.datex_DataPacket_time = (Time_t *)ASN1C_Alloc(sizeof(Time_t)); if (pMsg->options.datex_DataPacket_time == NULL) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -7; } pMsg->options.datex_DataPacket_time->time_Year_qty = (long *)ASN1C_Alloc(sizeof(long)); if (pMsg->options.datex_DataPacket_time->time_Year_qty == NULL) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -8; } *pMsg->options.datex_DataPacket_time->time_Year_qty = year; pMsg->options.datex_DataPacket_time->time_Month_qty = (long *)ASN1C_Alloc(sizeof(long)); if (pMsg->options.datex_DataPacket_time->time_Month_qty == NULL) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -9; } *pMsg->options.datex_DataPacket_time->time_Month_qty = month; pMsg->options.datex_DataPacket_time->time_Day_qty = (long *)ASN1C_Alloc(sizeof(long)); if (pMsg->options.datex_DataPacket_time->time_Day_qty == NULL) { ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return -10; } *pMsg->options.datex_DataPacket_time->time_Day_qty = day; pMsg->options.datex_DataPacket_time->time_Hour_qty = hour; pMsg->options.datex_DataPacket_time->time_Minute_qty = min; pMsg->options.datex_DataPacket_time->time_Second_qty = sec; pMsg->options.datex_DataPacket_time->time_SecondFractions_zz.present = time_SecondFractions_PR_milliseconds; pMsg->options.datex_DataPacket_time->time_SecondFractions_zz.choice.milliseconds = 0; #if 0 //TODO pMsg->options.datex_DataPacket_time->time_Timezone = (Timezone_t*)ASN1C_Alloc(sizeof(Timezone_t)); if (pMsg->options.datex_DataPacket_time->time_Timezone) { pMsg->options.datex_DataPacket_time->time_Timezone->timezone_Hour_qty = 9; pMsg->options.datex_DataPacket_time->time_Timezone->time_Minute_qty = 0; } #endif /* pMsg->options.datex_DataPacket_time->time_Timezone->timezone_Hour_qty */ /* pMsg->options.datex_DataPacket_time->time_Timezone->time_Minute_qty */ switch(cmd) { case AI_Initiate: /* Ãʱâ Åë½Å¿¬°áÀ» À§ÇÑ °³½Ã ¿äû µ¥ÀÌÅÍ ÆÐŶ */ pMsg->pdu.present = PDUs_PR_datex_Initiate_null; if(OCTET_STRING_fromString(&pMsg->pdu.choice.datex_Initiate_null.datex_Sender_txt, m_Server.LocalDomainNm.c_str()) != ASN_ERR_NONE){ result = -12; break; } if(OCTET_STRING_fromString(&pMsg->pdu.choice.datex_Initiate_null.datex_Destinatin_txt, m_Server.DomainNm.c_str()) != ASN_ERR_NONE){ result = -13; break; } result = SYS_ERR_NONE; LINFO(">>> AI_Initiate Àü¼Û Sender:%s Destinatin:%s", m_Server.LocalDomainNm.c_str(), m_Server.DomainNm.c_str()); break; case AI_Accept: /* Ŭ¶óÀ̾ðÆ®ÀÇ ¿äû¿¡ ´ëÇÑ ¼ö¿ë */ LINFO(">>> AI_Accept Àü¼Û"); pMsg->pdu.present = PDUs_PR_accept; if ((result = CommandAccept(&pMsg->pdu.choice.accept, arg->Accept.nbr, arg->Accept.type, arg->Accept.sub)) != SYS_ERR_NONE) { SERROR("CommandAccept result failed: %d", result); result = -14; } break; case AI_Reject: /* Ŭ¶óÀ̾ðÆ®ÀÇ ¿äû¿¡ ´ëÇÑ °ÅºÎ */ LINFO(">>> AI_Reject Àü¼Û"); pMsg->pdu.present = PDUs_PR_reject; if ((result = CommandReject(&pMsg->pdu.choice.reject, arg->Reject.nbr, arg->Reject.type, arg->Reject.code)) != SYS_ERR_NONE) { SERROR("CommandReject failed: %d", result); result = -15; } break; case AI_FrED: /* ¼­¹ö¿Í Ŭ¶óÀ̾ðÆ®ÀÇ ¿¬°áÀ» À¯ÁöÇϱâ À§ÇÑ È®ÀÎ µ¥ÀÌÅÍ ÆÐŶ */ pMsg->pdu.present = PDUs_PR_fred; if (asn_long2INTEGER(&pMsg->pdu.choice.fred, arg->FrED) != ASN_ERR_NONE) { LINFO(">>> AI_FrED Àü¼Û Failed"); result = -16; break; } result = SYS_ERR_NONE; LINFO(">>> AI_FrED Àü¼Û: %u", arg->FrED); break; case AI_Terminate: /* ¿¬°áÀ» Á¾·áÇϰíÀÚ ÇÒ ¶§, ¼­¹ö¿¡¼­ Ŭ¶óÀÌ¾ðÆ®¿¡ ¿äûÇÏ´Â µ¥ÀÌÅÍ ÆÐŶ */ pMsg->pdu.present = PDUs_PR_terminate; if (asn_long2INTEGER(&pMsg->pdu.choice.terminate, arg->Terminate) != ASN_ERR_NONE) { LINFO(">>> AI_Terminate Àü¼Û Failed"); result = -17; break; } result = SYS_ERR_NONE; LINFO(">>> AI_Terminate Àü¼Û %u", arg->Terminate); break; case AI_RealTimeDisplayMessage: /* ½Ç½Ã°£Á¤º¸Ç¥Ãâ¸Þ½ÃÁö */ case AI_ScheduledDisplayMessage: /* °èȹµÈÁ¤º¸Ç¥Ãâ¸Þ½ÃÁö */ case AI_DownloadGraphicDataMessage: /* ±×·¡Çȵ¥ÀÌÅÍ ´Ù¿î·Îµå ¸Þ½ÃÁö */ case AI_StatusControlMessage: /* »óÅÂÁ¦¾î¸Þ½ÃÁö */ case AI_StatusSettingMessage: /* »óż³Á¤¸Þ½ÃÁö */ { LINFO(">>> PublicationData Àü¼Û"); PublicationData_t *pData; if ((pData = (PublicationData_t *)ASN1C_Alloc(sizeof(PublicationData_t))) == NULL) { result = -18; break; } pMsg->pdu.present = PDUs_PR_publication; pMsg->pdu.choice.publication.datexPublish_Guaranteed_bool = true; pMsg->pdu.choice.publication.datexPublish_Format.present = Publish_Format_PR_datexPublish_Data; if ((result = CommandPublicationData(pData, arg->Publication)) != SYS_ERR_NONE) { SERROR("CommandPublicationData failed: %d", result); result = -19; break; } if (ASN_SEQUENCE_ADD(&pMsg->pdu.choice.publication.datexPublish_Format.choice.datexPublish_Data, pData) != ASN_ERR_NONE) { result = -20; break; } result = SYS_ERR_NONE; } break; case AI_ScreenStatusMessage: /* Ç¥Ãâ»óÅÂÁ¤º¸¸Þ½ÃÁö */ { Subscription_t *pSubscripiton = &pMsg->pdu.choice.subscripiton; SubscriptionData_t *pData = &pSubscripiton->datexSubscribe_Type.choice.subscription; pMsg->pdu.present = PDUs_PR_subscripiton; if (asn_long2INTEGER(&pSubscripiton->datexSubscribe_Serial_nbr, arg->Publication.SubscribeSerialNbr) != ASN_ERR_NONE) { result = -31; break; } pSubscripiton->datexSubscribe_Type.present = SubscriptionType_PR_subscription; pData->datexSubscribe_Persistent_bool = false; if (asn_long2INTEGER(&pData->datexSubscribe_Status_cd, datexSubscribe_Status_cd_new) != ASN_ERR_NONE) { result = -32; break; } pData->datexSubscribe_Mode.present = SubscriptionMode_PR_single; if (asn_long2INTEGER(&pData->datexSubscribe_PublishFormat_cd, datexSubscribe_PublishFormat_cd_dataPacket) != ASN_ERR_NONE) { result = -33; break; } pData->datexSubscription_Priority_nbr = 1; pData->datexSubscribe_Guarantee_bool = true; ASN1C_SetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id, OBJ_ScreenStatus); // ScreenStatusMessage_t *pMS; MessageBodyScreenStatusMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyScreenStatusMessage_t)); /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyScreenStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL) { result = -32; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -33; break; } result = SYS_ERR_NONE; LINFO("ScreenStatus Subscribe Send"); } ASN1C_FreeC(&asn_DEF_MessageBodyScreenStatusMessage, &Msg); result = SYS_ERR_NONE; } break; case AI_DisplayingDataMessage: /* Ç¥ÃâÁ¤º¸¸Þ½ÃÁö */ { //pMsg->pdu.present = PDUs_PR_subscripiton; //result = SYS_ERR_NONE; } break; case AI_TransferDone: { AnsiString sFileName = AnsiString(arg->Publication.szFormId); pMsg->pdu.present = PDUs_PR_publication; pMsg->pdu.choice.publication.datexPublish_Guaranteed_bool = true; pMsg->pdu.choice.publication.datexPublish_Format.present = Publish_Format_PR_datexPublish_FileName_txt; if (OCTET_STRING_fromString(&pMsg->pdu.choice.publication.datexPublish_Format.choice.datexPublish_FileName_txt, sFileName.c_str()) != ASN_ERR_NONE) { result = -41; break; } result = SYS_ERR_NONE; } break; #if 1 // FOR Yongin case AI_Subscription: pMsg->pdu.present = PDUs_PR_subscripiton; #if 0 if ((result = CommandSubscription(&pMsg->pdu.choice.subscripiton, arg->Subscription)) != SYS_ERR_NONE) { SERROR("CommandSubscription result %d", result); result = -15; } #endif break; // END Yongin #endif default: LERROR("ProcessCommand Unknown cmd: %d", cmd); result = SYS_ERR_UNKNOWN_COMMAND; break; } if (result == SYS_ERR_NONE) { /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_C2CAuthenticatedMessage, pMsg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_C2CAUTHENTICATEDMESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; result = SendPacket(MsgBuf, eLen, cmd); } } ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg); return result; } //--------------------------------------------------------------------------- /* * ¼Û½Å ÆÐŶ »ý¼º * arguments * void * return * void */ int __fastcall TVMSSThread::CommandAccept(Accept_t *pAccept, DWORD nbr, int type, DWORD sub) { FErrLine = 11; int result; int oid[3] = {2, 1, 1}; result = SYS_ERR_OTHER; if(asn_long2INTEGER(&pAccept->datexAccept_Packet_nbr, nbr) != ASN_ERR_NONE){ return -1; } pAccept->datexAccept_Type.present = (datexAccept_Type_PR)type; switch(type) { case datexAccept_Type_PR_logIn: if (ASN1C_SetObjectIdentifier(&pAccept->datexAccept_Type.choice.logIn, oid, sizeof(oid)) != ASN_ERR_NONE) { LINFO(" *** Accept_Type_PR_logIn Failed"); return -2; } result = SYS_ERR_NONE; LINFO(" *** Accept_Type_PR_logIn Àü¼Û: %u", nbr); break; case datexAccept_Type_PR_single_subscription: result = SYS_ERR_NONE; LINFO(" *** Accept_Type_PR_single_subscription Àü¼Û: %u", nbr); break; case datexAccept_Type_PR_registered_subscription: if (asn_long2INTEGER(&pAccept->datexAccept_Type.choice.registered_subscription, sub) != ASN_ERR_NONE) { LINFO(" *** Accept_Type_PR_registered_subscription Failed"); return -3; } result = SYS_ERR_NONE; LINFO(" *** Accept_Type_PR_registered_subscription Àü¼Û: %u, %u", nbr, sub); break; case datexAccept_Type_PR_publication: result = SYS_ERR_NONE; LINFO(" *** Accept_Type_PR_publication Àü¼Û: %u", nbr); break; default: result = SYS_ERR_ACCEPT_TYPE; LINFO(" *** Unknown Accept_Type: %u, %d", nbr, type); break; } return result; } //--------------------------------------------------------------------------- /* * ¼Û½Å ÆÐŶ »ý¼º * arguments * void * return * void */ int __fastcall TVMSSThread::CommandReject(Reject_t *pReject, DWORD nbr, int type, int code) { FErrLine = 12; int result; result = SYS_ERR_OTHER; if (asn_long2INTEGER(&pReject->datexReject_Packet_nbr, nbr) != ASN_ERR_NONE) { return -1; } pReject->datexReject_Type.present = (RejectType_PR)type; switch(type){ case RejectType_PR_datexReject_Login_cd: if(asn_long2INTEGER(&pReject->datexReject_Type.choice.datexReject_Login_cd, code) != ASN_ERR_NONE){ return -2; } result = SYS_ERR_NONE; LINFO("·Î±×ÀÎ °ÅºÎ Àü¼Û %u %d", nbr, code); break; case RejectType_PR_datexReject_Subscription_cd: if(asn_long2INTEGER(&pReject->datexReject_Type.choice.datexReject_Subscription_cd, code) != ASN_ERR_NONE){ return -3; } result = SYS_ERR_NONE; LINFO("¼­ºê½ºÅ©¸³¼Ç °ÅºÎ Àü¼Û %u %d", nbr, code); break; case RejectType_PR_datexReject_Publication_cd: if(asn_long2INTEGER(&pReject->datexReject_Type.choice.datexReject_Publication_cd, code) != ASN_ERR_NONE){ return -4; } result = SYS_ERR_NONE; LINFO("Publication Reject Àü¼Û %u %d", nbr, code); break; default: result = SYS_ERR_ACCEPT_TYPE; LINFO("Unknown Reject Àü¼Û %u %d", nbr, type); break; } /* pReject->datexReject_AlternateRequest */ return result; } //--------------------------------------------------------------------------- /* * ¼Û½Å ÆÐŶ »ý¼º * arguments * void * return * void */ int __fastcall TVMSSThread::CommandPublicationData(PublicationData_t *pData, PUBLICATION_ARGUMENT Arg) { FErrLine = 13; int result; asn_enc_rval_t er; /* Encoder return value */ BYTE MsgBuf[SERVER_MSG_BUF_SIZE]; int eLen; int i; result = SYS_ERR_OTHER; if (asn_long2INTEGER(&pData->datexPublish_SubscribeSerial_nbr, Arg.SubscribeSerialNbr) != ASN_ERR_NONE) { return -1; } pData->datexPublish_LatePublicationFlag = true; pData->datexPublish_Type.present = PublicationType_PR_datexPublish_Data; #if 0 { long lv; asn_INTEGER2long(&pData->datexPublish_SubscribeSerial_nbr, &lv); LDEBUG("datexPublish_SubscribeSerial_nbr: %u", lv); asn_INTEGER2long(&pData->datexPublish_Serial_nbr, &lv); LDEBUG(" datexPublish_Serial_nbr: %u", lv); LDEBUG("datexPublish_LatePublicationFlag: %d", pData->datexPublish_LatePublicationFlag); } #endif if (FVmsObj->FIsOldProtocol) { int s_arcs[6]; int *arcs = s_arcs; s_arcs[0] = 1; s_arcs[1] = 0; s_arcs[2] = 14827; s_arcs[3] = 2; s_arcs[4] = 0; s_arcs[5] = Arg.obj; int count = OBJECT_IDENTIFIER_set_arcs(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id, arcs, sizeof(*arcs), 6); } else { ASN1C_SetObjId(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id, Arg.obj); } switch(Arg.obj) { case OBJ_RealTimeDisplay: /* ½Ç½Ã°£Á¤º¸Ç¥Ãâ */ { LINFO(" *** OBJ_RealTimeDisplay"); RealTimeDisplayMessage_t *pRTD; MessageBodyRealTimeDisplayMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyRealTimeDisplayMessage_t)); for ( i = 0; i < 1; i++) { if ((pRTD = (RealTimeDisplayMessage_t *)ASN1C_Alloc(sizeof(RealTimeDisplayMessage_t))) == NULL) { result = -10; break; } if (FVmsObj->FBmpDownload) { //Àüü À̹ÌÁö·Î ´Ù¿î·Îµå ÇÏ´Â °æ¿ìÀ̰ųª //ÀÌÀüVMSÁß¿¡ FTP·Î ´Ù¿î·Îµå ÇÏ´Â °æ¿ìÀÓ... result = RealTimeDisplayBitmap(pRTD, Arg); } else { result = RealTimeDisplayData(pRTD, Arg); } if (result != SYS_ERR_NONE) { SERROR("RealTimeDisplayData failed: %d", result); result = -11; break; } if (ASN_SEQUENCE_ADD(&Msg, pRTD)!= ASN_ERR_NONE) { result = -12; break; } #if 0 { long lv; Object_t *pObj; char Utf8Buf[256+1]; LDEBUG("[%d]", i); LDEBUG("message_serialID: %.*s", pRTD->message_serialID.size, pRTD->message_serialID.buf); asn_INTEGER2long(&pRTD->display_DurationQty, &lv); LDEBUG("display_DurationQty: %u", lv); asn_INTEGER2long(&pRTD->display_ModeCode, &lv); LDEBUG("display_ModeCode: %u", lv); asn_INTEGER2long(&pRTD->display_DirectionCode, &lv); LDEBUG("display_DirectionCode: %u", lv); asn_INTEGER2long(&pRTD->background_ColorCode, &lv); LDEBUG("background_ColorCode: %u", lv); asn_INTEGER2long(&pRTD->object_Nbr, &lv); LDEBUG("object_Nbr: %u", lv); for (int j = 0; j < pRTD->objects_zz.list.count; j++) { LDEBUG("objects: [%d]", j); pObj = (Object_t *)pRTD->objects_zz.list.array[j]; asn_INTEGER2long(&pObj->object_TypeCode, &lv); LDEBUG("object_TypeCode: %u", lv); asn_INTEGER2long(&pObj->blinking_Code, &lv); LDEBUG("blinking_Code: %u", lv); asn_INTEGER2long(&pObj->x_Coordinate, &lv); LDEBUG("x_Coordinate: %u", lv); asn_INTEGER2long(&pObj->y_Coordinate, &lv); LDEBUG("y_Coordinate: %u", lv); asn_INTEGER2long(&pObj->data_BackgroundColor, &lv); LDEBUG("data_BackgroundColor: %u", lv); LDEBUG("object_Data: %d", pObj->object_Data.present); switch(pObj->object_Data.present) { case ObjectData_PR_text_object_data: asn_INTEGER2long(&pObj->object_Data.choice.text_object_data.font_ColorCode, &lv); LDEBUG("font_ColorCode: %u", lv); asn_INTEGER2long(&pObj->object_Data.choice.text_object_data.font_Size, &lv); LDEBUG("font_Size: %u", lv); LDEBUG("font_TypeCode: %.*s", pObj->object_Data.choice.text_object_data.font_TypeCode.size, pObj->object_Data.choice.text_object_data.font_TypeCode.buf); asn_INTEGER2long(&pObj->object_Data.choice.text_object_data.font_Thickness, &lv); LDEBUG("font_Thickness: %u", lv); UTF8String2Hangul((char *)pObj->object_Data.choice.text_object_data.text_Data.buf, Utf8Buf, sizeof(Utf8Buf)); LDEBUG("text_Data: %.256s", Utf8Buf); break; case ObjectData_PR_graphic_object_data: asn_INTEGER2long(&pObj->object_Data.choice.graphic_object_data.graphic_Type, &lv); LDEBUG("graphic_Type: %u", lv); asn_INTEGER2long(&pObj->object_Data.choice.graphic_object_data.graphic_Width, &lv); LDEBUG("graphic_Width: %u", lv); asn_INTEGER2long(&pObj->object_Data.choice.graphic_object_data.graphic_Height, &lv); LDEBUG("graphic_Height: %u", lv); LDEBUG("graphic_Data:"); //m_Log->WriteHex(LOG_DEBUG, (BYTE *)pObj->object_Data.choice.graphic_object_data.graphic_Data.buf, pObj->object_Data.choice.graphic_object_data.graphic_Data.size); break; case ObjectData_PR_graphicID_object_data: asn_INTEGER2long(&pObj->object_Data.choice.graphicID_object_data.graphic_Type, &lv); LDEBUG("graphic_Type: %u", lv); asn_INTEGER2long(&pObj->object_Data.choice.graphicID_object_data.graphic_Width, &lv); LDEBUG("graphic_Width: %u", lv); asn_INTEGER2long(&pObj->object_Data.choice.graphicID_object_data.graphic_Height, &lv); LDEBUG("graphic_Height: %u", lv); LDEBUG("graphic_DataID: %.*s", pObj->object_Data.choice.graphicID_object_data.graphic_DataID.size, pObj->object_Data.choice.graphicID_object_data.graphic_DataID.buf); break; default: break; } } } #endif }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyRealTimeDisplayMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL) { result = -13; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -14; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyRealTimeDisplayMessage, &Msg); } break; case OBJ_ScheduledDisplay: /* °èȹµÈÁ¤º¸Ç¥Ãâ */ { LINFO(" *** OBJ_ScheduledDisplay"); ScheduledDisplayMessage_t *pSD; MessageBodyScheduledDisplayMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyScheduledDisplayMessage_t)); for ( i = 0; i < 1; i++) { if ((pSD = (ScheduledDisplayMessage_t *)ASN1C_Alloc(sizeof(ScheduledDisplayMessage_t))) == NULL) { result = -20; break; } if ((result = ScheduledDisplayData(pSD, Arg)) != SYS_ERR_NONE) { SERROR("ScheduledDisplayData result %d", result); result = -21; break; } if (ASN_SEQUENCE_ADD(&Msg, pSD)!= ASN_ERR_NONE) { result = -22; break; } #if 0 { long lv; OCTET_STRING_t *pSid; LDEBUG("[%d]", i); asn_INTEGER2long(&pSD->message_Nbr, &lv); LDEBUG("message_Nbr: %u", lv); for (int j = 0; j < pSD->message_serialIDs.list.count; j++) { LDEBUG("message_serialIDs: [%d]", j); pSid = (OCTET_STRING_t *)pSD->message_serialIDs.list.array[j]; LDEBUG("serialIDs: %.*s", pSid->size, pSid->buf); } } #endif }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyScheduledDisplayMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL) { result = -23; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -24; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyScheduledDisplayMessage, &Msg); } break; case OBJ_DownloadGraphicData: /* ±×·¡Çȵ¥ÀÌÅÍ ´Ù¿î·Îµå */ { LINFO(" *** OBJ_DownloadGraphicData"); DownloadGraphicDataMessage_t *pDGD; MessageBodyDownloadGraphicDataMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyDownloadGraphicDataMessage_t)); for ( i = 0; i < 1; i++) { if ((pDGD = (DownloadGraphicDataMessage_t *)ASN1C_Alloc(sizeof(DownloadGraphicDataMessage_t))) == NULL) { result = -30; break; } if ((result = DownloadGraphicData(pDGD, Arg)) != VERR_NONE) { SERROR("DownloadGraphicData result %d", result); result = -31; break; } if (ASN_SEQUENCE_ADD(&Msg, pDGD)!= ASN_ERR_NONE) { result = -32; break; } #if 0 { LDEBUG("[%d]", i); LDEBUG("download_GraphicData_ID: %.*s", pDGD->download_GraphicData_ID.size, pDGD->download_GraphicData_ID.buf); LDEBUG("download_GraphicData:"); //m_Log->WriteHex(LOG_DEBUG, (BYTE *)pDGD->download_GraphicData.buf, pDGD->download_GraphicData.size); } #endif }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyDownloadGraphicDataMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL) { result = -33; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -34; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyDownloadGraphicDataMessage, &Msg); } break; case OBJ_StatusControl: /* »óÅÂÁ¦¾î */ { LINFO(" *** OBJ_StatusControl"); StatusControlMessage_t *pSC; MessageBodyStatusControlMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyStatusControlMessage_t)); for ( i = 0; i < 1; i++) { if ((pSC = (StatusControlMessage_t *)ASN1C_Alloc(sizeof(StatusControlMessage_t))) == NULL) { result = -40; break; } if ((result = StatusControlData(pSC, Arg)) != SYS_ERR_NONE) { SERROR("StatusControlData result %d", result); result = -41; break; } if (ASN_SEQUENCE_ADD(&Msg, pSC)!= ASN_ERR_NONE) { result = -42; break; } #if 0 { long lv; //LDEBUG("[%d]", i); asn_INTEGER2long(&pSC->modulePower_ControlCode, &lv); LDEBUG(" modulePower_ControlCode: %u", lv); asn_INTEGER2long(&pSC->luminance_ControlCode, &lv); LDEBUG(" luminance_ControlCode: %u", lv); asn_INTEGER2long(&pSC->fan_ControlCode, &lv); LDEBUG(" fan_ControlCode: %u", lv); asn_INTEGER2long(&pSC->heater_ControlCode, &lv); LDEBUG(" heater_ControlCode: %u", lv); if (pSC->externalLight_ControlCode) { asn_INTEGER2long(pSC->externalLight_ControlCode, &lv); LDEBUG("externalLight_ControlCode: %u", lv); } if (pSC->alarmLight_ControlCode) { asn_INTEGER2long(pSC->alarmLight_ControlCode, &lv); LDEBUG(" alarmLight_ControlCode: %u", lv); } if (pSC->speaker_ControlCode) { asn_INTEGER2long(pSC->speaker_ControlCode, &lv); LDEBUG(" speaker_ControlCode: %u", lv); } if (pSC->controller_Reset) { LDEBUG(" controller_Reset: %d", *pSC->controller_Reset); } if (pSC->controllerTime_Reset) { LDEBUG(" controllerTime_Reset: %.*s", pSC->controllerTime_Reset->size, pSC->controllerTime_Reset->buf); } } #endif }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyStatusControlMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL) { result = -43; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -44; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyStatusControlMessage, &Msg); } break; case OBJ_StatusSetting: /* »óż³Á¤ */ { LINFO(" *** OBJ_StatusSetting"); StatusSettingMessage_t *pSS; MessageBodyStatusSettingMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyStatusSettingMessage_t)); for ( i = 0; i < 1; i++) { if ((pSS = (StatusSettingMessage_t *)ASN1C_Alloc(sizeof(StatusSettingMessage_t))) == NULL) { result = -50; break; } if ((result = StatusSettingData(pSS, Arg)) != SYS_ERR_NONE) { SERROR("StatusSettingData result: %d", result); result = -51; break; } if (ASN_SEQUENCE_ADD(&Msg, pSS)!= ASN_ERR_NONE) { result = -52; break; } #if 0 { long lv; //LDEBUG("[%d]", i); asn_INTEGER2long(&pSS->scheduledMessage_OperatingTimeQty, &lv); LDEBUG(" scheduledMessage_OperatingTimeQty: %u", lv); asn_INTEGER2long(&pSS->module_OperatingTemperatureQty, &lv); LDEBUG(" module_OperatingTemperatureQty: %u", lv); asn_INTEGER2long(&pSS->fan_OperatingTemperatureQty, &lv); LDEBUG(" fan_OperatingTemperatureQty: %u", lv); asn_INTEGER2long(&pSS->heater_OperatingTemperatureQty, &lv); LDEBUG(" heater_OperatingTemperatureQty: %u", lv); if (pSS->externalLight_OperatingLuminanceQty) { asn_INTEGER2long(pSS->externalLight_OperatingLuminanceQty, &lv); LDEBUG("externalLight_OperatingLuminanceQty: %u", lv); } if (pSS->module_BasicFailureRate) { asn_INTEGER2long(pSS->module_BasicFailureRate, &lv); LDEBUG(" module_BasicFailureRate: %u", lv); } if (pSS->maximum_RetryQty) { asn_INTEGER2long(pSS->maximum_RetryQty, &lv); LDEBUG(" maximum_RetryQty: %u", lv); } if (pSS->response_TimeOutQty) { asn_INTEGER2long(pSS->response_TimeOutQty, &lv); LDEBUG(" response_TimeOutQty: %u", lv); } if (pSS->blinking_CycleTime) { asn_INTEGER2long(pSS->blinking_CycleTime, &lv); LDEBUG(" blinking_CycleTime: %u", lv); } } #endif }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyStatusSettingMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL) { result = -53; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -54; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyStatusSettingMessage, &Msg); } break; default: result = SYS_ERR_UNKNOWN_MESSAGE_ID; SERROR(" *** Unknown CommandPublicationData"); break; } return result; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::RecvFormDownResult(AnsiString AImageId) { if (AImageId.SubString(1,1) == "6" || AImageId.SubString(1,1) == "7" || AImageId.SubString(1,1) == "8" ) return VERR_NONE; AnsiString sImgId = AImageId; AnsiString sTmpId = AImageId.SubString(3,2); int nFormIdx; int nResult = VERR_NONE; COMMAND_ARGUMENT arg; BYTE CmdCode; //LINFO("FORM_IMAGE_ID: %s", AImageId.c_str()); CmdCode = 0x00; memset(&arg, 0x00, sizeof(arg)); memset(&FSvrCtl, 0x00, sizeof(FSvrCtl)); #if 0 if (FVmsObj->CTLMODE->Control == 'B') { sTmpId = AImageId.SubString(4,1); if (sTmpId == 'A') nFormIdx = 10; else if (sTmpId == 'B') nFormIdx = 11; else if (sTmpId == 'C') nFormIdx = 12; else if (sTmpId == 'D') nFormIdx = 13; else if (sTmpId == 'E') nFormIdx = 14; else if (sTmpId == 'F') nFormIdx = 15; else nFormIdx = sTmpId.ToIntDef(0); } else #endif { nFormIdx = sTmpId.ToIntDef(0); } m_pVmsFormList->Lock(); try { try { int nFormCnt = m_pVmsFormList->Count(); #if 0 if ((nFormCnt-1) == nFormIdx) { arg.Publication.SubscribeSerialNbr = NBR_BASE_SCHEDULEDDISPLAY; //arg.Publication.SubscribeSerialNbr = 50; arg.Publication.obj = OBJ_ScheduledDisplay; FSvrCtl.obj = OBJ_ScheduledDisplay; FSvrCtl.DataPacketNumber = m_DataPacketNumber; CmdCode = AI_ScheduledDisplayMessage; } else #endif if (nFormIdx < nFormCnt) { TVmsForm *pVmsForm = m_pVmsFormList->GetItem(nFormIdx); if (pVmsForm) { pVmsForm->FtpRes = true; if (pVmsForm->SvcRes == false) { arg.Publication.SubscribeSerialNbr = NBR_BASE_REALTIMEDISPLAY + nFormIdx; //arg.Publication.SubscribeSerialNbr = 49; arg.Publication.obj = OBJ_RealTimeDisplay; arg.Publication.Data.Form.Idx = nFormIdx; sprintf(arg.Publication.szFormId, "%s", sImgId.c_str()); FSvrCtl.obj = OBJ_RealTimeDisplay; FSvrCtl.DataPacketNumber = m_DataPacketNumber; FSvrCtl.Idx = nFormIdx; CmdCode = AI_RealTimeDisplayMessage; } } else { LERROR("Not found vms form: %s, %d", VMSID.c_str(), nFormIdx); } } arg.Publication.Data.Form.Mode = FVmsObj->CTLMODE->Control; } catch(Exception &e) { } } __finally { m_pVmsFormList->UnLock(); if (nResult == VERR_NONE && CmdCode != 0x00) { nResult = ProcessCommand(CmdCode, &arg); } } return nResult; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::RealTimeDisplayData(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg) { //BBBBBBB TVmsForm *pVmsForm = NULL; TVmsFormObj *pVmsObj = NULL; Object_t *pObj = NULL; AnsiString MessageId; char Utf8Buf[256+1]; int ii; bool bException = false; try { m_pVmsFormList->Lock(); pVmsForm = m_pVmsFormList->GetItem(Arg.Data.Form.Idx); if (!pVmsForm) { SERROR("FormId Memory Not Found: %d", Arg.Data.Form.Idx); return SYS_ERR_NONE; } if (Arg.Data.Form.Mode == 'B') //±âº»¿î¿µ¸ðµå { if (FVmsObj->FIsOldProtocol) MessageId.sprintf("%d", pVmsForm->ScenarioSeq); else MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq); } else { MessageId.sprintf("%d", pVmsForm->ScenarioSeq); } //LINFO("REALTIME: %s", MessageId.c_str()); if (OCTET_STRING_fromString(&pRTD->message_serialID, MessageId.c_str()) != ASN_ERR_NONE){ return -1; } if (asn_long2INTEGER(&pRTD->display_DurationQty, pVmsForm->DisplayTime) != ASN_ERR_NONE){ return -2; } if (asn_long2INTEGER(&pRTD->display_ModeCode, pVmsForm->DisplayMode.ToIntDef(0)) != ASN_ERR_NONE){ return -3; } if (asn_long2INTEGER(&pRTD->display_DirectionCode, pVmsForm->DisplayDir.ToIntDef(0)) != ASN_ERR_NONE){ return -4; } if (asn_long2INTEGER(&pRTD->background_ColorCode, pVmsForm->BkColor) != ASN_ERR_NONE){ return -5; } int nObjCnt = pVmsForm->Count(); if (asn_long2INTEGER(&pRTD->object_Nbr, nObjCnt) != ASN_ERR_NONE){ return -6; } for (ii = 0; ii < nObjCnt; ii++) { pVmsObj = pVmsForm->GetItem(ii); if ((pObj = (Object_t *)ASN1C_Alloc(sizeof(Object_t))) == NULL){ return -10; } #if 0 if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){ return -11; } #endif if (asn_long2INTEGER(&pObj->blinking_Code, pVmsObj->IsBlinking) != ASN_ERR_NONE){ return -12; } if (asn_long2INTEGER(&pObj->x_Coordinate, pVmsObj->PosX) != ASN_ERR_NONE){ return -13; } if (asn_long2INTEGER(&pObj->y_Coordinate, pVmsObj->PosY) != ASN_ERR_NONE){ return -14; } if (asn_long2INTEGER(&pObj->data_BackgroundColor, pVmsObj->BkColor) != ASN_ERR_NONE){ return -15; } switch(pVmsObj->ObjectKind) { case text_object_data: pObj->object_Data.present = ObjectData_PR_text_object_data; if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){ return -11; } if (asn_long2INTEGER(&pObj->object_Data.choice.text_object_data.font_ColorCode, pVmsObj->TextFontColor) != ASN_ERR_NONE){ return -100; } if (asn_long2INTEGER(&pObj->object_Data.choice.text_object_data.font_Size, pVmsObj->TextFontSize) != ASN_ERR_NONE){ return -101; } if (FVmsObj->FIsProtolFontName) { if (OCTET_STRING_fromString(&pObj->object_Data.choice.text_object_data.font_TypeCode, pVmsObj->StrTextFontName.c_str()) != ASN_ERR_NONE){ return -102; } } else { if (OCTET_STRING_fromString(&pObj->object_Data.choice.text_object_data.font_TypeCode, AnsiString(pVmsObj->TextFontName).c_str()) != ASN_ERR_NONE){ return -102; } } if (asn_long2INTEGER(&pObj->object_Data.choice.text_object_data.font_Thickness, pVmsObj->TextFontBold) != ASN_ERR_NONE){ return -103; } Hangul2UTF8String(pVmsObj->TextData.c_str(), Utf8Buf, sizeof(Utf8Buf)); if (OCTET_STRING_fromString(&pObj->object_Data.choice.text_object_data.text_Data, Utf8Buf) != ASN_ERR_NONE) { return -104; } break; case graphic_object_data: pObj->object_Data.present = ObjectData_PR_graphic_object_data; if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){ return -11; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, pVmsObj->ImageType.ToIntDef(0)) != ASN_ERR_NONE){ return -200; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsObj->Width) != ASN_ERR_NONE){ return -201; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsObj->Height) != ASN_ERR_NONE){ return -202; } try { pVmsObj->pImageStream->Position = 0; if (OCTET_STRING_fromBuf(&pObj->object_Data.choice.graphic_object_data.graphic_Data, (char *)pVmsObj->pImageStream->Memory, pVmsObj->pImageStream->Size) != ASN_ERR_NONE){ return -203; } } catch(Exception &e) { bException = true; SERROR("MemoryStream Allocation error: %s, FormId: %s", AnsiString(e.Message).c_str(), pVmsForm->FormId.c_str()); } break; case graphicID_object_data: if (FVmsObj->FIsOldProtocol) { pObj->object_Data.present = ObjectData_PR_graphicID_object_data; if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){ return -11; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphicID_object_data.graphic_Type, pVmsObj->ImageType.ToIntDef(0)) != ASN_ERR_NONE){ return -300; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphicID_object_data.graphic_Width, pVmsObj->Width) != ASN_ERR_NONE){ return -301; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphicID_object_data.graphic_Height, pVmsObj->Height) != ASN_ERR_NONE){ return -302; } AnsiString sFtpImgId = GetFtpImageId(pVmsObj->ImageId); //if (OCTET_STRING_fromString(&pObj->object_Data.choice.graphicID_object_data.graphic_DataID, pVmsObj->ImageId.c_str()) != ASN_ERR_NONE){ if (OCTET_STRING_fromString(&pObj->object_Data.choice.graphicID_object_data.graphic_DataID, sFtpImgId.c_str()) != ASN_ERR_NONE){ return -303; } } else { pObj->object_Data.present = ObjectData_PR_graphic_object_data; if (asn_long2INTEGER(&pObj->object_TypeCode, graphic_object_data) != ASN_ERR_NONE){ return -11; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, pVmsObj->ImageType.ToIntDef(0)) != ASN_ERR_NONE){ return -200; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsObj->Width) != ASN_ERR_NONE){ return -201; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsObj->Height) != ASN_ERR_NONE){ return -202; } try { pVmsObj->pImageStream->Position = 0; if (OCTET_STRING_fromBuf(&pObj->object_Data.choice.graphic_object_data.graphic_Data, (char *)pVmsObj->pImageStream->Memory, pVmsObj->pImageStream->Size) != ASN_ERR_NONE){ return -203; } } catch(Exception &e) { bException = true; SERROR("MemoryStream Allocation error: %s, FormId: %s", AnsiString(e.Message).c_str(), pVmsForm->FormId.c_str()); } } break; } //switch if (ASN_SEQUENCE_ADD(&pRTD->objects_zz, pObj)!= ASN_ERR_NONE) { return -16; } } //for } __finally { m_pVmsFormList->UnLock(); if (bException) { SERROR("LockFree OK"); } } return SYS_ERR_NONE; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::RealTimeDisplayBitmap(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg) { /* ¸ðµç VMS¸¦ À̹ÌÁö·Î ´Ù¿î·Îµå ÇÏ´Â °æ¿ìÀÓ ÀÌÀü VMSµµ FTP¸¦ ÀÌ¿ëÇÏ´Â °æ¿ì(µµÇü½Ä) À̰ųª ¹®ÀÚ½Ä À̰ųª ¸ðµÎ FTP·Î ´Ù¿î·Îµå ÇÔ */ int result; if (FVmsObj->FIsOldProtocol) { result = RealTimeDisplayBitmapOld(pRTD, Arg); } else { result = RealTimeDisplayBitmapNew(pRTD, Arg); } return result; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::RealTimeDisplayBitmapOld(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg) { TVmsForm *pVmsForm = NULL; Object_t *pObj = NULL; AnsiString ImageId; AnsiString MessageId; int ii; bool bException = false; ImageId = String(Arg.szFormId); try { m_pVmsFormList->Lock(); pVmsForm = m_pVmsFormList->GetItem(Arg.Data.Form.Idx); if (!pVmsForm) { SERROR("FormId Memory Not Found: %d", Arg.Data.Form.Idx); return SYS_ERR_NONE; } if (Arg.Data.Form.Mode == 'B') //±âº»¿î¿µ¸ðµå { if (FVmsObj->FIsOldProtocol) MessageId.sprintf("%d", pVmsForm->ScenarioSeq); else MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq); } else { MessageId.sprintf("%d", pVmsForm->ScenarioSeq); } //LINFO("BMP_REALTIME(OLD): %s", MessageId.c_str()); if (OCTET_STRING_fromString(&pRTD->message_serialID, MessageId.c_str()) != ASN_ERR_NONE){ return -1; } if (asn_long2INTEGER(&pRTD->display_DurationQty, pVmsForm->DisplayTime) != ASN_ERR_NONE){ return -2; } if (asn_long2INTEGER(&pRTD->display_ModeCode, pVmsForm->DisplayMode.ToIntDef(0)) != ASN_ERR_NONE){ return -3; } if (asn_long2INTEGER(&pRTD->display_DirectionCode, pVmsForm->DisplayDir.ToIntDef(0)) != ASN_ERR_NONE){ return -4; } if (asn_long2INTEGER(&pRTD->background_ColorCode, pVmsForm->BkColor) != ASN_ERR_NONE){ return -5; } if (asn_long2INTEGER(&pRTD->object_Nbr, 1) != ASN_ERR_NONE){ return -6; } //À̹ÌÁö °´Ã¼ Á¤º¸ »ý¼º if ((pObj = (Object_t *)ASN1C_Alloc(sizeof(Object_t))) == NULL){ return -10; } if (asn_long2INTEGER(&pObj->object_TypeCode, object_TypeCode_graphic_id_object) != ASN_ERR_NONE){ return -11; } int IsBlinking = 0; if (asn_long2INTEGER(&pObj->blinking_Code, blinking_Code_off) != ASN_ERR_NONE){ return -12; } if (asn_long2INTEGER(&pObj->x_Coordinate, 0) != ASN_ERR_NONE){ return -13; } if (asn_long2INTEGER(&pObj->y_Coordinate, 0) != ASN_ERR_NONE){ return -14; } int BkColor = 0; if (asn_long2INTEGER(&pObj->data_BackgroundColor, color_black) != ASN_ERR_NONE){ return -15; } //À̹ÌÁöIDµ¥ÀÌÅÍ pObj->object_Data.present = ObjectData_PR_graphicID_object_data; if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, graphic_Type_bitmap) != ASN_ERR_NONE){ return -200; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsForm->Width) != ASN_ERR_NONE){ return -201; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsForm->Height) != ASN_ERR_NONE){ return -202; } if (OCTET_STRING_fromString(&pObj->object_Data.choice.graphicID_object_data.graphic_DataID, ImageId.c_str()) != ASN_ERR_NONE){ return -303; } FErrLine = 33; if (ASN_SEQUENCE_ADD(&pRTD->objects_zz, pObj)!= ASN_ERR_NONE) { return -16; } } __finally { FErrLine = 34; m_pVmsFormList->UnLock(); if (bException) { SERROR("LockFree OK"); } } return SYS_ERR_NONE; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::RealTimeDisplayBitmapNew(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg) { TVmsForm *pVmsForm = NULL; Object_t *pObj = NULL; AnsiString MessageId; int ii; bool bException = false; try { m_pVmsFormList->Lock(); pVmsForm = m_pVmsFormList->GetItem(Arg.Data.Form.Idx); if (!pVmsForm) { SERROR("FormId Memory Not Found: %d", Arg.Data.Form.Idx); return SYS_ERR_NONE; } if (Arg.Data.Form.Mode == 'B') //±âº»¿î¿µ¸ðµå { if (FVmsObj->FIsOldProtocol) MessageId.sprintf("%d", pVmsForm->ScenarioSeq); else MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq); } else { MessageId.sprintf("%d", pVmsForm->ScenarioSeq); } //LINFO("BMP_REALTIME(NEW): %s", MessageId.c_str()); if (OCTET_STRING_fromString(&pRTD->message_serialID, MessageId.c_str()) != ASN_ERR_NONE){ return -1; } if (asn_long2INTEGER(&pRTD->display_DurationQty, pVmsForm->DisplayTime) != ASN_ERR_NONE){ return -2; } if (asn_long2INTEGER(&pRTD->display_ModeCode, pVmsForm->DisplayMode.ToIntDef(0)) != ASN_ERR_NONE){ return -3; } if (asn_long2INTEGER(&pRTD->display_DirectionCode, pVmsForm->DisplayDir.ToIntDef(0)) != ASN_ERR_NONE){ return -4; } if (asn_long2INTEGER(&pRTD->background_ColorCode, pVmsForm->BkColor) != ASN_ERR_NONE){ return -5; } if (asn_long2INTEGER(&pRTD->object_Nbr, 1) != ASN_ERR_NONE){ return -6; } //À̹ÌÁö °´Ã¼ Á¤º¸ »ý¼º if ((pObj = (Object_t *)ASN1C_Alloc(sizeof(Object_t))) == NULL){ return -10; } if (asn_long2INTEGER(&pObj->object_TypeCode, object_TypeCode_graphic_object) != ASN_ERR_NONE){ return -11; } int IsBlinking = 0; if (asn_long2INTEGER(&pObj->blinking_Code, blinking_Code_off) != ASN_ERR_NONE){ return -12; } if (asn_long2INTEGER(&pObj->x_Coordinate, 0) != ASN_ERR_NONE){ return -13; } if (asn_long2INTEGER(&pObj->y_Coordinate, 0) != ASN_ERR_NONE){ return -14; } int BkColor = 0; if (asn_long2INTEGER(&pObj->data_BackgroundColor, color_black) != ASN_ERR_NONE){ return -15; } //À̹ÌÁöµ¥ÀÌÅÍ pObj->object_Data.present = ObjectData_PR_graphic_object_data; if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, graphic_Type_bitmap) != ASN_ERR_NONE){ return -200; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsForm->Width) != ASN_ERR_NONE){ return -201; } if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsForm->Height) != ASN_ERR_NONE){ return -202; } try { pVmsForm->pStream->Position = 0; if (OCTET_STRING_fromBuf(&pObj->object_Data.choice.graphic_object_data.graphic_Data, (char *)pVmsForm->pStream->Memory, pVmsForm->pStream->Size) != ASN_ERR_NONE){ return -203; } } catch(Exception &e) { bException = true; SERROR("MemoryStream Allocation error: %s, FormId: %s", AnsiString(e.Message).c_str(), pVmsForm->FormId.c_str()); } if (ASN_SEQUENCE_ADD(&pRTD->objects_zz, pObj)!= ASN_ERR_NONE) { return -16; } } __finally { m_pVmsFormList->UnLock(); if (bException) { SERROR("LockFree OK"); } } return SYS_ERR_NONE; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::ScheduledDisplayData(ScheduledDisplayMessage_t *pSD, PUBLICATION_ARGUMENT Arg) { //AAAAAAAAAA FErrLine = 15; OCTET_STRING_t *pSid; AnsiString MessageId; int ii; try { m_pVmsFormList->Lock(); int nFormCnt = m_pVmsFormList->Count(); if (asn_long2INTEGER(&pSD->message_Nbr, nFormCnt) != ASN_ERR_NONE) { return -1; } for (ii = 0; ii < nFormCnt; ii++) { TVmsForm *pVmsForm = m_pVmsFormList->GetItem(ii); if (!pVmsForm) continue; if (Arg.Data.Form.Mode == 'B') { if (FVmsObj->FIsOldProtocol) MessageId.sprintf("%d", pVmsForm->ScenarioSeq); else MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq); } else { MessageId.sprintf("%d", pVmsForm->ScenarioSeq); } //LINFO("SCHEDULE: %s", MessageId.c_str()); if ((pSid = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t))) == NULL) { return -10; } if (OCTET_STRING_fromString(pSid, MessageId.c_str()) != ASN_ERR_NONE) { return -11; } if (ASN_SEQUENCE_ADD(&pSD->message_serialIDs, pSid)!= ASN_ERR_NONE) { return -12; } } } __finally { m_pVmsFormList->UnLock(); } return SYS_ERR_NONE; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::DownloadGraphicData(DownloadGraphicDataMessage_t *pDGD, PUBLICATION_ARGUMENT Arg) { FErrLine = 16; AnsiString sNmbr = FVmsObj->DOWNLOAD->Unit[Arg.Data.Down.Idx].FileId; TCDSImage *pVmsImage = ImageManager->FLists.Find(sNmbr+"0"); if (!pVmsImage) return -10; TMemoryStream *pStream = new TMemoryStream; try { if (OCTET_STRING_fromString(&pDGD->download_GraphicData_ID, sNmbr.c_str()) != ASN_ERR_NONE) { return -1; } pStream->Clear(); pStream->Position = 0; pVmsImage->pImage->Canvas->Lock(); pVmsImage->pImage->Picture->Graphic->SaveToStream(pStream); pVmsImage->pImage->Canvas->Unlock(); pStream->Position = 0; if (OCTET_STRING_fromBuf(&pDGD->download_GraphicData, (char *)pStream->Memory, pStream->Size) != ASN_ERR_NONE) { return -2; } } __finally { SAFE_DELETE(pStream); } return VERR_NONE; } //--------------------------------------------------------------------------- /* * ¼Û½Å ÆÐŶ »ý¼º * arguments * void * return * void */ int __fastcall TVMSSThread::StatusControlData(StatusControlMessage_t *pSC, PUBLICATION_ARGUMENT Arg) { FErrLine = 17; int modulePower; int luminance = 0; #if 0 //TODO if (m_pState->Comm == vms_normal) { luminance = (int)m_pState->LuminanceStatus; } #endif if (Arg.Data.Ctl == CTL_MODULE_POWER_ON) { modulePower = modulePower_ControlCode_on; } else if (Arg.Data.Ctl == CTL_MODULE_POWER_OFF) { modulePower = modulePower_ControlCode_off; } else if (Arg.Data.Ctl == CTL_CONTROLLER_RESET) { modulePower = modulePower_ControlCode_on; } else if (Arg.Data.Ctl == CTL_LUMINANCE_SET) { modulePower = modulePower_ControlCode_on; luminance = (int)FCliCtl.CtlType; } else { return -1; } if (asn_long2INTEGER(&pSC->modulePower_ControlCode, modulePower) != ASN_ERR_NONE) { return -2; } #if 1 if (asn_long2INTEGER(&pSC->luminance_ControlCode, luminance) != ASN_ERR_NONE) { return -3; } #else if (asn_long2INTEGER(&pSC->luminance_ControlCode, 0) != ASN_ERR_NONE) { return -3; } #endif if (asn_long2INTEGER(&pSC->fan_ControlCode, fan_ControlCode_auto) != ASN_ERR_NONE) { return -4; } if (asn_long2INTEGER(&pSC->heater_ControlCode, heater_ControlCode_auto) != ASN_ERR_NONE) { return -5; } pSC->externalLight_ControlCode = NULL; pSC->alarmLight_ControlCode = NULL; pSC->speaker_ControlCode = NULL; if (Arg.Data.Ctl == CTL_CONTROLLER_RESET) { if ((pSC->controller_Reset = (BOOLEAN_t *)ASN1C_Alloc(sizeof(BOOLEAN_t))) == NULL) { return -6; } *pSC->controller_Reset = true; } else { if ((pSC->controller_Reset = (BOOLEAN_t *)ASN1C_Alloc(sizeof(BOOLEAN_t))) == NULL) { return -6; } *pSC->controller_Reset = false; //pSC->controller_Reset = NULL; } pSC->controllerTime_Reset = NULL; return SYS_ERR_NONE; } //--------------------------------------------------------------------------- /* * ¼Û½Å ÆÐŶ »ý¼º * arguments * void * return * void */ int __fastcall TVMSSThread::StatusSettingData(StatusSettingMessage_t *pSS, PUBLICATION_ARGUMENT Arg) { FErrLine = 18; //INTEGER_t scheduledMessage_OperatingTimeQty; //INTEGER_t module_OperatingTemperatureQty; //INTEGER_t fan_OperatingTemperatureQty; //INTEGER_t heater_OperatingTemperatureQty; INTEGER_t *externalLight_OperatingLuminanceQty /* OPTIONAL */; //INTEGER_t *module_BasicFailureRate /* OPTIONAL */; //INTEGER_t *maximum_RetryQty /* OPTIONAL */; //INTEGER_t *response_TimeOutQty /* OPTIONAL */; INTEGER_t *blinking_CycleTime /* OPTIONAL */; if(asn_long2INTEGER(&pSS->scheduledMessage_OperatingTimeQty, Arg.Data.Set.SchMsgTime) != ASN_ERR_NONE) { return -1; } if(asn_long2INTEGER(&pSS->module_OperatingTemperatureQty, Arg.Data.Set.ModuleTemp) != ASN_ERR_NONE) { return -2; } if(asn_long2INTEGER(&pSS->fan_OperatingTemperatureQty, Arg.Data.Set.FanTemp) != ASN_ERR_NONE) { return -3; } if(asn_long2INTEGER(&pSS->heater_OperatingTemperatureQty, Arg.Data.Set.HeaterTemp) != ASN_ERR_NONE) { return -4; } pSS->externalLight_OperatingLuminanceQty = NULL; if ((pSS->module_BasicFailureRate = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL) { return -5; } if(asn_long2INTEGER(pSS->module_BasicFailureRate, Arg.Data.Set.ModuleFail) != ASN_ERR_NONE) { return -6; } if ((pSS->maximum_RetryQty = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL) { return -7; } if(asn_long2INTEGER(pSS->maximum_RetryQty, Arg.Data.Set.RetryCount) != ASN_ERR_NONE) { return -8; } if ((pSS->response_TimeOutQty = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL) { return -9; } if(asn_long2INTEGER(pSS->response_TimeOutQty, Arg.Data.Set.TimeOut) != ASN_ERR_NONE) { return -10; } if (FVmsObj->FIsOldProtocol) { if ((pSS->blinking_CycleTime = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL) { return -5; } if(asn_long2INTEGER(pSS->blinking_CycleTime, 5) != ASN_ERR_NONE) { return -6; } } else { pSS->blinking_CycleTime = NULL; } return SYS_ERR_NONE; } //--------------------------------------------------------------------------- /* * ¼­¹ö ó¸® ·çƾ * arguments * void * return * void */ void __fastcall TVMSSThread::ServerStateMachine(void) { FErrLine = 19; int result; bool flag; result = SYS_ERR_NONE; //timeout check if (m_RxLen && (CommUtil_TimeDiff(m_rTimer) > m_Server.TimeOut)) { m_RxLen = 0; ProcErrorState(TRUE, SYS_ERR_RECEIVE_TIMEOUT); return; } #if 0 { switch (m_Server.State) { #if 0 case ST_IDLE: LDEBUG("IDLE"); break; case ST_INITIATE: LDEBUG("INITIATE"); break; case ST_SECTION: LDEBUG("SECTION"); break; case ST_CLOSE: LDEBUG("CLOSE"); break; #endif case ST_LOCAL_COMMAND: LDEBUG("LOCAL_COMMAND"); break; case ST_CLIENT_COMMAND: LDEBUG("CLIENT_COMMAND"); break; case ST_LOCAL_WAIT: LDEBUG("LOCAL_WAIT"); break; case ST_CLIENT_WAIT: LDEBUG("CLIENT_WAIT"); break; default: LDEBUG("Unknown State[%d]", m_Server.State); break; } } #endif switch(m_Server.State) { case ST_IDLE: if (CommUtil_TimeDiff(m_Server.sTimer) > SERVER_CONNECT_RETRY_TIME) { m_Server.sTimer = Now(); if (m_Server.iRetry <= 0) { m_Server.State = ST_CLOSE; } else { m_Server.State = ST_INITIATE; } } break; case ST_INITIATE: if ((result = ProcessCommand(AI_Initiate, NULL)) == SYS_ERR_NONE) { m_Server.State = ST_IDLE; m_Server.iRetry = 0; } else { if (--m_Server.iRetry <= 0) { m_Server.State = ST_CLOSE; } } break; case ST_SECTION: if (CommUtil_TimeDiff(m_WatchDogTimer) > FWatchDogTime) { SERROR("WatchDogTime over"); /* Åë½Å offline Á¾·á ó¸® */ m_Server.State = ST_CLOSE; break; } /* ·¹Áö½ºÅÍ Á¤º¸ üũ */ CheckRegistered(); break; case ST_CLOSE: #if 0 arg.Terminate = Logout_serverShutdown; ProcessCommand(AI_Terminate, &arg); #endif Terminate(); break; case ST_LOCAL_COMMAND: result = CheckLocalData(&flag); if (flag) { if (result == VERR_NONE) { m_Server.State = ST_LOCAL_WAIT; } else { if (--m_Server.iRetry <= 0) { m_Server.State = ST_CLOSE; } } } else { m_Server.State = ST_CLIENT_COMMAND; } break; case ST_CLIENT_COMMAND: result = CheckClientData(&flag); if (flag) { if (result == VERR_NONE) { m_Server.State = ST_CLIENT_WAIT; } else { if (--m_Server.iRetry <= 0) { m_Server.State = ST_CLOSE; } } } else { m_Server.State = ST_SECTION; } break; case ST_LOCAL_WAIT: if (CommUtil_TimeDiff(m_Server.cTimer) > m_Server.TimeOut) { if (m_Server.iRetry > 0){ m_Server.State = ST_LOCAL_COMMAND; }else{ m_Server.State = ST_CLOSE; } } break; case ST_CLIENT_WAIT: if (CommUtil_TimeDiff(m_Server.cTimer) > m_Server.TimeOut) { if (m_Server.iRetry > 0) { ClientResponse(SYS_ERR_NO_RES); m_Server.State = ST_CLIENT_COMMAND; } else { m_Server.State = ST_CLOSE; } } break; default: m_Server.State = ST_IDLE; break; }/* end switch */ if (result) { ProcErrorState(FALSE, result); } } //--------------------------------------------------------------------------- /* * ¿¡·¯ ó¸® * arguments * void * return * void */ void __fastcall TVMSSThread::ProcErrorState(bool flag, int result) { FErrLine = 20; #if 1 { AnsiString strLog; switch(result) { case SYS_ERR_NONE: strLog.sprintf("no error [%d]", result); break; case SYS_ERR_OTHER: strLog.sprintf("other [%d]", result); break; case SYS_ERR_INTERNAL: strLog.sprintf("internal system error(kernel..) [%d]", result); break; case SYS_ERR_MEMORY: strLog.sprintf("memory overflow [%d]", result); break; case SYS_ERR_DATABASE: strLog.sprintf("system database error [%d]", result); break; case SYS_ERR_RESET: strLog.sprintf("system reset [%d]", result); break; case SYS_ERR_START: strLog.sprintf("system start [%d]", result); break; case SYS_ERR_OFFLINE: strLog.sprintf("offline [%d]", result); break; case SYS_ERR_NO_RES: strLog.sprintf("no response [%d]", result); break; case SYS_ERR_ACCESS: strLog.sprintf("access denied [%d]", result); break; case SYS_ERR_INVALID: strLog.sprintf("invalid data type [%d]", result); break; case SYS_ERR_UNKNOWN: strLog.sprintf("unknown data type [%d]", result); break; case SYS_ERR_WRITE_LENGTH: strLog.sprintf("write length [%d]", result); break; case SYS_ERR_PACKET_SIZE_LARGE: strLog.sprintf("packet size large [%d]", result); break; case SYS_ERR_INVALID_TAG: strLog.sprintf("invalid tag [%d]", result); break; case SYS_ERR_CRC: strLog.sprintf("crc [%d]", result); break; case SYS_ERR_LENGTH: strLog.sprintf("length [%d]", result); break; case SYS_ERR_ADDRESS: strLog.sprintf("address [%d]", result); break; case SYS_ERR_HEADER_OPTIONS: strLog.sprintf("header options [%d]", result); break; case SYS_ERR_UNKNOWN_COMMAND: strLog.sprintf("unknown command [%d]", result); break; case SYS_ERR_RECEIVE_TIMEOUT: strLog.sprintf("receive timeout [%d]", result); break; case SYS_ERR_DATA_SIZE: strLog.sprintf("data size [%d]", result); break; case SYS_ERR_MISMATCH: strLog.sprintf("mismatch command [%d]", result); break; case SYS_ERR_INVALID_PARA: strLog.sprintf("invalid parameter [%d]", result); break; case SYS_ERR_MOVEMENT: strLog.sprintf("movement [%d]", result); break; case SYS_ERR_UNAUTHORIZED: strLog.sprintf("unauthorized [%d]", result); break; case SYS_ERR_DATEXDATAPACKET_DECODE: strLog.sprintf("DatexDataPacket decode [%d]", result); break; case SYS_ERR_INVALID_VERSION_NUMBER: strLog.sprintf("invalid version number [%d]", result); break; case SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE: strLog.sprintf("C2CAuthenticatedMessage decode [%d]", result); break; case SYS_ERR_C2CAUTHENTICATEDMESSAGE: strLog.sprintf("C2CAuthenticatedMessage [%d]", result); break; case SYS_ERR_NOT_LOGIN: strLog.sprintf("Not login [%d]", result); break; case SYS_ERR_ACCEPT_TYPE: strLog.sprintf("Accept Type [%d]", result); break; case SYS_ERR_DATEXPUBLISH_FORMAT: strLog.sprintf("datexPublish Format [%d]", result); break; case SYS_ERR_DATEXPUBLISH_TYPE: strLog.sprintf("datexPublish Type [%d]", result); break; case SYS_ERR_UNKNOWN_MESSAGE_ID: strLog.sprintf("unknown Message id [%d]", result); break; case SYS_ERR_MESSAGE_DECODE: strLog.sprintf("Message decode [%d]", result); break; case SYS_ERR_DATEXDATAPACKET_ENCODE: strLog.sprintf("DatexDataPacket encode [%d]", result); break; case SYS_ERR_C2CAUTHENTICATEDMESSAGE_ENCODE: strLog.sprintf("C2CAuthenticatedMessage encode [%d]", result); break; case SYS_ERR_MESSAGE_ENCODE: strLog.sprintf("Message encode [%d]", result); break; case SYS_ERR_PUBLICATIONDATA_ENCODE: strLog.sprintf("PublicationData encode [%d]", result); break; case SYS_ERR_MISMATCH_DESTINATION_TEXT: strLog.sprintf("mismatch Destination text [%d]", result); break; case SYS_ERR_DATEXLOGIN_VALUE: strLog.sprintf("Login Value [%d]", result); break; case SYS_ERR_SUBSCRIPTION_TYPE: strLog.sprintf("SubscriptionType Type [%d]", result); break; case SYS_ERR_SUBSCRIPTION_STATUS_VALUE: strLog.sprintf("SubscriptionType Status Value [%d]", result); break; case SYS_ERR_SUBSCRIPTION_MODE_VALUE: strLog.sprintf("SubscriptionType Mode Value [%d]", result); break; case SYS_ERR_SUBSCRIPTION_FORMAT_VALUE: strLog.sprintf("SubscriptionType Format Value [%d]", result); break; case SYS_ERR_HANGUL_CONVERSION: strLog.sprintf("Hangul Conversion [%d]", result); break; case SYS_ERR_INVALID_TAGANDLEN: strLog.sprintf("invalid Tag And Len [%d]", result); break; case SYS_ERR_PUBLICATIONDATA_DECODE: strLog.sprintf("PublicationData decode [%d]", result); break; default: strLog.sprintf("Unknown Error [%d]", result); break; } if (flag){ SERROR("Recv Error %s", strLog.c_str()); }else{ SERROR("Send Error %s", strLog.c_str()); } } #endif } //--------------------------------------------------------------------------- /* * »óÅ º¯°æ * arguments * void * return * void */ void __fastcall TVMSSThread::SetServerState(int Case) { FErrLine = 21; switch(m_Server.State) { case ST_LOCAL_WAIT: if (Case == SET_SERVER_SUCC) { m_Server.State = ST_CLIENT_COMMAND; } else if (Case == SET_SERVER_FAIL) { m_Server.State = ST_LOCAL_COMMAND; } break; case ST_CLIENT_WAIT: if (Case == SET_SERVER_SUCC) { m_Server.State = ST_SECTION; } else if (Case == SET_SERVER_FAIL) { m_Server.State = ST_CLIENT_COMMAND; } break; default: break; } } //--------------------------------------------------------------------------- /* * * arguments * void * return * void */ int __fastcall TVMSSThread::CheckRegistered() { FErrLine = 22; int result; result = SYS_ERR_NONE; m_Server.State = ST_LOCAL_COMMAND; return result; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::CheckLocalData(bool *AFlag) { FErrLine = 23; int nResult = VERR_NONE; COMMAND_ARGUMENT arg; BYTE CmdCode; *AFlag = false; CmdCode = 0x00; memset(&arg, 0x00, sizeof(arg)); memset(&FSvrCtl, 0x00, sizeof(FSvrCtl)); #if 0 #if 0 if (m_Registered.RealTimeDisplayMessage == false) { LINFO("**** RealTimeDisplayMessage ¿äû"); arg.Publication.SubscribeSerialNbr = NBR_REALTIME_DISPLAY_REQ; arg.Publication.obj = OBJ_DisplayingData; arg.Publication.Data.Ctl = CTL_REALTIMEDISPLAY_REQ; CmdCode = AI_DisplayingDataMessage; nResult = ProcessCommand(CmdCode, &arg); *AFlag = true; return nResult; } #endif if (m_Registered.ScreenDataStatusMessage == false) { LINFO("**** ScreenDataStatusMessage ¿äû"); arg.Publication.SubscribeSerialNbr = NBR_SCREEN_STATUS_REQ; arg.Publication.obj = OBJ_ScreenStatus; arg.Publication.Data.Ctl = CTL_SCREENSTATUS_REQ; CmdCode = AI_ScreenStatusMessage; nResult = ProcessCommand(CmdCode, &arg); *AFlag = true; return nResult; } #endif /* FORM */ if (FVmsObj->CTLMODE->Enable == object_enable) { m_pVmsFormList->Lock(); try { //pObj->FBmpDownload, Bitmap Àü¼Û¿©ºÎ¿Í »ó°ü¾øÀÌ //FTP´Ù¿î·Îµå°¡ ÇÊ¿äÇÑ °æ¿ìÀÓ... if (FVmsObj->FIsFtpDownload) { int nFormCnt = m_pVmsFormList->Count(); for (int ii = 0; ii < nFormCnt; ii++) { TVmsForm *pVmsForm = m_pVmsFormList->GetItem(ii); if (pVmsForm) { if (pVmsForm->FtpRes == false) { arg.Publication.SubscribeSerialNbr = NBR_BASE_REALTIMEDISPLAY + ii; arg.Publication.obj = OBJ_RealTimeDisplay; arg.Publication.Data.Form.Idx = ii; if (FVmsObj->CTLMODE->Control == 'B') //±âº»¿î¿µ¸ðµå { if (FVmsObj->FIsOldProtocol) sprintf(arg.Publication.szFormId, "%s%02d", FVmsObj->VmsDownId.c_str(), ii); else sprintf(arg.Publication.szFormId, "%s9%d", FVmsObj->VmsDownId.c_str(), ii); } else { sprintf(arg.Publication.szFormId, "%s%02d", FVmsObj->VmsDownId.c_str(), ii); } FSvrCtl.obj = OBJ_RealTimeDisplay; FSvrCtl.DataPacketNumber = m_DataPacketNumber; FSvrCtl.Idx = ii; CmdCode = AI_TransferDone; break; } } } if (CmdCode == 0x00) { arg.Publication.SubscribeSerialNbr = NBR_BASE_SCHEDULEDDISPLAY; arg.Publication.obj = OBJ_ScheduledDisplay; FSvrCtl.obj = OBJ_ScheduledDisplay; FSvrCtl.DataPacketNumber = m_DataPacketNumber; CmdCode = AI_ScheduledDisplayMessage; } arg.Publication.Data.Form.Mode = FVmsObj->CTLMODE->Control; } else { int nFormCnt = m_pVmsFormList->Count(); for (int ii = 0; ii < nFormCnt; ii++) { TVmsForm *pVmsForm = m_pVmsFormList->GetItem(ii); if (pVmsForm) { if (pVmsForm->SvcRes == false) { arg.Publication.SubscribeSerialNbr = NBR_BASE_REALTIMEDISPLAY + ii; arg.Publication.obj = OBJ_RealTimeDisplay; arg.Publication.Data.Form.Idx = ii; FSvrCtl.obj = OBJ_RealTimeDisplay; FSvrCtl.DataPacketNumber = m_DataPacketNumber; FSvrCtl.Idx = ii; CmdCode = AI_RealTimeDisplayMessage; break; } } } if (CmdCode == 0x00) { arg.Publication.SubscribeSerialNbr = NBR_BASE_SCHEDULEDDISPLAY; arg.Publication.obj = OBJ_ScheduledDisplay; FSvrCtl.obj = OBJ_ScheduledDisplay; FSvrCtl.DataPacketNumber = m_DataPacketNumber; CmdCode = AI_ScheduledDisplayMessage; } arg.Publication.Data.Form.Mode = FVmsObj->CTLMODE->Control; } } __finally { m_pVmsFormList->UnLock(); if (nResult == VERR_NONE && CmdCode != 0x00) { nResult = ProcessCommand(CmdCode, &arg); } *AFlag = true; } } /* ON/OFF */ if (FVmsObj->MODULE.PowerOnTime != FVmsObj->MODULE.PowerOffTime) { //On/Off ½Ã°¢ÀÌ °°Áö ¾ÊÀ» °æ¿ì On/Off ¸í·É ¼öÇà if ((FVmsObj->MODULE.PowerOnTime == Now().FormatString("yyyymmddhhnn")) && (FVmsObj->MODULE.Retry > 0)) { arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER; arg.Publication.obj = OBJ_StatusControl; arg.Publication.Data.Ctl = CTL_MODULE_POWER_ON; CmdCode = AI_StatusControlMessage; nResult = ProcessCommand(CmdCode, &arg); if (nResult == SYS_ERR_NONE) { } LINFO("**** Module Power On: %d", FVmsObj->MODULE.Retry); --FVmsObj->MODULE.Retry; // 3ȸ Àü¼Û *AFlag = true; return nResult; } if ((FVmsObj->MODULE.PowerOffTime == Now().FormatString("yyyymmddhhnn")) && (FVmsObj->MODULE.Retry > 0)) { arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER; arg.Publication.obj = OBJ_StatusControl; arg.Publication.Data.Ctl = CTL_MODULE_POWER_OFF; CmdCode = AI_StatusControlMessage; nResult = ProcessCommand(CmdCode, &arg); if (nResult == SYS_ERR_NONE) { } LINFO("**** Module Power Off: %d", FVmsObj->MODULE.Retry); --FVmsObj->MODULE.Retry; // 3ȸ Àü¼Û *AFlag = true; return nResult; } } /* LUMINANCE */ //LUMINANCE½Ã°¢ÀÌ °°À» °æ¿ì LUMINANCE ¸í·É ¼öÇà if ((FVmsObj->LUMINANCE.SchTime == Now().FormatString("yyyymmddhhnn")) && (FVmsObj->LUMINANCE.Retry > 0)) { arg.Publication.SubscribeSerialNbr = NBR_LUMINANCE; arg.Publication.obj = OBJ_StatusControl; arg.Publication.Data.Ctl = CTL_LUMINANCE_SET; FCliCtl.CtlType = FVmsObj->LUMINANCE.Value; CmdCode = AI_StatusControlMessage; nResult = ProcessCommand(CmdCode, &arg); if (nResult == SYS_ERR_NONE) { } LINFO("**** Luminance control: %d", FVmsObj->LUMINANCE.Retry); --FVmsObj->LUMINANCE.Retry; // 3ȸ Àü¼Û *AFlag = true; return nResult; } /* DOWNLOAD */ if (FVmsObj->DOWNLOAD->Enable == vms_download_enable) { for (int ii = 0; ii < FVmsObj->DOWNLOAD->Count; ii++) { if (FVmsObj->DOWNLOAD->Unit[ii].SendResult == vms_download_fail) { arg.Publication.SubscribeSerialNbr = NBR_BASE_DOWNLOADGRAPHICDATA + ii; arg.Publication.obj = OBJ_DownloadGraphicData; arg.Publication.Data.Down.Idx = ii; FSvrCtl.obj = OBJ_DownloadGraphicData; FSvrCtl.DataPacketNumber = m_DataPacketNumber; FSvrCtl.Idx = ii; CmdCode = AI_DownloadGraphicDataMessage; break; } } if ((nResult == VERR_NONE) && (CmdCode != 0x00)) { nResult = ProcessCommand(CmdCode, &arg); if (nResult == SYS_ERR_NONE) { } *AFlag = true; return nResult; } } return nResult; } //--------------------------------------------------------------------------- /* * * arguments * void * return * void */ int __fastcall TVMSSThread::CheckClientData(bool *AFlag) { FErrLine = 24; int nResult = VERR_NONE; IPCUDPPACKET *pPI = NULL; TList *pPackQueue; COMMAND_ARGUMENT arg; BYTE CmdCode; *AFlag = false; pPackQueue = FVmsObj->pPackQueue->LockList(); try { for (int ii = 0; ii < pPackQueue->Count; ii++) { pPI = (IPCUDPPACKET *)pPackQueue->Items[ii]; memcpy((char*)&FCliReq, pPI, sizeof(FCliReq)); memset((char*)&FCliCtl, 0x00, sizeof(FCliCtl)); memset((char*)&arg, 0x00, sizeof(arg)); switch(pPI->OPCode) { case INT_OP_VMS_POWER_CTL: if (pPI->Data) { INT_VMS_POWER_CTL_REQ *pReq = (INT_VMS_POWER_CTL_REQ*)pPI->Data; memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID); memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID); memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME); FCliCtl.Result = CTL_RESULT_FAIL; if (pReq->Command == vms_board_power_on) { arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER; arg.Publication.obj = OBJ_StatusControl; arg.Publication.Data.Ctl = CTL_MODULE_POWER_ON; FCliCtl.CtlType = CTL_TYPE_MODULE_ON; CmdCode = AI_StatusControlMessage; } else if (pReq->Command == vms_board_power_off) { arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER; arg.Publication.obj = OBJ_StatusControl; arg.Publication.Data.Ctl = CTL_MODULE_POWER_OFF; FCliCtl.CtlType = CTL_TYPE_MODULE_OFF; CmdCode = AI_StatusControlMessage; } else { nResult = VERR_UNKNOWN; break; } } else { nResult = VERR_DATA_SIZE; } break; case INT_OP_VMS_LUMINANCE_CTL: if (pPI->Data) { INT_VMS_LUMINANCE_REQ *pReq = (INT_VMS_LUMINANCE_REQ*)pPI->Data; memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID); memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID); memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME); FCliCtl.Result = CTL_RESULT_FAIL; arg.Publication.SubscribeSerialNbr = NBR_LUMINANCE; arg.Publication.obj = OBJ_StatusControl; arg.Publication.Data.Ctl = CTL_LUMINANCE_SET; FCliCtl.CtlType = pReq->Luminance; CmdCode = AI_StatusControlMessage; } else { nResult = VERR_DATA_SIZE; } break; case INT_OP_VMS_RESET: if (pPI->Data) { INT_VMS_RESET_REQ *pReq = (INT_VMS_RESET_REQ*)pPI->Data; memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID); memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID); memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME); FCliCtl.Result = CTL_RESULT_FAIL; arg.Publication.SubscribeSerialNbr = NBR_CONTROLLER_RESET; arg.Publication.obj = OBJ_StatusControl; arg.Publication.Data.Ctl = CTL_CONTROLLER_RESET; FCliCtl.CtlType = CTL_TYPE_RESET; CmdCode = AI_StatusControlMessage; } else { nResult = VERR_DATA_SIZE; } break; case INT_OP_VMS_PARA_SET: if (pPI->Data) { INT_VMS_PARA_SET_REQ *pReq = (INT_VMS_PARA_SET_REQ*)pPI->Data; memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID); memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID); memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME); FCliCtl.Result = CTL_RESULT_FAIL; arg.Publication.SubscribeSerialNbr = NBR_STATUS_SETTING; arg.Publication.obj = OBJ_StatusSetting; arg.Publication.Data.Set.SchMsgTime = (int)pReq->SchMsgTime; arg.Publication.Data.Set.ModuleTemp = (int)pReq->ModuleTemp; arg.Publication.Data.Set.FanTemp = (int)pReq->FanTemp; arg.Publication.Data.Set.HeaterTemp = (int)pReq->HeaterTemp; arg.Publication.Data.Set.ModuleFail = (int)pReq->ModuleFail; arg.Publication.Data.Set.RetryCount = (int)pReq->RetryCount; arg.Publication.Data.Set.TimeOut = (int)pReq->TimeOut; FCliCtl.Data.Para.SchMsgTime = (int)pReq->SchMsgTime; FCliCtl.Data.Para.ModuleTemp = (int)pReq->ModuleTemp; FCliCtl.Data.Para.FanTemp = (int)pReq->FanTemp; FCliCtl.Data.Para.HeaterTemp = (int)pReq->HeaterTemp; FCliCtl.Data.Para.ModuleFail = (int)pReq->ModuleFail; FCliCtl.Data.Para.RetryCount = (int)pReq->RetryCount; FCliCtl.Data.Para.TimeOut = (int)pReq->TimeOut; FCliCtl.CtlType = CTL_TYPE_PARA_SET; CmdCode = AI_StatusSettingMessage; } else { nResult = VERR_DATA_SIZE; } break; default: nResult = VERR_UNKNOWN_COMMAND; break; } if (nResult == VERR_NONE) { nResult = ProcessCommand(CmdCode, &arg); } //ClientResponse(nResult); if (pPI->Size > 0) { delete []pPI->Data; } delete pPI; pPI = NULL; pPackQueue->Delete(ii); *AFlag = true; break; } } __finally { FVmsObj->pPackQueue->UnlockList(); } return nResult; } //--------------------------------------------------------------------------- int TVMSSThread::LogData(char *ASndRcv, BYTE *AData, int ALen) { int result = -1; if (!FLogFile) return result; if (!FLogFile->FLogCfg.Data) return result; try { FLogFile->LogData(ASndRcv, AData, ALen); if (FVmsObj->FDispLog) { IPC_LOG_MESSAGE *pLog = &FLogMsg;//new IPC_LOG_MESSAGE; if (pLog) { pLog->Kind = eLOG_DATA; pLog->Flag = ASndRcv[0] == 'S' ? 1 : 2; pLog->Len = ALen > MAX_LOG_BUFFER ? MAX_LOG_BUFFER-1 : ALen; pLog->Tm = Now(); pLog->Type = 'S'; memset(pLog->Msg, 0x00, sizeof(pLog->Msg)); memcpy(pLog->Msg, (char*)AData, pLog->Len); pLog->Obj = (void*)FVmsObj; DWORD dwResult = 0; LRESULT lResult = SEND_LOGMSG(FrmVmsLog->Handle, WM_LOG_DISPLAY, (WPARAM)pLog, NULL, SMTO_NORMAL, 2000, dwResult); if (lResult == 0) { dwResult = GetLastError(); if (dwResult == ERROR_TIMEOUT) { } //SAFE_DELETE(pLog); } } } } catch(Exception &e) { } return result; } //--------------------------------------------------------------------------- int TVMSSThread::SysLogWrite(int ALogKind, char *AFmt, ...) { va_list ap; int cnt = 0; char szFmtData[MAX_LOG_BUFFER]; AnsiString sLogKind; int nStep = 0; if (!FLogFile) return cnt; bool bLog = false; switch(ALogKind) { case eLOG_INFO : bLog = FLogFile->FLogCfg.Info; sLogKind = " [INF] "; break; case eLOG_DATA : bLog = FLogFile->FLogCfg.Data; sLogKind = " [DAT] "; break; case eLOG_ERROR : bLog = FLogFile->FLogCfg.Error; sLogKind = " [ERR] "; break; case eLOG_WARNING: bLog = FLogFile->FLogCfg.Warning; sLogKind = " [WAN] "; break; case eLOG_DEBUG : bLog = FLogFile->FLogCfg.Debug; sLogKind = " [DBG] "; break; case eLOG_DETAIL : bLog = FLogFile->FLogCfg.Detail; sLogKind = " [DET] "; break; } if (!bLog) return -1; try { va_start(ap, AFmt); cnt = vsprintf(szFmtData, AFmt, ap); va_end(ap); FLogFile->LogWrite(NULL, ALogKind, szFmtData); IPC_LOG_MESSAGE *pLog = &FLogMsg;//new IPC_LOG_MESSAGE; if (pLog) { pLog->Kind = ALogKind; pLog->Flag = 0; pLog->Len = strlen(szFmtData); pLog->Tm = Now(); pLog->Type = 'S'; memset(pLog->Msg, 0x00, sizeof(pLog->Msg)); sprintf(pLog->Msg, "%s+SVR %s, %s", sLogKind.c_str(), VMSID.c_str(), szFmtData); pLog->Obj = (void*)FVmsObj; DWORD dwResult = 0; LRESULT lResult = SEND_LOGMSG(FrmSysLog->Handle, WM_LOG_DISPLAY, pLog, NULL, SMTO_NORMAL, 2000, dwResult); if (lResult == 0) { dwResult = GetLastError(); if (dwResult == ERROR_TIMEOUT) { } //SAFE_DELETE(pLog); } } if (FVmsObj->FDispLog) { IPC_LOG_MESSAGE *pLog2 = &FLogMsg;//new IPC_LOG_MESSAGE; if (pLog2) { pLog2->Kind = ALogKind; pLog2->Flag = 0; pLog2->Len = strlen(szFmtData); pLog2->Tm = Now(); pLog2->Type = 'S'; memset(pLog2->Msg, 0x00, sizeof(pLog2->Msg)); sprintf(pLog2->Msg, "%s+SVR %s, %s", sLogKind.c_str(), VMSID.c_str(), szFmtData); pLog2->Obj = (void*)FVmsObj; DWORD dwResult = 0; LRESULT lResult = SEND_LOGMSG(FrmVmsLog->Handle, WM_LOG_DISPLAY, pLog2, NULL, SMTO_NORMAL, 2000, dwResult); if (lResult == 0) { dwResult = GetLastError(); if (dwResult == ERROR_TIMEOUT) { } //SAFE_DELETE(pLog2); } } } } catch(Exception &e) { } return cnt; } //--------------------------------------------------------------------------- int TVMSSThread::LogWrite(int ALogKind, char *AFmt, ...) { va_list ap; int cnt = 0; char szFmtData[MAX_LOG_BUFFER]; AnsiString sLogKind; int nStep = 0; if (!FLogFile) return cnt; bool bLog = false; switch(ALogKind) { case eLOG_INFO : bLog = FLogFile->FLogCfg.Info; sLogKind = " [INF] "; break; case eLOG_DATA : bLog = FLogFile->FLogCfg.Data; sLogKind = " [DAT] "; break; case eLOG_ERROR : bLog = FLogFile->FLogCfg.Error; sLogKind = " [ERR] "; break; case eLOG_WARNING: bLog = FLogFile->FLogCfg.Warning; sLogKind = " [WAN] "; break; case eLOG_DEBUG : bLog = FLogFile->FLogCfg.Debug; sLogKind = " [DBG] "; break; case eLOG_DETAIL : bLog = FLogFile->FLogCfg.Detail; sLogKind = " [DET] "; break; } if (!bLog) return -1; try { va_start(ap, AFmt); cnt = vsprintf(szFmtData, AFmt, ap); va_end(ap); FLogFile->LogWrite(NULL, ALogKind, szFmtData); if (FVmsObj->FDispLog) { IPC_LOG_MESSAGE *pLog = &FLogMsg;//new IPC_LOG_MESSAGE; if (pLog) { pLog->Kind = ALogKind; pLog->Flag = 0; pLog->Len = strlen(szFmtData); pLog->Tm = Now(); pLog->Type = 'S'; memset(pLog->Msg, 0x00, sizeof(pLog->Msg)); sprintf(pLog->Msg, "%s+SVR %s, %s", sLogKind.c_str(), VMSID.c_str(), szFmtData); pLog->Obj = (void*)FVmsObj; DWORD dwResult = 0; LRESULT lResult = SEND_LOGMSG(FrmVmsLog->Handle, WM_LOG_DISPLAY, pLog, NULL, SMTO_NORMAL, 2000, dwResult); if (lResult == 0) { dwResult = GetLastError(); if (dwResult == ERROR_TIMEOUT) { } //SAFE_DELETE(pLog); } } } } catch(Exception &e) { } return cnt; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::CommandSubscription(Subscription_t *pSubscripiton, SUBSCRIPTION_ARGUMENT Arg) { FErrLine = 12; int result; SubscriptionData_t *pData; asn_enc_rval_t er; /* Encoder return value */ BYTE MsgBuf[SERVER_MSG_BUF_SIZE]; int eLen; int i, count = 0; result = SYS_ERR_OTHER; if (asn_long2INTEGER(&pSubscripiton->datexSubscribe_Serial_nbr, Arg.nbr) != ASN_ERR_NONE) { return -1; } pSubscripiton->datexSubscribe_Type.present = SubscriptionType_PR_subscription; pData = &pSubscripiton->datexSubscribe_Type.choice.subscription; pData->datexSubscribe_Persistent_bool = false; if (asn_long2INTEGER(&pData->datexSubscribe_Status_cd, datexSubscribe_Status_cd_new) != ASN_ERR_NONE) { return -3; } switch(Arg.mode) { case SubscriptionMode_PR_single: pData->datexSubscribe_Mode.present = SubscriptionMode_PR_single; break; case SubscriptionMode_PR_event_driven: pData->datexSubscribe_Mode.present = SubscriptionMode_PR_event_driven; /* Registered_PR_continuous 1 */ /* Registered_PR_daily 2 */ pData->datexSubscribe_Mode.choice.event_driven.present = Registered_PR_continuous; pData->datexSubscribe_Mode.choice.event_driven.choice.continuous.datexRegistered_UpdateDelay_qty = Arg.delay; /* pData->datexSubscribe_Mode.choice.event_driven.choice.continuous.datexRegistered_StartTime */ /* pData->datexSubscribe_Mode.choice.event_driven.choice.continuous.datexRegistered_EndTime */ break; case SubscriptionMode_PR_periodic: pData->datexSubscribe_Mode.present = SubscriptionMode_PR_periodic; /* Registered_PR_continuous 1 */ /* Registered_PR_daily 2 */ pData->datexSubscribe_Mode.choice.periodic.present = Registered_PR_continuous; pData->datexSubscribe_Mode.choice.periodic.choice.continuous.datexRegistered_UpdateDelay_qty = Arg.delay; /* pData->datexSubscribe_Mode.choice.periodic.choice.continuous.datexRegistered_StartTime */ /* pData->datexSubscribe_Mode.choice.periodic.choice.continuous.datexRegistered_EndTime */ break; default: pData->datexSubscribe_Mode.present = SubscriptionMode_PR_single; break; } if (asn_long2INTEGER(&pData->datexSubscribe_PublishFormat_cd, datexSubscribe_PublishFormat_cd_dataPacket) != ASN_ERR_NONE) { return -4; } pData->datexSubscription_Priority_nbr = 1; pData->datexSubscribe_Guarantee_bool = true; #if 0 { long lv; asn_INTEGER2long(&pSubscripiton->datexSubscribe_Serial_nbr, &lv); LDEBUG(" SubscriptionMode: %d", Arg.mode); LDEBUG("datexSubscribe_Serial_nbr: %u", lv); LDEBUG(" datexSubscribe_Type: %d", pSubscripiton->datexSubscribe_Type.present); switch(pSubscripiton->datexSubscribe_Type.present) { case SubscriptionType_PR_subscription: asn_INTEGER2long(&pData->datexSubscribe_Status_cd, &lv); LDEBUG("datexSubscribe_Persistent_bool: %d", pData->datexSubscribe_Persistent_bool); LDEBUG(" datexSubscribe_Status_cd: %d", lv); LDEBUG(" datexSubscribe_Mode: %d", pData->datexSubscribe_Mode.present); switch(pData->datexSubscribe_Mode.present) { case SubscriptionMode_PR_single: break; case SubscriptionMode_PR_event_driven: case SubscriptionMode_PR_periodic: { Registered_t *pRegistered; int numbits, bit; if(pData->datexSubscribe_Mode.present == SubscriptionMode_PR_event_driven) { pRegistered = &pData->datexSubscribe_Mode.choice.event_driven; } else { pRegistered = &pData->datexSubscribe_Mode.choice.periodic; } LDEBUG("Registered: %d", pRegistered->present); switch(pRegistered->present) { case Registered_PR_continuous: LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.continuous.datexRegistered_UpdateDelay_qty); if (pRegistered->choice.continuous.datexRegistered_StartTime) { LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_StartTime); } if (pRegistered->choice.continuous.datexRegistered_EndTime) { LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_EndTime); } break; case Registered_PR_daily: LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.daily.datexRegistered_UpdateDelay_qty); numbits = DATEX_NUMBITS(pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd); LDEBUG("datexRegistered_DaysOfWeek_cd numbits: %d", numbits); for (bit = 0; bit < numbits; bit++) { LDEBUG("[%d]: %d", bit, ASN1C_CheckBitString(&pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd, bit)); } if (pRegistered->choice.daily.datexRegistered_StartDate) { LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartDate); } if (pRegistered->choice.daily.datexRegistered_EndDate) { LOG_WriteTime(pRegistered->choice.daily.datexRegistered_EndDate); } if (pRegistered->choice.daily.datexRegistered_StartTime) { LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartTime); } if (pRegistered->choice.daily.datexRegistered_Duration_qty) { //LDEBUG("datexRegistered_Duration_qty: %u", *pRegistered->choice.daily.datexRegistered_Duration_qty); } break; default: LDEBUG("Unknown Registered %d", pRegistered->present); break; }/* end swtich */ } break; default : LDEBUG("Unknown datexSubscribe_Mode %d", pData->datexSubscribe_Mode.present); break; }/* end switch */ asn_INTEGER2long(&pData->datexSubscribe_PublishFormat_cd, &lv); LDEBUG("datexSubscribe_PublishFormat_cd: %d", lv); LDEBUG(" datexSubscription_Priority_nbr: %d", pData->datexSubscription_Priority_nbr); LDEBUG(" datexSubscribe_Guarantee_bool: %d", pData->datexSubscribe_Guarantee_bool); break; case SubscriptionType_PR_datexSubscribe_CancelReason_cd: LDEBUG("datexSubscribe_CancelReason_cd: %d", pSubscripiton->datexSubscribe_Type.choice.datexSubscribe_CancelReason_cd); break; default: LDEBUG("Unknown datexSubscribe_Type %d", pSubscripiton->datexSubscribe_Type.present); break; }/* end switch */ } #endif ASN1C_SetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id, Arg.obj); switch(Arg.obj) { case OBJ_GeneralStatus: /* ±âº»»óÅÂÁ¤º¸ */ { LINFO(" *** OBJ_GeneralStatus Àü¼Û"); GeneralStatusMessage_t *pGS; MessageBodyGeneralStatusMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyGeneralStatusMessage_t)); for ( i = 0; i < count; i++) { if ((pGS = (GeneralStatusMessage_t *)ASN1C_Alloc(sizeof(GeneralStatusMessage_t))) == NULL) { result = -10; break; } if(ASN_SEQUENCE_ADD(&Msg, pGS)!= ASN_ERR_NONE) { result = -11; break; } }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyGeneralStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL) { result = -12; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -13; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyGeneralStatusMessage, &Msg); } break; #if 1 case OBJ_PowerStatus: /* Àü¿ø»óÅÂÁ¤º¸ */ { LINFO(" *** OBJ_PowerStatus Àü¼Û"); PowerStatusMessage_t *pMS; MessageBodyPowerStatusMessage_t Msg; memset((void *)&Msg, 0x00, sizeof(MessageBodyPowerStatusMessage_t)); for ( i = 0; i < count; i++) { if ((pMS = (PowerStatusMessage_t *)ASN1C_Alloc(sizeof(PowerStatusMessage_t))) == NULL) { result = -30; break; } if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE) { result = -31; break; } }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyPowerStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL) { result = -32; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -33; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyPowerStatusMessage, &Msg); } break; #endif case OBJ_ModuleStatus: /* ¸ðµâ»óÅÂÁ¤º¸ */ { LINFO(" *** OBJ_ModuleStatus Àü¼Û"); ModuleStatusMessage_t *pMS; MessageBodyModuleStatusMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyModuleStatusMessage_t)); for ( i = 0; i < count; i++) { if ((pMS = (ModuleStatusMessage_t *)ASN1C_Alloc(sizeof(ModuleStatusMessage_t))) == NULL) { result = -30; break; } if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE) { result = -31; break; } }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyModuleStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL) { result = -32; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -33; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyModuleStatusMessage, &Msg); } break; #if 0 case OBJ_DotStatus: /* µµÆ®»óÅÂÁ¤º¸ */ break; #endif case OBJ_ScreenStatus: /* Ç¥Ãâ»óÅÂÁ¤º¸ */ { LINFO(" *** OBJ_ScreenStatus Àü¼Û"); ScreenStatusMessage_t *pMS; MessageBodyScreenStatusMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyScreenStatusMessage_t)); for ( i = 0; i < count; i++) { if ((pMS = (ScreenStatusMessage_t *)ASN1C_Alloc(sizeof(ScreenStatusMessage_t))) == NULL) { result = -30; break; } if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE) { result = -31; break; } }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyScreenStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL) { result = -32; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -33; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyScreenStatusMessage, &Msg); } break; case OBJ_DisplayingData: /* Ç¥ÃâÁ¤º¸ */ { LINFO(" *** OBJ_DisplayingData Àü¼Û"); DisplayingDataMessage_t *pMS; MessageBodyDisplayingDataMessage_t Msg; /* Type to encode */ memset((void *)&Msg, 0x00, sizeof(MessageBodyDisplayingDataMessage_t)); for ( i = 0; i < count; i++) { if ((pMS = (DisplayingDataMessage_t *)ASN1C_Alloc(sizeof(DisplayingDataMessage_t))) == NULL) { result = -30; break; } if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE) { result = -31; break; } }/* end for */ /* Encode */ memset(MsgBuf, 0x00, sizeof(MsgBuf)); eLen = -1; er = der_encode_to_buffer(&asn_DEF_MessageBodyDisplayingDataMessage, &Msg, MsgBuf, sizeof(MsgBuf)); if (er.encoded == -1) { /* * Failed to encode the data. */ SERROR("Cannot encode %s", er.failed_type->name); result = SYS_ERR_MESSAGE_ENCODE; } else { /* Return the number of bytes */ eLen = er.encoded; pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen); if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL) { result = -32; break; } if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg, (char *)MsgBuf, eLen) != ASN_ERR_NONE) { result = -33; break; } result = SYS_ERR_NONE; }/* end if */ ASN1C_FreeC(&asn_DEF_MessageBodyDisplayingDataMessage, &Msg); } break; default: result = SYS_ERR_UNKNOWN_MESSAGE_ID; break; } return result; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::SendLoginAccept() { TStringList *sl = NULL; //Data Dump: 104 Bytes String sMsg = "30 66 80 01 01 81 5D 30 5B 80 01 08 81 02 03 12 " "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 " "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 " "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 " "11 83 01 0D 84 01 08 85 01 19 A6 03 82 01 00 A7 " "06 80 01 09 81 01 00 A4 0B A8 09 80 01 01 A1 04 " "80 02 51 01 82 02 B3 EF "; try { sl = new TStringList; sl->Delimiter = ' '; sl->StrictDelimiter = true; sl->DelimitedText = sMsg; int ii; unsigned int hn, ln; BYTE chn, cln, val; char szData[2048]; BYTE RxBuff[VMS_MAX_PACKET_SIZE]; int RxLen; RxLen = 0; memset(RxBuff, 0x00, sizeof(RxBuff)); for (ii = 0; ii < sl->Count; ii++) { AnsiString sTemp = sl->Strings[ii]; if (sTemp.Trim() == "") continue; sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll); if (sTemp.Trim() == "\r\n") continue; memset(szData, 0x00, sizeof(szData)); memcpy(szData, sTemp.c_str(), sTemp.Length()); chn = (BYTE)szData[0]; cln = (BYTE)szData[1]; hn = chn > '9' ? chn - 'A' + 10 : chn - '0'; ln = cln > '9' ? cln - 'A' + 10 : cln - '0'; val = (BYTE)((hn << 4 ) | ln); RxBuff[RxLen] = val; RxLen++; } int nSends = pClientSocket->SendBuf(RxBuff, RxLen); LINFO("SendLoginAccept: %d/%d Bytes", RxLen, nSends); if (sl) delete sl; } catch(Exception &e) { //Application->ShowException(&e); } return SYS_ERR_NONE; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::SendSubscriptionAccept(int AMsgId) { TStringList *sl = NULL; String sMsg = ""; String sRealTimeDisplay = "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 14 " "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 " "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 " "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 " "11 83 01 0D 84 01 08 85 01 19 A6 03 82 01 00 A7 " "06 80 01 09 81 01 00 A4 0A A8 08 80 01 04 A1 03 " "82 01 01 82 02 90 6A "; String sScheduledDisplay = "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 15 " "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 " "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 " "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 " "11 83 01 0D 84 01 08 85 01 1A A6 03 82 01 00 A7 " "06 80 01 09 81 01 00 A4 0A A8 08 80 01 05 A1 03 " "82 01 02 82 02 D5 7F "; String sDownloadGraphicData = "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 16 " "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 " "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 " "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 " "11 83 01 0D 84 01 08 85 01 1A A6 03 82 01 00 A7 " "06 80 01 09 81 01 00 A4 0A A8 08 80 01 06 A1 03 " "82 01 03 82 02 19 5C "; String sStatusControl = "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 17 " "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 " "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 " "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 " "11 83 01 0D 84 01 08 85 01 1A A6 03 82 01 00 A7 " "06 80 01 09 81 01 00 A4 0A A8 08 80 01 07 A1 03 " "82 01 04 82 02 DF 43 "; String sStatusSetting = "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 18 " "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 " "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 " "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 " "11 83 01 0D 84 01 08 85 01 1B A6 03 82 01 00 A7 " "06 80 01 09 81 01 00 A4 0A A8 08 80 01 08 A1 03 " "82 01 05 82 02 DF 10 "; switch(AMsgId) { case OBJ_RealTimeDisplay: /* ½Ç½Ã°£Á¤º¸Ç¥Ãâ */ sMsg = sRealTimeDisplay; //arg.Accept.nbr = 4; //arg.Accept.sub = 1; break; case OBJ_ScheduledDisplay: /* °èȹµÈÁ¤º¸Ç¥Ãâ */ sMsg = sScheduledDisplay; //arg.Accept.nbr = 5; //arg.Accept.sub = 2; break; case OBJ_DownloadGraphicData: /* ±×·¡Çȵ¥ÀÌÅÍ ´Ù¿î·Îµå */ sMsg = sDownloadGraphicData; //arg.Accept.nbr = 6; //arg.Accept.sub = 3; break; case OBJ_StatusControl: /* »óÅÂÁ¦¾î */ sMsg = sStatusControl; //arg.Accept.nbr = 7; //arg.Accept.sub = 4; break; case OBJ_StatusSetting: /* »óż³Á¤ */ sMsg = sStatusSetting; //arg.Accept.nbr = 8; //arg.Accept.sub = 5; break; default: return SYS_ERR_OTHER; } try { sl = new TStringList; sl->Delimiter = ' '; sl->StrictDelimiter = true; sl->DelimitedText = sMsg; int ii; unsigned int hn, ln; BYTE chn, cln, val; char szData[2048]; BYTE RxBuff[VMS_MAX_PACKET_SIZE]; int RxLen; RxLen = 0; memset(RxBuff, 0x00, sizeof(RxBuff)); for (ii = 0; ii < sl->Count; ii++) { AnsiString sTemp = sl->Strings[ii]; if (sTemp.Trim() == "") continue; sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll); if (sTemp.Trim() == "\r\n") continue; memset(szData, 0x00, sizeof(szData)); memcpy(szData, sTemp.c_str(), sTemp.Length()); chn = (BYTE)szData[0]; cln = (BYTE)szData[1]; hn = chn > '9' ? chn - 'A' + 10 : chn - '0'; ln = cln > '9' ? cln - 'A' + 10 : cln - '0'; val = (BYTE)((hn << 4 ) | ln); RxBuff[RxLen] = val; RxLen++; } int nSends = pClientSocket->SendBuf(RxBuff, RxLen); LINFO("SendSubscriptionAccept: [%02X] %d/%d Bytes", AMsgId, RxLen, nSends); if (sl) delete sl; } catch(Exception &e) { //Application->ShowException(&e); } return SYS_ERR_NONE; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::SendRealTimeDisplay(int AIndex) { TStringList *sl = NULL; //Data Dump: 104 Bytes String sMsg = ""; if (AIndex == 0) sMsg = "30 82 02 CE 80 01 01 81 82 02 C3 30 82 02 BF 80 " "01 00 81 02 03 8A 82 01 00 A3 42 81 08 30 30 30 " "30 30 30 30 30 83 08 30 30 30 30 30 30 30 30 85 " "0A 56 4D 53 31 30 30 30 30 31 33 A7 20 80 02 07 " "E0 81 01 0B 82 01 11 83 01 0D 84 01 0A 85 01 0C " "A6 03 82 01 00 A7 06 80 01 09 81 01 00 A4 82 02 " "6D A6 82 02 69 80 01 FF A1 82 02 62 A0 82 02 5E " "30 82 02 5A 80 01 31 81 01 01 82 01 00 A3 82 02 " "4D A1 82 02 49 80 06 28 F3 6B 02 00 01 A1 82 02 " "3D 30 82 02 39 30 82 02 35 80 01 31 81 01 0A 82 " "01 00 83 01 00 84 01 00 85 01 0C A6 82 02 1F 30 " "23 80 01 02 81 01 00 82 02 00 80 83 01 08 84 01 " "00 A5 11 A2 0F 80 01 00 81 01 1D 82 01 0F 83 04 " "30 30 30 32 30 23 80 01 02 81 01 00 82 02 00 80 " "83 01 2A 84 01 00 A5 11 A2 0F 80 01 00 81 01 1D " "82 01 0F 83 04 30 30 30 32 30 23 80 01 02 81 01 " "00 82 02 01 63 83 01 23 84 01 00 A5 11 A2 0F 80 " "01 00 81 01 15 82 01 19 83 04 30 30 30 38 30 23 " "80 01 02 81 01 00 82 02 01 63 83 01 05 84 01 00 " "A5 11 A2 0F 80 01 00 81 01 15 82 01 19 83 04 30 " "30 30 35 30 32 80 01 00 81 01 00 82 02 00 A9 83 " "01 25 84 01 00 A5 20 A0 1E 80 01 03 81 01 11 82 " "06 B1 BC B8 B2 C3 BC 83 01 02 84 0B EA B8 88 EA " "B3 A1 49 43 EC 95 9E 30 35 80 01 00 81 01 00 82 " "01 02 83 01 25 84 01 00 A5 24 A0 22 80 01 03 81 " "01 11 82 06 B1 BC B8 B2 C3 BC 83 01 02 84 0F EA " "B5 AC EC 84 B1 EC 9D B4 EB A7 88 ED 8A B8 30 2D " "80 01 00 81 01 00 82 02 01 27 83 01 05 84 01 00 " "A5 1B A0 19 80 01 03 81 01 11 82 06 B1 BC B8 B2 " "C3 BC 83 01 02 84 06 EC A7 80 EC B2 B4 30 36 80 " "01 00 81 01 00 82 02 00 9D 83 01 03 84 01 00 A5 " "24 A0 22 80 01 02 81 01 11 82 06 B1 BC B8 B2 C3 " "BC 83 01 02 84 0F EC A3 BD EC A0 84 EC 82 AC EA " "B1 B0 EB A6 AC 30 35 80 01 00 81 01 00 82 01 02 " "83 01 03 84 01 00 A5 24 A0 22 80 01 02 81 01 11 " "82 06 B1 BC B8 B2 C3 BC 83 01 02 84 0F EB B3 B4 " "EC A0 95 EA B5 90 EC B0 A8 EB A1 9C 30 2A 80 01 " "00 81 01 00 82 02 01 4A 83 01 25 84 01 00 A5 18 " "A0 16 80 01 02 81 01 11 82 06 B1 BC B8 B2 C3 BC " "83 01 02 84 03 EB B6 84 30 2A 80 01 00 81 01 00 " "82 02 01 1C 83 01 25 84 01 00 A5 18 A0 16 80 01 " "02 81 01 11 82 06 B1 BC B8 B2 C3 BC 83 01 02 84 " "03 EC 95 BD 30 28 80 01 00 81 01 00 82 02 01 39 " "83 01 25 84 01 00 A5 16 A0 14 80 01 02 81 01 11 " "82 06 B1 BC B8 B2 C3 BC 83 01 02 84 01 35 82 02 " "C1 95 "; else sMsg = "30 82 01 8B 80 01 01 81 82 01 80 30 82 01 7C 80 " "01 00 81 02 03 8B 82 01 00 A3 42 81 08 30 30 30 " "30 30 30 30 30 83 08 30 30 30 30 30 30 30 30 85 " "0A 56 4D 53 31 30 30 30 30 31 33 A7 20 80 02 07 " "E0 81 01 0B 82 01 11 83 01 0D 84 01 0A 85 01 0C " "A6 03 82 01 00 A7 06 80 01 09 81 01 00 A4 82 01 " "2A A6 82 01 26 80 01 FF A1 82 01 1F A0 82 01 1B " "30 82 01 17 80 01 31 81 01 01 82 01 00 A3 82 01 " "0A A1 82 01 06 80 06 28 F3 6B 02 00 01 A1 81 FB " "30 81 F8 30 81 F5 80 01 32 81 01 04 82 01 00 83 " "01 00 84 01 00 85 01 04 A6 81 E0 30 3F 80 01 00 " "81 01 00 82 01 11 83 01 23 84 01 00 A5 2E A0 2C " "80 01 02 81 01 13 82 06 B1 BC B8 B2 C3 BC 83 01 " "02 84 19 28 32 30 31 36 2E 30 36 2E 31 33 20 7E " "20 32 30 31 37 2E 31 32 2E 33 31 29 30 30 80 01 " "00 81 01 00 82 02 01 27 83 01 05 84 01 00 A5 1E " "A0 1C 80 01 01 81 01 14 82 06 B1 BC B8 B2 C3 BC " "83 01 02 84 09 EA B3 B5 EC 82 AC EC A4 91 30 34 " "80 01 00 81 01 00 82 02 00 9B 83 01 05 84 01 00 " "A5 22 A0 20 80 01 03 81 01 14 82 06 B1 BC B8 B2 " "C3 BC 83 01 02 84 0D EB B2 8C EB A7 90 7E EB A7 " "A4 EC 86 A1 30 35 80 01 00 81 01 00 82 01 0A 83 " "01 05 84 01 00 A5 24 A0 22 80 01 02 81 01 13 82 " "06 B1 BC B8 B2 C3 BC 83 01 02 84 0F EB B6 84 EB " "8B B9 EC 88 98 EC 84 9C EB A1 9C 82 02 73 03 "; try { sl = new TStringList; sl->Delimiter = ' '; sl->StrictDelimiter = true; sl->DelimitedText = sMsg; int ii; unsigned int hn, ln; BYTE chn, cln, val; char szData[2048]; BYTE RxBuff[VMS_MAX_PACKET_SIZE]; int RxLen; RxLen = 0; memset(RxBuff, 0x00, sizeof(RxBuff)); for (ii = 0; ii < sl->Count; ii++) { AnsiString sTemp = sl->Strings[ii]; if (sTemp.Trim() == "") continue; sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll); if (sTemp.Trim() == "\r\n") continue; memset(szData, 0x00, sizeof(szData)); memcpy(szData, sTemp.c_str(), sTemp.Length()); chn = (BYTE)szData[0]; cln = (BYTE)szData[1]; hn = chn > '9' ? chn - 'A' + 10 : chn - '0'; ln = cln > '9' ? cln - 'A' + 10 : cln - '0'; val = (BYTE)((hn << 4 ) | ln); RxBuff[RxLen] = val; RxLen++; } int nSends = pClientSocket->SendBuf(RxBuff, RxLen); LINFO("SendRealTimeDisplay: %d/%d Bytes", RxLen, nSends); if (sl) delete sl; } catch(Exception &e) { //Application->ShowException(&e); } return SYS_ERR_NONE; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::SendScheduledDisplay() { TStringList *sl = NULL; //Data Dump: 104 Bytes String sMsg = "30 81 8E 80 01 01 81 81 84 30 81 81 80 01 00 81 " "02 03 8C 82 01 00 A3 42 81 08 30 30 30 30 30 30 " "30 30 83 08 30 30 30 30 30 30 30 30 85 0A 56 4D " "53 31 30 30 30 30 31 33 A7 20 80 02 07 E0 81 01 " "0B 82 01 11 83 01 0D 84 01 0A 85 01 0C A6 03 82 " "01 00 A7 06 80 01 09 81 01 00 A4 31 A6 2F 80 01 " "FF A1 2A A0 28 30 26 80 01 32 81 01 02 82 01 00 " "A3 1B A1 19 80 06 28 F3 6B 02 00 02 A1 0F 30 0D " "30 0B 80 01 02 A1 06 04 01 31 04 01 32 82 02 10 " "5D "; try { sl = new TStringList; sl->Delimiter = ' '; sl->StrictDelimiter = true; sl->DelimitedText = sMsg; int ii; unsigned int hn, ln; BYTE chn, cln, val; char szData[2048]; BYTE RxBuff[VMS_MAX_PACKET_SIZE]; int RxLen; RxLen = 0; memset(RxBuff, 0x00, sizeof(RxBuff)); for (ii = 0; ii < sl->Count; ii++) { AnsiString sTemp = sl->Strings[ii]; if (sTemp.Trim() == "") continue; sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll); if (sTemp.Trim() == "\r\n") continue; memset(szData, 0x00, sizeof(szData)); memcpy(szData, sTemp.c_str(), sTemp.Length()); chn = (BYTE)szData[0]; cln = (BYTE)szData[1]; hn = chn > '9' ? chn - 'A' + 10 : chn - '0'; ln = cln > '9' ? cln - 'A' + 10 : cln - '0'; val = (BYTE)((hn << 4 ) | ln); RxBuff[RxLen] = val; RxLen++; } int nSends = pClientSocket->SendBuf(RxBuff, RxLen); LINFO("SendScheduledDisplay: %d/%d Bytes", RxLen, nSends); if (sl) delete sl; } catch(Exception &e) { //Application->ShowException(&e); } return SYS_ERR_NONE; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::SendFtpImage() { LINFO("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"); int result; result = ProcessCommand(AI_TransferDone, NULL); return SYS_ERR_NONE; } //--------------------------------------------------------------------------- int __fastcall TVMSSThread::DownloadSymbolImage() { int nResult; COMMAND_ARGUMENT arg; BYTE CmdCode; CmdCode = 0x00; memset(&arg, 0x00, sizeof(arg)); AnsiString sFtpImgId; try { CDSImageItr it; for(it=ImageManager->FLists.FMapObject.begin(); it != ImageManager->FLists.FMapObject.end(); ++it) { TCDSImage *pTmp = (TCDSImage*)it->second; //FOR_STL(TCDSImage*, pTmp, ImageManager->FLists) //{ sFtpImgId = GetFtpImageId(pTmp->Nmbr); if (sFtpImgId.SubString(1,1) == "7" || pTmp->VmsType == "VMP1") continue; /* µµÇü½Ä ¹è°æÀ̹ÌÁö´Â ´Ù¿î·Îµå ÇÒ ÇÊ¿ä ¾øÀ½ */ arg.Publication.SubscribeSerialNbr = 0; arg.Publication.obj = OBJ_RealTimeDisplay; arg.Publication.Data.Form.Idx = 0; sprintf(arg.Publication.szFormId, "%s", sFtpImgId.c_str()); CmdCode = AI_TransferDone; nResult = ProcessCommand(CmdCode, &arg); Sleep(100); } } catch(Exception &e) { } FVmsObj->FSymbolDownload = false; return nResult; } //---------------------------------------------------------------------------