123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- /****************************************************************************
- * @source : VMSSThread.h
- * @description : VMS Server Socket Thread header
- ****************************************************************************
- * DATE AUTHOR DESCRIPTION
- * --------------------------------------------------------------------------
- * 2012/03/09 CYM [100] First Cut
- *
- ****************************************************************************/
- //---------------------------------------------------------------------------
- #ifndef VMSSThreadH
- #define VMSSThreadH
- //---------------------------------------------------------------------------
- #include <Classes.hpp>
- #include <Sockets.hpp>
- #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
|