VMSSThread.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /****************************************************************************
  2. * @source : VMSSThread.h
  3. * @description : VMS Server Socket Thread header
  4. ****************************************************************************
  5. * DATE AUTHOR DESCRIPTION
  6. * --------------------------------------------------------------------------
  7. * 2012/03/09 CYM [100] First Cut
  8. *
  9. ****************************************************************************/
  10. //---------------------------------------------------------------------------
  11. #ifndef VMSSThreadH
  12. #define VMSSThreadH
  13. //---------------------------------------------------------------------------
  14. #include <Classes.hpp>
  15. #include <Sockets.hpp>
  16. #include "VitzroCommF.h"
  17. #include "ITSLogF.h"
  18. #include "TVmsCtlrF.h"
  19. #include "VmsDataTypeF.h"
  20. #include "VMSProtocol.h"
  21. //---------------------------------------------------------------------------
  22. /***************************************
  23. **
  24. ** Constants
  25. **
  26. */
  27. #define SERVER_MSG_BUF_SIZE 65536 /* message buffer size */
  28. #define SERVER_MAX_PACKET_SIZE 65536 /* max packet size */
  29. #define SERVER_CONNECT_RETRY_TIME 60 /* connect retry time */
  30. // server thread
  31. typedef struct server_thread_struct
  32. {
  33. BYTE Idx; /* information index */
  34. AnsiString IpAddress; /* IP주소 */
  35. int Port; /* 포트번호 */
  36. int TimeOut; /* 시간초과 */
  37. int CycleTime; /* 주기 */
  38. int Addr; /* local id */
  39. AnsiString VmsId; /* VMS ID */
  40. int State; /* for the statemachine */
  41. TDateTime sTimer; /* timer for state check sending */
  42. int iRetry; /* retry count */
  43. TDateTime cTimer; /* timer for command timeout check */
  44. AnsiString LocalCenterId; /* 로컬 센터ID */
  45. AnsiString LocalDomainNm; /* 로컬 도메인명칭 */
  46. AnsiString CenterId; /* 센터ID */
  47. AnsiString DomainNm; /* 도메인명칭 */
  48. AnsiString UserName; /* 사용자명 */
  49. AnsiString UserPasswd; /* 사용자비밀번호 */
  50. int MaxHeartbeatTime; /* 최대허트비트지속시간 */
  51. int DatagramSize; /* 데이터그램 크기 */
  52. } SERVER_THREAD_STRUCT;
  53. enum
  54. {
  55. /* common */
  56. ST_IDLE = 1,
  57. ST_INITIATE,
  58. ST_SECTION,
  59. ST_CLOSE,
  60. /* sender */
  61. ST_LOCAL_COMMAND,
  62. ST_CLIENT_COMMAND,
  63. /* receiver */
  64. ST_LOCAL_WAIT,
  65. ST_CLIENT_WAIT
  66. };
  67. enum
  68. {
  69. SET_SERVER_SUCC,
  70. SET_SERVER_FAIL
  71. };
  72. enum EN_PUBLICATION_NBR
  73. {
  74. NBR_MODULE_POWER = 1,
  75. NBR_LUMINANCE,
  76. NBR_CONTROLLER_RESET,
  77. NBR_STATUS_SETTING,
  78. NBR_SCREEN_STATUS_REQ,
  79. NBR_REALTIME_DISPLAY_REQ,
  80. NBR_BASE_REALTIMEDISPLAY = 100,
  81. NBR_BASE_SCHEDULEDDISPLAY = 200,
  82. NBR_BASE_DOWNLOADGRAPHICDATA = 300
  83. };
  84. enum EN_STATUS_CONTROL
  85. {
  86. CTL_MODULE_POWER_ON = 1,
  87. CTL_MODULE_POWER_OFF,
  88. CTL_LUMINANCE_SET,
  89. CTL_CONTROLLER_RESET,
  90. CTL_SCREENSTATUS_REQ,
  91. CTL_REALTIMEDISPLAY_REQ,
  92. };
  93. /***************************************
  94. **
  95. ** Type definitions
  96. **
  97. */
  98. typedef struct
  99. {
  100. DWORD SubscribeSerialNbr; /* Subscribe Serial Nbr */
  101. int obj; /* EN_OBJECT_ID */
  102. char szFormId[10];
  103. union
  104. {
  105. struct
  106. {
  107. BYTE Mode; /* EN_VMS_MODE */
  108. int Idx; /* index */
  109. } Form;
  110. struct
  111. {
  112. int Idx; /* index */
  113. } Down;
  114. BYTE Ctl; /* EN_STATUS_CONTROL */
  115. struct
  116. {
  117. int SchMsgTime; /* scheduledMessage_OperatingTimeQty */
  118. int ModuleTemp; /* module_OperatingTemperatureQty */
  119. int FanTemp; /* fan_OperatingTemperatureQty */
  120. int HeaterTemp; /* heater_OperatingTemperatureQty */
  121. int ModuleFail; /* module_BasicFailureRate */
  122. int RetryCount; /* maximum_RetryQty */
  123. int TimeOut; /* response_TimeOutQty */
  124. } Set;
  125. } Data;
  126. } PUBLICATION_ARGUMENT;
  127. typedef union {
  128. /* Initiate */
  129. /* Login */
  130. DWORD FrED; /* datexFrED_ConfirmPacket_nbr */
  131. int Terminate; /* terminate code */
  132. /* Logout */
  133. /* Subscription */
  134. /* TransferDone */
  135. struct
  136. {
  137. DWORD nbr; /* datexAccept_Packet_nbr */
  138. int type; /* accept type */
  139. DWORD sub; /* registered subscription */
  140. } Accept;
  141. struct
  142. {
  143. DWORD nbr; /* datexReject_Packet_nbr */
  144. int type; /* reject type */
  145. int code; /* reject code */
  146. } Reject;
  147. PUBLICATION_ARGUMENT Publication; /* Publication */
  148. SUBSCRIPTION_ARGUMENT Subscription; /* Subscription */
  149. } COMMAND_ARGUMENT;
  150. /* 설정 정보 */
  151. typedef struct set_info_struct
  152. {
  153. BYTE VmsId[INT_VMS_MAX_ID+1]; /* VMS ID */
  154. BYTE CtlType; /* 제어유형 */
  155. union
  156. {
  157. struct
  158. {
  159. BYTE Result; /* 제어결과 */
  160. BYTE OperId[INT_VMS_MAX_OPER_ID+1]; /* 제어운영자ID */
  161. } Control;
  162. struct
  163. {
  164. int SchMsgTime; /* 계획된 메시지 동작시간 */
  165. int ModuleTemp; /* 모듈전원 OFF 온도 */
  166. int FanTemp; /* Fan동작 기준온도 */
  167. int HeaterTemp; /* Heater동작 기준온도 */
  168. int ModuleFail; /* 모듈장애 판단율 */
  169. int RetryCount; /* 재시도 횟수 */
  170. int TimeOut; /* 최대응답대기시간 */
  171. } Para;
  172. } Data;
  173. } SET_INFO_STRUCT;
  174. // 제어유형
  175. enum EN_CONTROL_TYPE
  176. {
  177. CTL_TYPE_PARA_SET = 1, /* 1:환경설정정보 전송 */
  178. CTL_TYPE_POWER_ON = 11, /* 11:전원 On */
  179. CTL_TYPE_POWER_OFF = 12, /* 12:전원 Off */
  180. CTL_TYPE_HEATER_ON = 21, /* 21:히터 On */
  181. CTL_TYPE_HEATER_OFF = 22, /* 22:히터 Off */
  182. CTL_TYPE_FAN_ON = 31, /* 31:팬 On */
  183. CTL_TYPE_FAN_OFF = 32, /* 32:팬 Off */
  184. CTL_TYPE_MODULE_ON = 41, /* 41:전광판 On */
  185. CTL_TYPE_MODULE_OFF = 42, /* 42:전광판 Off */
  186. CTL_TYPE_RESET = 61, /* 61:제어기리셋 */
  187. CTL_TYPE_LUMINANCE = 71, /* 71:휘도제어 */
  188. };
  189. typedef struct
  190. {
  191. bool GeneralStatus; /* 기본상태정보 */
  192. bool ModuleStatus; /* 모듈상태정보 */
  193. bool PowerStatus; /* 전원상태정보 */
  194. bool ScreenDataStatusMessage;
  195. bool RealTimeDisplayMessage;
  196. } REQUEST_REGISTERED;
  197. //---------------------------------------------------------------------------
  198. class TVMSSThread : public TClientSocketThread
  199. {
  200. private:
  201. TCustomIpClient* pClientSocket;
  202. bool *ThreadActiveIndicator;
  203. TVmsCtlr *FVmsObj;
  204. AnsiString m_strName; /* thread name */
  205. int m_RxLen; /* received data length */
  206. BYTE m_RxBuff[SERVER_MAX_PACKET_SIZE]; /* receive data buffer */
  207. TDateTime m_rTimer; /* timer for receiver */
  208. TDateTime m_WatchDogTimer; /* watchdog timer */
  209. SERVER_THREAD_STRUCT m_Server; /* server thread */
  210. bool m_InitFlag; /* Init Flag */
  211. DWORD m_DataPacketNumber; /* DataPacket Number */
  212. DWORD m_FrEDConfirmPacketNumber; /* FrEDConfirmPacket Number */
  213. bool m_LoginFlag; /* Login Flag */
  214. DWORD m_PublishSerialNbr; /* Publish Serial Nbr */
  215. IPCUDPPACKET FCliReq;
  216. VMS_CONTROL_INFO FCliCtl;
  217. VMS_SERVER_CTL_INFO FSvrCtl; /* local control */
  218. REQ_INFO_STRUCT m_Req; /* client request */
  219. SET_INFO_STRUCT m_Set; /* client set */
  220. REQUEST_REGISTERED m_Registered; /* local command */
  221. INT_VMS_STATE *m_pState; /* VMS 상태 정보 */
  222. TVmsFormManager *m_pVmsFormList; /* VmsFormList */
  223. TITSLog *FLogFile;
  224. int FWatchDogTime;
  225. int FErrLine;
  226. int __fastcall ServerInitMem(void);
  227. void __fastcall ServerInitInfo(void);
  228. void __fastcall ServerTerminate(void);
  229. void __fastcall LOG_WriteTime(Time_t *pTime);
  230. void __fastcall ClientResponse(int error);
  231. int __fastcall SendDbThreadMessage(UINT Msg, int wParam, int lParam);
  232. int __fastcall SendDbThreadDataMessage(UINT Msg, void *pData, int iLen);
  233. int __fastcall Hangul2UTF8String(char *pIn, char *pOut, int outSize);
  234. int __fastcall UTF8String2Hangul(char *pIn, char *pOut, int outSize);
  235. int __fastcall RecvPacket(void *Data, int Len);
  236. int __fastcall ProcessRecvPacket(BYTE *pBuffer, int Len);
  237. int __fastcall PacketLogin(Login_t *pLogin, DWORD nbr);
  238. int __fastcall PacketSubscription(Subscription_t *pSubscripiton);
  239. int __fastcall PacketAccept(Accept_t *pAccept);
  240. int __fastcall PacketReject(Reject_t *pReject);
  241. int __fastcall SendPacket(void *Data, int Len, BYTE cmd);
  242. int __fastcall ProcessCommand(BYTE cmd, COMMAND_ARGUMENT *arg);
  243. int __fastcall CommandAccept(Accept_t *pAccept, DWORD nbr, int type, DWORD sub);
  244. int __fastcall CommandReject(Reject_t *pReject, DWORD nbr, int type, int code);
  245. int __fastcall CommandPublicationData(PublicationData_t *pData, PUBLICATION_ARGUMENT Arg);
  246. int __fastcall RealTimeDisplayBitmap(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg);
  247. int __fastcall RealTimeDisplayBitmapOld(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg);
  248. int __fastcall RealTimeDisplayBitmapNew(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg);
  249. int __fastcall RealTimeDisplayData(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg);
  250. int __fastcall ScheduledDisplayData(ScheduledDisplayMessage_t *pSD, PUBLICATION_ARGUMENT Arg);
  251. int __fastcall DownloadGraphicData(DownloadGraphicDataMessage_t *pDGD, PUBLICATION_ARGUMENT Arg);
  252. int __fastcall StatusControlData(StatusControlMessage_t *pSC, PUBLICATION_ARGUMENT Arg);
  253. int __fastcall StatusSettingData(StatusSettingMessage_t *pSS, PUBLICATION_ARGUMENT Arg);
  254. int __fastcall RecvPacketPublication(Publication_t *pPublication);
  255. int __fastcall RecvPacketPublicationData(PublicationData_t *pData);
  256. int __fastcall SaveStateData(GeneralStatusMessage_t *pGS);
  257. void __fastcall ServerStateMachine(void);
  258. void __fastcall ProcErrorState(bool flag, int result);
  259. void __fastcall SetServerState(int Case);
  260. int __fastcall CheckRegistered();
  261. int __fastcall CheckLocalData(bool *AFlag);
  262. int __fastcall CheckClientData(bool *AFlag);
  263. protected:
  264. void __fastcall Execute();
  265. void __fastcall TcpServerDisconnect(TObject *Sender);
  266. void __fastcall TcpServerClientError(TObject *Sender, int SocketError);
  267. bool __fastcall SocketActivity(bool &AError);
  268. bool __fastcall SocketActivity();
  269. void __fastcall Close(void);
  270. public:
  271. bool FDupClose;
  272. __fastcall TVMSSThread(TServerSocketThread* ServerSocketThread, TCustomIpClient* ClientSocket, int Tag, bool *ActiveIndicator);
  273. __fastcall ~TVMSSThread();
  274. bool __fastcall CheckClientThread(bool ARun);
  275. IPC_LOG_MESSAGE FLogMsg;
  276. int LogData(char *ASndRcv, BYTE *AData, int ALen);
  277. int LogWrite(int ALogKind, char *AFmt, ...);
  278. int SysLogWrite(int ALogKind, char *AFmt, ...);
  279. // FOR Yongin
  280. int __fastcall CommandSubscription(Subscription_t *pSubscripiton, SUBSCRIPTION_ARGUMENT Arg);
  281. int __fastcall RecvFormDownResult(AnsiString AImageId);
  282. int __fastcall SendLoginAccept();
  283. int __fastcall SendSubscriptionAccept(int AMsgId);
  284. int __fastcall SendRealTimeDisplay(int AIndex);
  285. int __fastcall SendScheduledDisplay();
  286. int __fastcall SendFtpImage();
  287. int __fastcall DownloadSymbolImage();
  288. };
  289. //---------------------------------------------------------------------------
  290. #endif