FrmMainF.cpp 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  1. //---------------------------------------------------------------------------
  2. #define WIN32_LEAN_AND_MEAN
  3. #include <DateUtils.hpp>
  4. #include "ITSNetF.h"
  5. #include <vcl.h>
  6. #pragma hdrstop
  7. #include <psapi.h>
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <time.h>
  11. //---------------------------------------------------------------------------
  12. #include "AppGlobalF.h"
  13. #include "VmsUtilsF.h"
  14. #include "FrmMainF.h"
  15. #include "MainCommF.h"
  16. #include "FrmOptionF.h"
  17. #include "FrmSysLogF.h"
  18. #include "FrmCommLogF.h"
  19. #include "FrmControllerInfoF.h"
  20. #include "FrmNetworkF.h"
  21. #include "LogThreadF.h"
  22. #include "DbmThreadF.h"
  23. #include "JobThreadF.h"
  24. #include "DMAdoDbF.h"
  25. #include "PacketHandllingF.h"
  26. #include "ClientSessionManagerF.h"
  27. //---------------------------------------------------------------------------
  28. #include "CDSProcessF.h"
  29. #include "CDSCtlrF.h"
  30. #include "CDSImageF.h"
  31. #include "CDSFormF.h"
  32. #include "CDSIfscF.h"
  33. #include "CDSFontF.h"
  34. #include "CDSColorF.h"
  35. #include "CDSAtmpF.h"
  36. #include "CDSParkF.h"
  37. #include "CDSManagerF.h"
  38. //---------------------------------------------------------------------------
  39. #pragma package(smart_init)
  40. #pragma link "IdAntiFreeze"
  41. #pragma link "IdAntiFreezeBase"
  42. #pragma link "IdBaseComponent"
  43. #pragma link "IdComponent"
  44. #pragma link "IdUDPBase"
  45. #pragma link "IdUDPServer"
  46. #pragma resource "*.dfm"
  47. TItsMap<int, TItsThread*> G_Threads;
  48. typedef std::map<int, TItsThread*>::iterator thrIterator;
  49. TFrmMain *FrmMain;
  50. //---------------------------------------------------------------------------
  51. __fastcall TFrmMain::TFrmMain(TComponent* Owner)
  52. : TForm(Owner)
  53. {
  54. Application->OnException = OnAppException;
  55. ::CoInitialize(NULL);
  56. FServerRun = false;
  57. FTickState = 0;
  58. g_AppCfg.bAppLoad = false;
  59. g_AppCfg.bAppClose = false;
  60. Caption = " " + g_AppCfg.sTitle + " - " + Now().FormatString("yyyy-MM-dd hh:nn:ss");
  61. ClientSessionManager = new TClientSessionManager();
  62. CDSProcessManager = new TCDSProcessManager();
  63. CDSCtlrManager = new TCDSCtlrManager();
  64. CDSFormManager = new TCDSFormManager();
  65. CDSImageManager = new TCDSImageManager();
  66. CDSIfscManager = new TCDSIfscManager();
  67. CDSFontManager = new TCDSFontManager();
  68. #if 0
  69. CDSAtmpManager = new TCDSAtmpManager();
  70. CDSParkManager = new TCDSParkManager();
  71. #endif
  72. CDSManager = new TCDSManager();
  73. #if 0
  74. CDSVmsIfscTrafManager = new TCDSVmsIfscTrafManager();
  75. #endif
  76. FCurrMin = StrToInt(Now().FormatString("nn"));;
  77. FCur1MinComm = FCurrMin;
  78. FCur1MinRun = FCurrMin;
  79. FCur5Min = FCurrMin;
  80. FCurrHour = -1;
  81. FCurrSec = -1;
  82. FTimeSyncDay = -1;
  83. FTimeSyncMin = -1;
  84. FUnitSttsHsMin = -1;
  85. FCtlrSttsHsMin = -1;
  86. FProvideRemain = -1;
  87. FOneMinCycle = false;
  88. FFirstRunning = true;
  89. m_dtChkDbAive = Now();
  90. FrmCommLog = new TFrmCommLog(Application);
  91. FrmNetwork = new TFrmNetwork(Application);
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TFrmMain::OnAppException(TObject *Sender, Exception *exception)
  95. {
  96. AnsiString sClassName = (NULL != Sender) ? AnsiString(Sender->ClassName()) : AnsiString("Unknown_Class");
  97. AnsiString sErrCls = (NULL != exception) ? AnsiString(exception->ClassName()) : AnsiString("Unknown_Error");
  98. AnsiString sErrMsg = (NULL != exception) ? AnsiString(exception->Message) : AnsiString("Unknown_Error");
  99. if (g_AppCfg.bAppClose)
  100. {
  101. LOGERROR("Program Close Exception Terminated. %s.%s.%s", sClassName.c_str(), sErrCls.c_str(), sErrMsg.c_str());
  102. }
  103. else
  104. {
  105. LOGERROR("Program Exception Terminated. %s.%s.%s", sClassName.c_str(), sErrCls.c_str(), sErrMsg.c_str());
  106. }
  107. Close();
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TFrmMain::FormCreate(TObject *Sender)
  111. {
  112. Application->ShowMainForm = false;
  113. try {
  114. Application->Icon->LoadFromResourceName(((unsigned int)HInstance), "MAINICON");
  115. } catch(...) { ShowMessage("LoadFromResourceName failed"); }
  116. g_AppCfg.lMainWinHandle = (long)Handle;
  117. FrmSysLog = new TFrmSysLog(pnlLog);
  118. FrmSysLog->Parent = pnlLog;
  119. FrmSysLog->Show();
  120. FrmControllerInfo = new TFrmControllerInfo(pnlController);
  121. FrmControllerInfo->Parent = pnlController;
  122. FrmControllerInfo->Show();
  123. char szLogMsg[MAX_LOG_BUFFER];
  124. if (!g_logQ.Create("vmsLog", MAX_LOGQ_BUFF))
  125. {
  126. sprintf(szLogMsg, "Log Q Create failed. Program abnormal terminate.");
  127. AbnormalTerminate(szLogMsg);
  128. Close();
  129. Close();
  130. }
  131. if (!g_dbmQ.Create("vmsDbm", MAX_DBMQ_BUFF))
  132. {
  133. sprintf(szLogMsg, "Dbm Q Create failed. Program abnormal terminate.");
  134. AbnormalTerminate(szLogMsg);
  135. Close();
  136. Close();
  137. }
  138. if (!g_jobQ.Create("vmsJob", MAX_JOBQ_BUFF))
  139. {
  140. sprintf(szLogMsg, "Job Q Create failed. Program abnormal terminate.");
  141. AbnormalTerminate(szLogMsg);
  142. Close();
  143. Close();
  144. }
  145. Application->ShowMainForm = true;
  146. }
  147. //---------------------------------------------------------------------------
  148. void __fastcall TFrmMain::FormShow(TObject *Sender)
  149. {
  150. FProvideRemain = SecondOfTheDay(Now());
  151. FProvideRemain %= g_AppCfg.nTrafficCycleTime;
  152. FProvideRemain = g_AppCfg.nTrafficCycleTime - FProvideRemain + g_AppCfg.nTrafficBasisTime;
  153. CheckResource((g_AppCfg.MaxMemory * 1024), g_AppCfg.MaxHandle, g_AppCfg.MaxThread, g_AppCfg.MaxGdi);
  154. Refresh();
  155. tmrAppState->Enabled = true;
  156. }
  157. //---------------------------------------------------------------------------
  158. void __fastcall TFrmMain::FormCloseQuery(TObject *Sender, bool &CanClose)
  159. {
  160. if (!g_AppCfg.bAppClose)
  161. {
  162. String strMsg;
  163. strMsg = Caption + "\r\n\r\nAre you sure you want to exit the program?\r\nIf the Process Manager is running the program will be restarted automatically!!!";
  164. //if (Application->MessageBox(strMsg.c_str(), L"Confirm program exit", MB_YESNO|MB_ICONQUESTION) == IDYES)
  165. {
  166. FServerRun = false;
  167. g_AppCfg.bAppClose = true;
  168. }
  169. CanClose = false;
  170. }
  171. }
  172. //---------------------------------------------------------------------------
  173. void __fastcall TFrmMain::FormClose(TObject *Sender, TCloseAction &Action)
  174. {
  175. CommClose();
  176. ::CoUninitialize();
  177. Action = caFree;
  178. FrmMain = NULL;
  179. }
  180. //---------------------------------------------------------------------------
  181. void __fastcall TFrmMain::CommClose()
  182. {
  183. try
  184. {
  185. g_AppCfg.bAppClose = true;
  186. APP_WriteConfigInfo("LOG", "LOGDAY", Now().FormatString("dd"), g_AppCfg.sConfigFile);
  187. if (IdUDPCenterServer->Active == true)
  188. {
  189. IdUDPCenterServer->Active = false;
  190. for (int ii = 0; ii < IdUDPCenterServer->Bindings->Count; ii++)
  191. {
  192. IdUDPCenterServer->Bindings->Items[ii]->Free();
  193. }
  194. }
  195. #if 0
  196. if (FrmCommLog) FrmCommLog->Close();
  197. if (FrmNetwork)
  198. {
  199. FrmNetwork->Stop();
  200. FrmNetwork->Close();
  201. }
  202. #endif
  203. }
  204. catch(Exception &e)
  205. {
  206. }
  207. }
  208. //---------------------------------------------------------------------------
  209. void __fastcall TFrmMain::AbnormalTerminate(char* AMsg)
  210. {
  211. for (int ii = 0; ii < 5; ii++)
  212. {
  213. ITSLog->LogWrite(NULL, eLOG_ERROR, AMsg);
  214. FrmSysLog->reMsg->Lines->Add(Now().FormatString("hh:nn:ss") + String(AMsg));
  215. Refresh();
  216. Sleep(1000);
  217. }
  218. }
  219. //---------------------------------------------------------------------------
  220. bool __fastcall TFrmMain::InitApplication()
  221. {
  222. int nResult;
  223. String sTitle, sMsg;
  224. char szLogMsg[MAX_LOG_BUFFER];
  225. Application->ProcessMessages();
  226. if (JobThreadStart() == false)
  227. {
  228. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  229. sprintf(szLogMsg, "Job Thread Create failed. Program abnormal terminate.");
  230. AbnormalTerminate(szLogMsg);
  231. return false;
  232. }
  233. MINFO("MAIN Program initialize start..."); // Q 생성후 메시지 출력함
  234. TDMAdoDb *FDb = new TDMAdoDb(NULL);
  235. try
  236. {
  237. MINFO("MAIN Database connect...");
  238. if (!FDb->Connect(g_AppCfg.db.sConnectStr))
  239. {
  240. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  241. sprintf(szLogMsg, "MAIN Database connect failed. Program abnormal terminate.");
  242. AbnormalTerminate(szLogMsg);
  243. return false;
  244. }
  245. if (CDSProcessManager)
  246. {
  247. MINFO("MAIN Process Information initialize...");
  248. if (CDSProcessManager->LoadUnitInfo(FDb->GetConnection()) < 0)
  249. {
  250. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  251. sprintf(szLogMsg, "MAIN Process Information initialize failed. Program abnormal terminate.");
  252. AbnormalTerminate(szLogMsg);
  253. return false;
  254. }
  255. }
  256. if (CDSCtlrManager)
  257. {
  258. MINFO("MAIN Controller Information initialize...");
  259. if (CDSCtlrManager->LoadCtlrInfo(FDb->GetConnection()) < 0)
  260. {
  261. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  262. sprintf(szLogMsg, "MAIN Controller Information initialize failed. Program abnormal terminate.");
  263. AbnormalTerminate(szLogMsg);
  264. return false;
  265. }
  266. }
  267. if (CDSFontManager)
  268. {
  269. MINFO("MAIN VMS Font Information initialize...");
  270. if (CDSFontManager->LoadFontInfo(FDb->GetConnection()) < 0)
  271. {
  272. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  273. sprintf(szLogMsg, "MAIN VMS Font Information initialize failed. Program abnormal terminate.");
  274. AbnormalTerminate(szLogMsg);
  275. return false;
  276. }
  277. }
  278. if (CDSIfscManager)
  279. {
  280. MINFO("MAIN VMS Scetion Information initialize...");
  281. if (CDSIfscManager->LoadVmsIfscInfo(FDb->GetConnection()) < 0)
  282. {
  283. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  284. sprintf(szLogMsg, "MAIN VMS Scetion Information initialize failed. Program abnormal terminate.");
  285. AbnormalTerminate(szLogMsg);
  286. return false;
  287. }
  288. }
  289. if (CDSImageManager)
  290. {
  291. MINFO("MAIN VMS Form Information initialize...");
  292. if (CDSImageManager->LoadVmsSymbolInfo(FDb->GetConnection()) < 0)
  293. {
  294. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  295. sprintf(szLogMsg, "MAIN VMS Form Information initialize failed. Program abnormal terminate.");
  296. AbnormalTerminate(szLogMsg);
  297. return false;
  298. }
  299. }
  300. if (CDSAtmpManager)
  301. {
  302. MINFO("MAIN VMS ATMP Information initialize...");
  303. if (CDSAtmpManager->LoadAtmpInfo(FDb->GetConnection()) < 0)
  304. {
  305. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  306. sprintf(szLogMsg, "MAIN VMS ATMP Information initialize failed. Program abnormal terminate.");
  307. AbnormalTerminate(szLogMsg);
  308. return false;
  309. }
  310. }
  311. if (CDSFormManager)
  312. {
  313. MINFO("MAIN VMS Form Information initialize...");
  314. if (CDSFormManager->LoadVmsFormInfo(FDb->GetConnection()) < 0)
  315. {
  316. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  317. sprintf(szLogMsg, "MAIN VMS Form Information initialize failed. Program abnormal terminate.");
  318. AbnormalTerminate(szLogMsg);
  319. return false;
  320. }
  321. }
  322. if (CDSVmsIfscTrafManager)
  323. {
  324. MINFO("MAIN VMS IFSC TRAF Information initialize...");
  325. if (CDSVmsIfscTrafManager->InitVmsIfscTraffic(FDb->GetConnection()) < 0)
  326. {
  327. memset(szLogMsg, 0x00, sizeof(szLogMsg));
  328. sprintf(szLogMsg, "MAIN VMS IFSC TRAF Information initialize failed. Program abnormal terminate.");
  329. AbnormalTerminate(szLogMsg);
  330. return false;
  331. }
  332. }
  333. }
  334. __finally
  335. {
  336. if (FDb)
  337. {
  338. FDb->Close();
  339. }
  340. SAFE_DELETE(FDb);
  341. }
  342. ClientSessionManager->Init(CDSCtlrManager->FLists.Size()*2);
  343. FrmControllerInfo->UpdateCtlrList();
  344. MINFO("MAIN Center communication initialize...");
  345. TCDSProcess *pPrcs = CDSProcessManager->FLists.Find(g_AppCfg.sSystemId);
  346. if (!pPrcs)
  347. {
  348. sMsg.printf(L"MAIN Center process information not found: %s, error %d", g_AppCfg.sSystemId.c_str(), nResult);
  349. MERROR(AnsiString(sMsg).c_str());
  350. return false;
  351. }
  352. g_AppCfg.comm.nCenterPort = pPrcs->PRGM_PORT.ToIntDef(g_AppCfg.comm.nCenterPort);
  353. //통신초기화를 최초 수행한 후 디비읽어서 처리
  354. nResult = CComm_Initialize((long)FrmMain->Handle, g_AppCfg.sSystemId, "VMS", g_AppCfg.comm.nCenterPort, g_AppCfg.sLogDay);
  355. if (VERR_NONE != nResult)
  356. {
  357. sMsg.printf(L"MAIN Center communication initialize failed: error %d", nResult);
  358. MERROR(AnsiString(sMsg).c_str());
  359. return false;
  360. }
  361. FOR_STL(TCDSProcess*, pObj, CDSProcessManager->FLists)
  362. {
  363. if (pObj->DEL_YN == "Y") continue;
  364. if (g_AppCfg.sSystemId == pObj->SYST_ID)
  365. {
  366. //자기자신은 목록에 추가하지 않는다...
  367. continue;
  368. }
  369. if (CComm_AddProcess(pObj->SYST_ID, pObj->SYST_TYPE, pObj->SYST_IP_1, pObj->PRGM_PORT) >= 0)
  370. {
  371. if ("UOT" == pObj->SYST_TYPE)
  372. {
  373. int nPort = pObj->PRGM_PORT.ToIntDef(0);
  374. CComm_AddProcess(pObj->SYST_ID, pObj->SYST_TYPE, pObj->SYST_IP_1, AnsiString(nPort+1)); /* VMS 운영단말 */
  375. #if 0
  376. CComm_AddProcess(pObj->SYST_ID, pObj->SYST_TYPE, pObj->SYST_IP_1, AnsiString(nPort+2)); /* CCTV 운영단말 */
  377. CComm_AddProcess(pObj->SYST_ID, pObj->SYST_TYPE, pObj->SYST_IP_1, AnsiString(nPort+3)); /* VDS 운영단말 */
  378. #endif
  379. }
  380. }
  381. }
  382. if (VERR_NONE != CComm_Open())
  383. {
  384. sMsg.printf(L"MAIN Center communication open failed: error %d", nResult);
  385. MERROR(AnsiString(sMsg).c_str());
  386. return false;
  387. }
  388. g_SysInfo->RunSts = state_normal;
  389. g_SysInfo->ComSts = state_error;
  390. g_SysInfo->DbmSts = state_normal;
  391. FTickState = 0;
  392. FServerRun = true;
  393. m_dtChkDbAive = Now(); // 데이터베이스 연결 체크 타이머
  394. m_dtChkVmsJob = Now(); // VMS 작업 및 주기작업
  395. m_dtProvider = Now()-1; // 정보제공 타이머
  396. COMM_MakeBasisTime(m_tTimer, g_AppCfg.nTrafficCycleTime, g_AppCfg.nTrafficBasisTime);
  397. //APP_PostDbThreadMessage(dbm_save_unit_stts);
  398. APP_PostDbThreadMessage(dbm_dnld_form_init);
  399. //통신서버 시작
  400. Sleep(500);
  401. tbConnectClick(this);
  402. MINFO("MAIN Program initialize success...[Completed]");
  403. return true;
  404. }
  405. //---------------------------------------------------------------------------
  406. void __fastcall TFrmMain::tmrAppStateTimer(TObject *Sender)
  407. {
  408. tmrAppState->Enabled = false;
  409. plTime->Caption = Now().FormatString("yyyy-MM-dd hh:nn:ss");
  410. if (!g_AppCfg.bAppLoad)
  411. {
  412. if (!InitApplication())
  413. {
  414. g_AppCfg.bAppClose = true;
  415. Close();
  416. return;
  417. }
  418. // 초기화작업완료
  419. CheckResource((g_AppCfg.MaxMemory * 1024), g_AppCfg.MaxHandle, g_AppCfg.MaxThread, g_AppCfg.MaxGdi);
  420. g_AppCfg.bAppLoad = true; // 프로그램이 로딩되었음을 확인
  421. tmrAppState->Interval = 980; // 프로그램 상태점검주기=1초
  422. tmrAppState->Enabled = true;
  423. return;
  424. }
  425. if (g_AppCfg.bAppClose)
  426. {
  427. // 응용프로그램 종료
  428. TerminateApplication();
  429. JobThreadStop();
  430. Close();
  431. return;
  432. }
  433. g_AppCfg.lMainWinHandle = (long)Handle;
  434. if (!(++FTickState % 5))
  435. {
  436. CheckCommState(); //통신상태정보 체크
  437. }
  438. UpdateProcessStatePanel();
  439. FCurrDay = StrToInt(Now().FormatString("dd"));
  440. FCurrHour = StrToInt(Now().FormatString("hh"));
  441. FCurrMin = StrToInt(Now().FormatString("nn"));
  442. FCurrSec = StrToInt(Now().FormatString("ss"));
  443. // 0시 3분에 시각 동기화 명령을 전송하자
  444. if (FCurrDay != FTimeSyncDay
  445. && FCurrMin != FTimeSyncMin
  446. && FCurrMin == 3
  447. && FCurrHour == 0)
  448. {
  449. FTimeSyncDay = FCurrDay;
  450. FTimeSyncMin = FCurrMin;
  451. SendTimeSync();
  452. }
  453. // 프로세스 상태정보 이력 DB 입력
  454. if (FCurrSec > 1)
  455. {
  456. //매 1분마다 상태정보 업데이트 하고 상태정보 업데이트 하는 곳에서 5분주기로 이력정보를 저장한다.
  457. if (FUnitSttsHsMin != FCurrMin)
  458. {
  459. FUnitSttsHsMin = FCurrMin;
  460. APP_PostDbThreadMessage(dbm_save_unit_stts);
  461. }
  462. }
  463. // 제어기 상태정보 이력 DB 입력
  464. if (FCurrSec > 3)
  465. {
  466. //매 1분마다 상태정보 업데이트 하고 상태정보 업데이트 하는 곳에서 5분주기로 이력정보를 저장한다.
  467. if (FCtlrSttsHsMin != FCurrMin)
  468. {
  469. FCtlrSttsHsMin = FCurrMin;
  470. APP_PostDbThreadMessage(dbm_save_ctlr_stts_all);
  471. }
  472. }
  473. if (FCurrSec > 5)
  474. {
  475. if (g_SysInfo->RunSts == state_normal && COMM_TimeDiff(m_dtChkDbAive) > 120)
  476. {
  477. //서버가 연결상태이고 DB 작업이 1분이상 경과된 경우 디비 연결상태를 체크한다.
  478. MINFO("MAIN *** Check Database Alive");
  479. APP_PostDbThreadMessage(dbm_check_db_alive);
  480. m_dtChkDbAive = Now();
  481. }
  482. }
  483. #if 0
  484. if (FCurrSec > 8)
  485. {
  486. if (g_SysInfo->RunSts == state_normal && COMM_TimeDiff(m_dtChkVmsJob) > 60)
  487. {
  488. //VMS 주기적인 작업을 데이터베이스에서 조회
  489. MINFO("MAIN *** Check VMS Job Schedule");
  490. APP_PostDbThreadMessage(dbm_load_onoff_time);
  491. APP_PostDbThreadMessage(dbm_load_download_job);
  492. m_dtChkVmsJob = Now();
  493. }
  494. }
  495. #endif
  496. plRemain->Caption = String(FProvideRemain--);
  497. if (FFirstRunning)
  498. {
  499. if ( (FCurrHour*3600 + FCurrMin*60) % g_AppCfg.nTrafficCycleTime == 0 &&
  500. FCurrSec >= g_AppCfg.nTrafficBasisTime )
  501. //if (CheckBasisTime(m_tTimer, g_AppCfg.nTrafficCycleTime, g_AppCfg.nTrafficBasisTime))
  502. {
  503. if (COMM_TimeDiff(m_dtProvider) > g_AppCfg.nTrafficCycleTime)
  504. {
  505. SendVmsTrafficProvide(1);
  506. }
  507. }
  508. }
  509. CheckProvideTimeout();
  510. if (!(FTickState % 60))
  511. {
  512. #if 0
  513. if (CheckResource((g_AppCfg.MaxMemory * 1024), g_AppCfg.MaxHandle, g_AppCfg.MaxThread, g_AppCfg.MaxGdi))
  514. {
  515. MERROR("MAIN Resource error");
  516. //AutoClose();
  517. }
  518. #endif
  519. }
  520. JobThreadCheck();
  521. #if 0
  522. g_logQ.PushBlocking(Q_TICK);
  523. g_dbmQ.PushBlocking(Q_TICK);
  524. #endif
  525. g_jobQ.PushBlocking(Q_TICK); //접속한 클라이언트 작업을 위해 스레드를 깨운다.
  526. tmrAppState->Enabled = true;
  527. }
  528. //---------------------------------------------------------------------------
  529. void __fastcall TFrmMain::AutoClose()
  530. {
  531. g_AppCfg.bAppClose = true;
  532. //Close();
  533. }
  534. //---------------------------------------------------------------------------
  535. void __fastcall TFrmMain::tbConnectClick(TObject *Sender)
  536. {
  537. g_AppCfg.bThrExit = false;
  538. //FrmNetwork->Show();
  539. if (FrmNetwork->Start())
  540. {
  541. FServerRun = true;
  542. tbConnect->Enabled = false;
  543. tbDisconnect->Enabled = true;
  544. }
  545. }
  546. //---------------------------------------------------------------------------
  547. void __fastcall TFrmMain::tbDisconnectClick(TObject *Sender)
  548. {
  549. FServerRun = false;
  550. g_jobQ.PushBlocking(eTcpCloseAll);
  551. FrmNetwork->Stop();
  552. tbDisconnect->Enabled = false;
  553. tbConnect->Enabled = true;
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TFrmMain::tbOptionsClick(TObject *Sender)
  557. {
  558. FrmOption = new TFrmOption(this);
  559. FrmOption->Left = FrmMain->Left + 80;
  560. FrmOption->Top = FrmMain->Top + 80;
  561. FrmOption->ShowModal();
  562. if (FrmOption->FUpdate)
  563. {
  564. try
  565. {
  566. ITSLog->FLogCfg = g_LogCfg;
  567. CtlrItr it;
  568. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  569. {
  570. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  571. if (!pObj->FDispLog)
  572. {
  573. pObj->FCLog->FLogCfg = g_LogCfg;
  574. pObj->FSLog->FLogCfg = g_LogCfg;
  575. }
  576. }
  577. }
  578. catch(Exception &e)
  579. {
  580. }
  581. }
  582. delete FrmOption;
  583. FrmOption = NULL;
  584. }
  585. //---------------------------------------------------------------------------
  586. void __fastcall TFrmMain::CheckCommState()
  587. {
  588. //g_SysInfo->RunSts = (FServerRun && DMManager->TcpServer->Active) ? state_normal : state_error;
  589. g_SysInfo->RunSts = (FServerRun) ? state_normal : state_error;
  590. if (g_SysInfo->RunSts == state_normal)
  591. {
  592. if (CDSCtlrManager->Total == CDSCtlrManager->Normal) g_SysInfo->ComSts = state_normal;
  593. else g_SysInfo->ComSts = state_error;
  594. }
  595. else
  596. {
  597. g_SysInfo->ComSts = state_error;
  598. }
  599. }
  600. //---------------------------------------------------------------------------
  601. void __fastcall TFrmMain::UpdateProcessStatePanel()
  602. {
  603. plStateAction->Color = (g_SysInfo->RunSts == state_normal) ? clGreen : clRed;
  604. plStateComm->Color = (g_SysInfo->ComSts == state_normal) ? clGreen : clRed;
  605. plStateDb->Color = (g_SysInfo->DbmSts == state_normal) ? clGreen : clRed;
  606. }
  607. //---------------------------------------------------------------------------
  608. void __fastcall TFrmMain::OnWMDbThreadMessage(TMessage &Msg)
  609. {
  610. int nCommand = (int)Msg.WParam;
  611. int nResult = (int)Msg.LParam;
  612. ReplyMessage(0);
  613. switch(nCommand)
  614. {
  615. case dbm_status:
  616. g_SysInfo->DbmSts = nResult >= 0 ? state_normal : state_error;
  617. break;
  618. case dbm_dnld_form_init:
  619. MINFO("MAIN VMS Message init start event");
  620. MakeVmsProvideForm();
  621. break;
  622. case dbm_dnld_form_cycle:
  623. case dbm_dnld_form_mode:
  624. MINFO("MAIN VMS Message create start event");
  625. MakeVmsProvideForm();
  626. APP_PostDbThreadMessage(dbm_save_form_download);
  627. break;
  628. case dbm_save_form_download:
  629. MINFO("MAIN VMS Message download start event");
  630. //클라이언트로 VMS폼 스케쥴이 저장되었다는 이벤트를 전송
  631. CDSManager->SendVmsDownloadForm();
  632. //VMS 제어기에 VMS폼 스케쥴을 다운로드 하도록 이벤트 전송
  633. g_jobQ.PushBlocking(eVmsFormDownload);
  634. CheckResource((g_AppCfg.MaxMemory * 1024), g_AppCfg.MaxHandle, g_AppCfg.MaxThread, g_AppCfg.MaxGdi);
  635. break;
  636. case dbm_initialize:
  637. break;
  638. }
  639. m_dtChkDbAive = Now(); // 데이터베이스 작업 성공/실패 여부와 상관없이 체크타이머 초기화
  640. }
  641. //---------------------------------------------------------------------------
  642. void __fastcall TFrmMain::OnWMUserMessage(TMessage &Msg)
  643. {
  644. ReplyMessage(0);
  645. if ((int)Msg.WParam == WM_WINDOW_RESTORE)
  646. {
  647. Application->Restore();
  648. Application->BringToFront();
  649. return;
  650. }
  651. }
  652. //---------------------------------------------------------------------------
  653. void __fastcall TFrmMain::OnTcpThreadMessage(TMessage &Msg)
  654. {
  655. TCDSCtlr *pObj = (TCDSCtlr*)Msg.LParam;
  656. CTLR_STTS stts;
  657. switch(Msg.WParam)
  658. {
  659. case WM_TCP_SERVER_STTS: // 클라이언트의 연결 또는 연결종료시 수신 메시지
  660. try
  661. {
  662. if (pObj->Server.commState == comm_open)
  663. {
  664. pObj->dwConnectCnt++;
  665. MINFO("MAIN VMS Connect Event: %s", pObj->CTLR_NMBR.c_str());
  666. }
  667. else
  668. {
  669. MINFO("MAIN VMS Closed Event: %s", pObj->CTLR_NMBR.c_str());
  670. }
  671. } catch(Exception &e) {}
  672. FrmControllerInfo->UpdateServerState((int)pObj);
  673. stts.Type = 1;
  674. stts.ObjPtr = (void*)pObj;
  675. APP_PostDbThreadMessage(dbm_save_ctlr_stts, sizeof(stts), &stts);
  676. break;
  677. case WM_CTLR_STATE_STTS: // 연결된 제어기로 부터 상태정보를 수신할시
  678. try
  679. {
  680. MINFO("MAIN VMS State Event: %s", pObj->CTLR_NMBR.c_str());
  681. } catch(Exception &e) {}
  682. FrmControllerInfo->UpdateClientState((int)pObj);
  683. stts.Type = 0;
  684. stts.ObjPtr = (void*)pObj;
  685. APP_PostDbThreadMessage(dbm_save_ctlr_stts, sizeof(stts), &stts);
  686. break;
  687. }
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TFrmMain::OnUdpDataRecvMessage(TMessage &Msg)
  691. {
  692. int nResult;
  693. IPC_MSG_DATA *RcvData = (IPC_MSG_DATA*)Msg.LParam;
  694. INT_SENDER *Sender = &RcvData->Sender;
  695. INT_PACKET *Pkt = &RcvData->Pkt;
  696. INT_HEAD *head = &Pkt->head;
  697. INT_DATA *data = &Pkt->data;
  698. char *pData = &Pkt->data.Data[0];
  699. BYTE OpCode = head->OpCode;
  700. MINFO("MAIN Center Msg: %s.%d, OpCode: %02X, From: %02X, To: %02X", CComm_ulong2ip(Sender->IP), Sender->Port, OpCode, head->SendId, head->RecvId);
  701. switch(OpCode)
  702. {
  703. case INT_OP_TRAFFIC_CHANGE:
  704. MINFO("MAIN INT_OP_TRAFFIC_CHANGE");
  705. CDSManager->FIsStaticCycle = true; //정주기 정보제공주기 플래그 설정
  706. SendVmsTrafficProvide(0);
  707. break;
  708. case INT_OP_VMS_PARAM_REQ:
  709. {
  710. INT_VMS_PARAM_REQ *pReq = (INT_VMS_PARAM_REQ*)pData;
  711. MINFO("MAIN INT_OP_VMS_PARAM_REQ: %d", pReq->Count);
  712. for (int ii = 0; ii < pReq->Count && ii < INT_MAX_IMDT_SCN_DNLD_MAX; ii++)
  713. {
  714. TCDSCtlr *pCDSCtlr = CDSCtlrManager->FLists.Find(AnsiString(pReq->VMS_CTLR_NMBR[ii]));
  715. if (!pCDSCtlr) continue;
  716. if (!pCDSCtlr->FSession) continue;
  717. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  718. pMsg->Type = eVmsParamReq;
  719. pMsg->ObjPtr = (DWORD)pCDSCtlr->FSession;
  720. g_jobQ.PushBlocking((DWORD)pMsg);
  721. }
  722. }
  723. break;
  724. case INT_OP_VMS_POWER_CTL: //전광판 On/Off
  725. {
  726. INT_VMS_POWER_CTL_REQ *pReq = (INT_VMS_POWER_CTL_REQ*)pData;
  727. MINFO("MAIN INT_OP_VMS_POWER_CTL: %.*s %d, %s, %d", INT_VMS_MAX_DATETIME, pReq->CmdTime, pReq->VMS_CTLR_NMBR, pReq->OperId, pReq->Command);
  728. TCDSCtlr *pCDSCtlr = CDSCtlrManager->FLists.Find(AnsiString(pReq->VMS_CTLR_NMBR));
  729. if (!pCDSCtlr) break;
  730. if (!pCDSCtlr->FSession) break;
  731. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  732. pMsg->Type = eVmsLedPowerControl;
  733. pMsg->ObjPtr = (DWORD)pCDSCtlr->FSession;
  734. pMsg->Buff[0] = pReq->Command;
  735. g_jobQ.PushBlocking((DWORD)pMsg);
  736. }
  737. break;
  738. case INT_OP_VMS_LUMINANCE_CTL: //휘도설정
  739. {
  740. INT_VMS_LUMINANCE_REQ *pReq = (INT_VMS_LUMINANCE_REQ*)pData;
  741. MINFO("MAIN INT_OP_VMS_LUMINANCE_CTL: %.*s %d, %s, %02X", INT_VMS_MAX_DATETIME, pReq->CmdTime, pReq->VMS_CTLR_NMBR, pReq->OperId, pReq->BrghMode);
  742. TCDSCtlr *pCDSCtlr = CDSCtlrManager->FLists.Find(AnsiString(pReq->VMS_CTLR_NMBR));
  743. if (!pCDSCtlr) break;
  744. if (!pCDSCtlr->FSession) break;
  745. SIGNT_BRGH_SET set;
  746. set.VMS_CTLR_NMBR = pReq->VMS_CTLR_NMBR;
  747. set.BrghMode = pReq->BrghMode;
  748. set.BrghCurrStep = pReq->BrghCurrStep;
  749. set.BrghWeekStep = pReq->BrghWeekStep;
  750. set.BrghNghtStep = pReq->BrghNghtStep;
  751. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  752. pMsg->Type = eVmsBrghSet;
  753. pMsg->ObjPtr = (DWORD)pCDSCtlr->FSession;
  754. memcpy(pMsg->Buff, (char*)&set, sizeof(SIGNT_BRGH_SET));
  755. g_jobQ.PushBlocking((DWORD)pMsg);
  756. }
  757. break;
  758. case INT_OP_VMS_RESET:
  759. {
  760. INT_VMS_RESET_REQ *pReq = (INT_VMS_RESET_REQ*)pData;
  761. MINFO("MAIN INT_OP_VMS_RESET: %.*s %d, %s, %d", INT_VMS_MAX_DATETIME, pReq->CmdTime, pReq->VMS_CTLR_NMBR, pReq->OperId, pReq->Mode);
  762. TCDSCtlr *pCDSCtlr = CDSCtlrManager->FLists.Find(AnsiString(pReq->VMS_CTLR_NMBR));
  763. if (!pCDSCtlr) break;
  764. if (!pCDSCtlr->FSession) break;
  765. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  766. pMsg->Type = eVmsReset;
  767. pMsg->ObjPtr = (DWORD)pCDSCtlr->FSession;
  768. pMsg->Buff[0] = pReq->Mode; //리셋모드
  769. g_jobQ.PushBlocking((DWORD)pMsg);
  770. }
  771. break;
  772. case INT_OP_VMS_PARA_SET: //환경설정 정보 설정
  773. {
  774. INT_VMS_PARA_SET_REQ *pReq = (INT_VMS_PARA_SET_REQ*)pData;
  775. MINFO("MAIN INT_OP_VMS_PARA_SET: %.*s %d, %s", INT_VMS_MAX_DATETIME, pReq->CmdTime, pReq->VMS_CTLR_NMBR, pReq->OperId);
  776. TCDSCtlr *pCDSCtlr = CDSCtlrManager->FLists.Find(AnsiString(pReq->VMS_CTLR_NMBR));
  777. if (!pCDSCtlr) break;
  778. if (!pCDSCtlr->FSession) break;
  779. SIGNT_CONFIG_SET set;
  780. set.VMS_CTLR_NMBR = pCDSCtlr->CTLR_NMBR.ToIntDef(0);
  781. set.FanRunTmpr = pReq->FanRunTmpr;
  782. set.HetrRunTmpr = pReq->HetrRunTmpr;
  783. memcpy(set.PanlOnTime, pReq->DispStrTm, 4);
  784. memcpy(set.PanlOffTime, pReq->DispEndTm, 4);
  785. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  786. pMsg->Type = eVmsConfigSet;
  787. pMsg->ObjPtr = (DWORD)pCDSCtlr->FSession;
  788. memcpy(pMsg->Buff, (char*)&set, sizeof(SIGNT_CONFIG_SET));
  789. g_jobQ.PushBlocking((DWORD)pMsg);
  790. }
  791. break;
  792. case INT_OP_VMS_IMMEDIATE_SCN_DNLD:
  793. {
  794. INT_VMS_IMMEDIATE_SCENARIO_DNLD_REQ *pReq = (INT_VMS_IMMEDIATE_SCENARIO_DNLD_REQ*)pData;
  795. MINFO("MAIN INT_OP_VMS_IMMEDIATE_SCN_DNLD: %.*s, %s", INT_VMS_MAX_DATETIME, pReq->CmdTime, pReq->OperId);
  796. for (int ii = 0; ii < pReq->Count && ii < INT_MAX_IMDT_SCN_DNLD_MAX; ii++)
  797. {
  798. TCDSCtlr *pObj = CDSCtlrManager->FLists.Find(AnsiString(pReq->VMS_CTLR_NMBR[ii]));
  799. if (!pObj) continue;
  800. if (!pObj->FSession) continue;
  801. CDSCtlrManager->InitProvide(pObj);
  802. #if 0
  803. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  804. pMsg->Type = eVmsScenarioDownload;
  805. pMsg->ObjPtr = (DWORD)pObj->FSession;
  806. g_jobQ.PushBlocking((DWORD)pMsg);
  807. #endif
  808. }
  809. APP_PostDbThreadMessage(dbm_dnld_form_cycle);
  810. //APP_PostDbThreadMessage(dbm_dnld_form_mode);
  811. }
  812. break;
  813. case INT_OP_VMS_MODE:
  814. {
  815. INT_VMS_MODE_REQ *pReq = (INT_VMS_MODE_REQ*)pData;
  816. MINFO("MAIN INT_OP_VMS_MODE: %.*s %s, %s, %d EA", INT_VMS_MAX_DATETIME, pReq->CmdTime, pReq->OperId, pReq->Count);
  817. //모든 VMS에 메시지다운로드 플래그 비활성화 시킴
  818. //CDSCtlrManager->InitProvide(false);
  819. //수신한 VMS에 대하여 다운로드 플래그 활성화 시킴
  820. for(int ii = 0; ii < pReq->Count && ii < INT_VMS_MAX_MODE; ii++)
  821. {
  822. TCDSCtlr *pObj = CDSCtlrManager->FLists.Find(AnsiString(pReq->Unit[ii].VMS_CTLR_NMBR));
  823. if (!pObj) continue;
  824. if (pObj->Server.useFlag != use_enable) continue;
  825. if (pObj->CTRLMODE->Control == pReq->Unit[ii].Mode)
  826. pObj->FModeChange = false;
  827. else
  828. pObj->FModeChange = true;
  829. pObj->CTRLMODE->Control = pReq->Unit[ii].Mode;
  830. pObj->DSTATE.OprMode = pObj->CTRLMODE->Control;
  831. pObj->RSTATE.OprMode = pObj->CTRLMODE->Control;
  832. if (pObj->CTRLMODE->Control == 'A') pObj->OPER_MODE = "A";
  833. else if (pObj->CTRLMODE->Control == 'B') pObj->OPER_MODE = "B";
  834. else pObj->OPER_MODE = "F";
  835. //pObj->FProvide = true;
  836. CDSCtlrManager->InitProvide(pObj);
  837. }
  838. FrmControllerInfo->UpdateCtlrList();
  839. APP_PostDbThreadMessage(dbm_dnld_form_mode);
  840. }
  841. break;
  842. case INT_OP_VMS_STATE_REQ:
  843. MINFO("MAIN INT_OP_VMS_STATE_REQ");
  844. CDSCtlrManager->SendCtlrSttsAll();
  845. break;
  846. case INT_OP_VMS_IMAGE_SYMBOL:
  847. MINFO("MAIN INT_OP_VMS_IMAGE_SYMBOL");
  848. APP_PostDbThreadMessage(dbm_master_symbol_image);
  849. break;
  850. case INT_OP_VMS_IMAGE_TRAFFIC:
  851. MINFO("MAIN INT_OP_VMS_IMAGE_TRAFFIC");
  852. APP_PostDbThreadMessage(dbm_master_symbol_traffic);
  853. break;
  854. case INT_OP_VMS_FORM_UPDATE:
  855. MINFO("MAIN INT_OP_VMS_FORM_UPDATE");
  856. APP_PostDbThreadMessage(dbm_master_form);
  857. break;
  858. case INT_OP_VMS_IFSC_UPDATE:
  859. MINFO("MAIN INT_OP_VMS_IFSC_UPDATE");
  860. APP_PostDbThreadMessage(dbm_master_vms_ifsc);
  861. break;
  862. default:
  863. MINFO("MAIN INT_UNKNOWN: %02X", OpCode);
  864. break;
  865. }
  866. }
  867. //---------------------------------------------------------------------------
  868. #if 0
  869. void __fastcall TFrmMain::ClientResponse(int Flag, REQ_INFO_STRUCT *pReq, int error, void *pData)
  870. {
  871. #ifdef CENTERCOMM
  872. BYTE ErrCode;
  873. int sResult;
  874. switch(error)
  875. {
  876. case SYS_ERR_NONE: break;
  877. case SYS_ERR_OTHER: ErrCode = INT_ERROR_OTHER; break;
  878. case SYS_ERR_INTERNAL: ErrCode = INT_ERROR_SYSTEM; break;
  879. case SYS_ERR_MEMORY: ErrCode = INT_ERROR_SYSTEM; break;
  880. case SYS_ERR_DATABASE: ErrCode = INT_ERROR_SYSTEM; break;
  881. case SYS_ERR_RESET: ErrCode = INT_ERROR_SYSTEM; break;
  882. case SYS_ERR_START: ErrCode = INT_ERROR_SYSTEM; break;
  883. case SYS_ERR_OFFLINE: ErrCode = INT_ERROR_OFFLINE; break;
  884. case SYS_ERR_NO_RES: ErrCode = INT_ERROR_NO_RESPONSE; break;
  885. case SYS_ERR_ACCESS: ErrCode = INT_ERROR_PROCESS; break;
  886. case SYS_ERR_INVALID: ErrCode = INT_ERROR_OTHER; break;
  887. case SYS_ERR_UNKNOWN: ErrCode = INT_ERROR_UNKNOWN_CODE; break;
  888. case SYS_ERR_WRITE_LENGTH: ErrCode = INT_ERROR_OTHER; break;
  889. case SYS_ERR_PACKET_SIZE_LARGE: ErrCode = INT_ERROR_OTHER; break;
  890. case SYS_ERR_INVALID_TAG: ErrCode = INT_ERROR_OTHER; break;
  891. case SYS_ERR_CRC: ErrCode = INT_ERROR_OTHER; break;
  892. case SYS_ERR_LENGTH: ErrCode = INT_ERROR_LENGTH; break;
  893. case SYS_ERR_ADDRESS: ErrCode = INT_ERROR_ADDRESS; break;
  894. case SYS_ERR_HEADER_OPTIONS: ErrCode = INT_ERROR_HEADER; break;
  895. case SYS_ERR_UNKNOWN_COMMAND: ErrCode = INT_ERROR_UNKNOWN_OPCODE; break;
  896. case SYS_ERR_RECEIVE_TIMEOUT: ErrCode = INT_ERROR_OTHER; break;
  897. case SYS_ERR_DATA_SIZE: ErrCode = INT_ERROR_DISCORD; break;
  898. case SYS_ERR_MISMATCH: ErrCode = INT_ERROR_OTHER; break;
  899. case SYS_ERR_INVALID_PARA: ErrCode = INT_ERROR_INVALID_DATA; break;
  900. case SYS_ERR_MOVEMENT: ErrCode = INT_ERROR_MOVEMENT; break;
  901. case SYS_ERR_UNAUTHORIZED: ErrCode = INT_ERROR_UNAUTHORIZED; break;
  902. default: ErrCode = INT_ERROR_OTHER; break;
  903. }
  904. if (Flag == SEND_ACK)
  905. {
  906. INT_ACK_RES Ack;
  907. memset(&Ack, 0x00, sizeof(Ack));
  908. Ack.OPCode.Type = INT_TYPE(pReq->OpCode);
  909. Ack.OPCode.Kind = INT_KIND(pReq->OpCode);
  910. Ack.MsgSeq = pReq->MsgSeq;
  911. if ((sResult = AckRes(&Ack, pReq->ProcessID)) != UDP_ERR_NONE)
  912. {
  913. MERROR("MAIN AckRes fail %d", sResult);
  914. }
  915. }
  916. else
  917. if (Flag == SEND_NACK)
  918. {
  919. INT_NACK_RES Nack;
  920. memset(&Nack, 0x00, sizeof(Nack));
  921. Nack.OPCode.Type = INT_TYPE(pReq->OpCode);
  922. Nack.OPCode.Kind = INT_KIND(pReq->OpCode);
  923. Nack.MsgSeq = pReq->MsgSeq;
  924. Nack.ErrCode = ErrCode;
  925. if ((sResult = NackRes(&Nack, pReq->ProcessID)) != UDP_ERR_NONE)
  926. {
  927. MERROR("MAIN NackRes fail %d", sResult);
  928. }
  929. }
  930. #endif
  931. }
  932. //---------------------------------------------------------------------------
  933. #endif
  934. bool __fastcall TFrmMain::CheckBasisTime(char *p, int Cycle, int Basis)
  935. {
  936. char cTime[15];
  937. COMM_MakeBasisTime(cTime, Cycle, Basis);
  938. if (memcmp(p, cTime, 14) != 0)
  939. {
  940. memcpy(p, cTime, 14);
  941. return true;
  942. }
  943. return false;
  944. }
  945. //---------------------------------------------------------------------------
  946. void __fastcall TFrmMain::CheckProvideTimeout()
  947. {
  948. VMS_PROVIDE_RESULE ProvideSave;
  949. VMS_PROVIDE_RESULE DownLoadSave;
  950. memset(&ProvideSave, 0x00, sizeof(ProvideSave));
  951. memset(&DownLoadSave, 0x00, sizeof(DownLoadSave));
  952. ProvideSave.Type = provide_form;
  953. ProvideSave.Count = 0;
  954. DownLoadSave.Type = provide_download;
  955. DownLoadSave.Count = 0;
  956. CtlrItr it;
  957. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  958. {
  959. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  960. if (pObj->Server.useFlag != use_enable) continue;
  961. if ((pObj->DOWNLOAD->SaveFlag == false) &&
  962. (COMM_TimeDiff(pObj->DOWNLOAD->dTimer) > VMS_DOWNLOAD_TIMEOUT))
  963. {
  964. DownLoadSave.pObj[DownLoadSave.Count++] = (void *)pObj;
  965. pObj->DOWNLOAD->SaveFlag = true;
  966. }
  967. if ((pObj->CTRLMODE->SaveFlag == false) &&
  968. (COMM_TimeDiff(pObj->CTRLMODE->pTimer) > VMS_PROVIDE_TIMEOUT))
  969. {
  970. ProvideSave.pObj[ProvideSave.Count++] = (void *)pObj;
  971. pObj->CTRLMODE->SaveFlag = true;
  972. }
  973. // 패킷크기가 채워졌으면 DB 작업스레드로 전송
  974. if (ProvideSave.Count >= MAX_VMS_PROVIDE_RESULT)
  975. {
  976. APP_PostDbThreadMessage(dbm_provide_result, sizeof(ProvideSave), &ProvideSave);
  977. }
  978. if (DownLoadSave.Count >= MAX_VMS_PROVIDE_RESULT)
  979. {
  980. APP_PostDbThreadMessage(dbm_provide_result, sizeof(DownLoadSave), &DownLoadSave);
  981. }
  982. }
  983. // 실패작업이 존재하면 DB 작업스레드로 전송
  984. if (ProvideSave.Count > 0)
  985. {
  986. APP_PostDbThreadMessage(dbm_provide_result, sizeof(ProvideSave), &ProvideSave);
  987. }
  988. if (DownLoadSave.Count > 0)
  989. {
  990. APP_PostDbThreadMessage(dbm_provide_result, sizeof(DownLoadSave), &DownLoadSave);
  991. }
  992. }
  993. //---------------------------------------------------------------------------
  994. void __fastcall TFrmMain::SendTimeSync()
  995. {
  996. CtlrItr it;
  997. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  998. {
  999. TCDSCtlr *pCDSCtlr = (TCDSCtlr*)it->second;
  1000. if (pCDSCtlr->Server.useFlag != use_enable) continue;
  1001. if (pCDSCtlr->FSession)
  1002. {
  1003. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  1004. pMsg->Type = eVmsTimeControl;
  1005. pMsg->ObjPtr = (DWORD)pCDSCtlr->FSession;
  1006. memcpy(pMsg->Buff, AnsiString(Now().FormatString("yyyymmddhhnnss")).c_str(), MAX_SYS_TIME);
  1007. g_jobQ.PushBlocking((DWORD)pMsg);
  1008. // 제어기가 연결되어 있으면 전송
  1009. MINFO("MAIN SendTimeSync command send: %s", pCDSCtlr->CTLR_NMBR.c_str());
  1010. }
  1011. }
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. bool __fastcall TFrmMain::CheckResource(size_t MaxMemory, DWORD MaxHandle, DWORD MaxThread, DWORD MaxGdi)
  1015. {
  1016. bool result;
  1017. HANDLE hProcess;
  1018. PROCESS_MEMORY_COUNTERS pmc;
  1019. size_t uSize;
  1020. DWORD HandleCount, ThreadCount, GdiCount;
  1021. HANDLE hProcessSnap;
  1022. PROCESSENTRY32 pe32;
  1023. DWORD ProcessId;
  1024. result = false;
  1025. uSize = 0;
  1026. HandleCount = 0;
  1027. ThreadCount = 0;
  1028. GdiCount = 0;
  1029. hProcess = GetCurrentProcess();
  1030. if (hProcess != NULL)
  1031. {
  1032. if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) )
  1033. {
  1034. uSize = pmc.WorkingSetSize/1024;
  1035. if ((MaxMemory != 0) && (uSize > MaxMemory))
  1036. {
  1037. MERROR("MAIN Memory usage exceeds standards!!!...[%d][%d]", MaxMemory, uSize);
  1038. result = true;
  1039. }
  1040. }
  1041. if ( GetProcessHandleCount( hProcess, &HandleCount) )
  1042. {
  1043. if ((MaxHandle != 0) && (HandleCount > MaxHandle))
  1044. {
  1045. MERROR("MAIN Window handle exceed standards!!!...[%d][%d]", MaxHandle, HandleCount);
  1046. result = true;
  1047. }
  1048. }
  1049. ProcessId = GetCurrentProcessId();
  1050. if ((hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 )) != INVALID_HANDLE_VALUE)
  1051. {
  1052. pe32.dwSize = sizeof( PROCESSENTRY32 );
  1053. if ( Process32First( hProcessSnap, &pe32 ) )
  1054. {
  1055. do
  1056. {
  1057. if (pe32.th32ProcessID == ProcessId)
  1058. {
  1059. ThreadCount = pe32.cntThreads;
  1060. if ((MaxThread != 0) && (ThreadCount > MaxThread))
  1061. {
  1062. MERROR("MAIN Criteria exceeded thread!!!...[%d][%d]", MaxThread, ThreadCount);
  1063. result = true;
  1064. }
  1065. break;
  1066. }
  1067. } while( Process32Next( hProcessSnap, &pe32 ) );
  1068. }
  1069. CloseHandle( hProcessSnap );
  1070. }
  1071. GdiCount = GetGuiResources( hProcess, GR_GDIOBJECTS);
  1072. if ((MaxGdi != 0) && (GdiCount > MaxGdi))
  1073. {
  1074. MERROR("MAIN GDI Objects exceeding standards!!!...[%d][%d]", MaxGdi, GdiCount);
  1075. result = true;
  1076. }
  1077. CloseHandle( hProcess );
  1078. }
  1079. try
  1080. {
  1081. FMemSize = uSize;
  1082. plMemory->Caption = FormatFloat("##,##0", uSize) ;// + " KB";
  1083. plHandle->Caption = FormatFloat("##,##0", HandleCount);// + " EA";
  1084. plThread->Caption = FormatFloat("##,##0", ThreadCount);// + " EA";
  1085. plGdi->Caption = FormatFloat("##,##0", GdiCount) ;// + " EA";
  1086. MINFO("MAIN Memory: %s, Haldle: %s, Thread: %s, GDI: %s",
  1087. AnsiString(plMemory->Caption).c_str(),
  1088. AnsiString(plHandle->Caption).c_str(),
  1089. AnsiString(plThread->Caption).c_str(),
  1090. AnsiString(plGdi->Caption).c_str()
  1091. );
  1092. } catch (Exception &e) {}
  1093. return result;
  1094. }
  1095. //---------------------------------------------------------------------------
  1096. void __fastcall TFrmMain::Panel16DblClick(TObject *Sender)
  1097. {
  1098. CheckResource((g_AppCfg.MaxMemory * 1024), g_AppCfg.MaxHandle, g_AppCfg.MaxThread, g_AppCfg.MaxGdi);
  1099. }
  1100. //---------------------------------------------------------------------------
  1101. void __fastcall TFrmMain::plStateDbDblClick(TObject *Sender)
  1102. {
  1103. APP_PostDbThreadMessage(dbm_master_symbol_image);
  1104. APP_PostDbThreadMessage(dbm_master_form);
  1105. APP_PostDbThreadMessage(dbm_master_vms_ifsc);
  1106. }
  1107. //---------------------------------------------------------------------------
  1108. void __fastcall TFrmMain::plStateCommDblClick(TObject *Sender)
  1109. {
  1110. AnsiString VMS_IFSC_ID;
  1111. int SECT_LNGT;
  1112. TItsMap<int, TObjectId*> FLists;
  1113. TItsMap<AnsiString, TVmsIfscGrad*> FGrads;
  1114. VMS_TRAF traf;
  1115. int SPED; // N NUMBER(3) Y 0 속도
  1116. int TRVL_HH; // N NUMBER(6) Y 0 통행 시간
  1117. AnsiString CMTR_GRAD_CD; // N VARCHAR2(7) Y 소통 등급 코드
  1118. if (!CDSVmsIfscTrafManager) return;
  1119. FOR_STL(TCDSVmsIfscTraf*, pObj, CDSVmsIfscTrafManager->FVmsIfscLists)
  1120. {
  1121. int objValid = pObj->IsValid == false ? 0 : 1;
  1122. MINFO("VMS_IFSC_ID: %s, SECT_LNGT: %5d, VALID: %d, Objects: %d, SPED: %3d, TRVL_HH: %4d, GRAD_CD: %s",
  1123. pObj->VMS_IFSC_ID, pObj->SECT_LNGT, objValid, pObj->FLists.Size(), pObj->traf.SPED, pObj->traf.TRVL_HH, pObj->traf.CMTR_GRAD_CD);
  1124. FOR_STL(TVmsIfscGrad*, pGrad, pObj->FGrads)
  1125. {
  1126. int gradValid = pGrad->IsValid == false ? 0 : 1;
  1127. MINFO(" GRAD_CD: %s, VALID: %d, LWSTSPED: %3d, HGHSSPED: %3d", pGrad->CMTR_GRAD_CD, gradValid, pGrad->LWSTSPED, pGrad->HGHSSPED);
  1128. }
  1129. int ii = 1;
  1130. FOR_STL(TObjectId*, pID, pObj->FLists)
  1131. {
  1132. int idValid = pID->IsValid == false ? 0 : 1;
  1133. TCDSIfscTraf* pIfsc = CDSVmsIfscTrafManager->FIfscTrafLists.Find(pID->ID);
  1134. if (pIfsc)
  1135. {
  1136. MINFO(" %2d: IFSC_ID: %s, SECT_LNGT: %5d, VALID: %d, SPED: %3d, TRVL_HH: %4d", ii, pIfsc->IFSC_ID, pIfsc->SECT_LNGT, idValid, pIfsc->SPED, pIfsc->TRVL_HH);
  1137. }
  1138. else
  1139. {
  1140. MINFO(" %2d: IFSC_ID: %s, Not Found", ii, pID->ID);
  1141. }
  1142. ii++;
  1143. }
  1144. MINFO("");
  1145. }
  1146. }
  1147. //---------------------------------------------------------------------------
  1148. void __fastcall TFrmMain::plStateActionDblClick(TObject *Sender)
  1149. {
  1150. plStateAction->Enabled = false;
  1151. tmrRunProvide->Enabled = false;
  1152. tmrRunProvide->Enabled = true;
  1153. CDSManager->FIsStaticCycle = true; //정주기 정보제공주기 플래그 설정
  1154. CtlrItr it;
  1155. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  1156. {
  1157. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  1158. if (!pObj->FSession) continue;
  1159. CDSCtlrManager->InitProvide(pObj);
  1160. }
  1161. APP_PostDbThreadMessage(dbm_dnld_form_cycle);
  1162. }
  1163. //---------------------------------------------------------------------------
  1164. void __fastcall TFrmMain::tmrRunProvideTimer(TObject *Sender)
  1165. {
  1166. tmrRunProvide->Enabled = false;
  1167. plStateAction->Enabled = true;
  1168. }
  1169. //---------------------------------------------------------------------------
  1170. bool __fastcall TFrmMain::JobThreadStart()
  1171. {
  1172. int nThreadCnt = 0;
  1173. if (true)
  1174. {
  1175. LogThread = new TLogThread();
  1176. if (!LogThread) return false;
  1177. LogThread->FPnlState = plStateLog;
  1178. LogThread->Name = "LogThread";
  1179. LogThread->Execute();
  1180. G_Threads.Push(nThreadCnt++, LogThread);
  1181. }
  1182. if (true)
  1183. {
  1184. DbmThread = new TDbmThread();
  1185. if (!DbmThread) return false;
  1186. DbmThread->FPnlState = plStateDbm;
  1187. DbmThread->Name = "DbmThread";
  1188. DbmThread->Execute();
  1189. G_Threads.Push(nThreadCnt++, DbmThread);
  1190. }
  1191. if (true)
  1192. {
  1193. JobThread = new TJobThread();
  1194. if (!JobThread) return false;
  1195. JobThread->FPnlState = plStateJob;
  1196. JobThread->Name = "JobThread";
  1197. JobThread->Execute();
  1198. G_Threads.Push(nThreadCnt++, JobThread);
  1199. }
  1200. return true;
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TFrmMain::JobThreadCheck()
  1204. {
  1205. int nTermCnt = 0;
  1206. for (thrIterator it=G_Threads.FObjects.begin(); it != G_Threads.FObjects.end(); ++it)
  1207. {
  1208. TItsThread *pObj = (TItsThread*)it->second;
  1209. if (pObj->IsTerm())
  1210. {
  1211. pObj->Execute();
  1212. nTermCnt++;
  1213. }
  1214. }
  1215. }
  1216. //---------------------------------------------------------------------------
  1217. void __fastcall TFrmMain::JobThreadStop()
  1218. {
  1219. g_AppCfg.bThrExit = true;
  1220. g_jobQ.PushBlocking(Q_CLOSE);
  1221. g_dbmQ.PushBlocking(Q_CLOSE);
  1222. g_logQ.PushBlocking(Q_CLOSE);
  1223. HANDLE handles[50];
  1224. int nWaits = 0;
  1225. for (thrIterator it=G_Threads.FObjects.begin(); it != G_Threads.FObjects.end(); ++it)
  1226. {
  1227. TItsThread *pObj = (TItsThread*)it->second;
  1228. if (!pObj->IsTerm())
  1229. {
  1230. //pObj->Terminate(2000);
  1231. handles[nWaits++] = pObj->Handle;
  1232. }
  1233. }
  1234. WaitForMultipleObjects(nWaits, handles, true, 1000);
  1235. G_Threads.RemoveAll();
  1236. }
  1237. //---------------------------------------------------------------------------
  1238. void __fastcall TFrmMain::TerminateApplication()
  1239. {
  1240. MERROR("MAIN Program terminated start");
  1241. SendTerminal();
  1242. CComm_Close();
  1243. MERROR("MAIN Program terminated end");
  1244. g_logQ.PushBlocking(Q_CLOSE);
  1245. for (int ii = 0; ii < 50; ii++)
  1246. {
  1247. Sleep(30);
  1248. Application->ProcessMessages();
  1249. if (g_AppCfg.bThrJobExit) break;
  1250. }
  1251. }
  1252. //---------------------------------------------------------------------------
  1253. void __fastcall TFrmMain::SendTerminal()
  1254. {
  1255. int result;
  1256. MINFO("MAIN SendTerminal");
  1257. // 동작, 통신, DB 모두 이상 처리
  1258. g_SysInfo->RunSts = state_error;
  1259. g_SysInfo->ComSts = state_error;
  1260. g_SysInfo->DbmSts = state_error;
  1261. // 모든 시설물 통신 오프라인 처리
  1262. CtlrItr it;
  1263. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  1264. {
  1265. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  1266. if (!pObj->Used) continue;
  1267. pObj->Server.thrState = thr_stop;
  1268. pObj->Client.thrState = thr_stop;
  1269. pObj->Server.commState = comm_close;
  1270. pObj->Client.commState = comm_close;
  1271. }
  1272. INT_PG_STATE_RES PgState;
  1273. memset(&PgState, 0x00, sizeof(PgState));
  1274. PgState.Count = 1;
  1275. PgState.Unit[0].Type = INT_ID_VMS_SERVER;
  1276. PgState.Unit[0].DB = g_SysInfo->DbmSts;
  1277. PgState.Unit[0].Comm = g_SysInfo->ComSts;
  1278. PgState.Unit[0].Action = g_SysInfo->RunSts;
  1279. result = CComm_CmmProcessStateNotify(&PgState);
  1280. TDMAdoDb *FDb = new TDMAdoDb(NULL);
  1281. try
  1282. {
  1283. if (FDb->Connect(g_AppCfg.db.sConnectStr))
  1284. {
  1285. CDSProcessManager->SaveUnitStts(FDb->GetConnection());
  1286. CDSCtlrManager->SaveCtlrSttsAll(FDb->GetConnection());
  1287. }
  1288. }
  1289. __finally
  1290. {
  1291. if (FDb)
  1292. {
  1293. FDb->Close();
  1294. }
  1295. SAFE_DELETE(FDb);
  1296. }
  1297. }
  1298. //---------------------------------------------------------------------------
  1299. int __fastcall TFrmMain::SendVmsThreadMessage(BYTE *AVmsId, IPC_MSG_DATA *ARcvData, BYTE AOpCode, char *AData)
  1300. {
  1301. #if 0
  1302. AnsiString sVmsId;
  1303. IPCUDPPACKET *pPI = NULL;
  1304. sVmsId.sprintf("%.*s", INT_VMS_MAX_ID, (char*)AVmsId);
  1305. TCDSCtlr *pObj = CDSCtlrManager->FLists.Find(sVmsId);
  1306. if (!pObj)
  1307. {
  1308. return VERR_NOTFOUND_VMS;
  1309. }
  1310. if (pObj->Server.commState != comm_close)
  1311. {
  1312. return VERR_OFFLINE;
  1313. }
  1314. if (!pObj->pPackQueue)
  1315. {
  1316. return VERR_INTERNAL;
  1317. }
  1318. pPI = new IPCUDPPACKET;
  1319. if (pPI == NULL) return VERR_MEMORY_ALLOC;
  1320. pPI->Sender.IP = ARcvData->Sender.IP;
  1321. pPI->Sender.Port = ARcvData->Sender.Port;
  1322. pPI->RecvId = ARcvData->Pkt.head.SendId;
  1323. pPI->OPCode = AOpCode;
  1324. pPI->Size = (int)ARcvData->Pkt.head.Length;
  1325. if (pPI->Size > 0)
  1326. {
  1327. pPI->Data = new char[pPI->Size];
  1328. if (!pPI->Data)
  1329. {
  1330. delete pPI;
  1331. return VERR_INTERNAL;
  1332. }
  1333. CopyMemory(pPI->Data, AData, pPI->Size);
  1334. }
  1335. pObj->pPackQueue->Add((void*)pPI);
  1336. #endif
  1337. return VERR_NONE;
  1338. }
  1339. //---------------------------------------------------------------------------
  1340. void __fastcall TFrmMain::plTimeDblClick(TObject *Sender)
  1341. {
  1342. if (!FrmNetwork->Showing)
  1343. {
  1344. FrmNetwork->Show();
  1345. }
  1346. }
  1347. //---------------------------------------------------------------------------
  1348. void __fastcall TFrmMain::tmrProvideTimer(TObject *Sender)
  1349. {
  1350. SendVmsTrafficProvide(2);
  1351. }
  1352. //---------------------------------------------------------------------------
  1353. void __fastcall TFrmMain::SendVmsTrafficProvide(int AType)
  1354. {
  1355. #if 0
  1356. tmrProvide->Enabled = false;
  1357. MINFO("MAIN *** VMS Traffic Event Acitve, %d", AType);
  1358. APP_PostDbThreadMessage(dbm_dnld_form_cycle);
  1359. m_dtProvider = Now(); // 정보제공 타이머
  1360. if (AType == 0)
  1361. {
  1362. tmrProvide->Interval = (g_AppCfg.nTrafficCycleTime)*1000 + (g_AppCfg.nTrafficBasisTime*1000);
  1363. plRemain->Color = clBlack;
  1364. }
  1365. else
  1366. {
  1367. tmrProvide->Interval = (g_AppCfg.nTrafficCycleTime)*1000; //분단위 주기만큼 타이머가동해야 함(소통정보 이벤트 처리가 없는 경우)
  1368. plRemain->Color = clGreen;
  1369. }
  1370. FFirstRunning = false;
  1371. FProvideRemain = tmrProvide->Interval / 1000;
  1372. tmrProvide->Enabled = true;
  1373. #else
  1374. tmrProvide->Enabled = false;
  1375. MINFO("MAIN *** VMS Traffic Event Acitve, %d", AType);
  1376. APP_PostDbThreadMessage(dbm_dnld_form_cycle);
  1377. m_dtProvider = Now(); // 정보제공 타이머
  1378. int nProvideRemain = 0;
  1379. nProvideRemain = SecondOfTheDay(Now());
  1380. nProvideRemain %= g_AppCfg.nTrafficCycleTime;
  1381. nProvideRemain = g_AppCfg.nTrafficCycleTime - nProvideRemain;
  1382. nProvideRemain += g_AppCfg.nTrafficBasisTime;
  1383. if (AType == 0)
  1384. {
  1385. tmrProvide->Interval = nProvideRemain*1000;
  1386. //tmrProvide->Interval = (g_AppCfg.nTrafficCycleTime)*1000 + (g_AppCfg.nTrafficBasisTime*1000);
  1387. plRemain->Color = clBlack;
  1388. }
  1389. else
  1390. {
  1391. //tmrProvide->Interval = (g_AppCfg.nTrafficCycleTime)*1000; //분단위 주기만큼 타이머가동해야 함(소통정보 이벤트 처리가 없는 경우)
  1392. tmrProvide->Interval = nProvideRemain*1000; //분단위 주기만큼 타이머가동해야 함(소통정보 이벤트 처리가 없는 경우)
  1393. plRemain->Color = clGreen;
  1394. }
  1395. FFirstRunning = false;
  1396. //FProvideRemain = tmrProvide->Interval / 1000;
  1397. FProvideRemain = nProvideRemain;
  1398. tmrProvide->Enabled = true;
  1399. #endif
  1400. }
  1401. //---------------------------------------------------------------------------