PacketHandllingF.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. //---------------------------------------------------------------------------
  2. #pragma hdrstop
  3. #include <DateUtils.hpp>
  4. #include "PacketHandllingF.h"
  5. #include "ClientSessionF.h"
  6. #include "VMSCommLibF.h"
  7. #include "VmsProtocolF.h"
  8. //---------------------------------------------------------------------------
  9. #define TERROR(args...) ASession->SysLogWrite(eLOG_ERROR, ##args)
  10. #define TDEBUG(args...) ASession->LogWrite(eLOG_DEBUG, ##args)
  11. #pragma package(smart_init)
  12. //---------------------------------------------------------------------------
  13. typedef int (*RecvPktHandlerFunc)(TClientSession *ASession, int APktLen);
  14. //---------------------------------------------------------------------------
  15. static int UnknownPktHandler(TClientSession *ASession, int APktLen)
  16. {
  17. if (ASession->CDSLogCtlr)
  18. TERROR("+CLI Invalid packet handler: %s. will be closed.", ASession->IpAddress.c_str());
  19. MERROR("+CLI Invalid packet handler: %s. will be closed.", ASession->IpAddress.c_str());
  20. ASession->LogData("ERCV", (BYTE*)ASession->GetRecvBuff(), APktLen);
  21. ASession->Disconnect();
  22. return -1;
  23. }
  24. //---------------------------------------------------------------------------
  25. //---------------------------------------------------------------------------
  26. static RecvPktHandlerFunc G_FuncPktHandler[e_rpkt_MAX] = {NULL};
  27. //---------------------------------------------------------------------------
  28. struct _init_pkt_handler
  29. {
  30. //정적 패킷핸들러 함수 초기화
  31. _init_pkt_handler()
  32. {
  33. for (int ii = 0; ii < e_rpkt_MAX; ii++)
  34. {
  35. G_FuncPktHandler[ii] = UnknownPktHandler;
  36. }
  37. }
  38. };
  39. static _init_pkt_handler init_pkt_handler;
  40. //---------------------------------------------------------------------------
  41. struct RegisterHandler
  42. {
  43. RegisterHandler(BYTE AOpCode, RecvPktHandlerFunc AFuncHandler)
  44. {
  45. G_FuncPktHandler[(int)AOpCode] = AFuncHandler;
  46. }
  47. };
  48. //---------------------------------------------------------------------------
  49. #define REGISTER_HANDLER(PKT_TYPE) \
  50. static int Handler_##PKT_TYPE(TClientSession* ASession, int APktLen); \
  51. static RegisterHandler _register_##PKT_TYPE(PKT_TYPE, Handler_##PKT_TYPE); \
  52. static int Handler_##PKT_TYPE(TClientSession* ASession, int APktLen)
  53. void CALLBACK RecvCompletion(DWORD dwError, DWORD cbTransferred, LPWSAOVERLAPPED lpOverlapped, DWORD dwFlags)
  54. {
  55. TClientSession *pSession = static_cast<OverlappedIO*>(lpOverlapped)->FSession;
  56. if (!pSession->IsConnected)
  57. {
  58. MERROR("+SVR RecvCompletion(IsConnected false): %s[%d]", pSession->IpAddress.c_str(), pSession->Socket);
  59. return;
  60. }
  61. /// 에러 발생시 해당 세션 종료
  62. if (dwError || cbTransferred == 0)
  63. {
  64. MERROR("+SVR RecvCompletion(dwError || cbTransferred==0): %s[%d], will be closed", pSession->IpAddress.c_str(), pSession->Socket);
  65. pSession->Disconnect();
  66. return;
  67. }
  68. /// 받은 데이터 처리
  69. pSession->OnRead(cbTransferred);
  70. }
  71. //---------------------------------------------------------------------------
  72. void CALLBACK SendCompletion(DWORD dwError, DWORD cbTransferred, LPWSAOVERLAPPED lpOverlapped, DWORD dwFlags)
  73. {
  74. TClientSession *pSession = static_cast<OverlappedIO*>(lpOverlapped)->FSession;
  75. if (!pSession->IsConnected)
  76. {
  77. MERROR("+SVR SendCompletion(IsConnected false): %s[%d]", pSession->IpAddress.c_str(), pSession->Socket);
  78. return;
  79. }
  80. /// 에러 발생시 해당 세션 종료
  81. if (dwError || cbTransferred == 0)
  82. {
  83. MERROR("+SVR SendCompletion(dwError || cbTransferred==0): %s[%d], will be closed", pSession->IpAddress.c_str(), pSession->Socket);
  84. pSession->Disconnect();
  85. return;
  86. }
  87. pSession->OnWriteComplete(cbTransferred, cbTransferred);
  88. }
  89. //---------------------------------------------------------------------------
  90. static TCDSCtlr* FindControllerByIpAddr(AnsiString AIpAddress)
  91. {
  92. CtlrItr it;
  93. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  94. {
  95. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  96. if (!pObj->Used) continue;
  97. if (pObj->CTLR_IP.AnsiCompare(AIpAddress) == 0)
  98. {
  99. return pObj;
  100. }
  101. }
  102. return NULL;
  103. }
  104. //---------------------------------------------------------------------------
  105. static TCDSCtlr* FindControllerById(AnsiString ACtrlNmbrId)
  106. {
  107. CtlrItr it;
  108. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  109. {
  110. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  111. if (!pObj->Used) continue;
  112. if (pObj->CTLR_NMBR_ID.AnsiCompare(ACtrlNmbrId) == 0)
  113. {
  114. return pObj;
  115. }
  116. }
  117. return NULL;
  118. }
  119. //---------------------------------------------------------------------------
  120. bool TClientSession::ReqLogin()
  121. {
  122. MINFO("+CLI Client send request Login Info: %s.", FIpAddress.c_str());
  123. // VMS ID 요청
  124. st_vms_id_req req;
  125. if (!SendRequest((char*)&req, sizeof(req)))
  126. {
  127. MERROR("+CLI Client send request faild: %s. will be closed.", FIpAddress.c_str());
  128. return false;
  129. }
  130. FState = eSS_LoginReq;
  131. return true;
  132. }
  133. //---------------------------------------------------------------------------
  134. bool TClientSession::CheckLoginClient()
  135. {
  136. #if 0
  137. if (g_AppCfg.IsIpChecking == false)
  138. {
  139. return ReqLogin();
  140. }
  141. #endif
  142. TCDSCtlr *pCDSCtlr = FindControllerByIpAddr(FIpAddress);
  143. if (!pCDSCtlr)
  144. {
  145. MERROR("+CLI Unknown client address: %s. will be closed.", FIpAddress.c_str());
  146. return false;
  147. }
  148. //이전 접속정보가 있는지 확인한다.
  149. if (FCDSCtlr)
  150. {
  151. TClientSession *pSession = FCDSCtlr->FSession;
  152. if (pSession)
  153. {
  154. //이전 접속을 종료하고 현재 접속을 새로운 VMS 제어기 통신으로 사용한다.
  155. MERROR("+CLI Client allready connect: %s. old connection will be closed.", FIpAddress.c_str());
  156. pSession->Disconnect();
  157. }
  158. }
  159. return ReqLogin();
  160. //
  161. // VMS ID 요청
  162. st_vms_id_req req;
  163. if (!SendRequest((char*)&req, sizeof(req)))
  164. {
  165. MERROR("+CLI Client send request faild: %s. will be closed.", FIpAddress.c_str());
  166. return false;
  167. }
  168. FState = eSS_Connected; //연결요청 수립
  169. FCDSCtlr = pCDSCtlr;
  170. FCDSLogCtlr = pCDSCtlr;
  171. FCDSCtlr->FSession = this;
  172. FCDSCtlr->LOGIN_IPADDR = FIpAddress; //연결된 IP주소 설정
  173. FCDSCtlr->Server.commState = comm_open;
  174. FCDSCtlr->Server.ConnectTm = Now().FormatString("yyyy-MM-dd hh:nn:ss");
  175. FCtlrId.printf("%10.010d", FCDSCtlr->CTLR_NMBR.ToIntDef(0));
  176. POST_MSG(MAINHANDLE, WM_TCP_THREAD, WM_TCP_SERVER_STTS, (int)pCDSCtlr);
  177. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  178. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  179. pMsg->Type = eVmsScenarioDownload;
  180. pMsg->ObjPtr = (DWORD)FCDSCtlr->FSession;
  181. g_jobQ.PushBlocking((DWORD)pMsg);
  182. return true;
  183. }
  184. //---------------------------------------------------------------------------
  185. bool TClientSession::OnDisconnected()
  186. {
  187. if (FCDSCtlr)
  188. {
  189. FCDSCtlr->Server.DisconnectTm = Now().FormatString("yyyy-MM-dd hh:nn:ss");
  190. FCDSCtlr->Server.commState = comm_close;
  191. FCDSCtlr->FSession = NULL;
  192. //FCDSCtlr->LOGIN_IPADDR = "";
  193. LERROR("VMS %s disconnected.", CtlrId.c_str());
  194. MERROR("%s.%d, VMS %s disconnected.", FIpAddress.c_str(), FSocket, CtlrId.c_str());
  195. TCDSCtlr* pCDSCtlr = FCDSCtlr;
  196. POST_MSG(MAINHANDLE, WM_TCP_THREAD, WM_TCP_SERVER_STTS, (int)pCDSCtlr);
  197. }
  198. else
  199. {
  200. MERROR("%s.%d, disconnected.", FIpAddress.c_str(), FSocket);
  201. }
  202. FState = eSS_Disconnect;
  203. return true;
  204. }
  205. //---------------------------------------------------------------------------
  206. /*
  207. * 1개의 패킷을 모두 전송한 후 호출됨
  208. */
  209. void TClientSession::OnWrite(char *APktPtr, int ASendLen)
  210. {
  211. st_head *pHd = (st_head*)APktPtr;
  212. if (!pHd) return;
  213. if (ASendLen > 0)
  214. {
  215. LINFO("SEND: %d Bytes", ASendLen);
  216. LogData("SEND", APktPtr, ASendLen);
  217. }
  218. InfoPacket(pHd->OpCode, ASendLen, true, 0);
  219. switch(pHd->OpCode)
  220. {
  221. case VMS_ID_REQ: // 0xFF // server -> client
  222. case DNLD_SCENARIO_REQ: // 0x02 // server -> client
  223. case CTRL_RESET_REQ: // 0x03 // server -> client
  224. case DNLD_FILE_REQ: // 0x04 // server -> client
  225. case PARAMETER_REQ: // 0x05 // server -> client
  226. case CTRL_LED_POWER_REQ: // 0x06 // server -> client
  227. case CTRL_FAN_POWER_REQ: // 0x07 // server -> client
  228. case CTRL_BRGH_REQ: // 0x08 // server -> client
  229. case CTRL_CONFIG_REQ: // 0x09 // server -> client
  230. case CTRL_TIME_REQ: // 0x10 // server -> client
  231. FTmrSend = Now();
  232. if (FChkRecvTO == false)
  233. {
  234. FTmrRecv = Now();
  235. }
  236. FChkRecvTO = true;
  237. break;
  238. default:
  239. FChkRecvTO = false; // 0x01 // server -> client
  240. break;
  241. }
  242. }
  243. //---------------------------------------------------------------------------
  244. /*
  245. * 프로토콜에 따른 처리
  246. */
  247. void TClientSession::OnRead(int ALen)
  248. {
  249. st_head *pHd;
  250. int pktLen;
  251. FRecvIdx += ALen;
  252. if (FRecvIdx > 0)
  253. {
  254. LINFO("RECV: %d Bytes", FRecvIdx);
  255. LogData("RECV", (char*)FRecvBuff, FRecvIdx);
  256. }
  257. while(true)
  258. {
  259. // 프로토콜 헤더 만큼 데이터가 들어왔는지 체크
  260. if (FRecvIdx < (int)sizeof(st_head))
  261. {
  262. break;
  263. }
  264. pHd = (st_head*)FRecvBuff;
  265. // 프로토콜 헤더의 길이가 비정상적인지 체크
  266. if (pHd->Length < 0 || pHd->Length > 2048)
  267. {
  268. MERROR("+CLI Packet parsing data length overflow: %s, %d bytes", FIpAddress.c_str(), pHd->Length);
  269. Disconnect();
  270. break;
  271. }
  272. pktLen = (int)(pHd->Length+sizeof(st_head)+1); // 데이터길이, 헤더사이즈, ETX
  273. if (FRecvIdx < pktLen)
  274. {
  275. break;
  276. }
  277. try
  278. {
  279. if (pHd->OpCode != e_rpkt_NOTIFY_STTS) // 제어기에서 스스로 올리는 OpCode
  280. {
  281. FChkRecvTO = false;
  282. FTmrRecv = Now();
  283. }
  284. if (FState == eSS_LoginReq && pHd->OpCode != e_rpkt_VMS_ID_RES)
  285. {
  286. MERROR("+CLI Not Login Unknown OPCODE: %s, %02. will be closed.", FIpAddress.c_str(), pHd->OpCode);
  287. Disconnect();
  288. break;
  289. }
  290. // 패킷처리
  291. InfoPacket(pHd->OpCode, pktLen, false, 0);
  292. if (G_FuncPktHandler[pHd->OpCode](this, pktLen) < 0)
  293. {
  294. Disconnect();
  295. return;
  296. }
  297. SendFlush();
  298. }
  299. catch(Exception &e)
  300. {
  301. MERROR("+CLI Packet parsing exception: %s, %s, %s", FIpAddress.c_str(), AnsiString(e.ClassName()).c_str(), AnsiString(e.Message).c_str());
  302. Disconnect();
  303. break;
  304. }
  305. }
  306. }
  307. //---------------------------------------------------------------------------
  308. template <class PKT_TYPE>
  309. bool TClientSession::ParsePacket(PKT_TYPE& pkt, int APktLen)
  310. {
  311. if (APktLen > FRecvIdx)
  312. {
  313. MERROR("+CLI ParsePacket Error: %s, PktLen: %d, RecvIdx: %d", FIpAddress.c_str(), APktLen, FRecvIdx);
  314. return false;
  315. }
  316. memcpy((char*)&pkt, FRecvBuff, APktLen);
  317. FRecvIdx -= APktLen;
  318. if (FRecvIdx > 0)
  319. {
  320. memmove(FRecvBuff, FRecvBuff+APktLen, FRecvIdx);
  321. }
  322. return true;
  323. }
  324. //---------------------------------------------------------------------------
  325. bool TClientSession::InfoPacket(BYTE AOpCode, int ALen, bool ASend, int AResult/*=0*/)
  326. {
  327. TCDSCtlr* pCDSCtlr = FCDSLogCtlr;
  328. if (!pCDSCtlr) return -1;
  329. //if (!pCDSCtlr->FDispLog) return -1;
  330. //if (!g_LogCfg.Debug) return -1;
  331. if (!g_LogCfg.Info) return -1;
  332. AnsiString sCmd;
  333. switch(AOpCode)
  334. {
  335. case VMS_ID_REQ: // 0xFF // server -> client
  336. if (ASend) sCmd = "VMS_ID_REQ";
  337. else sCmd = "VMS_ID_RES";
  338. break;
  339. case NOTIFY_STTS_ACK: // 0x01 // server -> client
  340. if (ASend) sCmd = "NOTIFY_STTS_ACK";
  341. else sCmd = "NOTIFY_STTS_RES";
  342. break;
  343. case DNLD_SCENARIO_REQ: // 0x02 // server -> client
  344. if (ASend) sCmd = "DNLD_SCENARIO_REQ";
  345. else sCmd = "DNLD_SCENARIO_RES";
  346. break;
  347. case DNLD_FILE_REQ: // 0x04 // server -> client
  348. if (ASend) sCmd = "DNLD_FILE_REQ";
  349. else sCmd = "DNLD_FILE_RES";
  350. break;
  351. case PARAMETER_REQ: // 0x05 // server -> client
  352. if (ASend) sCmd = "PARAMETER_REQ";
  353. else sCmd = "PARAMETER_RES";
  354. break;
  355. case CTRL_LED_POWER_REQ: // 0x06 // server -> client
  356. if (ASend) sCmd = "CTRL_LED_POWER_REQ";
  357. else sCmd = "CTRL_LED_POWER_RES";
  358. break;
  359. case CTRL_FAN_POWER_REQ: // 0x07 // server -> client
  360. if (ASend) sCmd = "CTRL_FAN_POWER_REQ";
  361. else sCmd = "CTRL_FAN_POWER_RES";
  362. break;
  363. case CTRL_BRGH_REQ: // 0x08 // server -> client
  364. if (ASend) sCmd = "CTRL_BRGH_REQ";
  365. else sCmd = "CTRL_BRGH_RES";
  366. break;
  367. case CTRL_CONFIG_REQ: // 0x09 // server -> client
  368. if (ASend) sCmd = "CTRL_CONFIG_REQ";
  369. else sCmd = "CTRL_CONFIG_RES";
  370. break;
  371. case CTRL_TIME_REQ: // 0x10 // server -> client
  372. if (ASend) sCmd = "CTRL_TIME_REQ";
  373. else sCmd = "CTRL_TIME_RES";
  374. break;
  375. case CTRL_RESET_REQ: // 0x10 // server -> client
  376. if (ASend) sCmd = "CTRL_RESET_REQ";
  377. else sCmd = "CTRL_RESET_RES";
  378. break;
  379. default:
  380. sCmd.printf("UNKNOWN Packet: %02X", AOpCode);
  381. return false;
  382. }
  383. if (ASend)
  384. {
  385. if (AResult == 0)
  386. LINFO("SEND: %s, %d Bytes", sCmd.c_str(), ALen);
  387. else
  388. LERROR("SEND FAIL: %s, %d Bytes", sCmd.c_str(), ALen);
  389. }
  390. else
  391. {
  392. LINFO("RECV: %s, %d Bytes", sCmd.c_str(), ALen);
  393. }
  394. return true;
  395. }
  396. //---------------------------------------------------------------------------
  397. /////////////////////////////////////////////////////////
  398. REGISTER_HANDLER(e_rpkt_VMS_ID_RES)
  399. {
  400. st_vms_id_res res;
  401. if (false == ASession->ParsePacket(res, APktLen))
  402. {
  403. TERROR("%s.%d, VMS_ID_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  404. MERROR("%s.%d, VMS_ID_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  405. return -1;
  406. }
  407. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  408. TDEBUG("VMS_ID_RES: %d bytes, Length:%d, Ack:%02X", APktLen, res.Length, res.Ack);
  409. AnsiString sVmsId;
  410. sVmsId.printf("%10.10s", res.vmsid);
  411. if (ASession->State == eSS_LoginReq)
  412. {
  413. TCDSCtlr *pCDSCtlr = FindControllerById(sVmsId);
  414. if (!pCDSCtlr)
  415. {
  416. MERROR("+CLI Unknown client id: %s,%s. will be closed.", ASession->IpAddress.c_str(), sVmsId.c_str());
  417. ASession->Disconnect();
  418. return -1;
  419. }
  420. if (g_AppCfg.IsIpChecking)
  421. {
  422. if (ASession->IpAddress != pCDSCtlr->CTLR_IP)
  423. {
  424. MERROR("+CLI Controller IP Address Miss Match: %s,%s. (%s). will be closed.", ASession->IpAddress.c_str(), pCDSCtlr->CTLR_IP.c_str(), sVmsId.c_str());
  425. ASession->Disconnect();
  426. return -1;
  427. }
  428. }
  429. //이전 접속정보가 있는지 확인한다.
  430. if (pCDSCtlr)
  431. {
  432. TClientSession *pSession = pCDSCtlr->FSession;
  433. if (pSession)
  434. {
  435. //이전 접속을 종료하고 현재 접속을 새로운 VMS 제어기 통신으로 사용한다.
  436. MERROR("+CLI Client allready connect: %s. old connection will be closed.", ASession->IpAddress.c_str());
  437. pSession->Disconnect();
  438. }
  439. }
  440. ASession->State = eSS_Connected; //연결요청 수립
  441. ASession->CDSCtlr = pCDSCtlr;
  442. ASession->CDSLogCtlr = pCDSCtlr;
  443. ASession->CDSCtlr->FSession = ASession;
  444. ASession->CDSCtlr->LOGIN_IPADDR = ASession->IpAddress; //연결된 IP주소 설정
  445. ASession->CDSCtlr->Server.commState = comm_open;
  446. ASession->CDSCtlr->Server.ConnectTm = Now().FormatString("yyyy-MM-dd hh:nn:ss");
  447. ASession->CtlrId.printf("%10.010d", pCDSCtlr->CTLR_NMBR.ToIntDef(0));
  448. POST_MSG(MAINHANDLE, WM_TCP_THREAD, WM_TCP_SERVER_STTS, (int)pCDSCtlr);
  449. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  450. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  451. pMsg->Type = eVmsScenarioDownload;
  452. pMsg->ObjPtr = (DWORD)ASession;
  453. g_jobQ.PushBlocking((DWORD)pMsg);
  454. }
  455. else
  456. {
  457. if (sVmsId != ASession->CtlrId)
  458. {
  459. MERROR("+CLI Receive packet Vms Id error: %s, %s. will be closed.", ASession->CtlrId.c_str(), sVmsId.c_str());
  460. ASession->Disconnect();
  461. return -2;
  462. }
  463. }
  464. return 0;
  465. }
  466. //---------------------------------------------------------------------------
  467. /////////////////////////////////////////////////////////
  468. REGISTER_HANDLER(e_rpkt_CTRL_RESET_RES)
  469. {
  470. st_reset_res res;
  471. if (false == ASession->ParsePacket(res, APktLen))
  472. {
  473. TERROR("%s.%d, CTRL_RESET_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  474. MERROR("%s.%d, CTRL_RESET_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  475. return -1;
  476. }
  477. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  478. TDEBUG("CTRL_RESET_RES: %d bytes, Length:%d, Ack:%02X", APktLen, res.Length, res.Ack);
  479. return 0;
  480. }
  481. //---------------------------------------------------------------------------
  482. /////////////////////////////////////////////////////////
  483. REGISTER_HANDLER(e_rpkt_NOTIFY_STTS)
  484. {
  485. st_notify_stts res;
  486. if (false == ASession->ParsePacket(res, APktLen))
  487. {
  488. TERROR("%s.%d, NOTIFY_STTS parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  489. MERROR("%s.%d, NOTIFY_STTS parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  490. return -1;
  491. }
  492. if (!ASession->CDSCtlr)
  493. {
  494. TERROR("%s.%d, NOTIFY_STTS controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  495. MERROR("%s.%d, NOTIFY_STTS controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  496. return -2;
  497. }
  498. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  499. st_notify_stts *pData = &res;
  500. INT_VMS_STATE *FStts = &ASession->CDSCtlr->RSTATE;
  501. TDEBUG("NOTIFY_STTS: %d bytes, Length:%d, time: %14.14s, led:%02X, door: %02X, fan:%02X, hetr:%02X, tmpr:%02X, brgh:%02X, comm:%02X",
  502. APktLen, res.Length, pData->stts.time, pData->stts.led, pData->stts.door, pData->stts.fan, pData->stts.hetr, pData->stts.tmpr, pData->stts.brgh, pData->stts.comm);
  503. memcpy(FStts->ControllerCurrentTime, pData->stts.time, INT_VMS_MAX_DATETIME); /* 선택 제어기 시간 (YYYYMMDDHHMMSS) */
  504. if (pData->stts.led == 0x00) FStts->ModulePowerStatus = vms_module_power_off;
  505. else if (pData->stts.led == 0x01) FStts->ModulePowerStatus = vms_module_power_on;
  506. else FStts->ModulePowerStatus = vms_module_power_unknown;
  507. if (pData->stts.door == 0x00) FStts->DoorStatus = vms_door_close;
  508. else if (pData->stts.door == 0x01) FStts->DoorStatus = vms_door_open;
  509. else FStts->DoorStatus = vms_door_unknown;
  510. if (pData->stts.fan == 0x00) FStts->FanStatus = vms_fan_off;
  511. else if (pData->stts.fan == 0x01) FStts->FanStatus = vms_fan_on;
  512. else FStts->FanStatus = vms_fan_unknown;
  513. if (pData->stts.hetr == 0x00) FStts->HeaterStatus = vms_heater_off;
  514. else if (pData->stts.hetr == 0x01) FStts->HeaterStatus = vms_heater_on;
  515. else FStts->HeaterStatus = vms_heater_unknown;
  516. FStts->BodyTemp = (short)pData->stts.tmpr; /* 함체온도값(℃), 범위(-128~127) */
  517. FStts->LuminanceStatus = pData->stts.brgh; /* 화면의 밝기값 (최대 휘도값을 100으로 했을 때의 백분율 값), 범위(0~100) */
  518. FStts->Wcomm = pData->stts.comm == 0x00 ? vms_comm_normal : vms_comm_error; /* 무선통신상태, 0:정상 1:장애 */
  519. //
  520. // 응답
  521. st_notify_stts_ack ack;
  522. memcpy(ack.vmsid, res.vmsid, MAX_VMS_ID);
  523. if (!ASession->SendRequest((char*)&ack, sizeof(ack)))
  524. {
  525. ASession->Disconnect();
  526. TERROR("%s.%d, Client ack response send faild. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  527. MERROR("%s.%d, Client ack response send faild. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  528. return false;
  529. }
  530. POST_MSG(MAINHANDLE, WM_TCP_THREAD, WM_CTLR_STATE_STTS, (int)ASession->CDSCtlr);
  531. return 0;
  532. }
  533. //---------------------------------------------------------------------------
  534. /////////////////////////////////////////////////////////
  535. REGISTER_HANDLER(e_rpkt_DNLD_SCENARIO_RES)
  536. {
  537. st_dnld_scenario_res res;
  538. if (false == ASession->ParsePacket(res, APktLen))
  539. {
  540. TERROR("%s.%d, DNLD_SCENARIO_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  541. MERROR("%s.%d, DNLD_SCENARIO_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  542. return -1;
  543. }
  544. if (!ASession->CDSCtlr)
  545. {
  546. TERROR("%s.%d, DNLD_SCENARIO_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  547. MERROR("%s.%d, DNLD_SCENARIO_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  548. return -2;
  549. }
  550. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  551. TDEBUG("DNLD_SCENARIO_RES: %d bytes, Length:%d, Ack:%02X", APktLen, res.Length, res.Ack);
  552. if (res.Ack != ACK_NORMAL)
  553. {
  554. ASession->Disconnect();
  555. TERROR("%s.%d, DNLD_SCENARIO_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  556. MERROR("%s.%d, DNLD_SCENARIO_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  557. return -3;
  558. }
  559. TCDSCtlr *AObj = ASession->CDSCtlr;
  560. if (AObj)
  561. {
  562. if (AObj->CTRLMODE->Schedule)
  563. {
  564. VMS_PROVIDE_RESULE ProvideSave;
  565. memset(&ProvideSave, 0x00, sizeof(ProvideSave));
  566. ProvideSave.Type = provide_form;
  567. ProvideSave.Count = 1;
  568. ProvideSave.pObj[0] = (void*)AObj;
  569. AObj->CTRLMODE->Enable = object_disable;
  570. AObj->CTRLMODE->SvcDate = Now().FormatString("yyyymmddhhnnss");
  571. AObj->CTRLMODE->SaveFlag = true;
  572. AObj->CTRLMODE->Result = true;
  573. APP_PostDbThreadMessage(dbm_provide_result, sizeof(ProvideSave), &ProvideSave);
  574. }
  575. }
  576. return 0;
  577. }
  578. //---------------------------------------------------------------------------
  579. /////////////////////////////////////////////////////////
  580. REGISTER_HANDLER(e_rpkt_DNLD_FILE_RES)
  581. {
  582. st_dnld_file_res res;
  583. if (false == ASession->ParsePacket(res, APktLen))
  584. {
  585. TERROR("%s.%d, DNLD_FILE_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  586. MERROR("%s.%d, DNLD_FILE_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  587. return -1;
  588. }
  589. if (!ASession->CDSCtlr)
  590. {
  591. TERROR("%s.%d, DNLD_FILE_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  592. MERROR("%s.%d, DNLD_FILE_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  593. return -2;
  594. }
  595. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  596. TDEBUG("DNLD_FILE_RES: %d bytes, Length:%d, Ack:%02X", APktLen, res.Length, res.Ack);
  597. if (res.Ack != ACK_NORMAL)
  598. {
  599. ASession->Disconnect();
  600. TERROR("%s.%d, DNLD_FILE_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  601. MERROR("%s.%d, DNLD_FILE_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  602. return -3;
  603. }
  604. return 0;
  605. }
  606. //---------------------------------------------------------------------------
  607. /////////////////////////////////////////////////////////
  608. REGISTER_HANDLER(e_rpkt_PARAMETER_RES)
  609. {
  610. st_parameter_res res;
  611. if (false == ASession->ParsePacket(res, APktLen))
  612. {
  613. TERROR("%s.%d, PARAMETER_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  614. MERROR("%s.%d, PARAMETER_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  615. return -1;
  616. }
  617. if (!ASession->CDSCtlr)
  618. {
  619. TERROR("%s.%d, PARAMETER_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  620. MERROR("%s.%d, PARAMETER_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  621. return -2;
  622. }
  623. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  624. TDEBUG("PARAMETER_RES: %d bytes, Length:%d, Ack:%02X, led:%02X, fan:%02X, fanTmpr:%02X, hetr:%02X, hetrTmpr:%02X, brgh:%02X, brghVal:%02X, brghDay:%02X, brghNight:%02X, time:%14.14s",
  625. APktLen, res.Length, res.Ack, res.para.led, res.para.fan, res.para.fanTmpr, res.para.hetr, res.para.hetrTmpr, res.para.brgh, res.para.brghVal, res.para.brghDay, res.para.brghNight, res.para.time);
  626. //파라미터 요청 응답
  627. if (res.Ack != ACK_NORMAL)
  628. {
  629. ASession->Disconnect();
  630. TERROR("%s.%d, PARAMETER_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  631. MERROR("%s.%d, PARAMETER_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  632. return -3;
  633. }
  634. TCDSCtlr *AObj = ASession->CDSCtlr;
  635. if (AObj)
  636. {
  637. AObj->PANL_PWER_MODE = res.para.led; // N NUMBER(3) Y 2 전광판 전원 모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
  638. AObj->FAN_MODE = res.para.fan; // N NUMBER(3) Y 2 FAN 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
  639. AObj->FAN_RUN_TMPR = res.para.fanTmpr; // N NUMBER(3) Y 30 팬 동작 온도
  640. AObj->HETR_MODE = res.para.hetr; // N NUMBER(3) Y 2 히터 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
  641. AObj->HETR_RUN_TMPR = res.para.hetrTmpr; // N NUMBER(3) Y 0 히터 동작 온도
  642. AObj->BRGH_MODE = res.para.brgh; // N NUMBER(3) Y 2 휘도 모드(0x00:주간,0x01:야간,0x00:자동,0x09:알수없음)
  643. AObj->BRGH_CURR_STEP = res.para.brghVal; // N NUMBER(3) Y 40 휘도 현재 단계(0~100)
  644. AObj->BRGH_WEEK_STEP = res.para.brghDay; // N NUMBER(3) Y 64 휘도 주간 단계(0~100)
  645. AObj->BRGH_NGHT_STEP = res.para.brghNight; // N NUMBER(3) Y 48 휘도 야간 단계(0~100)
  646. AObj->ParamResTime.printf("%s", res.para.time);
  647. CTLR_STTS stts;
  648. stts.Type = 2;
  649. stts.ObjPtr = (void*)AObj;
  650. APP_PostDbThreadMessage(dbm_parma_res, sizeof(stts), &stts);
  651. }
  652. return 0;
  653. }
  654. //---------------------------------------------------------------------------
  655. /////////////////////////////////////////////////////////
  656. REGISTER_HANDLER(e_rpkt_CTRL_LED_POWER_RES)
  657. {
  658. st_ctrl_led_power_res res;
  659. if (false == ASession->ParsePacket(res, APktLen))
  660. {
  661. TERROR("%s.%d, CTRL_LED_POWER_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  662. MERROR("%s.%d, CTRL_LED_POWER_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  663. return -1;
  664. }
  665. if (!ASession->CDSCtlr)
  666. {
  667. TERROR("%s.%d, CTRL_LED_POWER_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  668. MERROR("%s.%d, CTRL_LED_POWER_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  669. return -2;
  670. }
  671. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  672. TDEBUG("CTRL_LED_POWER_RES: %d bytes, Length:%d, Ack:%02X", APktLen, res.Length, res.Ack);
  673. if (res.Ack != ACK_NORMAL)
  674. {
  675. ASession->Disconnect();
  676. TERROR("%s.%d, CTRL_LED_POWER_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  677. MERROR("%s.%d, CTRL_LED_POWER_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  678. return -3;
  679. }
  680. return 0;
  681. }
  682. //---------------------------------------------------------------------------
  683. /////////////////////////////////////////////////////////
  684. REGISTER_HANDLER(e_rpkt_CTRL_FAN_POWER_RES)
  685. {
  686. st_ctrl_fan_power_res res;
  687. if (false == ASession->ParsePacket(res, APktLen))
  688. {
  689. TERROR("%s.%d, CTRL_FAN_POWER_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  690. MERROR("%s.%d, CTRL_FAN_POWER_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  691. return -1;
  692. }
  693. if (!ASession->CDSCtlr)
  694. {
  695. TERROR("%s.%d, CTRL_FAN_POWER_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  696. MERROR("%s.%d, CTRL_FAN_POWER_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  697. return -2;
  698. }
  699. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  700. TDEBUG("CTRL_FAN_POWER_RES: %d bytes, Length:%d, Ack:%02X", APktLen, res.Length, res.Ack);
  701. if (res.Ack != ACK_NORMAL)
  702. {
  703. ASession->Disconnect();
  704. TERROR("%s.%d, CTRL_FAN_POWER_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  705. MERROR("%s.%d, CTRL_FAN_POWER_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  706. return -3;
  707. }
  708. return 0;
  709. }
  710. //---------------------------------------------------------------------------
  711. /////////////////////////////////////////////////////////
  712. REGISTER_HANDLER(e_rpkt_CTRL_BRGH_RES)
  713. {
  714. st_ctrl_brgh_res res;
  715. if (false == ASession->ParsePacket(res, APktLen))
  716. {
  717. TERROR("%s.%d, CTRL_BRGH_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  718. MERROR("%s.%d, CTRL_BRGH_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  719. return -1;
  720. }
  721. if (!ASession->CDSCtlr)
  722. {
  723. TERROR("%s.%d, CTRL_BRGH_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  724. MERROR("%s.%d, CTRL_BRGH_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  725. return -2;
  726. }
  727. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  728. TDEBUG("CTRL_BRGH_RES: %d bytes, Length:%d, Ack:%02X", APktLen, res.Length, res.Ack);
  729. if (res.Ack != ACK_NORMAL)
  730. {
  731. ASession->Disconnect();
  732. TERROR("%s.%d, CTRL_BRGH_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  733. MERROR("%s.%d, CTRL_BRGH_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  734. return -3;
  735. }
  736. return 0;
  737. }
  738. //---------------------------------------------------------------------------
  739. /////////////////////////////////////////////////////////
  740. REGISTER_HANDLER(e_rpkt_CTRL_CONFIG_RES)
  741. {
  742. st_ctrl_cfg_res res;
  743. if (false == ASession->ParsePacket(res, APktLen))
  744. {
  745. TERROR("%s.%d, CTRL_CONFIG_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  746. MERROR("%s.%d, CTRL_CONFIG_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  747. return -1;
  748. }
  749. if (!ASession->CDSCtlr)
  750. {
  751. TERROR("%s.%d, CTRL_CONFIG_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  752. MERROR("%s.%d, CTRL_CONFIG_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  753. return -2;
  754. }
  755. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  756. TDEBUG("CTRL_CONFIG_RES: %d bytes, Length:%d, Ack:%02X", APktLen, res.Length, res.Ack);
  757. if (res.Ack != ACK_NORMAL)
  758. {
  759. ASession->Disconnect();
  760. TERROR("%s.%d, CTRL_CONFIG_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  761. MERROR("%s.%d, CTRL_CONFIG_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  762. return -3;
  763. }
  764. return 0;
  765. }
  766. //---------------------------------------------------------------------------
  767. /////////////////////////////////////////////////////////
  768. REGISTER_HANDLER(e_rpkt_CTRL_TIME_RES)
  769. {
  770. st_ctrl_time_res res;
  771. if (false == ASession->ParsePacket(res, APktLen))
  772. {
  773. TERROR("%s.%d, CTRL_TIME_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  774. MERROR("%s.%d, CTRL_TIME_RES parsePacket error. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  775. return -1;
  776. }
  777. if (!ASession->CDSCtlr)
  778. {
  779. TERROR("%s.%d, CTRL_TIME_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  780. MERROR("%s.%d, CTRL_TIME_RES controller not found. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  781. return -2;
  782. }
  783. //ASession->InfoPacket(res.OpCode, APktLen, false, 0);
  784. TDEBUG("CTRL_TIME_RES: %d bytes, Length:%d, Ack:%02X", APktLen, res.Length, res.Ack);
  785. if (res.Ack != ACK_NORMAL)
  786. {
  787. ASession->Disconnect();
  788. TERROR("%s.%d, CTRL_TIME_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  789. MERROR("%s.%d, CTRL_TIME_RES failed. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  790. return -3;
  791. }
  792. return 0;
  793. }
  794. //---------------------------------------------------------------------------
  795. int TClientSession::DownloadScenarioForm(bool ASchedule/*=true*/)
  796. {
  797. int nSelCnt = 0;
  798. TCDSCtlr *AObj = FCDSCtlr;
  799. if (!AObj) return -1;
  800. int nFormCnt = AObj->pForms->Count();
  801. if (nFormCnt == 0) return nSelCnt;
  802. if (nFormCnt > INT_VMS_MAX_FORM) nFormCnt = INT_VMS_MAX_FORM;
  803. AnsiString sDispStrTm = Now().FormatString("yyyymmddhhnn");
  804. AnsiString sDispEndTm = (IncMinute(Now(), 10)).FormatString("yyyymmddhhnn");
  805. if (AObj->CTRLMODE->Control == 'B')
  806. {
  807. //디폴트 시나리오인 경우...
  808. sDispEndTm = "20991231235959";
  809. }
  810. st_dnld_scenario_req req;
  811. st_scenario *pScn;
  812. memset((char*)&req, 0x00, sizeof(st_dnld_scenario_req));
  813. req.Stx = VMS_STX;
  814. req.OpCode = (BYTE)DNLD_SCENARIO_REQ;
  815. memcpy(req.vmsid, FCtlrId.c_str(), sizeof(req.vmsid));
  816. req.Length = 0; // count senario//
  817. //scenario info
  818. //ETX
  819. AObj->pForms->Lock();
  820. try
  821. {
  822. for (int ii = 0; ii < nFormCnt; ii++)
  823. {
  824. TVmsForm *pForm = AObj->pForms->GetItem(ii);
  825. if (!pForm->Success) continue;
  826. pScn = &req.scenario[nSelCnt++];
  827. pScn->seq = (BYTE)nSelCnt; // 시나리오 순번
  828. pScn->type = pForm->fileType; // 표출타입
  829. if (pForm->fileType == P_FILE_TYPE_VIDEO ||
  830. pForm->fileType == P_FILE_TYPE_STREAM)
  831. {
  832. pScn->dispEffect = 0x00; // 표출효과
  833. }
  834. else
  835. {
  836. pScn->dispEffect = (BYTE)pForm->VMS_FORM_DSPL_MTHD_CD.ToIntDef(0);
  837. }
  838. sprintf(pScn->fileName, "%s", pForm->FtpFileName.c_str()); // 파일명
  839. pScn->dispTm = (pForm->fileType == P_FILE_TYPE_VIDEO) ? 0 : (BYTE)pForm->DSPL_HH; // 표출문구 표출시각('03' : 3초)
  840. memcpy(pScn->dispStrTm, sDispStrTm.c_str(), MAX_DISP_TIME); // 표출시작시간(0000 00 00 0000)
  841. memcpy(pScn->dispEndTm, sDispEndTm.c_str(), MAX_DISP_TIME); // 표출종료시각(999912312359)
  842. pScn->dnldFlag = 'D'; // 파일다운로드 여부 D : 다운로드
  843. if (nSelCnt >= MAX_SCENARIO) break;
  844. }
  845. }
  846. __finally
  847. {
  848. AObj->pForms->UnLock();
  849. }
  850. if (nSelCnt == 0) return 0;
  851. AObj->CTRLMODE->Schedule = ASchedule; // 스케쥴 모드인 경우 디비에 저장한다.
  852. req.type = (AObj->CTRLMODE->Control == 'B') ? 0x00 : 0x01;
  853. req.cnt = (BYTE)nSelCnt; // 해당 VMS의 전체시나리오 수
  854. req.Length = (short)((nSelCnt * sizeof(st_scenario))+2);
  855. req.scenario[nSelCnt].seq = VMS_ETX; //시나리오 구조체의 첫번째가 ETX 자리임
  856. int nSendBytes = sizeof(st_head) + req.Length + 1;
  857. if (!SendRequest((char*)&req, nSendBytes))
  858. {
  859. SERROR("+CLI DownloadScenarioForm send request faild: %s will be closed.", FIpAddress.c_str());
  860. MERROR("+CLI DownloadScenarioForm send request faild: %s will be closed.", FIpAddress.c_str());
  861. Disconnect();
  862. return -1;
  863. }
  864. return nSelCnt;
  865. }
  866. //---------------------------------------------------------------------------
  867. int TClientSession::ReqParameter()
  868. {
  869. TCDSCtlr *AObj = FCDSCtlr;
  870. if (!AObj) return -1;
  871. st_parameter_req req;
  872. memcpy(req.vmsid, FCtlrId.c_str(), sizeof(req.vmsid));
  873. req.OpCode = (BYTE)PARAMETER_REQ;
  874. if (!SendRequest((char*)&req, sizeof(req)))
  875. {
  876. SERROR("+CLI ReqParameter send request faild: %s will be closed.", FIpAddress.c_str());
  877. MERROR("+CLI ReqParameter send request faild: %s will be closed.", FIpAddress.c_str());
  878. Disconnect();
  879. return -1;
  880. }
  881. return 1;
  882. }
  883. //---------------------------------------------------------------------------
  884. int TClientSession::ReqLedPowerControl(BYTE AOnOff)
  885. {
  886. TCDSCtlr *AObj = FCDSCtlr;
  887. if (!AObj) return -1;
  888. st_ctrl_led_power_req req;
  889. memcpy(req.vmsid, FCtlrId.c_str(), sizeof(req.vmsid));
  890. req.cmd = AOnOff;
  891. if (!SendRequest((char*)&req, sizeof(req)))
  892. {
  893. SERROR("+CLI ReqLedPowerControl send request faild: %s will be closed.", FIpAddress.c_str());
  894. MERROR("+CLI ReqLedPowerControl send request faild: %s will be closed.", FIpAddress.c_str());
  895. Disconnect();
  896. return -1;
  897. }
  898. return 1;
  899. }
  900. //---------------------------------------------------------------------------
  901. int TClientSession::ReqFanPowerControl(BYTE AOnOff)
  902. {
  903. TCDSCtlr *AObj = FCDSCtlr;
  904. if (!AObj) return -1;
  905. st_ctrl_fan_power_req req;
  906. memcpy(req.vmsid, FCtlrId.c_str(), sizeof(req.vmsid));
  907. req.cmd = AOnOff;
  908. if (!SendRequest((char*)&req, sizeof(req)))
  909. {
  910. SERROR("+CLI ReqFanPowerControl send request faild: %s will be closed.", FIpAddress.c_str());
  911. MERROR("+CLI ReqFanPowerControl send request faild: %s will be closed.", FIpAddress.c_str());
  912. Disconnect();
  913. return -1;
  914. }
  915. return 1;
  916. }
  917. //---------------------------------------------------------------------------
  918. int TClientSession::ReqTimeControl(char *ATime)
  919. {
  920. TCDSCtlr *AObj = FCDSCtlr;
  921. if (!AObj) return -1;
  922. st_ctrl_time_req req;
  923. memcpy(req.vmsid, FCtlrId.c_str(), sizeof(req.vmsid));
  924. //memcpy(req.set.time, ATime, MAX_SYS_TIME);
  925. memcpy(req.set.time, AnsiString(Now().FormatString("yyyymmddhhnnss")).c_str(), MAX_SYS_TIME);
  926. if (!SendRequest((char*)&req, sizeof(req)))
  927. {
  928. SERROR("+CLI ReqTimeControl send request faild: %s will be closed.", FIpAddress.c_str());
  929. MERROR("+CLI ReqTimeControl send request faild: %s will be closed.", FIpAddress.c_str());
  930. Disconnect();
  931. return -1;
  932. }
  933. return 1;
  934. }
  935. //---------------------------------------------------------------------------
  936. int TClientSession::ReqBrightSet(char *ACmd)
  937. {
  938. TCDSCtlr *AObj = FCDSCtlr;
  939. if (!AObj) return -1;
  940. SIGNT_BRGH_SET *pCmd = (SIGNT_BRGH_SET*)ACmd;
  941. st_ctrl_brgh_req req;
  942. memcpy(req.vmsid, FCtlrId.c_str(), sizeof(req.vmsid));
  943. req.set.brgh = pCmd->BrghMode;
  944. req.set.brghVal = pCmd->BrghCurrStep;
  945. req.set.brghDay = pCmd->BrghWeekStep;
  946. req.set.brghNight = pCmd->BrghNghtStep;
  947. if (!SendRequest((char*)&req, sizeof(req)))
  948. {
  949. SERROR("+CLI ReqBrightSet send request faild: %s will be closed.", FIpAddress.c_str());
  950. MERROR("+CLI ReqBrightSet send request faild: %s will be closed.", FIpAddress.c_str());
  951. Disconnect();
  952. return -1;
  953. }
  954. return 1;
  955. }
  956. //---------------------------------------------------------------------------
  957. int TClientSession::ReqConfigSet(char *ACmd)
  958. {
  959. TCDSCtlr *AObj = FCDSCtlr;
  960. if (!AObj) return -1;
  961. SIGNT_CONFIG_SET *pCmd = (SIGNT_CONFIG_SET*)ACmd;
  962. st_ctrl_cfg_req req;
  963. memcpy(req.vmsid, FCtlrId.c_str(), sizeof(req.vmsid));
  964. req.set.fanTmpr = pCmd->FanRunTmpr;
  965. req.set.hetrTmpr = pCmd->HetrRunTmpr;
  966. memcpy(req.set.dispOnTm, pCmd->PanlOnTime, sizeof(req.set.dispOnTm));
  967. memcpy(req.set.dispOffTm, pCmd->PanlOffTime, sizeof(req.set.dispOffTm));
  968. if (!SendRequest((char*)&req, sizeof(req)))
  969. {
  970. SERROR("+CLI ReqConfigSet send request faild: %s will be closed.", FIpAddress.c_str());
  971. MERROR("+CLI ReqConfigSet send request faild: %s will be closed.", FIpAddress.c_str());
  972. Disconnect();
  973. return -1;
  974. }
  975. return 1;
  976. }
  977. //---------------------------------------------------------------------------
  978. int TClientSession::ReqReset(int AMode)
  979. {
  980. TCDSCtlr *AObj = FCDSCtlr;
  981. if (!AObj) return -1;
  982. st_reset_req req;
  983. memcpy(req.vmsid, FCtlrId.c_str(), sizeof(req.vmsid));
  984. req.OpCode = (BYTE)CTRL_RESET_REQ;
  985. req.type = (BYTE)AMode; //제어기 리셋
  986. if (!SendRequest((char*)&req, sizeof(req)))
  987. {
  988. SERROR("+CLI ReqReset send request faild: %s will be closed.", FIpAddress.c_str());
  989. MERROR("+CLI ReqReset send request faild: %s will be closed.", FIpAddress.c_str());
  990. Disconnect();
  991. return -1;
  992. }
  993. return 1;
  994. }
  995. //---------------------------------------------------------------------------