/**************************************************************************** * @source : VMSSThread.h * @description : VMS Server Socket Thread header **************************************************************************** * DATE AUTHOR DESCRIPTION * -------------------------------------------------------------------------- * 2012/03/09 CYM [100] First Cut * ****************************************************************************/ //--------------------------------------------------------------------------- #ifndef VMSSThreadH #define VMSSThreadH //--------------------------------------------------------------------------- #include #include #include "VitzroCommF.h" #include "ITSLogF.h" #include "TVmsCtlrF.h" #include "VmsDataTypeF.h" #include "VMSProtocol.h" //--------------------------------------------------------------------------- /*************************************** ** ** Constants ** */ #define SERVER_MSG_BUF_SIZE 65536 /* message buffer size */ #define SERVER_MAX_PACKET_SIZE 65536 /* max packet size */ #define SERVER_CONNECT_RETRY_TIME 60 /* connect retry time */ // server thread typedef struct server_thread_struct { BYTE Idx; /* information index */ AnsiString IpAddress; /* IPÁÖ¼Ò */ int Port; /* Æ÷Æ®¹øÈ£ */ int TimeOut; /* ½Ã°£Ãʰú */ int CycleTime; /* ÁÖ±â */ int Addr; /* local id */ AnsiString VmsId; /* VMS ID */ int State; /* for the statemachine */ TDateTime sTimer; /* timer for state check sending */ int iRetry; /* retry count */ TDateTime cTimer; /* timer for command timeout check */ AnsiString LocalCenterId; /* ·ÎÄà ¼¾ÅÍID */ AnsiString LocalDomainNm; /* ·ÎÄà µµ¸ÞÀθíĪ */ AnsiString CenterId; /* ¼¾ÅÍID */ AnsiString DomainNm; /* µµ¸ÞÀθíĪ */ AnsiString UserName; /* »ç¿ëÀÚ¸í */ AnsiString UserPasswd; /* »ç¿ëÀÚºñ¹Ð¹øÈ£ */ int MaxHeartbeatTime; /* ÃÖ´ëÇãÆ®ºñÆ®Áö¼Ó½Ã°£ */ int DatagramSize; /* µ¥ÀÌÅͱ׷¥ Å©±â */ } SERVER_THREAD_STRUCT; enum { /* common */ ST_IDLE = 1, ST_INITIATE, ST_SECTION, ST_CLOSE, /* sender */ ST_LOCAL_COMMAND, ST_CLIENT_COMMAND, /* receiver */ ST_LOCAL_WAIT, ST_CLIENT_WAIT }; enum { SET_SERVER_SUCC, SET_SERVER_FAIL }; enum EN_PUBLICATION_NBR { NBR_MODULE_POWER = 1, NBR_LUMINANCE, NBR_CONTROLLER_RESET, NBR_STATUS_SETTING, NBR_SCREEN_STATUS_REQ, NBR_REALTIME_DISPLAY_REQ, NBR_BASE_REALTIMEDISPLAY = 100, NBR_BASE_SCHEDULEDDISPLAY = 200, NBR_BASE_DOWNLOADGRAPHICDATA = 300 }; enum EN_STATUS_CONTROL { CTL_MODULE_POWER_ON = 1, CTL_MODULE_POWER_OFF, CTL_LUMINANCE_SET, CTL_CONTROLLER_RESET, CTL_SCREENSTATUS_REQ, CTL_REALTIMEDISPLAY_REQ, }; /*************************************** ** ** Type definitions ** */ typedef struct { DWORD SubscribeSerialNbr; /* Subscribe Serial Nbr */ int obj; /* EN_OBJECT_ID */ char szFormId[10]; union { struct { BYTE Mode; /* EN_VMS_MODE */ int Idx; /* index */ } Form; struct { int Idx; /* index */ } Down; BYTE Ctl; /* EN_STATUS_CONTROL */ struct { int SchMsgTime; /* scheduledMessage_OperatingTimeQty */ int ModuleTemp; /* module_OperatingTemperatureQty */ int FanTemp; /* fan_OperatingTemperatureQty */ int HeaterTemp; /* heater_OperatingTemperatureQty */ int ModuleFail; /* module_BasicFailureRate */ int RetryCount; /* maximum_RetryQty */ int TimeOut; /* response_TimeOutQty */ } Set; } Data; } PUBLICATION_ARGUMENT; typedef union { /* Initiate */ /* Login */ DWORD FrED; /* datexFrED_ConfirmPacket_nbr */ int Terminate; /* terminate code */ /* Logout */ /* Subscription */ /* TransferDone */ struct { DWORD nbr; /* datexAccept_Packet_nbr */ int type; /* accept type */ DWORD sub; /* registered subscription */ } Accept; struct { DWORD nbr; /* datexReject_Packet_nbr */ int type; /* reject type */ int code; /* reject code */ } Reject; PUBLICATION_ARGUMENT Publication; /* Publication */ SUBSCRIPTION_ARGUMENT Subscription; /* Subscription */ } COMMAND_ARGUMENT; /* ¼³Á¤ Á¤º¸ */ typedef struct set_info_struct { BYTE VmsId[INT_VMS_MAX_ID+1]; /* VMS ID */ BYTE CtlType; /* Á¦¾îÀ¯Çü */ union { struct { BYTE Result; /* Á¦¾î°á°ú */ BYTE OperId[INT_VMS_MAX_OPER_ID+1]; /* Á¦¾î¿î¿µÀÚID */ } Control; struct { int SchMsgTime; /* °èȹµÈ ¸Þ½ÃÁö µ¿À۽ð£ */ int ModuleTemp; /* ¸ðµâÀü¿ø OFF ¿Âµµ */ int FanTemp; /* Fanµ¿ÀÛ ±âÁؿµµ */ int HeaterTemp; /* Heaterµ¿ÀÛ ±âÁؿµµ */ int ModuleFail; /* ¸ðµâÀå¾Ö ÆÇ´ÜÀ² */ int RetryCount; /* Àç½Ãµµ Ƚ¼ö */ int TimeOut; /* ÃÖ´ëÀÀ´ä´ë±â½Ã°£ */ } Para; } Data; } SET_INFO_STRUCT; // Á¦¾îÀ¯Çü enum EN_CONTROL_TYPE { CTL_TYPE_PARA_SET = 1, /* 1:ȯ°æ¼³Á¤Á¤º¸ Àü¼Û */ CTL_TYPE_POWER_ON = 11, /* 11:Àü¿ø On */ CTL_TYPE_POWER_OFF = 12, /* 12:Àü¿ø Off */ CTL_TYPE_HEATER_ON = 21, /* 21:È÷ÅÍ On */ CTL_TYPE_HEATER_OFF = 22, /* 22:È÷ÅÍ Off */ CTL_TYPE_FAN_ON = 31, /* 31:ÆÒ On */ CTL_TYPE_FAN_OFF = 32, /* 32:ÆÒ Off */ CTL_TYPE_MODULE_ON = 41, /* 41:Àü±¤ÆÇ On */ CTL_TYPE_MODULE_OFF = 42, /* 42:Àü±¤ÆÇ Off */ CTL_TYPE_RESET = 61, /* 61:Á¦¾î±â¸®¼Â */ CTL_TYPE_LUMINANCE = 71, /* 71:ÈÖµµÁ¦¾î */ }; typedef struct { bool GeneralStatus; /* ±âº»»óÅÂÁ¤º¸ */ bool ModuleStatus; /* ¸ðµâ»óÅÂÁ¤º¸ */ bool PowerStatus; /* Àü¿ø»óÅÂÁ¤º¸ */ bool ScreenDataStatusMessage; bool RealTimeDisplayMessage; } REQUEST_REGISTERED; //--------------------------------------------------------------------------- class TVMSSThread : public TClientSocketThread { private: TCustomIpClient* pClientSocket; bool *ThreadActiveIndicator; TVmsCtlr *FVmsObj; AnsiString m_strName; /* thread name */ int m_RxLen; /* received data length */ BYTE m_RxBuff[SERVER_MAX_PACKET_SIZE]; /* receive data buffer */ TDateTime m_rTimer; /* timer for receiver */ TDateTime m_WatchDogTimer; /* watchdog timer */ SERVER_THREAD_STRUCT m_Server; /* server thread */ bool m_InitFlag; /* Init Flag */ DWORD m_DataPacketNumber; /* DataPacket Number */ DWORD m_FrEDConfirmPacketNumber; /* FrEDConfirmPacket Number */ bool m_LoginFlag; /* Login Flag */ DWORD m_PublishSerialNbr; /* Publish Serial Nbr */ IPCUDPPACKET FCliReq; VMS_CONTROL_INFO FCliCtl; VMS_SERVER_CTL_INFO FSvrCtl; /* local control */ REQ_INFO_STRUCT m_Req; /* client request */ SET_INFO_STRUCT m_Set; /* client set */ REQUEST_REGISTERED m_Registered; /* local command */ INT_VMS_STATE *m_pState; /* VMS »óÅ Á¤º¸ */ TVmsFormManager *m_pVmsFormList; /* VmsFormList */ TITSLog *FLogFile; int FWatchDogTime; int FErrLine; int __fastcall ServerInitMem(void); void __fastcall ServerInitInfo(void); void __fastcall ServerTerminate(void); void __fastcall LOG_WriteTime(Time_t *pTime); void __fastcall ClientResponse(int error); int __fastcall SendDbThreadMessage(UINT Msg, int wParam, int lParam); int __fastcall SendDbThreadDataMessage(UINT Msg, void *pData, int iLen); int __fastcall Hangul2UTF8String(char *pIn, char *pOut, int outSize); int __fastcall UTF8String2Hangul(char *pIn, char *pOut, int outSize); int __fastcall RecvPacket(void *Data, int Len); int __fastcall ProcessRecvPacket(BYTE *pBuffer, int Len); int __fastcall PacketLogin(Login_t *pLogin, DWORD nbr); int __fastcall PacketSubscription(Subscription_t *pSubscripiton); int __fastcall PacketAccept(Accept_t *pAccept); int __fastcall PacketReject(Reject_t *pReject); int __fastcall SendPacket(void *Data, int Len, BYTE cmd); int __fastcall ProcessCommand(BYTE cmd, COMMAND_ARGUMENT *arg); int __fastcall CommandAccept(Accept_t *pAccept, DWORD nbr, int type, DWORD sub); int __fastcall CommandReject(Reject_t *pReject, DWORD nbr, int type, int code); int __fastcall CommandPublicationData(PublicationData_t *pData, PUBLICATION_ARGUMENT Arg); int __fastcall RealTimeDisplayBitmap(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg); int __fastcall RealTimeDisplayBitmapOld(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg); int __fastcall RealTimeDisplayBitmapNew(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg); int __fastcall RealTimeDisplayData(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg); int __fastcall ScheduledDisplayData(ScheduledDisplayMessage_t *pSD, PUBLICATION_ARGUMENT Arg); int __fastcall DownloadGraphicData(DownloadGraphicDataMessage_t *pDGD, PUBLICATION_ARGUMENT Arg); int __fastcall StatusControlData(StatusControlMessage_t *pSC, PUBLICATION_ARGUMENT Arg); int __fastcall StatusSettingData(StatusSettingMessage_t *pSS, PUBLICATION_ARGUMENT Arg); int __fastcall RecvPacketPublication(Publication_t *pPublication); int __fastcall RecvPacketPublicationData(PublicationData_t *pData); int __fastcall SaveStateData(GeneralStatusMessage_t *pGS); void __fastcall ServerStateMachine(void); void __fastcall ProcErrorState(bool flag, int result); void __fastcall SetServerState(int Case); int __fastcall CheckRegistered(); int __fastcall CheckLocalData(bool *AFlag); int __fastcall CheckClientData(bool *AFlag); protected: void __fastcall Execute(); void __fastcall TcpServerDisconnect(TObject *Sender); void __fastcall TcpServerClientError(TObject *Sender, int SocketError); bool __fastcall SocketActivity(bool &AError); bool __fastcall SocketActivity(); void __fastcall Close(void); public: bool FDupClose; __fastcall TVMSSThread(TServerSocketThread* ServerSocketThread, TCustomIpClient* ClientSocket, int Tag, bool *ActiveIndicator); __fastcall ~TVMSSThread(); bool __fastcall CheckClientThread(bool ARun); IPC_LOG_MESSAGE FLogMsg; int LogData(char *ASndRcv, BYTE *AData, int ALen); int LogWrite(int ALogKind, char *AFmt, ...); int SysLogWrite(int ALogKind, char *AFmt, ...); // FOR Yongin int __fastcall CommandSubscription(Subscription_t *pSubscripiton, SUBSCRIPTION_ARGUMENT Arg); int __fastcall RecvFormDownResult(AnsiString AImageId); int __fastcall SendLoginAccept(); int __fastcall SendSubscriptionAccept(int AMsgId); int __fastcall SendRealTimeDisplay(int AIndex); int __fastcall SendScheduledDisplay(); int __fastcall SendFtpImage(); int __fastcall DownloadSymbolImage(); }; //--------------------------------------------------------------------------- #endif