PacketHandllingF.cpp 138 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576
  1. //---------------------------------------------------------------------------
  2. #pragma hdrstop
  3. #include <DateUtils.hpp>
  4. #include "PacketHandllingF.h"
  5. #include "ClientSessionF.h"
  6. #include "VMSCommLibF.h"
  7. #include "CenterCommF.h"
  8. //---------------------------------------------------------------------------
  9. #define TERROR(args...) ASession->SysLogWrite(eLOG_ERROR, ##args)
  10. #define TDEBUG(args...) ASession->LogWrite(eLOG_DEBUG, ##args)
  11. #define TINFO(args...) ASession->LogWrite(eLOG_INFO, ##args)
  12. #define OK_DEBUG 0
  13. #pragma package(smart_init)
  14. extern const unsigned short g_crc16_table[256] =
  15. {
  16. 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
  17. 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
  18. 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
  19. 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
  20. 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
  21. 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
  22. 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
  23. 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
  24. 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
  25. 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
  26. 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
  27. 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
  28. 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
  29. 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
  30. 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
  31. 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
  32. 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
  33. 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
  34. 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
  35. 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
  36. 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
  37. 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
  38. 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
  39. 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
  40. 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
  41. 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
  42. 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
  43. 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
  44. 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
  45. 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
  46. 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
  47. 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
  48. };
  49. //---------------------------------------------------------------------------
  50. //---------------------------------------------------------------------------
  51. static WORD GETCRC16(char *AData, int ALen)
  52. {
  53. WORD crc = 0;
  54. for (int ii = 0; ii < ALen; ii++)
  55. {
  56. crc = ( (crc >> 8) ^ g_crc16_table[(crc ^ AData[ii]) & 0x0ff] );
  57. }
  58. return crc;
  59. }
  60. //---------------------------------------------------------------------------
  61. //---------------------------------------------------------------------------
  62. typedef int (*RecvPktHandlerFunc)(TClientSession *ASession, BYTE *AData, int APktLen);
  63. //---------------------------------------------------------------------------
  64. static int UnknownPktHandler(TClientSession *ASession, BYTE *AData, int APktLen)
  65. {
  66. if (ASession->CDSLogCtlr)
  67. {
  68. TERROR("+CLI Invalid packet handler: %s. will be closed.", ASession->IpAddress.c_str());
  69. }
  70. VMS_HEAD *pHd = (VMS_HEAD*)AData;
  71. if (!pHd) return -1;
  72. MERROR("+CLI Invalid packet handler: %s. 0x%02X, will be closed.", ASession->IpAddress.c_str(), pHd->OpCode);
  73. ASession->LogData("RECV", (BYTE*)ASession->GetRecvBuff(), APktLen);
  74. ASession->Disconnect();
  75. return -1;
  76. }
  77. //---------------------------------------------------------------------------
  78. //---------------------------------------------------------------------------
  79. static RecvPktHandlerFunc G_FuncPktHandler[e_vms_MAX] = {NULL};
  80. //---------------------------------------------------------------------------
  81. struct _init_pkt_handler
  82. {
  83. //정적 패킷핸들러 함수 초기화
  84. _init_pkt_handler()
  85. {
  86. for (int ii = 0; ii < e_vms_MAX; ii++)
  87. {
  88. G_FuncPktHandler[ii] = UnknownPktHandler;
  89. }
  90. }
  91. };
  92. static _init_pkt_handler init_pkt_handler;
  93. //---------------------------------------------------------------------------
  94. struct RegisterHandler
  95. {
  96. RegisterHandler(BYTE AOpCode, RecvPktHandlerFunc AFuncHandler)
  97. {
  98. G_FuncPktHandler[(int)AOpCode] = AFuncHandler;
  99. }
  100. };
  101. //---------------------------------------------------------------------------
  102. #define REGISTER_HANDLER(PKT_TYPE) \
  103. static int Handler_##PKT_TYPE(TClientSession* ASession, BYTE *AData, int APktLen); \
  104. static RegisterHandler _register_##PKT_TYPE(PKT_TYPE, Handler_##PKT_TYPE); \
  105. static int Handler_##PKT_TYPE(TClientSession* ASession, BYTE *AData, int APktLen)
  106. void CALLBACK RecvCompletion(DWORD dwError, DWORD cbTransferred, LPWSAOVERLAPPED lpOverlapped, DWORD dwFlags)
  107. {
  108. TClientSession *pSession = static_cast<OverlappedIO*>(lpOverlapped)->FSession;
  109. if (!pSession->IsConnected)
  110. {
  111. MERROR("+SVR RecvCompletion(IsConnected false): %s[%d]", pSession->IpAddress.c_str(), pSession->Socket);
  112. return;
  113. }
  114. /// 에러 발생시 해당 세션 종료
  115. if (dwError || cbTransferred == 0)
  116. {
  117. MERROR("+SVR RecvCompletion(dwError || cbTransferred==0): %s[%d], will be closed", pSession->IpAddress.c_str(), pSession->Socket);
  118. pSession->Disconnect();
  119. return;
  120. }
  121. /// 받은 데이터 처리
  122. pSession->OnRead(cbTransferred);
  123. }
  124. //---------------------------------------------------------------------------
  125. #if 0
  126. void CALLBACK SendCompletion(DWORD dwError, DWORD cbTransferred, LPWSAOVERLAPPED lpOverlapped, DWORD dwFlags)
  127. {
  128. TClientSession *pSession = static_cast<OverlappedIO*>(lpOverlapped)->FSession;
  129. if (!pSession->IsConnected)
  130. {
  131. MERROR("+SVR SendCompletion(IsConnected false): %s[%d]", pSession->IpAddress.c_str(), pSession->Socket);
  132. return;
  133. }
  134. /// 에러 발생시 해당 세션 종료
  135. if (dwError || cbTransferred == 0)
  136. {
  137. MERROR("+SVR SendCompletion(dwError || cbTransferred==0): %s[%d], will be closed", pSession->IpAddress.c_str(), pSession->Socket);
  138. pSession->Disconnect();
  139. return;
  140. }
  141. pSession->OnWriteComplete(cbTransferred, cbTransferred);
  142. }
  143. //---------------------------------------------------------------------------
  144. #endif
  145. static TCDSCtlr* FindControllerByIpAddr(AnsiString AIpAddress)
  146. {
  147. CtlrItr it;
  148. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  149. {
  150. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  151. if (!pObj->Used) continue;
  152. if (pObj->CTLR_IP.AnsiCompare(AIpAddress) == 0)
  153. {
  154. return pObj;
  155. }
  156. }
  157. return NULL;
  158. }
  159. //---------------------------------------------------------------------------
  160. static TCDSCtlr* FindControllerById(AnsiString ACtrlNmbrId)
  161. {
  162. CtlrItr it;
  163. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  164. {
  165. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  166. if (!pObj->Used) continue;
  167. if (pObj->CTLR_NMBR_ID.AnsiCompare(ACtrlNmbrId) == 0)
  168. {
  169. return pObj;
  170. }
  171. }
  172. return NULL;
  173. }
  174. //---------------------------------------------------------------------------
  175. static int RequestJob(TClientSession *ASession, int AJob, char *AData, int ALen)
  176. {
  177. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  178. pMsg->Type = AJob;
  179. pMsg->ObjPtr = (DWORD)ASession;
  180. if (ALen > 0)
  181. {
  182. memcpy(pMsg->Buff, AData, ALen);
  183. }
  184. pMsg->Len = ALen;
  185. g_jobQ.PushBlocking((DWORD)pMsg);
  186. return 0;
  187. }
  188. //---------------------------------------------------------------------------
  189. bool TClientSession::SendPacketDleStuffing(char *AData, int ADataLen)
  190. {
  191. int nSendLen;
  192. int nLen;
  193. WORD crc;
  194. BYTE c;
  195. BYTE *msgPrt;
  196. BYTE *pData;
  197. msgPrt = FMsgBuff;
  198. pData = AData;
  199. nLen = ADataLen;
  200. crc = GETCRC16(pData, nLen);
  201. *msgPrt++ = VMS_DLE;
  202. *msgPrt++ = VMS_STX;
  203. // DLE Stuffing
  204. for (int ii = 0; ii < ADataLen; ii++)
  205. {
  206. *msgPrt++ = AData[ii];
  207. if (pData[ii] == VMS_DLE)
  208. {
  209. *msgPrt++ = VMS_DLE;
  210. }
  211. }
  212. *msgPrt++ = VMS_DLE;
  213. *msgPrt++ = VMS_ETX;
  214. *msgPrt++ = HIBYTE(crc);
  215. *msgPrt++ = LOBYTE(crc);
  216. nSendLen = msgPrt - FMsgBuff;
  217. if (!SendRequest((char*)FMsgBuff, nSendLen))
  218. {
  219. SERROR("+CLI SendPacketDleStuffing send request faild: %s, 0x%02X will be closed.", FIpAddress.c_str(), AData[4]);
  220. MERROR("+CLI SendPacketDleStuffing send request faild: %s, 0x%02X will be closed.", FIpAddress.c_str(), AData[4]);
  221. Disconnect();
  222. return false;
  223. }
  224. return SendFlushComplete();
  225. }
  226. //---------------------------------------------------------------------------
  227. bool TClientSession::SendPacketDLE(char *AData, int ADataLen, bool AIsDle)
  228. {
  229. int nSendLen;
  230. int nLen;
  231. BYTE c;
  232. BYTE *msgPrt;
  233. BYTE *pData;
  234. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  235. msgPrt = (BYTE*)pMsg->Buff;
  236. pData = AData;
  237. *msgPrt++ = AData[0];
  238. *msgPrt++ = AData[1];
  239. // DLE Stuffing
  240. for (int ii = 2; ii < ADataLen-4; ii++)
  241. {
  242. *msgPrt++ = AData[ii];
  243. if (AIsDle && pData[ii] == VMS_DLE)
  244. {
  245. *msgPrt++ = VMS_DLE;
  246. }
  247. }
  248. *msgPrt++ = AData[ADataLen-4]; // DLE
  249. *msgPrt++ = AData[ADataLen-3]; // ETX
  250. *msgPrt++ = AData[ADataLen-2]; // CRC
  251. *msgPrt++ = AData[ADataLen-1]; // CRC
  252. nSendLen = msgPrt - (BYTE*)pMsg->Buff;
  253. pMsg->Type = eVmsSendPacket;
  254. pMsg->ObjPtr = (DWORD)this;
  255. pMsg->Len = nSendLen;
  256. g_jobQ.PushBlocking((DWORD)pMsg);
  257. Sleep(20);
  258. return true;
  259. }
  260. //---------------------------------------------------------------------------
  261. bool TClientSession::SendPacket(char *AData, int ADataLen)
  262. {
  263. int nSendLen;
  264. int nLen;
  265. WORD crc;
  266. BYTE c;
  267. BYTE *msgPtr;
  268. BYTE *pData;
  269. msgPtr = FMsgBuff;
  270. pData = AData;
  271. nLen = ADataLen;
  272. crc = GETCRC16(pData, nLen);
  273. *msgPtr++ = VMS_DLE;
  274. *msgPtr++ = VMS_STX;
  275. // DLE Stuffing
  276. for (int ii = 0; ii < ADataLen; ii++)
  277. {
  278. *msgPtr++ = AData[ii];
  279. if (pData[ii] == VMS_DLE)
  280. {
  281. *msgPtr++ = VMS_DLE;
  282. }
  283. }
  284. *msgPtr++ = VMS_DLE;
  285. *msgPtr++ = VMS_ETX;
  286. *msgPtr++ = HIBYTE(crc);
  287. *msgPtr++ = LOBYTE(crc);
  288. nSendLen = msgPtr - FMsgBuff;
  289. if (!SendRequest((char*)FMsgBuff, nSendLen))
  290. {
  291. SERROR("+CLI SendPacket send request faild: %s, 0x%02X will be closed.", FIpAddress.c_str(), AData[4]);
  292. MERROR("+CLI SendPacket send request faild: %s, 0x%02X will be closed.", FIpAddress.c_str(), AData[4]);
  293. Disconnect();
  294. return false;
  295. }
  296. return true;
  297. #if 0
  298. int nSendLen;
  299. int nLen;
  300. WORD crc;
  301. BYTE c;
  302. BYTE *msgPtr;
  303. BYTE *pData;
  304. msgPtr = FMsgBuff;
  305. pData = AData;
  306. nLen = ADataLen;
  307. crc = GETCRC16(pData, nLen);
  308. msgPtr[0] = VMS_DLE;
  309. msgPtr[1] = VMS_STX;
  310. if (ADataLen > 0)
  311. {
  312. memcpy(&msgPtr[2], AData, ADataLen);
  313. }
  314. msgPtr[ADataLen+2] = VMS_DLE;
  315. msgPtr[ADataLen+3] = VMS_ETX;
  316. msgPtr[ADataLen+4] = HIBYTE(crc);
  317. msgPtr[ADataLen+5] = LOBYTE(crc);
  318. #if 0
  319. for (int ii = 0; ii < ADataLen; ii++)
  320. {
  321. *msgPrt++ = AData[ii];
  322. #if 0
  323. if (pData[ii] == VMS_DLE)
  324. {
  325. *msgPrt++ = VMS_DLE;
  326. }
  327. #endif
  328. }
  329. #endif
  330. nSendLen = ADataLen + 6;
  331. if (!SendRequest((char*)msgPtr, nSendLen))
  332. {
  333. SERROR("+CLI SendPacket send request faild: %s, 0x%02X will be closed.", FIpAddress.c_str(), AData[4]);
  334. MERROR("+CLI SendPacket send request faild: %s, 0x%02X will be closed.", FIpAddress.c_str(), AData[4]);
  335. Disconnect();
  336. return false;
  337. }
  338. return true;
  339. #endif
  340. }
  341. //---------------------------------------------------------------------------
  342. bool TClientSession::CheckLoginClient()
  343. {
  344. TCDSCtlr *pCDSCtlr = FindControllerByIpAddr(FIpAddress);
  345. if (!pCDSCtlr)
  346. {
  347. MERROR("+CLI Unknown client address: %s. will be closed.", FIpAddress.c_str());
  348. return false;
  349. }
  350. //이전 접속정보가 있는지 확인한다.
  351. if (FCDSCtlr)
  352. {
  353. TClientSession *pSession = FCDSCtlr->FSession;
  354. if (pSession)
  355. {
  356. //이전 접속을 종료하고 현재 접속을 새로운 VMS 제어기 통신으로 사용한다.
  357. MERROR("+CLI Client allready connect: %s. old connection will be closed.", FIpAddress.c_str());
  358. pSession->Disconnect();
  359. }
  360. }
  361. FState = eSS_LoginReq; //최초접속후 폼을 다운로드 하기위해 사용할 플래그(기존에는 로그인체크용으로 사용)
  362. FCDSCtlr = pCDSCtlr;
  363. FCDSLogCtlr = pCDSCtlr;
  364. FCDSCtlr->FSession = this;
  365. FCDSCtlr->LOGIN_IPADDR = FIpAddress; //연결된 IP주소 설정
  366. FCDSCtlr->Server.commState = comm_open;
  367. FCDSCtlr->Server.ConnectTm = Now().FormatString("yyyy-MM-dd hh:nn:ss");
  368. FCtlrId.printf("%10.010d", FCDSCtlr->CTLR_NMBR.ToIntDef(0));
  369. POST_MSG(MAINHANDLE, WM_TCP_THREAD, WM_TCP_SERVER_STTS, (int)pCDSCtlr);
  370. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  371. // 최초에 폼정보를 모두 다운로드 해버리자.(TODO: 메모리 할당이 위에서 끝난다음에 초기화해야함)
  372. FCDSCtlr->InitDownloadFileInfo();
  373. //최초에 상태정보를 요청하고 상태정보요청 응답이 완료되면 시나리오를 다운로드 하자.
  374. RequestJob(this, eVmsStatusReq, NULL, 0);
  375. return true;
  376. }
  377. //---------------------------------------------------------------------------
  378. bool TClientSession::OnDisconnected()
  379. {
  380. if (FCDSCtlr)
  381. {
  382. if (FCDSCtlr->IsVideo) {
  383. FCDSCtlr->InitFtpFileInfo(); // TODO: FTP 다운로드 정보를 초기화 한다.
  384. }
  385. FCDSCtlr->Server.DisconnectTm = Now().FormatString("yyyy-MM-dd hh:nn:ss");
  386. FCDSCtlr->Server.commState = comm_close;
  387. FCDSCtlr->FSession = NULL;
  388. //FCDSCtlr->LOGIN_IPADDR = "";
  389. LERROR("VMS %s disconnected.", CtlrId.c_str());
  390. MERROR("%s.%d, VMS %s disconnected.", FIpAddress.c_str(), FSocket, CtlrId.c_str());
  391. TCDSCtlr* pCDSCtlr = FCDSCtlr;
  392. POST_MSG(MAINHANDLE, WM_TCP_THREAD, WM_TCP_SERVER_STTS, (int)pCDSCtlr);
  393. }
  394. else
  395. {
  396. MERROR("%s.%d, disconnected.", FIpAddress.c_str(), FSocket);
  397. }
  398. FState = eSS_Disconnect;
  399. return true;
  400. }
  401. //---------------------------------------------------------------------------
  402. /*
  403. * 1개의 패킷을 모두 전송한 후 호출됨
  404. */
  405. void TClientSession::OnWrite(char *APktPtr, int ASendLen)
  406. {
  407. VMS_HEAD *pHd = (VMS_HEAD*)APktPtr;
  408. if (!pHd) return;
  409. if (ASendLen > 0)
  410. {
  411. LDEBUG("SEND: %d Bytes", ASendLen);
  412. LogData("SEND", APktPtr, ASendLen);
  413. }
  414. InfoPacket(pHd->OpCode, ASendLen, true, 0);
  415. #if 0
  416. switch(pHd->OpCode)
  417. {
  418. case VMS_ID_REQ: // 0xFF // server -> client
  419. case DNLD_SCENARIO_REQ: // 0x02 // server -> client
  420. case CTRL_RESET_REQ: // 0x03 // server -> client
  421. case DNLD_FILE_REQ: // 0x04 // server -> client
  422. case PARAMETER_REQ: // 0x05 // server -> client
  423. case CTRL_LED_POWER_REQ: // 0x06 // server -> client
  424. case CTRL_FAN_POWER_REQ: // 0x07 // server -> client
  425. case CTRL_BRGH_REQ: // 0x08 // server -> client
  426. case CTRL_CONFIG_REQ: // 0x09 // server -> client
  427. case CTRL_TIME_REQ: // 0x10 // server -> client
  428. FTmrSend = Now();
  429. if (FChkRecvTO == false)
  430. {
  431. FTmrRecv = Now();
  432. }
  433. FChkRecvTO = true;
  434. break;
  435. default:
  436. FChkRecvTO = false; // 0x01 // server -> client
  437. break;
  438. }
  439. #endif
  440. }
  441. //---------------------------------------------------------------------------
  442. /*
  443. * 프로토콜에 따른 처리
  444. */
  445. void TClientSession::OnRead(int ALen)
  446. {
  447. int readIdx;
  448. int stuffing;
  449. int dleEtx;
  450. int msgSize;
  451. BYTE msgBuff[SESSION_SEND_BUFFER];
  452. BYTE data;
  453. WORD crc;
  454. VMS_RES_HEAD *pHead;
  455. FRecvIdx += ALen;
  456. if (FRecvIdx > 0)
  457. {
  458. LDEBUG("RECV: %d Bytes", FRecvIdx);
  459. LogData("RECV", (char*)FRecvBuff, FRecvIdx);
  460. }
  461. while(true)
  462. {
  463. if (FRecvIdx < (int)sizeof(VMS_HEAD))
  464. {
  465. break;
  466. }
  467. if (FRecvBuff[0] != VMS_DLE && FRecvBuff[1] != VMS_STX)
  468. {
  469. MERROR("+CLI Packet parsing data start command error: %s, 0x%02X, 0x%02X. will be closed.", FIpAddress.c_str(), FRecvBuff[0], FRecvBuff[1]);
  470. Disconnect();
  471. return;
  472. }
  473. readIdx = 0;
  474. stuffing = 0; // 연속된 DLE 데이터 체크, 1 이면 DLE Stuffing
  475. dleEtx = 0; // DLE_ETX, ETX를 체크하기 위함, 1 이고 ETX 데이터를 읽었으면 패킷의 마지막(DLE_ETX, ETX 데이터 임)
  476. msgSize = 0; // 순수 데이터 사이즈
  477. while (readIdx < FRecvIdx && msgSize < (int)sizeof(msgBuff))
  478. {
  479. data = FRecvBuff[readIdx++];
  480. if (data == VMS_DLE)
  481. {
  482. if (stuffing)
  483. {
  484. stuffing = 0;
  485. dleEtx = 0; // TODO
  486. }
  487. else
  488. {
  489. msgBuff[msgSize++] = data;
  490. stuffing = 1;
  491. dleEtx = 1;
  492. }
  493. }
  494. else
  495. if (data == VMS_ETX)
  496. {
  497. msgBuff[msgSize++] = data;
  498. if (dleEtx)
  499. {
  500. // 이전데이터가 DLE이고 현재 데이터가 ETX이면 패킷의 끝임.
  501. // 다음 2바이트는 CRC 데이터임, 남아 있는 데이터가 CRC 2바이트를 포함한 크기보다 작으면
  502. // 하나의 패킷을 완전히 수신하지 못한 것임
  503. if ((readIdx + 2) > FRecvIdx)
  504. {
  505. // 하나의 패킷을 읽지 못함
  506. return;
  507. }
  508. msgBuff[msgSize++] = FRecvBuff[readIdx++]; // CRC1
  509. msgBuff[msgSize++] = FRecvBuff[readIdx++]; // CRC2
  510. // 하나의 패킷을 완전히 읽었음.
  511. ResetPacket(readIdx); // 메모리에서 수신 인덱스 초기화
  512. #if 0
  513. // dle, stx 제외, dle,etx,crc(2) 제외
  514. crc = GETCRC16(&msgBuff[2], msgSize-2-sizeof(VMS_TAIL));
  515. if (msgBuff[readIdx-2] != HIBYTE(crc) || msgBuff[readIdx-1] != LOBYTE(crc))
  516. {
  517. MERROR("+CLI Packet parsing data crc error: %s, 0x%02X, 0x%02X, 0x%02X, 0x%02X. will be closed.",
  518. FIpAddress.c_str(), msgBuff[readIdx-2], msgBuff[readIdx-1], HIBYTE(crc), LOBYTE(crc));
  519. Disconnect();
  520. return;
  521. }
  522. #endif
  523. pHead = (VMS_RES_HEAD*)msgBuff;
  524. if (pHead->Length != msgSize-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL))
  525. {
  526. MERROR("+CLI Packet parsing data length error: %s, %d, %d. will be closed.",
  527. FIpAddress.c_str(), pHead->Length, msgSize-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL));
  528. ITSLog->LogData("RECV", FRecvBuff, FRecvIdx);
  529. if (FCDSCtlr != NULL && FCDSCtlr->FSLog->FLogCfg.Data) FCDSCtlr->FSLog->LogData("RECV", FRecvBuff, FRecvIdx);
  530. Disconnect();
  531. return;
  532. }
  533. InfoPacket(pHead->OpCode, msgSize, false, 0);
  534. if (G_FuncPktHandler[pHead->OpCode](this, msgBuff, msgSize) < 0)
  535. {
  536. Disconnect();
  537. return;
  538. }
  539. SendFlush();
  540. break;
  541. }
  542. else
  543. {
  544. dleEtx = 0;
  545. }
  546. }
  547. else
  548. {
  549. // 순수 데이터를 읽음
  550. msgBuff[msgSize++] = data;
  551. stuffing = 0;
  552. dleEtx = 0;
  553. }
  554. }
  555. if (readIdx >= FRecvIdx)
  556. {
  557. break;
  558. }
  559. }
  560. }
  561. //---------------------------------------------------------------------------
  562. template <class PKT_TYPE>
  563. bool TClientSession::ParsePacket(PKT_TYPE& pkt, int APktLen)
  564. {
  565. if (APktLen > FRecvIdx)
  566. {
  567. MERROR("+CLI ParsePacket Error: %s, PktLen: %d, RecvIdx: %d", FIpAddress.c_str(), APktLen, FRecvIdx);
  568. return false;
  569. }
  570. memcpy((char*)&pkt, FRecvBuff, APktLen);
  571. FRecvIdx -= APktLen;
  572. if (FRecvIdx > 0)
  573. {
  574. memmove(FRecvBuff, FRecvBuff+APktLen, FRecvIdx);
  575. }
  576. return true;
  577. }
  578. //---------------------------------------------------------------------------
  579. bool TClientSession::InfoPacket(BYTE AOpCode, int ALen, bool ASend, int AResult/*=0*/)
  580. {
  581. TCDSCtlr* pCDSCtlr = FCDSLogCtlr;
  582. if (!pCDSCtlr) return -1;
  583. //if (!pCDSCtlr->FDispLog) return -1;
  584. //if (!g_LogCfg.Debug) return -1;
  585. if (!g_LogCfg.Info) return -1;
  586. AnsiString sCmd;
  587. switch(AOpCode)
  588. {
  589. case e_txt_disp_immediate_text:// = 0x02, // Display Immediate Text Opcode = 2 [0x02] ⇔ Opcode = 72 [0x48]
  590. sCmd = "txt_disp_immediate_text";
  591. break;
  592. case e_txt_disp_immediate_graphic:// = 0x04, // Display Immediate graphics Opcode = 4 [0x04] ⇔ Opcode = 72 [0x48]
  593. sCmd = "txt_disp_immediate_graphic";
  594. break;
  595. case e_txt_disp_lib_message:// = 0x06, // Display Library Message Opcode = 6 [0x06] ⇔ Opcode = 72 [0x48]
  596. sCmd = "txt_disp_lib_message";
  597. break;
  598. case e_txt_download_message_lib:// = 0x08, // Download A Message Library Opcode = 8 [0x08] ⇔ Opcode = 72 [0x48]
  599. sCmd = "txt_download_message_lib";
  600. break;
  601. case e_txt_download_full_graphic_lib:// = 0x0A, // Download Graphics Library Opcode = 10 [0x0A] ⇔ Opcode = 72 [0x48]
  602. sCmd = "txt_download_full_graphic_lib";
  603. break;
  604. case e_txt_download_graphic_symb_lib:// = 0x0C, // Download Graphic Symbol Library Opcode = 12 [0x0C] ⇔ Opcode = 72 [0x48]
  605. sCmd = "txt_download_graphic_symb_lib";
  606. break;
  607. case e_txt_display_schedule_msg:// = 0x0E, // Display Schedule Message Opcode = 14 [0x0E] ⇔ Opcode = 72 [0x48]
  608. sCmd = "txt_display_schedule_msg";
  609. break;
  610. case e_txt_initialize:// = 0x12, // Initailize Opcode = 18 [0x12] ⇔ Opcode = 72 [0x48]
  611. sCmd = "txt_initialize";
  612. break;
  613. case e_txt_disp_test_pattern:// = 0x14, // Display Test Pattern Opcode = 20 [0x14] ⇔ Opcode = 72 [0x48]
  614. sCmd = "txt_disp_test_pattern";
  615. break;
  616. case e_txt_blank:// = 0x16, // Blank Opcode = 22 [0x16] ⇔ Opcode = 72 [0x48]
  617. sCmd = "txt_blank";
  618. break;
  619. case e_txt_download_parameter:// = 0x1C, // Download Parameter Opcode = 28 [0x1C] ⇔ Opcode = 72 [0x48]
  620. sCmd = "txt_download_parameter";
  621. break;
  622. case e_txt_display_default_msg:// = 0x1E, // Display Default Message Opcode = 30 [0x1E] ⇔ Opcode = 72 [0x48]
  623. sCmd = "txt_display_default_msg";
  624. break;
  625. case e_txt_set_luminance_level:// = 0x20, // Set Luminance Level Opcode = 32 [0x20] ⇔ Opcode = 72 [0x48]
  626. sCmd = "txt_set_luminance_level";
  627. break;
  628. case e_txt_signboard_control:// = 0x24, // Signboard Power Control Opcode = 36 [0x24] ⇔ Opcode = 72 [0x48]
  629. sCmd = "txt_signboard_control";
  630. break;
  631. case e_txt_signboard_alarm_control:// = 0x2A, // Signboard Alarm Control Opcode = 42 [0x2A] ⇔ Opcode = 72 [0x48]
  632. sCmd = "txt_signboard_alarm_control";
  633. break;
  634. case e_txt_pan_hetr_temp_control:// = 0x31, // 함체 PAN/HEATER 온도 설정 Opcode = 49 [0x31] ⇔ Opcode = 72 [0x48]
  635. sCmd = "txt_pan_hetr_temp_control";
  636. break;
  637. case e_txt_status_req:// = 0x18, // Status Request Opcode = 24 [0x18] ⇔ Opcode = 64 [0x40]
  638. sCmd = "txt_status_req";
  639. break;
  640. case e_txt_status_res:// = 0x40, // Status Response Opcode = 24 [0x18] ⇔ Opcode = 64 [0x40]
  641. sCmd = "txt_status_res";
  642. break;
  643. case e_txt_upload_modl_status_req:// = 0x28, // Upload Module Status Opcode = 40 [0x28] ⇔ Opcode = 74 [0x4A]
  644. sCmd = "txt_upload_modl_status_req";
  645. break;
  646. case e_txt_upload_modl_status_res:// = 0x4A, // Upload Module Status Opcode = 40 [0x28] ⇔ Opcode = 74 [0x4A]
  647. sCmd = "txt_upload_modl_status_res";
  648. break;
  649. case e_txt_pan_hetr_temp_req:// = 0x32, // 함체 PAN/HEATER 온도 요청 Opcode = 50 [0x32] ⇔ Opcode = 66 [0x42]
  650. sCmd = "txt_pan_hetr_temp_req";
  651. break;
  652. //case e_txt_pan_hetr_temp_res:// = 0x42, // 함체 PAN/HEATER 온도 요청 Opcode = 50 [0x32] ⇔ Opcode = 66 [0x42]
  653. // sCmd = "txt_pan_hetr_temp_res";
  654. // break;
  655. case e_txt_failed_elem_data_req:// = 0x1A, // Failed Element Data Request Opcode = 26 [0x1A] ⇔ Opcode = 66 [0x42]
  656. sCmd = "txt_failed_elem_data_req";
  657. break;
  658. case e_txt_failed_elem_data_res:// = 0x42, // Failed Element Data Response Opcode = 26 [0x1A] ⇔ Opcode = 66 [0x42]
  659. sCmd = "txt_failed_elem_data_res";
  660. break;
  661. case e_txt_upload_msg_req:// = 0x22, // Upload A Message Opcode = 34 [0x22] ⇔ Opcode = 68 [0x44]
  662. sCmd = "txt_upload_msg_req";
  663. break;
  664. case e_txt_upload_msg_res:// = 0x44, // Upload A Message Response Opcode = 34 [0x22] ⇔ Opcode = 68 [0x44]
  665. sCmd = "txt_upload_msg_res";
  666. break;
  667. case e_txt_upload_schedule_msg_req:// = 0x23, // Upload Schedule Message Opcode = 35 [0x23] ⇔ Opcode = 69 [0x45]
  668. sCmd = "txt_upload_schedule_msg_req";
  669. break;
  670. case e_txt_upload_schedule_msg_res:// = 0x45, // Upload Schedule Message Opcode = 35 [0x23] ⇔ Opcode = 69 [0x45]
  671. sCmd = "txt_upload_schedule_msg_res";
  672. break;
  673. case e_txt_msg_echo_back_req:// = 0x26, // Message Echo Back Opcode = 38 [0x26] ⇔ Opcode = 70 [0x46]
  674. sCmd = "txt_msg_echo_back_req";
  675. break;
  676. case e_txt_msg_echo_back_res:// = 0x46, // Message Echo Back Opcode = 38 [0x26] ⇔ Opcode = 70 [0x46]
  677. sCmd = "txt_msg_echo_back_res";
  678. break;
  679. case e_txt_image_req:// = 0x2C, // 영상이미지 요청 Status Opcode = 44 [0x2C] ⇔ Opcode = 76 [0x4C]
  680. sCmd = "txt_image_req";
  681. break;
  682. case e_txt_image_res:// = 0x4C, // 영상이미지 요청 Status Opcode = 44 [0x2C] ⇔ Opcode = 76 [0x4C]
  683. sCmd = "txt_image_res";
  684. break;
  685. //case e_txt_ftp_download:// = 0x2C, // 동영상 파일 FTP 다운로드 Opcode = 44 [0x2C] ⇔ Opcode = 72 [0x48]
  686. // sCmd = "txt_ftp_download";
  687. // break;
  688. case e_txt_ftp_download_completed:// = 0x2E, // 동영상 파일 FTP 다운로드 완료 Opcode = 46 [0x2E]
  689. sCmd = "txt_ftp_download_completed";
  690. break;
  691. case e_txt_response:// = 0x48, // 제어기 응답(ACK/NAK)
  692. sCmd = "txt_response";
  693. break;
  694. case e_vms_form_display:// = 0x80,// 폼 데이터 표출 송신 표출할 폼 데이터 송신 센터 → VMS
  695. sCmd = "vms_form_display";
  696. break;
  697. case e_vms_file_download:// = 0x82,// 데이터 다운로드 송신 INI, CFG , Bitmap , Data파일송신 센터 → VMS
  698. sCmd = "vms_file_download";
  699. break;
  700. case e_vms_data_upload:// = 0x84,// 데이터 업로드 송신 INI, CFG , Bitmap , Data파일 업로드 요구 센터 → VMS
  701. sCmd = "vms_data_upload";
  702. break;
  703. case e_vms_status_control:// = 0x86,// VMS 상태제어 송신 VMS 제어정보 송신 센터 → VMS
  704. sCmd = "vms_status_control";
  705. break;
  706. case e_vms_status:// = 0x88,// VMS Status 요구 송신 VMS 상태정보 요구 송신 센터 → VMS
  707. sCmd = "vms_status";
  708. break;
  709. case e_vms_parameter:// = 0x8A,// VMS 파라미터 요구 송신 VMS 로컬 상태 요구 송신 센터 → VMS
  710. sCmd = "vms_parameter";
  711. break;
  712. case e_vms_power_module_status:// = 0x8C,// 전원 모듈 상태 요구 송신 전원 모듈 상태를 검사 결과를 요청한다 센터 → VMS
  713. sCmd = "vms_power_module_status";
  714. break;
  715. case e_vms_display_module_status:// = 0x8E,// 표출 모듈 상태 요구 송신 표출 모듈 상태를 검사 결과를 요청한다 센터 → VMS
  716. sCmd = "vms_display_module_status";
  717. break;
  718. case e_vms_pixel_image:// = 0x92,// VMS Pixel Image 요구 송신 VMS LED Pixel 상태요구 송신 센터 → VMS
  719. sCmd = "vms_pixel_image";
  720. break;
  721. case e_vms_current_display_form:// = 0x94,// 현재표출폼 Upload 송신 Local에서 표출 중인 폼 Upload요구 센터 → VMS
  722. sCmd = "vms_current_display_form";
  723. break;
  724. case e_vms_download_schedule_form:// = 0x96,// Display Schedule Form 송신 계획된 Form 표출 요구 센터 → VMS
  725. sCmd = "vms_download_schedule_form";
  726. break;
  727. case e_vms_display_default_form:// = 0x98,// Display Default Form 송신 디폴트 From표출 요구 센터 → VMS
  728. sCmd = "vms_display_default_form";
  729. break;
  730. case e_vms_download_form:// = 0x9A,// Download Form 송신 Form download 센터 → VMS
  731. sCmd = "vms_download_form";
  732. break;
  733. case e_vms_upload_schedule_form:// = 0x9C,// Upload Schedule Form 송신 스케줄 메시지 업로드 요구 센터 → VMS
  734. sCmd = "vms_upload_schedule_form";
  735. break;
  736. case e_vms_blank:// = 0x9E,// Blank 송신 schedule 표출 센터 → VMS
  737. sCmd = "vms_blank";
  738. break;
  739. case e_vms_display_form_id:// = 0xA0,// Display Form ID 송신 Form ID에 해당하는 Form 표출 센터 → VMS
  740. sCmd = "vms_display_form_id";
  741. break;
  742. case e_vms_video_ftp_download_req:// = 0xA1, // 동영상 파일 FTP 다운로드 요청 센터 → VMS
  743. sCmd = "e_vms_video_ftp_download_req";
  744. break;
  745. case e_vms_video_ftp_download_completed:// = 0xA2, // 동영상 파일 FTP 다운로드 완료 센터 ← VMS
  746. sCmd = "e_vms_video_ftp_download_completed";
  747. break;
  748. default:
  749. sCmd.printf("UNKNOWN Packet: %02X", AOpCode);
  750. return false;
  751. }
  752. if (ASend)
  753. {
  754. if (AResult == 0) {
  755. if (pCDSCtlr->IsDle)
  756. LINFO("SEND: %s, %d Bytes, [DLE Stuffing]", sCmd.c_str(), ALen);
  757. else
  758. LINFO("SEND: %s, %d Bytes.", sCmd.c_str(), ALen);
  759. }
  760. else {
  761. if (pCDSCtlr->IsDle)
  762. LERROR("SEND FAIL: %s, %d Bytes, [DLE Stuffing]", sCmd.c_str(), ALen);
  763. else
  764. LERROR("SEND FAIL: %s, %d Bytes.", sCmd.c_str(), ALen);
  765. }
  766. }
  767. else
  768. {
  769. if (pCDSCtlr->IsDle)
  770. LINFO("RECV: %s, %d Bytes, [DLE Stuffing]", sCmd.c_str(), ALen);
  771. else
  772. LINFO("RECV: %s, %d Bytes.", sCmd.c_str(), ALen);
  773. }
  774. return true;
  775. }
  776. //---------------------------------------------------------------------------
  777. void TClientSession::DisplayResponseError(BYTE *AData)
  778. {
  779. BYTE *pData = &AData[sizeof(VMS_RES_HEAD)];
  780. if (pData[0] != VMS_NAK)
  781. {
  782. return;
  783. }
  784. AnsiString sErr = "";
  785. switch(pData[1])
  786. {
  787. case 0x30: sErr = "Data Length가 2,047 Byte 보다 크면 보고되는 오류"; break;
  788. case 0x31: sErr = "Data Length 이후의 데이터가 Data Length + 5Byte가 되지 않는 오류"; break;
  789. case 0x32: sErr = "데이터 크기 불일치"; break;
  790. case 0x33: sErr = "작업이전 작업 진행중 작업요구"; break;
  791. case 0x34: sErr = "파라미터 범위 초과"; break;
  792. case 0x35: sErr = "저장되지 않은 폼데이터 요구"; break;
  793. case 0x36: sErr = "업무처리 해당사항 없음"; break;
  794. case 0x37: sErr = "STN Address 틀림"; break;
  795. default : sErr.printf("NAK, Unknown Result Code 0x%02X", (int)pData[1]); break;
  796. }
  797. LERROR(sErr.c_str());
  798. }
  799. //---------------------------------------------------------------------------
  800. /////////////////////////////////////////////////////////
  801. REGISTER_HANDLER(e_txt_response)
  802. {
  803. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  804. #if 0
  805. if (nLength < 1) // ACK or NAK
  806. {
  807. TERROR("%s.%d, e_txt_response Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  808. MERROR("%s.%d, e_txt_response Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  809. return -1;
  810. }
  811. #endif
  812. TDEBUG("e_txt_response Length: %d", nLength);
  813. TDownloadForm *pInfo = NULL;
  814. VMS_RES_HEAD *pRes = (VMS_RES_HEAD*)AData;
  815. TCDSCtlr *AObj = ASession->CDSCtlr;
  816. if (AObj)
  817. {
  818. if (pRes->Ctlr != (BYTE)AObj->CTLR_LOCAL_NO)
  819. {
  820. TERROR("%s.%d, e_txt_response Controller No Error: %d, %d.", ASession->IpAddress.c_str(), ASession->Socket, AObj->CTLR_LOCAL_NO, (int)pRes->Ctlr);
  821. MERROR("%s.%d, e_txt_response Controller No Error: %d, %d.", ASession->IpAddress.c_str(), ASession->Socket, AObj->CTLR_LOCAL_NO, (int)pRes->Ctlr);
  822. return -3;
  823. }
  824. if (AObj->FTxtOpCode == e_txt_download_full_graphic_lib)
  825. {
  826. //라이브러리폼을 계속 다운로드
  827. TCDSCtlr *AObj = ASession->CDSCtlr;
  828. if (AObj)
  829. {
  830. pInfo = AObj->FDownloadLists.Find(AObj->DownloadFormId);
  831. if (pInfo)
  832. {
  833. pInfo->AlreadyDownload = true;
  834. pInfo->DownloadTm = Now();
  835. }
  836. }
  837. ASession->download_lib_form_0x0A();
  838. }
  839. else
  840. if (AObj->FTxtOpCode == e_txt_display_schedule_msg)
  841. {
  842. //스케쥴다운로드가 완료됐으므로 blank 명령 전송
  843. ASession->download_blank_0x16();
  844. }
  845. else
  846. if (AObj->FTxtOpCode == e_txt_blank)
  847. {
  848. //Blank 명령 전송 완료 수신하면 OpCode 초기화
  849. AObj->FTxtOpCode == 0x00;
  850. // 폼 스케쥴 정보 다운로드 완료 메시지 처리
  851. ASession->download_form_schedule_complete();
  852. }
  853. }
  854. if (nLength == 1 && AData[sizeof(VMS_RES_HEAD)] == VMS_ACK)
  855. {
  856. #if OK_DEBUG
  857. TINFO("e_txt_response : ACK...");
  858. #endif
  859. }
  860. else
  861. if (nLength == 2 && AData[sizeof(VMS_RES_HEAD)] == VMS_NAK)
  862. {
  863. if (AObj && pInfo)
  864. {
  865. pInfo->AlreadyDownload = false;
  866. }
  867. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  868. TERROR("%s.%d, e_txt_response Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  869. MERROR("%s.%d, e_txt_response Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  870. ASession->DisplayResponseError(AData);
  871. return -2;
  872. }
  873. #if OK_DEBUG
  874. else
  875. {
  876. TINFO("e_txt_response : OK...");
  877. }
  878. #endif
  879. return 0;
  880. }
  881. //---------------------------------------------------------------------------
  882. /////////////////////////////////////////////////////////
  883. REGISTER_HANDLER(e_txt_status_res)
  884. {
  885. TCDSCtlr *AObj = ASession->CDSCtlr;
  886. if (!AObj)
  887. {
  888. TERROR("%s.%d, e_txt_status_res Controller NULL. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  889. MERROR("%s.%d, e_txt_status_res Controller NULL. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  890. return -5;
  891. }
  892. if (ASession->State == eSS_LoginReq)
  893. {
  894. VMS_RES_HEAD *pRes = (VMS_RES_HEAD*)AData;
  895. if (pRes->Ctlr != (BYTE)AObj->CTLR_LOCAL_NO)
  896. {
  897. TERROR("%s.%d, e_txt_status_res Controller No Error: %d, %d.", ASession->IpAddress.c_str(), ASession->Socket, AObj->CTLR_LOCAL_NO, (int)pRes->Ctlr);
  898. MERROR("%s.%d, e_txt_status_res Controller No Error: %d, %d.", ASession->IpAddress.c_str(), ASession->Socket, AObj->CTLR_LOCAL_NO, (int)pRes->Ctlr);
  899. return -4;
  900. }
  901. }
  902. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  903. if (nLength < 2)
  904. {
  905. TERROR("%s.%d, e_txt_status_res Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  906. MERROR("%s.%d, e_txt_status_res Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  907. return -1;
  908. }
  909. TDEBUG("e_txt_status_res Length: %d", nLength);
  910. int nReqSize = sizeof(VMS_TXT_STATUS);
  911. if (nLength != nReqSize)
  912. {
  913. TERROR("%s.%d, e_txt_status_res Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  914. MERROR("%s.%d, e_txt_status_res Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  915. if (nLength == 2)
  916. {
  917. ASession->DisplayResponseError(AData);
  918. }
  919. return -2;
  920. }
  921. VMS_TXT_STATUS *pStatus = (VMS_TXT_STATUS*)&AData[sizeof(VMS_RES_HEAD)];
  922. TDEBUG("VMS_TXT_STATUS: Door(%02X), Power(%02X), Fan(%02X), Heater(%02X), Reset(%02X), Temp(%02X,%d)",
  923. pStatus->DOOR,
  924. pStatus->POWER,
  925. pStatus->FAN,
  926. pStatus->HEATER,
  927. pStatus->RESET,
  928. pStatus->CBOX_TEMP,
  929. pStatus->CBOX_TEMP
  930. );
  931. INT_VMS_STATE *FStts = &AObj->RSTATE;
  932. #if 0
  933. BYTE DOOR; // Door Open/Close 상태 0x00 : Open, 0x01 : Close, 0x09 : Unknown
  934. BYTE POWER; // 전원의 ON/OFF 상태 0x00 : On, 0x01 : Off (Sign Board)
  935. BYTE FAN; // VMS Fan 동작상태 0x00 : On, 0x01 : Off, 0x09: Unknown
  936. // 함체 Fan 동작상태 0x00 : On, 0x10 : Off, 0x90: Unknown
  937. BYTE HEATER; // VMS Heater 동작상태 0x00 : On, 0x01 : Off, 0x09: Unknown
  938. // 함체 Heater 동작상태 x00 : On, 0x10 : Off, 0x90: Unknown
  939. WORD FORM_NUM; // 표출 폼 번호 0x00 : 통신 폼, 0x01 : 디폴트 폼
  940. BYTE REBOOT_YN; // 재실행 여부 0x00 : 정상, 0x01 : 재실행
  941. char CBOX_TEMP; // 함체온도 127 ~ -127 -128 : Unknown
  942. BYTE BRIGHT[4]; // 화면의 밝기 최대를 100으로 했을 때의 백분율 값 및 기준휘도
  943. // 0: 현재 휘도(00:주간,01:야간,02:자동)
  944. // 1: 야간휘도설정값
  945. // 2: 주간휘도설정값
  946. // 3: 현재휘도값(이건 나의 추측)
  947. char DP_TEMP; // 표출부온도 127 ~ -127 -128 : Unknown
  948. BYTE DP_HUM; // 표출부습도 0~100%, 포항UTIS부터 추가함
  949. #endif
  950. if (pStatus->POWER == 0x00) FStts->ModulePowerStatus = vms_module_power_off;
  951. else if (pStatus->POWER == 0x01) FStts->ModulePowerStatus = vms_module_power_on;
  952. else FStts->ModulePowerStatus = vms_module_power_unknown;
  953. if (pStatus->DOOR == 0x00) FStts->DoorStatus = vms_door_close;
  954. else if (pStatus->DOOR == 0x01) FStts->DoorStatus = vms_door_open;
  955. else FStts->DoorStatus = vms_door_unknown;
  956. if (pStatus->FAN == 0x00) FStts->FanStatus = vms_fan_off;
  957. else if (pStatus->FAN == 0x01) FStts->FanStatus = vms_fan_on;
  958. else FStts->FanStatus = vms_fan_unknown;
  959. if (pStatus->HEATER == 0x00) FStts->HeaterStatus = vms_heater_off;
  960. else if (pStatus->HEATER == 0x01) FStts->HeaterStatus = vms_heater_on;
  961. else FStts->HeaterStatus = vms_heater_unknown;
  962. FStts->PowerCtrlStatus = FStts->ModulePowerStatus; // 문자식은 받아오는게 없으니까 모듈전원상태와 동일한것으로 하자
  963. FStts->BodyTemp = (short)pStatus->CBOX_TEMP; /* 함체온도값(℃), 범위(-128~127) */
  964. //FStts->LuminanceStatus = (BYTE)pStatus->BRIGHT[3]; /* 화면의 밝기값 (최대 휘도값을 100으로 했을 때의 백분율 값), 범위(0~100) */
  965. FStts->Wcomm = vms_comm_normal;// : vms_comm_error; /* 무선통신상태, 0:정상 1:장애 */
  966. //AObj->BRGH_WEEK_STEP = pStatus->BRIGHT[2];
  967. //AObj->BRGH_NGHT_STEP = pStatus->BRIGHT[1];
  968. RequestJob(ASession, eVmsDisplayModuleStatusReq, NULL, 0);
  969. return 0;
  970. }
  971. //---------------------------------------------------------------------------
  972. /////////////////////////////////////////////////////////
  973. REGISTER_HANDLER(e_txt_failed_elem_data_res)
  974. {
  975. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  976. if (nLength < (int)sizeof(VMS_TXT_MODL_STATUE)) // module count 2 byte
  977. {
  978. TERROR("%s.%d, e_txt_failed_elem_data_res Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  979. MERROR("%s.%d, e_txt_failed_elem_data_res Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  980. return -1;
  981. }
  982. TDEBUG("e_txt_failed_elem_data_res Length: %d", nLength);
  983. VMS_TXT_MODL_STATUE *pData = (VMS_TXT_MODL_STATUE*)&AData[sizeof(VMS_RES_HEAD)];
  984. int idx = 0;
  985. int xCnt = 0;
  986. int yCnt = 0;
  987. TCDSCtlr *AObj = ASession->CDSCtlr;
  988. if (AObj)
  989. {
  990. INT_VMS_STATE *FStts = &AObj->RSTATE;
  991. yCnt = AObj->ROW_NUM;
  992. xCnt = AObj->COL_NUM;
  993. FStts->ModuleHorizontal = xCnt; /* 가로 모듈수 */
  994. FStts->ModuleVertical = yCnt; /* 세로 모듈수 */
  995. idx = 0;
  996. for (int ii = 0; ii < yCnt && ii < MAX_TXT_MODL_ROWS; ii++)
  997. {
  998. for (int jj = 0; jj < xCnt && jj < MAX_TXT_MODL_COLS; jj++)
  999. {
  1000. CComm_SetBitValue(FStts->ModuleStatus, idx, pData->Modl[ii][jj] == 0 ? 1 : 0);
  1001. idx++;
  1002. }
  1003. }
  1004. }
  1005. TDEBUG("VMS_DISPLAY_MODULE : X(%d) Y(%d)", xCnt, yCnt);
  1006. AnsiString sModSts = "";
  1007. AnsiString sTmp;
  1008. AnsiString MODL_STTS = "";
  1009. idx = 0;
  1010. for (int ii = 0; ii < yCnt && ii < MAX_TXT_MODL_ROWS; ii++)
  1011. {
  1012. sModSts = "";
  1013. for (int jj = 0; jj < xCnt && jj < MAX_TXT_MODL_COLS; jj++)
  1014. {
  1015. sTmp.printf("%d", pData->Modl[ii][jj]); //0x00 : Off, 0x01 : On, 0x02 : Unknown,
  1016. sModSts += sTmp;
  1017. idx++;
  1018. }
  1019. MODL_STTS += sModSts;
  1020. TDEBUG("VMS_DISPLAY_MODULE: %02d, %s", ii+1, sModSts.c_str());
  1021. }
  1022. if (AObj) AObj->MODL_STTS = MODL_STTS;
  1023. POST_MSG(MAINHANDLE, WM_TCP_THREAD, WM_CTLR_STATE_STTS, (int)ASession->CDSCtlr); // 상태정보 업데이트
  1024. #if 0
  1025. // 설정온도 요청하면 응답으로 모듈상태정보가 올라와서 사용할 수 없음.
  1026. RequestJob(ASession, eVmsParamReq, NULL, 0);
  1027. #else
  1028. if (ASession->State == eSS_LoginReq)
  1029. {
  1030. ASession->State = eSS_Connected;
  1031. // 제어기가 최초 접속했을 때 마지막으로 시나리오를 전송한 시각과 다음 전송할 시각을 계산해서
  1032. // 1분 이상 차이가 있을때에 시나리오를 전송하도록 한다.
  1033. RequestJob(ASession, eVmsScenarioDownload, NULL, 0);
  1034. }
  1035. #endif
  1036. return 0;
  1037. }
  1038. //---------------------------------------------------------------------------
  1039. #if 0
  1040. //TODO: 이거 사용하면 OpCode가 중복이 되어 모듈상태정보 처리를 하지 못한다.
  1041. /////////////////////////////////////////////////////////
  1042. REGISTER_HANDLER(e_txt_pan_hetr_temp_res)
  1043. {
  1044. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1045. if (nLength < (int)sizeof(VMS_TXT_PARAMETER)) // module count 2 byte
  1046. {
  1047. TERROR("%s.%d, e_txt_pan_hetr_temp_res Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1048. MERROR("%s.%d, e_txt_pan_hetr_temp_res Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1049. return -1;
  1050. }
  1051. TDEBUG("e_txt_pan_hetr_temp_res Length: %d", nLength);
  1052. VMS_TXT_PARAMETER *pParam = (VMS_TXT_PARAMETER*)&AData[sizeof(VMS_RES_HEAD)];
  1053. int nReqSize = sizeof(VMS_TXT_PARAMETER);
  1054. if (nLength != nReqSize) // module count 2 byte
  1055. {
  1056. TERROR("%s.%d, e_txt_pan_hetr_temp_res Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1057. MERROR("%s.%d, e_txt_pan_hetr_temp_res Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1058. if (nLength == 2)
  1059. {
  1060. ASession->DisplayResponseError(AData);
  1061. }
  1062. return -2;
  1063. }
  1064. TCDSCtlr *AObj = ASession->CDSCtlr;
  1065. if (AObj)
  1066. {
  1067. AObj->FAN_RUN_TMPR = pParam->FanRunTemp; // Fan의 동작개시온도 1 Byte 온도( 0x00 ~0x03f )
  1068. AObj->HETR_RUN_TMPR = pParam->HeaterRunTemp; // Heater 의 동작개시온도 1 Byte 온도(0x00 ~ 0x3f )
  1069. TDEBUG("VMS_TXT_PARAMETER: ");
  1070. TDEBUG(" FAN_RUN_TMPR: %d", AObj->FAN_RUN_TMPR);
  1071. TDEBUG(" HETR_RUN_TMPR: %02X", AObj->HETR_RUN_TMPR);
  1072. CTLR_STTS stts;
  1073. stts.Type = 2;
  1074. stts.ObjPtr = (void*)AObj;
  1075. INT_VMS_STATE *FStts = &ASession->CDSCtlr->RSTATE;
  1076. if (AObj->MODULE.IsOnOff)
  1077. {
  1078. if (AObj->MODULE.OnOff != AObj->PANL_PWER_MODE)
  1079. {
  1080. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  1081. pMsg->Type = eVmsStatusControl;
  1082. pMsg->ObjPtr = (DWORD)ASession;
  1083. pMsg->Buff[0] = 0x01;
  1084. pMsg->Buff[1] = ASession->CDSCtlr->MODULE.OnOff;// == vms_module_power_off ? 0x00 : 0x01;
  1085. pMsg->Len = 2;
  1086. g_jobQ.PushBlocking((DWORD)pMsg);
  1087. }
  1088. else
  1089. {
  1090. AObj->MODULE.IsOnOff = false;
  1091. }
  1092. }
  1093. //1분마다 주기적으로 상태정보를 업데이트 하니까 실시간으로 업데이트 할 필요가 없다.
  1094. //운영단말로 실시간으로 데이터만 보내도록 하자
  1095. APP_PostDbThreadWriteMessage(dbm_parma_res, sizeof(stts), &stts); // 파라미터 저장
  1096. POST_MSG(MAINHANDLE, WM_TCP_THREAD, WM_CTLR_STATE_STTS, (int)ASession->CDSCtlr); // 상태정보 업데이트
  1097. }
  1098. if (ASession->State == eSS_LoginReq)
  1099. {
  1100. ASession->State = eSS_Connected;
  1101. // 제어기가 최초 접속했을 때 마지막으로 시나리오를 전송한 시각과 다음 전송할 시각을 계산해서
  1102. // 1분 이상 차이가 있을때에 시나리오를 전송하도록 한다.
  1103. RequestJob(ASession, eVmsScenarioDownload, NULL, 0);
  1104. }
  1105. return 0;
  1106. }
  1107. //---------------------------------------------------------------------------
  1108. #endif
  1109. /////////////////////////////////////////////////////////
  1110. REGISTER_HANDLER(e_vms_status)
  1111. {
  1112. TCDSCtlr *AObj = ASession->CDSCtlr;
  1113. if (!AObj)
  1114. {
  1115. TERROR("%s.%d, e_vms_status Controller NULL. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  1116. MERROR("%s.%d, e_vms_status Controller NULL. will be closed.", ASession->IpAddress.c_str(), ASession->Socket);
  1117. return -5;
  1118. }
  1119. if (ASession->State == eSS_LoginReq)
  1120. {
  1121. VMS_RES_HEAD *pRes = (VMS_RES_HEAD*)AData;
  1122. if (pRes->Ctlr != (BYTE)AObj->CTLR_LOCAL_NO)
  1123. {
  1124. TERROR("%s.%d, e_vms_status Controller No Error: %d, %d.", ASession->IpAddress.c_str(), ASession->Socket, AObj->CTLR_LOCAL_NO, (int)pRes->Ctlr);
  1125. MERROR("%s.%d, e_vms_status Controller No Error: %d, %d.", ASession->IpAddress.c_str(), ASession->Socket, AObj->CTLR_LOCAL_NO, (int)pRes->Ctlr);
  1126. return -4;
  1127. }
  1128. }
  1129. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1130. if (nLength < 2)
  1131. {
  1132. TERROR("%s.%d, e_vms_status Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1133. MERROR("%s.%d, e_vms_status Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1134. return -1;
  1135. }
  1136. TDEBUG("e_vms_status Length: %d", nLength);
  1137. int nReqSize = sizeof(VMS_STATUS);
  1138. if (nLength != nReqSize)
  1139. {
  1140. TERROR("%s.%d, e_vms_status Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1141. MERROR("%s.%d, e_vms_status Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1142. if (nLength == 2)
  1143. {
  1144. ASession->DisplayResponseError(AData);
  1145. }
  1146. return -2;
  1147. }
  1148. VMS_STATUS *pStatus = (VMS_STATUS*)&AData[sizeof(VMS_RES_HEAD)];
  1149. pStatus->FORM_NO = htons(pStatus->FORM_NO);
  1150. //pStatus->BRIGHT = htonl(pStatus->BRIGHT);
  1151. TDEBUG("VMS_STATUS: Door(%02X), Power(%02X), Fan(%02X), Heater(%02X), FormNo(%d), Reboot(%02X), Temp(%02X,%d), Bright(%02X,%02X,%02X,%02X), ExtTemp(%02X,%d), ExtHum(%02X,%d)",
  1152. pStatus->DOOR,
  1153. pStatus->POWER,
  1154. pStatus->FAN,
  1155. pStatus->HEATER,
  1156. pStatus->FORM_NO,
  1157. pStatus->REBOOT_YN,
  1158. pStatus->CBOX_TEMP,
  1159. pStatus->CBOX_TEMP,
  1160. pStatus->BRIGHT[0],
  1161. pStatus->BRIGHT[1],
  1162. pStatus->BRIGHT[2],
  1163. pStatus->BRIGHT[3],
  1164. pStatus->DP_TEMP,
  1165. pStatus->DP_TEMP,
  1166. pStatus->DP_HUM,
  1167. pStatus->DP_HUM
  1168. );
  1169. INT_VMS_STATE *FStts = &AObj->RSTATE;
  1170. #if 0
  1171. BYTE DOOR; // Door Open/Close 상태 0x00 : Open, 0x01 : Close, 0x09 : Unknown
  1172. BYTE POWER; // 전원의 ON/OFF 상태 0x00 : On, 0x01 : Off (Sign Board)
  1173. BYTE FAN; // VMS Fan 동작상태 0x00 : On, 0x01 : Off, 0x09: Unknown
  1174. // 함체 Fan 동작상태 0x00 : On, 0x10 : Off, 0x90: Unknown
  1175. BYTE HEATER; // VMS Heater 동작상태 0x00 : On, 0x01 : Off, 0x09: Unknown
  1176. // 함체 Heater 동작상태 x00 : On, 0x10 : Off, 0x90: Unknown
  1177. WORD FORM_NUM; // 표출 폼 번호 0x00 : 통신 폼, 0x01 : 디폴트 폼
  1178. BYTE REBOOT_YN; // 재실행 여부 0x00 : 정상, 0x01 : 재실행
  1179. char CBOX_TEMP; // 함체온도 127 ~ -127 -128 : Unknown
  1180. BYTE BRIGHT[4]; // 화면의 밝기 최대를 100으로 했을 때의 백분율 값 및 기준휘도
  1181. // 0: 현재 휘도(00:주간,01:야간,02:자동)
  1182. // 1: 야간휘도설정값
  1183. // 2: 주간휘도설정값
  1184. // 3: 현재휘도값(이건 나의 추측)
  1185. char DP_TEMP; // 표출부온도 127 ~ -127 -128 : Unknown
  1186. BYTE DP_HUM; // 표출부습도 0~100%, 포항UTIS부터 추가함
  1187. #endif
  1188. if (pStatus->POWER == 0x01) FStts->ModulePowerStatus = vms_module_power_off;
  1189. else if (pStatus->POWER == 0x00) FStts->ModulePowerStatus = vms_module_power_on;
  1190. else FStts->ModulePowerStatus = vms_module_power_unknown;
  1191. if (pStatus->DOOR == 0x01) FStts->DoorStatus = vms_door_close;
  1192. else if (pStatus->DOOR == 0x00) FStts->DoorStatus = vms_door_open;
  1193. else FStts->DoorStatus = vms_door_unknown;
  1194. // 2021.03.25 신규 추가 VMS
  1195. // 랩에서 테스트시 장비가 연결되어 있지 않아서 9로 올라옴. ==> 현장에서는 정상적으로 올라올거라함.
  1196. int S1, S2;
  1197. // 둘다 꺼져 있으면 OFF, 하나라도 켜져 있으면 ON
  1198. S1 = (pStatus->FAN & 0x0F);
  1199. S2 = (pStatus->FAN & 0xF0) >> 4;
  1200. if (S1 != 0 && S1 != 1) S1 = 1;
  1201. if (S2 != 0 && S2 != 1) S2 = 1;
  1202. if (S1 == 1 && S2 == 1)
  1203. pStatus->FAN = 0x01;
  1204. else
  1205. pStatus->FAN = 0x00;
  1206. //VMS : 0x00 : On, 0x01 : Off, 0x09: Unknown
  1207. //함체: 0x00 : On, 0x10 : Off, 0x90: Unknown
  1208. if (pStatus->FAN == 0x00) FStts->FanStatus = vms_fan_on;
  1209. else if (pStatus->FAN == 0x01) FStts->FanStatus = vms_fan_off;
  1210. else if (pStatus->FAN == 0x10) FStts->FanStatus = vms_fan_off;
  1211. else if (pStatus->FAN == 0x11) FStts->FanStatus = vms_fan_off; // ??? 실제 현장 상황에 맞게
  1212. else FStts->FanStatus = vms_fan_unknown;
  1213. // 둘다 꺼져 있으면 OFF, 하나라도 켜져 있으면 ON
  1214. S1 = (pStatus->HEATER & 0x0F);
  1215. S2 = (pStatus->HEATER & 0xF0) >> 4;
  1216. if (S1 != 0 && S1 != 1) S1 = 1;
  1217. if (S2 != 0 && S2 != 1) S2 = 1;
  1218. if (S1 == 1 && S2 == 1)
  1219. pStatus->HEATER = 0x01;
  1220. else
  1221. pStatus->HEATER = 0x00;
  1222. //VMS : 0x00 : On, 0x01 : Off, 0x09: Unknown
  1223. //함체: 0x00 : On, 0x10 : Off, 0x90: Unknown
  1224. if (pStatus->HEATER == 0x00) FStts->HeaterStatus = vms_heater_on;
  1225. else if (pStatus->HEATER == 0x01) FStts->HeaterStatus = vms_heater_off;
  1226. else if (pStatus->HEATER == 0x10) FStts->HeaterStatus = vms_heater_off;
  1227. else if (pStatus->HEATER == 0x11) FStts->HeaterStatus = vms_heater_off; // // ??? 실제 현장 상황에 맞게
  1228. else FStts->HeaterStatus = vms_heater_unknown;
  1229. FStts->BodyTemp = (short)pStatus->CBOX_TEMP; /* 함체온도값(℃), 범위(-128~127) */
  1230. FStts->LuminanceStatus = (BYTE)pStatus->BRIGHT[3]; /* 화면의 밝기값 (최대 휘도값을 100으로 했을 때의 백분율 값), 범위(0~100) */
  1231. FStts->Wcomm = vms_comm_normal;// : vms_comm_error; /* 무선통신상태, 0:정상 1:장애 */
  1232. AObj->BRGH_WEEK_STEP = pStatus->BRIGHT[2];
  1233. AObj->BRGH_NGHT_STEP = pStatus->BRIGHT[1];
  1234. RequestJob(ASession, eVmsPowerModuleStautsReq, NULL, 0);
  1235. return 0;
  1236. }
  1237. //---------------------------------------------------------------------------
  1238. /////////////////////////////////////////////////////////
  1239. REGISTER_HANDLER(e_vms_power_module_status)
  1240. {
  1241. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1242. if (nLength < 1) // module count 1 byte
  1243. {
  1244. TERROR("%s.%d, e_vms_power_module_status Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1245. MERROR("%s.%d, e_vms_power_module_status Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1246. return -1;
  1247. }
  1248. TDEBUG("e_vms_power_module_status Length: %d", nLength);
  1249. BYTE *pData = &AData[sizeof(VMS_RES_HEAD)];
  1250. int nModCnt = pData[0];
  1251. // pData[1] ==> Reserved area
  1252. int nReqSize = (nModCnt+2);
  1253. if (nLength != nReqSize)
  1254. {
  1255. TERROR("%s.%d, e_vms_power_module_status Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1256. MERROR("%s.%d, e_vms_power_module_status Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1257. if (nLength == 2)
  1258. {
  1259. ASession->DisplayResponseError(AData);
  1260. }
  1261. return -2;
  1262. }
  1263. TCDSCtlr *AObj = ASession->CDSCtlr;
  1264. if (AObj)
  1265. {
  1266. INT_VMS_STATE *FStts = &ASession->CDSCtlr->RSTATE;
  1267. FStts->PowerCount = nModCnt;
  1268. for (int ii = 0; ii < nModCnt; ii++)
  1269. {
  1270. CComm_SetBitValue(FStts->PowerStatus, ii, pData[2+ii]);
  1271. }
  1272. }
  1273. TDEBUG("VMS_POWER_MODULE COUNT: %d", nModCnt);
  1274. AnsiString sModSts = "";
  1275. AnsiString sTmp;
  1276. AnsiString PWER_STTS = "";
  1277. for (int ii = 0; ii < nModCnt; ii++)
  1278. {
  1279. sTmp.printf("%d", pData[2+ii]); //0x00 : Off, 0x01 : On, 0x02 : Unknown,
  1280. sModSts += sTmp;
  1281. }
  1282. PWER_STTS += sModSts;
  1283. if (AObj) AObj->PWER_STTS = PWER_STTS;
  1284. TDEBUG("VMS_POWER_MODULE STATUS: %s", sModSts.c_str());
  1285. RequestJob(ASession, eVmsDisplayModuleStatusReq, NULL, 0);
  1286. return 0;
  1287. }
  1288. //---------------------------------------------------------------------------
  1289. /////////////////////////////////////////////////////////
  1290. REGISTER_HANDLER(e_vms_display_module_status)
  1291. {
  1292. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1293. if (nLength < 2) // module count 2 byte
  1294. {
  1295. TERROR("%s.%d, e_vms_display_module_status Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1296. MERROR("%s.%d, e_vms_display_module_status Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1297. return -1;
  1298. }
  1299. TDEBUG("e_vms_display_module_status Length: %d", nLength);
  1300. BYTE *pData = (BYTE*)&AData[sizeof(VMS_RES_HEAD)];
  1301. int xCnt = pData[0]; // 1 Byte(X축) VMS 모듈수 //가로
  1302. int yCnt = pData[1]; // 1 Byte(Y축) VMS 모듈수 //세로
  1303. // 예)VMS 모듈수 : 2단 5열일 경우 모듈개수 (5(x), 2(y))를 표지한다.
  1304. int nReqSize = (xCnt*yCnt+2);
  1305. if (nLength < nReqSize) // module count 2 byte
  1306. {
  1307. TERROR("%s.%d, e_vms_display_module_status Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1308. MERROR("%s.%d, e_vms_display_module_status Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1309. if (nLength == 2)
  1310. {
  1311. ASession->DisplayResponseError(AData);
  1312. }
  1313. return -2;
  1314. }
  1315. int idx = 0;
  1316. TCDSCtlr *AObj = ASession->CDSCtlr;
  1317. if (AObj)
  1318. {
  1319. INT_VMS_STATE *FStts = &AObj->RSTATE;
  1320. FStts->ModuleHorizontal = xCnt; /* 가로 모듈수 */
  1321. FStts->ModuleVertical = yCnt; /* 세로 모듈수 */
  1322. idx = 0;
  1323. for (int ii = 0; ii < yCnt; ii++)
  1324. {
  1325. for (int jj = 0; jj < xCnt; jj++)
  1326. {
  1327. //CComm_SetBitValue(FStts->ModuleStatus, idx, pData[2+idx]);
  1328. CComm_SetBitValue(FStts->ModuleStatus, idx, pData[2+idx] == 0 ? 1 : 0);
  1329. idx++;
  1330. }
  1331. }
  1332. }
  1333. TDEBUG("VMS_DISPLAY_MODULE : X(%d) Y(%d)", xCnt, yCnt);
  1334. AnsiString sModSts = "";
  1335. AnsiString sTmp;
  1336. AnsiString MODL_STTS = "";
  1337. idx = 0;
  1338. for (int ii = 0; ii < yCnt; ii++)
  1339. {
  1340. sModSts = "";
  1341. for (int jj = 0; jj < xCnt; jj++)
  1342. {
  1343. sTmp.printf("%d", pData[2+idx]); //0x00 : Off, 0x01 : On, 0x02 : Unknown,
  1344. sModSts += sTmp;
  1345. idx++;
  1346. }
  1347. MODL_STTS += sModSts;
  1348. TDEBUG("VMS_DISPLAY_MODULE: %02d, %s", ii+1, sModSts.c_str());
  1349. }
  1350. if (AObj) AObj->MODL_STTS = MODL_STTS;
  1351. //백분율 컬럼 없음(프로토콜 문서에는 있는데 제어기에서 올리지 않음)
  1352. //TDEBUG("VMS_DISPLAY_MODULE: Error Rate: 0x%02X, 0x%02X", pData[2+(xCnt*yCnt)], pData[2+(xCnt*yCnt)+1];
  1353. RequestJob(ASession, eVmsParamReq, NULL, 0);
  1354. return 0;
  1355. }
  1356. //---------------------------------------------------------------------------
  1357. /////////////////////////////////////////////////////////
  1358. REGISTER_HANDLER(e_vms_parameter)
  1359. {
  1360. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1361. if (nLength < (int)sizeof(VMS_PARAMETER)) // module count 2 byte
  1362. {
  1363. TERROR("%s.%d, e_vms_parameter Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1364. MERROR("%s.%d, e_vms_parameter Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1365. return -1;
  1366. }
  1367. TDEBUG("e_vms_parameter Length: %d", nLength);
  1368. VMS_PARAMETER *pParam = (VMS_PARAMETER*)&AData[sizeof(VMS_RES_HEAD)];
  1369. int nReqSize = sizeof(VMS_PARAMETER);
  1370. if (nLength != nReqSize) // module count 2 byte
  1371. {
  1372. TERROR("%s.%d, e_vms_parameter Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1373. MERROR("%s.%d, e_vms_parameter Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1374. if (nLength == 2)
  1375. {
  1376. ASession->DisplayResponseError(AData);
  1377. }
  1378. return -2;
  1379. }
  1380. TCDSCtlr *AObj = ASession->CDSCtlr;
  1381. if (AObj)
  1382. {
  1383. AObj->PANL_PWER_MODE = pParam->PowerCtrlMode; // 전원제어 모드 1 Byte 0x00 : 꺼짐, 0x01 : 켜짐,
  1384. AObj->FAN_MODE = pParam->FanRunMode; // Fan 동작모드 1 Byte 0x00 : 꺼짐, 0x01 : 켜짐, 0x02 : 자동, 0x09: Unknown
  1385. AObj->FAN_RUN_TMPR = pParam->FanRunTemp; // Fan의 동작개시온도 1 Byte 온도( 0x00 ~0x03f )
  1386. AObj->HETR_MODE = pParam->HeaterRunMode; // Heater의 동작모드 1 Byte 0x00 : 꺼짐, 0x01 : 켜짐, 0x02 : 자동, 0x09: Unknown
  1387. AObj->HETR_RUN_TMPR = pParam->HeaterRunTemp; // Heater 의 동작개시온도 1 Byte 온도(0x00 ~ 0x3f )
  1388. AObj->BRGH_MODE = pParam->BrightMode; // 밝기 모드 2 Byte 0x0 : 수동, 0x1 : 자동, 비율 : 0-100
  1389. AObj->BRGH_CURR_STEP = pParam->BrightRate; // 밝기 모드 2 Byte 0x0 : 수동, 0x1 : 자동, 비율 : 0-100
  1390. //AObj->BRGH_WEEK_STEP = 0x00; // res.para.brghDay; // N NUMBER(3) Y 64 휘도 주간 단계(0~100)
  1391. //AObj->BRGH_NGHT_STEP = 0x00; // res.para.brghNight; // N NUMBER(3) Y 48 휘도 야간 단계(0~100)
  1392. AObj->ParamResTime.printf("%04d%02d%02d%02d%02d%02d",
  1393. pParam->Year+2000, // 년 1 Byte 0x00 ~ 0x32
  1394. pParam->Mon, // 월 1 Byte 0x01 ~ 0x0c
  1395. pParam->Day, // 일 1 Byte 0x01 ~ 0x1f
  1396. pParam->Hour, // 시 1 Byte 0x00 ~ 0x17
  1397. pParam->Min, // 분 1 Byte 0x00 ~ 0x3b
  1398. pParam->Sec // 초 1 Byte 0x00 ~ 0x3b
  1399. );
  1400. #if 0
  1401. pParam->BlinkTime; // 깜빡이는 시간주기 1 Byte 문자 비트맵의 깜빡이는 시간주기 0x00 ~ 0x1e( 0.1 ~3.0 )
  1402. pParam->ScnTurnTime; // 디폴트 시나리오로 전환시간 2 Byte 디폴트 시나리오로 전환될 때까지 기다리는 시간, 단위 : 초
  1403. pParam->Reserved; // 기타 1 Byte
  1404. #endif
  1405. TDEBUG("VMS_PARAMETER: PANL_PWER_MODE: 0x%02X", AObj->PANL_PWER_MODE);
  1406. TDEBUG(" FAN_MODE: 0x%02X", AObj->FAN_MODE);
  1407. TDEBUG(" FAN_RUN_TMPR: 0x%02X, %d", AObj->FAN_RUN_TMPR);
  1408. TDEBUG(" HETR_MODE: 0x%02X", AObj->HETR_MODE);
  1409. TDEBUG(" HETR_RUN_TMPR: 0x%02X", AObj->HETR_RUN_TMPR);
  1410. TDEBUG(" BRGH_MODE: 0x%02X", AObj->BRGH_MODE);
  1411. TDEBUG(" BRGH_CURR_STEP: 0x%02X, %d", AObj->BRGH_CURR_STEP, AObj->BRGH_CURR_STEP);
  1412. TDEBUG(" LOCAL_TIME: %s", AObj->ParamResTime.c_str());
  1413. CTLR_STTS stts;
  1414. stts.Type = 2;
  1415. stts.ObjPtr = (void*)AObj;
  1416. // AObj->PANL_PWER_MODE 여기 정보가 모듈전원이 On/Off 된 것을 저장하고 있다.
  1417. INT_VMS_STATE *FStts = &ASession->CDSCtlr->RSTATE;
  1418. //FStts->PowerCtrlStatus = pParam->PowerCtrlMode; // 전원제어 모드 1 Byte 0x00 : 꺼짐, 0x01 : 켜짐,
  1419. if (pParam->PowerCtrlMode == 0x00) FStts->PowerCtrlStatus = vms_module_power_off;
  1420. else if (pParam->PowerCtrlMode == 0x01) FStts->PowerCtrlStatus = vms_module_power_on;
  1421. else FStts->PowerCtrlStatus = vms_module_power_unknown;
  1422. memcpy(FStts->ControllerCurrentTime, AObj->ParamResTime.c_str(), INT_VMS_MAX_DATETIME);
  1423. if (AObj->MODULE.IsOnOff)
  1424. {
  1425. if (AObj->MODULE.OnOff != AObj->PANL_PWER_MODE)
  1426. {
  1427. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  1428. pMsg->Type = eVmsStatusControl;
  1429. pMsg->ObjPtr = (DWORD)ASession;
  1430. pMsg->Buff[0] = 0x01;
  1431. pMsg->Buff[1] = ASession->CDSCtlr->MODULE.OnOff;// == vms_module_power_off ? 0x00 : 0x01;
  1432. pMsg->Len = 2;
  1433. g_jobQ.PushBlocking((DWORD)pMsg);
  1434. }
  1435. else
  1436. {
  1437. AObj->MODULE.IsOnOff = false;
  1438. }
  1439. }
  1440. //1분마다 주기적으로 상태정보를 업데이트 하니까 실시간으로 업데이트 할 필요가 없다.
  1441. //운영단말로 실시간으로 데이터만 보내도록 하자
  1442. APP_PostDbThreadWriteMessage(dbm_parma_res, sizeof(stts), &stts); // 파라미터 저장
  1443. POST_MSG(MAINHANDLE, WM_TCP_THREAD, WM_CTLR_STATE_STTS, (int)ASession->CDSCtlr); // 상태정보 업데이트
  1444. }
  1445. // TODO: 동영상 VMS 인 경우 동영상 파일을 다운로드 하도록 명령을 전송한다.
  1446. if (AObj->IsVideo && AObj->RemainFtpFile()) {
  1447. TINFO("ftp-file-download request to jobQ-1.");
  1448. RequestJob(ASession, eVmsFtpFileDownload, NULL, 0);
  1449. }
  1450. if (ASession->State == eSS_LoginReq)
  1451. {
  1452. ASession->State = eSS_Connected;
  1453. // 제어기가 최초 접속했을 때 마지막으로 시나리오를 전송한 시각과 다음 전송할 시각을 계산해서
  1454. // 1분 이상 차이가 있을때에 시나리오를 전송하도록 한다.
  1455. RequestJob(ASession, eVmsScenarioDownload, NULL, 0);
  1456. }
  1457. return 0;
  1458. }
  1459. //---------------------------------------------------------------------------
  1460. /////////////////////////////////////////////////////////
  1461. REGISTER_HANDLER(e_vms_pixel_image)
  1462. {
  1463. // 요거는 제어기에서 응답을 하지 않음.
  1464. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1465. if (nLength < (int)sizeof(VMS_PARAMETER)) // module count 2 byte
  1466. {
  1467. TERROR("%s.%d, e_vms_parameter Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1468. MERROR("%s.%d, e_vms_parameter Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1469. return -1;
  1470. }
  1471. TDEBUG("e_vms_parameter Length: %d", nLength);
  1472. VMS_PARAMETER *pParam = (VMS_PARAMETER*)&AData[sizeof(VMS_RES_HEAD)];
  1473. int nReqSize = sizeof(VMS_PARAMETER);
  1474. if (nLength != nReqSize) // module count 2 byte
  1475. {
  1476. TERROR("%s.%d, e_vms_parameter Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1477. MERROR("%s.%d, e_vms_parameter Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1478. if (nLength == 2)
  1479. {
  1480. ASession->DisplayResponseError(AData);
  1481. }
  1482. return -2;
  1483. }
  1484. return 0;
  1485. }
  1486. //---------------------------------------------------------------------------
  1487. /////////////////////////////////////////////////////////
  1488. REGISTER_HANDLER(e_vms_current_display_form)
  1489. {
  1490. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1491. if (nLength < (int)sizeof(VMS_PARAMETER)) // module count 2 byte
  1492. {
  1493. TERROR("%s.%d, e_vms_current_display_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1494. MERROR("%s.%d, e_vms_current_display_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1495. return -1;
  1496. }
  1497. TDEBUG("e_vms_current_display_form Length: %d", nLength);
  1498. return 0;
  1499. }
  1500. //---------------------------------------------------------------------------
  1501. /////////////////////////////////////////////////////////
  1502. REGISTER_HANDLER(e_vms_display_default_form)
  1503. {
  1504. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1505. #if 0
  1506. if (nLength < 1) // ACK or NAK
  1507. {
  1508. TERROR("%s.%d, e_vms_display_default_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1509. MERROR("%s.%d, e_vms_display_default_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1510. return -1;
  1511. }
  1512. #endif
  1513. TDEBUG("e_vms_display_default_form Length: %d", nLength);
  1514. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  1515. if (pRes->Result != VMS_ACK)
  1516. {
  1517. TERROR("%s.%d, e_vms_display_default_form Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1518. MERROR("%s.%d, e_vms_display_default_form Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1519. ASession->DisplayResponseError(AData);
  1520. return -2;
  1521. }
  1522. #if OK_DEBUG
  1523. else
  1524. {
  1525. TINFO("e_vms_display_default_form : OK...");
  1526. }
  1527. #endif
  1528. return 0;
  1529. }
  1530. //---------------------------------------------------------------------------
  1531. /////////////////////////////////////////////////////////
  1532. REGISTER_HANDLER(e_vms_upload_schedule_form)
  1533. {
  1534. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1535. #if 0
  1536. if (nLength < 1) // ACK or NAK
  1537. {
  1538. TERROR("%s.%d, e_vms_upload_schedule_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1539. MERROR("%s.%d, e_vms_upload_schedule_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1540. return -1;
  1541. }
  1542. #endif
  1543. TDEBUG("e_vms_upload_schedule_form Length: %d", nLength);
  1544. VMS_SCHEDULE_FORM *pRes = (VMS_SCHEDULE_FORM*)&AData[sizeof(VMS_RES_HEAD)];
  1545. int nReqSize = sizeof(VMS_SCHEDULE_FORM);
  1546. if (nLength < nReqSize)
  1547. {
  1548. TERROR("%s.%d, e_vms_upload_schedule_form Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1549. MERROR("%s.%d, e_vms_upload_schedule_form Data Size error(%d, %d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength, nReqSize);
  1550. if (nLength == 2)
  1551. {
  1552. ASession->DisplayResponseError(AData);
  1553. }
  1554. return -2;
  1555. }
  1556. for (int ii = 0; ii < MAX_VMS_SCENARIO_FORM; ii++)
  1557. {
  1558. TDEBUG("e_vms_upload_schedule_form %02d: FormNo: %d, Display Second: %d", ii+1, ntohs(pRes->Form[ii].FormNo), pRes->Form[ii].DispSec);
  1559. }
  1560. return 0;
  1561. }
  1562. //---------------------------------------------------------------------------
  1563. /////////////////////////////////////////////////////////
  1564. REGISTER_HANDLER(e_vms_display_form_id)
  1565. {
  1566. //프로토콜에는 있으나 제어기에서 반응을 하지 않음
  1567. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1568. #if 0
  1569. if (nLength < 1) // ACK or NAK
  1570. {
  1571. TERROR("%s.%d, e_vms_display_form_id Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1572. MERROR("%s.%d, e_vms_display_form_id Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1573. return -1;
  1574. }
  1575. #endif
  1576. TDEBUG("e_vms_display_form_id Length: %d", nLength);
  1577. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  1578. if (pRes->Result != VMS_ACK)
  1579. {
  1580. TERROR("%s.%d, e_vms_display_form_id Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1581. MERROR("%s.%d, e_vms_display_form_id Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1582. ASession->DisplayResponseError(AData);
  1583. return -2;
  1584. }
  1585. #if OK_DEBUG
  1586. else
  1587. {
  1588. TINFO("e_vms_display_form_id : OK...");
  1589. }
  1590. #endif
  1591. return 0;
  1592. }
  1593. //---------------------------------------------------------------------------
  1594. /////////////////////////////////////////////////////////
  1595. REGISTER_HANDLER(e_vms_status_control)
  1596. {
  1597. //프로토콜에는 있으나 제어기에서 반응을 하지 않음
  1598. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1599. #if 0
  1600. if (nLength < 1) // ACK or NAK
  1601. {
  1602. TERROR("%s.%d, e_vms_status_control Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1603. MERROR("%s.%d, e_vms_status_control Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1604. return -1;
  1605. }
  1606. #endif
  1607. TDEBUG("e_vms_status_control Length: %d", nLength);
  1608. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  1609. if (pRes->Result != VMS_ACK)
  1610. {
  1611. TERROR("%s.%d, e_vms_status_control Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1612. MERROR("%s.%d, e_vms_status_control Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1613. ASession->DisplayResponseError(AData);
  1614. return -2;
  1615. }
  1616. #if OK_DEBUG
  1617. else
  1618. {
  1619. TINFO("e_vms_status_control : OK...");
  1620. }
  1621. #endif
  1622. RequestJob(ASession, eVmsStatusReq, NULL, 0);
  1623. return 0;
  1624. }
  1625. //---------------------------------------------------------------------------
  1626. /////////////////////////////////////////////////////////
  1627. REGISTER_HANDLER(e_vms_download_form)
  1628. {
  1629. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1630. #if 0
  1631. if (nLength < 1) // ACK or NAK
  1632. {
  1633. TERROR("%s.%d, e_vms_download_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1634. MERROR("%s.%d, e_vms_download_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1635. return -1;
  1636. }
  1637. #endif
  1638. TDEBUG("e_vms_download_form Length: %d", nLength);
  1639. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  1640. if (pRes->Result != VMS_ACK)
  1641. {
  1642. TERROR("%s.%d, e_vms_download_form Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1643. MERROR("%s.%d, e_vms_download_form Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1644. ASession->DisplayResponseError(AData);
  1645. return -2;
  1646. }
  1647. #if OK_DEBUG
  1648. else
  1649. {
  1650. TINFO("e_vms_download_form : OK...");
  1651. }
  1652. #endif
  1653. // 폼정보를 계속해서 다운로드 한다.
  1654. // 스케쥴 모드가 기본모드인 경우에는 폼정보가 하나만 내려가기때문에
  1655. // 폼파일을 다운로드 해야 하고
  1656. // 일반모드(자동, 고정) 인경우에는 폼정보를 계속해서 다운로드 해야 한다.
  1657. if (ASession->CDSCtlr->FormDownload.IsDefault)
  1658. {
  1659. ASession->download_file_0x82();
  1660. }
  1661. else
  1662. {
  1663. ASession->download_form_0x9A();
  1664. }
  1665. return 0;
  1666. }
  1667. //---------------------------------------------------------------------------
  1668. /////////////////////////////////////////////////////////
  1669. REGISTER_HANDLER(e_vms_form_display)
  1670. {
  1671. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1672. #if 0
  1673. if (nLength < 1) // ACK or NAK
  1674. {
  1675. TERROR("%s.%d, e_vms_form_display Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1676. MERROR("%s.%d, e_vms_form_display Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1677. return -1;
  1678. }
  1679. #endif
  1680. TDEBUG("e_vms_form_display Length: %d", nLength);
  1681. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  1682. if (pRes->Result != VMS_ACK)
  1683. {
  1684. TERROR("%s.%d, e_vms_form_display Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1685. MERROR("%s.%d, e_vms_form_display Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1686. ASession->DisplayResponseError(AData);
  1687. return -2;
  1688. }
  1689. #if OK_DEBUG
  1690. else
  1691. {
  1692. TINFO("e_vms_form_display : OK...");
  1693. }
  1694. #endif
  1695. return 0;
  1696. }
  1697. //---------------------------------------------------------------------------
  1698. /////////////////////////////////////////////////////////
  1699. REGISTER_HANDLER(e_vms_download_schedule_form)
  1700. {
  1701. //프로토콜에는 있으나 제어기에서 반응을 하지 않음
  1702. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1703. #if 0
  1704. if (nLength < 1) // ACK or NAK
  1705. {
  1706. TERROR("%s.%d, e_vms_download_schedule_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1707. MERROR("%s.%d, e_vms_download_schedule_form Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1708. return -1;
  1709. }
  1710. #endif
  1711. TDEBUG("e_vms_download_schedule_form Length: %d", nLength);
  1712. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  1713. if (pRes->Result != VMS_ACK)
  1714. {
  1715. TERROR("%s.%d, e_vms_download_schedule_form Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1716. MERROR("%s.%d, e_vms_download_schedule_form Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1717. ASession->DisplayResponseError(AData);
  1718. return -2;
  1719. }
  1720. #if OK_DEBUG
  1721. else
  1722. {
  1723. TINFO("e_vms_download_schedule_form : OK...");
  1724. }
  1725. #endif
  1726. // 스케쥴 표출 마지막 데이터 전송
  1727. ASession->download_blank_0x9E();
  1728. return 0;
  1729. }
  1730. //---------------------------------------------------------------------------
  1731. /////////////////////////////////////////////////////////
  1732. REGISTER_HANDLER(e_vms_file_download)
  1733. {
  1734. //프로토콜에는 있으나 제어기에서 반응을 하지 않음
  1735. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1736. #if 0
  1737. if (nLength < 1) // ACK or NAK
  1738. {
  1739. TERROR("%s.%d, e_vms_file_download Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1740. MERROR("%s.%d, e_vms_file_download Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1741. return -1;
  1742. }
  1743. #endif
  1744. TDEBUG("e_vms_file_download Length: %d", nLength);
  1745. TDownloadForm *pInfo = NULL;
  1746. TCDSCtlr *AObj = ASession->CDSCtlr;
  1747. if (AObj)
  1748. {
  1749. pInfo = AObj->FDownloadLists.Find(AObj->DownloadFormId);
  1750. }
  1751. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  1752. if (pRes->Result != VMS_ACK)
  1753. {
  1754. if (pInfo)
  1755. {
  1756. pInfo->AlreadyDownload = false;
  1757. }
  1758. TERROR("%s.%d, e_vms_file_download Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1759. MERROR("%s.%d, e_vms_file_download Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1760. ASession->DisplayResponseError(AData);
  1761. return -2;
  1762. }
  1763. else
  1764. {
  1765. if (pInfo)
  1766. {
  1767. pInfo->AlreadyDownload = true;
  1768. pInfo->DownloadTm = Now();
  1769. }
  1770. #if OK_DEBUG
  1771. TINFO("e_vms_file_download : OK...");
  1772. #endif
  1773. }
  1774. // 폼이미지를 계속해서 다운로드 한다.
  1775. ASession->download_file_0x82();
  1776. return 0;
  1777. }
  1778. //---------------------------------------------------------------------------
  1779. /////////////////////////////////////////////////////////
  1780. REGISTER_HANDLER(e_vms_blank)
  1781. {
  1782. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1783. #if 0
  1784. if (nLength < 1) // ACK or NAK
  1785. {
  1786. TERROR("%s.%d, e_vms_blank Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1787. MERROR("%s.%d, e_vms_blank Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1788. return -1;
  1789. }
  1790. #endif
  1791. TDEBUG("e_vms_blank Length: %d", nLength);
  1792. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  1793. if (pRes->Result != VMS_ACK)
  1794. {
  1795. TERROR("%s.%d, e_vms_blank Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1796. MERROR("%s.%d, e_vms_blank Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1797. ASession->DisplayResponseError(AData);
  1798. return -2;
  1799. }
  1800. #if OK_DEBUG
  1801. else
  1802. {
  1803. TINFO("e_vms_blank : OK...");
  1804. }
  1805. #endif
  1806. if (ASession->CDSCtlr && ASession->CDSCtlr->FormDownload.IsDefault)
  1807. {
  1808. // 기본스케쥴인 경우에는 BLANK 명령을 내려보내지 말아야 한다.
  1809. //ASession->ReqDisplayDefaultForm();
  1810. //return download_form_schedule_complete();
  1811. }
  1812. // 폼 스케쥴 정보 다운로드 완료 메시지 처리
  1813. ASession->download_form_schedule_complete();
  1814. return 0;
  1815. }
  1816. //---------------------------------------------------------------------------
  1817. // TODO: 20241220 ==> FTP 다운로드 전송 메시지를 VMS에서 정상적으로 수신하였다는 메시지
  1818. /////////////////////////////////////////////////////////
  1819. REGISTER_HANDLER(e_vms_video_ftp_download_req)
  1820. {
  1821. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1822. TDEBUG("e_vms_video_ftp_download_req Length: %d", nLength);
  1823. VMS_RESULT *pRes = (VMS_RESULT*)&AData[sizeof(VMS_RES_HEAD)];
  1824. if (pRes->Result != VMS_ACK)
  1825. {
  1826. TERROR("%s.%d, e_vms_video_ftp_download_req Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1827. MERROR("%s.%d, e_vms_video_ftp_download_req Result Error. Error: 0x%02X.", ASession->IpAddress.c_str(), ASession->Socket, pRes->Error);
  1828. ASession->DisplayResponseError(AData);
  1829. return -2;
  1830. }
  1831. #if OK_DEBUG
  1832. else
  1833. {
  1834. TINFO("e_vms_video_ftp_download_req : OK...");
  1835. }
  1836. #endif
  1837. return 0;
  1838. }
  1839. //---------------------------------------------------------------------------
  1840. // TODO: 20241220 ==> FTP 다운로드 전송 메시지를 VMS에서 정상적으로 수신 후 FTP 까지 완료하였다는 메시지
  1841. /////////////////////////////////////////////////////////
  1842. REGISTER_HANDLER(e_vms_video_ftp_download_completed)
  1843. {
  1844. int nLength = APktLen-sizeof(VMS_RES_HEAD)-sizeof(VMS_TAIL);
  1845. if (nLength < (int)sizeof(VMS_FILE_FTP_DATA))
  1846. {
  1847. TERROR("%s.%d, e_vms_video_ftp_download_completed Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1848. MERROR("%s.%d, e_vms_video_ftp_download_completed Data Length error(%d). will be closed.", ASession->IpAddress.c_str(), ASession->Socket, nLength);
  1849. return -1;
  1850. }
  1851. VMS_FILE_FTP_DATA *pFtpFile = (VMS_FILE_FTP_DATA*)&AData[sizeof(VMS_RES_HEAD)];
  1852. AnsiString sFtpFileName = AnsiString(pFtpFile->FILE_NM);
  1853. TINFO("e_vms_video_ftp_download_completed: %s", sFtpFileName.c_str());
  1854. TCDSCtlr *AObj = ASession->CDSCtlr;
  1855. if (AObj)
  1856. {
  1857. TFtpFile *ftpFile = AObj->FFtpFileLists.Find(sFtpFileName);
  1858. if (ftpFile != NULL) {
  1859. ftpFile->IsFtpOk = true;
  1860. ftpFile->UpdateTm = Now();
  1861. }
  1862. // TODO: 동영상 파일을 다운로드 하도록 명령을 전송한다.
  1863. //if (AObj->RemainFtpFile())
  1864. {
  1865. //TINFO("ftp-file-download request to jobQ-2.");
  1866. RequestJob(ASession, eVmsFtpFileDownload, NULL, 0);
  1867. }
  1868. }
  1869. return 0;
  1870. }
  1871. //---------------------------------------------------------------------------
  1872. int TClientSession::ReqStauts()
  1873. {
  1874. TCDSCtlr *AObj = FCDSCtlr;
  1875. if (!AObj) return -1;
  1876. VMS_REQ_DATA req;
  1877. req.OpCode = (AObj->PROTOCOL_VER == 1) ? e_txt_status_req : e_vms_status;
  1878. req.Group = AObj->GROUP_NO;
  1879. req.Ctlr = AObj->CTLR_LOCAL_NO;
  1880. if (!SendPacket((char*)&req, sizeof(VMS_REQ_DATA)))
  1881. {
  1882. SERROR("+CLI ReqStauts send request faild: %s will be closed.", FIpAddress.c_str());
  1883. MERROR("+CLI ReqStauts send request faild: %s will be closed.", FIpAddress.c_str());
  1884. Disconnect();
  1885. return -1;
  1886. }
  1887. return 1;
  1888. }
  1889. //---------------------------------------------------------------------------
  1890. int TClientSession::ReqPowerModuleStatus()
  1891. {
  1892. TCDSCtlr *AObj = FCDSCtlr;
  1893. if (!AObj) return -1;
  1894. VMS_REQ_DATA req;
  1895. req.OpCode = e_vms_power_module_status;
  1896. req.Group = AObj->GROUP_NO;
  1897. req.Ctlr = AObj->CTLR_LOCAL_NO;
  1898. if (!SendPacket((char*)&req, sizeof(VMS_REQ_DATA)))
  1899. {
  1900. SERROR("+CLI ReqPowerModuleStatus send request faild: %s will be closed.", FIpAddress.c_str());
  1901. MERROR("+CLI ReqPowerModuleStatus send request faild: %s will be closed.", FIpAddress.c_str());
  1902. Disconnect();
  1903. return -1;
  1904. }
  1905. return 1;
  1906. }
  1907. //---------------------------------------------------------------------------
  1908. int TClientSession::ReqDisplayModuelStatus()
  1909. {
  1910. TCDSCtlr *AObj = FCDSCtlr;
  1911. if (!AObj) return -1;
  1912. VMS_REQ_DATA req;
  1913. req.OpCode = (AObj->PROTOCOL_VER == 1) ? e_txt_failed_elem_data_req : e_vms_display_module_status;
  1914. req.Group = AObj->GROUP_NO;
  1915. req.Ctlr = AObj->CTLR_LOCAL_NO;
  1916. if (!SendPacket((char*)&req, sizeof(VMS_REQ_DATA)))
  1917. {
  1918. SERROR("+CLI ReqDisplayModuelStatus send request faild: %s will be closed.", FIpAddress.c_str());
  1919. MERROR("+CLI ReqDisplayModuelStatus send request faild: %s will be closed.", FIpAddress.c_str());
  1920. Disconnect();
  1921. return -1;
  1922. }
  1923. return 1;
  1924. }
  1925. //---------------------------------------------------------------------------
  1926. int TClientSession::ReqParameter()
  1927. {
  1928. TCDSCtlr *AObj = FCDSCtlr;
  1929. if (!AObj) return -1;
  1930. VMS_REQ_DATA req;
  1931. #if 0
  1932. // 설정온도 요청하면 모듈상태정보가 응답으로 올라온다
  1933. // 프로토콜의 OpCode도 동일하다.
  1934. req.OpCode = (AObj->PROTOCOL_VER == 1) ? e_txt_pan_hetr_temp_req : e_vms_parameter;
  1935. #else
  1936. req.OpCode = e_vms_parameter;
  1937. #endif
  1938. req.Group = AObj->GROUP_NO;
  1939. req.Ctlr = AObj->CTLR_LOCAL_NO;
  1940. if (!SendPacket((char*)&req, sizeof(VMS_REQ_DATA)))
  1941. {
  1942. SERROR("+CLI ReqParameter send request faild: %s will be closed.", FIpAddress.c_str());
  1943. MERROR("+CLI ReqParameter send request faild: %s will be closed.", FIpAddress.c_str());
  1944. Disconnect();
  1945. return -1;
  1946. }
  1947. return 1;
  1948. }
  1949. //---------------------------------------------------------------------------
  1950. int TClientSession::ReqPixelImage(char *ACmd)
  1951. {
  1952. TCDSCtlr *AObj = FCDSCtlr;
  1953. if (!AObj) return -1;
  1954. VMS_REQ_INFO_DATA req;
  1955. req.OpCode = e_vms_pixel_image;
  1956. req.Group = AObj->GROUP_NO;
  1957. req.Ctlr = AObj->CTLR_LOCAL_NO;
  1958. req.Data[0] = ACmd[0];
  1959. req.Length = 1;
  1960. if (!SendPacket((char*)&req, sizeof(VMS_REQ_DATA)+1))
  1961. {
  1962. SERROR("+CLI ReqPixelImage send request faild: %s will be closed.", FIpAddress.c_str());
  1963. MERROR("+CLI ReqPixelImage send request faild: %s will be closed.", FIpAddress.c_str());
  1964. Disconnect();
  1965. return -1;
  1966. }
  1967. return 1;
  1968. }
  1969. //---------------------------------------------------------------------------
  1970. int TClientSession::ReqUploadCurrentForm()
  1971. {
  1972. TCDSCtlr *AObj = FCDSCtlr;
  1973. if (!AObj) return -1;
  1974. VMS_REQ_DATA req;
  1975. req.OpCode = e_vms_current_display_form;
  1976. req.Group = AObj->GROUP_NO;
  1977. req.Ctlr = AObj->CTLR_LOCAL_NO;
  1978. if (!SendPacket((char*)&req, sizeof(VMS_REQ_DATA)))
  1979. {
  1980. SERROR("+CLI ReqUploadCurrentForm send request faild: %s will be closed.", FIpAddress.c_str());
  1981. MERROR("+CLI ReqUploadCurrentForm send request faild: %s will be closed.", FIpAddress.c_str());
  1982. Disconnect();
  1983. return -1;
  1984. }
  1985. return 1;
  1986. }
  1987. //---------------------------------------------------------------------------
  1988. int TClientSession::ReqDisplayDefaultForm()
  1989. {
  1990. TCDSCtlr *AObj = FCDSCtlr;
  1991. if (!AObj) return -1;
  1992. VMS_REQ_DATA req;
  1993. req.OpCode = e_vms_display_default_form;
  1994. req.Group = AObj->GROUP_NO;
  1995. req.Ctlr = AObj->CTLR_LOCAL_NO;
  1996. if (!SendPacket((char*)&req, sizeof(VMS_REQ_DATA)))
  1997. {
  1998. SERROR("+CLI ReqDisplayDefaultForm send request faild: %s will be closed.", FIpAddress.c_str());
  1999. MERROR("+CLI ReqDisplayDefaultForm send request faild: %s will be closed.", FIpAddress.c_str());
  2000. Disconnect();
  2001. return -1;
  2002. }
  2003. return 1;
  2004. }
  2005. //---------------------------------------------------------------------------
  2006. int TClientSession::ReqUploadScheduleForm()
  2007. {
  2008. TCDSCtlr *AObj = FCDSCtlr;
  2009. if (!AObj) return -1;
  2010. VMS_REQ_DATA req;
  2011. req.OpCode = e_vms_upload_schedule_form;
  2012. req.Group = AObj->GROUP_NO;
  2013. req.Ctlr = AObj->CTLR_LOCAL_NO;
  2014. if (!SendPacket((char*)&req, sizeof(VMS_REQ_DATA)))
  2015. {
  2016. SERROR("+CLI ReqUploadScheduleForm send request faild: %s will be closed.", FIpAddress.c_str());
  2017. MERROR("+CLI ReqUploadScheduleForm send request faild: %s will be closed.", FIpAddress.c_str());
  2018. Disconnect();
  2019. return -1;
  2020. }
  2021. return 1;
  2022. }
  2023. //---------------------------------------------------------------------------
  2024. int TClientSession::ReqDisplayFormId(char *ACmd)
  2025. {
  2026. TCDSCtlr *AObj = FCDSCtlr;
  2027. if (!AObj) return -1;
  2028. VMS_REQ_INFO_DATA req;
  2029. req.OpCode = e_vms_display_form_id;
  2030. req.Group = AObj->GROUP_NO;
  2031. req.Ctlr = AObj->CTLR_LOCAL_NO;
  2032. req.Data[0] = 0;//ACmd[0];
  2033. req.Data[1] = 0;//ACmd[2];
  2034. req.Length = 2;
  2035. if (!SendPacket((char*)&req, sizeof(VMS_REQ_DATA)+2))
  2036. {
  2037. SERROR("+CLI ReqDisplayFormId send request faild: %s will be closed.", FIpAddress.c_str());
  2038. MERROR("+CLI ReqDisplayFormId send request faild: %s will be closed.", FIpAddress.c_str());
  2039. Disconnect();
  2040. return -1;
  2041. }
  2042. return 1;
  2043. }
  2044. //---------------------------------------------------------------------------
  2045. int TClientSession::ReqStatusControl(char *ACmd, int ALen)
  2046. {
  2047. TCDSCtlr *AObj = FCDSCtlr;
  2048. if (!AObj) return -1;
  2049. char *pSendData = NULL;
  2050. int nSendByte = 0;
  2051. if (AObj->PROTOCOL_VER == 1)
  2052. {
  2053. VMS_REQ_INFO_DATA req;
  2054. req.Group = AObj->GROUP_NO;
  2055. req.Ctlr = AObj->CTLR_LOCAL_NO;
  2056. if (ACmd[0] == 0x01)
  2057. {
  2058. //SignBoard On/Off
  2059. req.OpCode = e_txt_signboard_control;
  2060. req.Length = 1;
  2061. req.Data[0] = ACmd[1]; //Power Off=0, Power On = 1
  2062. pSendData = (char*)&req;
  2063. nSendByte = sizeof(VMS_REQ_DATA)+req.Length;
  2064. }
  2065. else
  2066. if (ACmd[0] == 0x02)
  2067. {
  2068. //Initialize(Reset)
  2069. req.OpCode = e_txt_initialize;
  2070. req.Length = 0;
  2071. pSendData = (char*)&req;
  2072. nSendByte = sizeof(VMS_REQ_DATA)+req.Length;
  2073. }
  2074. else
  2075. if (ACmd[0] == 0x06)
  2076. {
  2077. //Set luminance Level
  2078. req.OpCode = e_txt_set_luminance_level;
  2079. req.Length = 1;
  2080. req.Data[0] = ACmd[1];
  2081. switch(ACmd[1]) //도형식과 비교해서 값이 다름
  2082. {
  2083. case 0x00: //주간
  2084. req.Data[0] = 1;
  2085. break;
  2086. case 0x01: //야간
  2087. req.Data[0] = 2;
  2088. break;
  2089. case 0x02: //자동
  2090. req.Data[0] = 0;
  2091. break;
  2092. }
  2093. pSendData = (char*)&req;
  2094. nSendByte = sizeof(VMS_REQ_DATA)+req.Length;
  2095. }
  2096. }
  2097. else
  2098. {
  2099. VMS_REQ_INFO_DATA req;
  2100. req.OpCode = e_vms_status_control;
  2101. req.Group = AObj->GROUP_NO;
  2102. req.Ctlr = AObj->CTLR_LOCAL_NO;
  2103. memcpy(req.Data, ACmd, ALen);
  2104. req.Length = ALen;
  2105. pSendData = (char*)&req;
  2106. nSendByte = sizeof(VMS_REQ_DATA)+ALen;
  2107. }
  2108. if (pSendData == NULL || nSendByte == 0)
  2109. {
  2110. return 1;
  2111. }
  2112. if (!SendPacket(pSendData, nSendByte))
  2113. {
  2114. SERROR("+CLI ReqStatusControl send request faild: %s will be closed.", FIpAddress.c_str());
  2115. MERROR("+CLI ReqStatusControl send request faild: %s will be closed.", FIpAddress.c_str());
  2116. Disconnect();
  2117. return -1;
  2118. }
  2119. return 1;
  2120. }
  2121. //---------------------------------------------------------------------------
  2122. int TClientSession::download_form_schedule_complete()
  2123. {
  2124. // VMS 메시지 다운로드 완료
  2125. TCDSCtlr *AObj = FCDSCtlr;
  2126. if (AObj)
  2127. {
  2128. if (AObj->CTRLMODE->Schedule)
  2129. {
  2130. VMS_PROVIDE_RESULE ProvideSave;
  2131. memset(&ProvideSave, 0x00, sizeof(ProvideSave));
  2132. ProvideSave.Type = provide_form;
  2133. ProvideSave.Count = 1;
  2134. ProvideSave.pObj[0] = (void*)AObj;
  2135. AObj->CTRLMODE->Enable = object_disable;
  2136. AObj->CTRLMODE->SvcDate = Now().FormatString("yyyymmddhhnnss");
  2137. AObj->CTRLMODE->SaveFlag = true;
  2138. AObj->CTRLMODE->Result = true;
  2139. APP_PostDbThreadWriteMessage(dbm_provide_result, sizeof(ProvideSave), &ProvideSave);
  2140. }
  2141. }
  2142. return 0;
  2143. }
  2144. //---------------------------------------------------------------------------
  2145. int TClientSession::download_form_schedule(bool ASchedule/*=true*/)
  2146. {
  2147. TCDSCtlr *AObj = FCDSCtlr;
  2148. if (!AObj) return -1;
  2149. if (ASchedule)
  2150. {
  2151. LDEBUG("Download Form Schedule by schedule...");
  2152. }
  2153. else
  2154. {
  2155. LDEBUG("Download Form Schedule by user control...");
  2156. }
  2157. AObj->CTRLMODE->Schedule = ASchedule; // 스케쥴 모드인 경우 디비에 저장한다.
  2158. //다운로드 정보만 초기화 한다.
  2159. memset((char*)&AObj->FormDownload, 0x00, sizeof(VMS_DOWNLOAD_DATA));
  2160. AObj->FTxtOpCode == 0x00;
  2161. int nForms = 0;
  2162. int nFormCnt = 0;
  2163. AObj->pForms->Lock();
  2164. try
  2165. {
  2166. nFormCnt = AObj->pForms->Count();
  2167. if (nFormCnt == 0)
  2168. {
  2169. return 0;
  2170. }
  2171. for (int ii = 0; ii < nFormCnt; ii++)
  2172. {
  2173. TVmsForm *pForm = AObj->pForms->GetItem(ii);
  2174. if (!pForm->Success)
  2175. {
  2176. continue;
  2177. }
  2178. // TODO: 20241220
  2179. //if (pForm->fileType == P_FILE_TYPE_VIDEO || pForm->fileType == P_FILE_TYPE_STREAM)
  2180. if (pForm->fileType == P_FILE_TYPE_STREAM)
  2181. {
  2182. continue;
  2183. }
  2184. if (AObj->PROTOCOL_VER == 1 && pForm->fileType == P_FILE_TYPE_VIDEO)
  2185. {
  2186. // 문자식이면서 동영상 폼이면 표출하지 못함
  2187. continue;
  2188. }
  2189. if (!pForm->pStream || pForm->pStream->Size == 0)
  2190. {
  2191. continue;
  2192. }
  2193. AObj->FormDownload.Info[nForms].fileType = pForm->fileType;
  2194. AObj->FormDownload.Info[nForms].STRM_ADDR = pForm->STRM_ADDR;
  2195. AObj->FormDownload.Info[nForms].VMS_FORM_ID = pForm->VMS_FORM_ID;
  2196. AObj->FormDownload.Info[nForms].IsDownload = true;
  2197. AObj->FormDownload.Info[nForms].FormIdx = ii; // 리스트상의 순서
  2198. if (AObj->PROTOCOL_VER == 1)
  2199. {
  2200. //문자식 프로토콜 적용
  2201. //AObj->FormDownload.Info[nForms].BitmapId = (pForm->VMS_FORM_ID.ToIntDef(0) % 1000) + TEXT_BASE_FORMID; // 리스트상의 순서
  2202. AObj->FormDownload.Info[nForms].BitmapId = nForms + TEXT_BASE_FORMID; // 리스트상의 순서
  2203. AObj->FormDownload.Info[nForms].FormNo = AObj->FormDownload.Info[nForms].BitmapId; // 실재 다운로드되는 순서
  2204. }
  2205. else
  2206. {
  2207. //도형식 프로토콜 적용
  2208. //AObj->FormDownload.Info[nForms].BitmapId = (pForm->VMS_FORM_ID.ToIntDef(0) % 1000) + 1000; // 리스트상의 순서
  2209. AObj->FormDownload.Info[nForms].BitmapId = nForms + 1000; // 리스트상의 순서
  2210. AObj->FormDownload.Info[nForms].FormNo = PICTURE_BASE_FORMID+nForms; // 실재 다운로드되는 순서
  2211. }
  2212. AObj->FormDownload.Info[nForms].DispSec = (BYTE)pForm->DSPL_HH;
  2213. TDownloadForm *pInfo = AObj->FDownloadLists.Find(pForm->VMS_FORM_ID);
  2214. TCDSForm *pCDSForm = CDSFormManager->FLists.Find(pForm->VMS_FORM_ID);
  2215. if (pCDSForm)
  2216. {
  2217. if (pCDSForm->VMS_FORM_TYPE_CD == eFormTp_hongbo)
  2218. {
  2219. if (AObj->PROTOCOL_VER == 1)
  2220. {
  2221. //문자식 프로토콜 적용
  2222. AObj->FormDownload.Info[nForms].BitmapId = (pForm->VMS_FORM_ID.ToIntDef(0) % 1000) + TEXT_BASE_FORMID; // 리스트상의 순서
  2223. AObj->FormDownload.Info[nForms].FormNo = AObj->FormDownload.Info[nForms].BitmapId; // 실재 다운로드되는 순서
  2224. }
  2225. else
  2226. {
  2227. //도형식 프로토콜 적용
  2228. AObj->FormDownload.Info[nForms].BitmapId = (pForm->VMS_FORM_ID.ToIntDef(0) % 1000) + 1000; // 리스트상의 순서
  2229. }
  2230. }
  2231. //홍보폼이면서 신규폼이 아니면서 이전 다운로드 목록이 존재하는 경우에 다운로드 여부를 체크한다.
  2232. if (pCDSForm->VMS_FORM_TYPE_CD == eFormTp_hongbo && pCDSForm->IsNewForm == false && pInfo)
  2233. {
  2234. if (pInfo->AlreadyDownload)
  2235. {
  2236. // 이미 이전에 다운로드를 했기때문에 이번에는 제어기로 다운로드를 하지 않는다.
  2237. AObj->FormDownload.Info[nForms].IsDownload = false;
  2238. }
  2239. }
  2240. //이전에 다운로드한 정보가 존재하면
  2241. if (pInfo)
  2242. {
  2243. if (pInfo->UPDT_DT != pCDSForm->UPDT_DT)
  2244. {
  2245. // 업데이트시각이 다르기때문에 신규폼으로 판단한다.
  2246. pInfo->AlreadyDownload = false;
  2247. AObj->FormDownload.Info[nForms].IsDownload = true;
  2248. pInfo->UPDT_DT = pCDSForm->UPDT_DT;
  2249. }
  2250. }
  2251. }
  2252. if (!pInfo && pCDSForm)
  2253. {
  2254. pInfo = AObj->FDownloadLists.Find(pForm->VMS_FORM_ID);
  2255. if (!pInfo)
  2256. {
  2257. pInfo = new TDownloadForm();
  2258. if (pInfo)
  2259. {
  2260. //신규로추가
  2261. pInfo->VMS_FORM_ID = pForm->VMS_FORM_ID;
  2262. AObj->FDownloadLists.Push(pInfo->VMS_FORM_ID, pInfo);
  2263. }
  2264. }
  2265. if (pInfo)
  2266. {
  2267. //다운로드정보설정
  2268. pInfo->AlreadyDownload = false;
  2269. pInfo->UPDT_DT = pCDSForm->UPDT_DT;
  2270. }
  2271. }
  2272. nForms++;
  2273. if (nForms >= MAX_VMS_SCENARIO_FORM)
  2274. {
  2275. // 최대폼까지 다운로드
  2276. break;
  2277. }
  2278. }
  2279. }
  2280. __finally
  2281. {
  2282. AObj->pForms->UnLock();
  2283. }
  2284. for (int jj = 0; jj < nFormCnt; jj++)
  2285. {
  2286. LDEBUG("Form schedule(%2d), VMS_FORM_ID: %s, FormIdx: %d, FormId: %d, BitmapId: %d, IsDownload: %s",
  2287. jj,
  2288. AObj->FormDownload.Info[jj].VMS_FORM_ID.c_str(),
  2289. AObj->FormDownload.Info[jj].FormIdx,
  2290. AObj->FormDownload.Info[jj].FormNo,
  2291. AObj->FormDownload.Info[jj].BitmapId,
  2292. AObj->FormDownload.Info[jj].IsDownload ? "true" : "false");
  2293. }
  2294. if (nForms <= 0)
  2295. {
  2296. return 0;
  2297. }
  2298. AObj->FormDownload.MaxSchedule = nForms;
  2299. AObj->FormDownload.DownloadCnt = 0;
  2300. if (AObj->PROTOCOL_VER == 1)
  2301. {
  2302. //문자식 프로토콜 적용
  2303. AObj->FormDownload.IsDefault = false;
  2304. download_lib_form_0x0A();
  2305. }
  2306. else
  2307. {
  2308. //도형식 프로토콜 적용
  2309. if (AObj->OPER_MODE == "B")
  2310. {
  2311. // 기본모드인 경우
  2312. //e_vms_download_form = 0x9A,// Download Form 송신 Form download 센터 → VMS
  2313. //e_vms_file_download = 0x82,// 데이터 다운로드 송신 INI, CFG , Bitmap , Data파일송신 센터 → VMS
  2314. //e_vms_download_schedule_form = 0x96,// Display Schedule Form 송신 계획된 Form 표출 요구 센터 → VMS
  2315. //e_vms_blank = 0x9E,// Blank 송신 schedule 표출 센터 → VMS
  2316. AObj->FormDownload.IsDefault = true;
  2317. download_default_form_0x9A(); // Download Form (기본폼은 하나의 폼에 여러폼을 다운로드한다.)
  2318. }
  2319. else
  2320. {
  2321. // 스케쥴 모드인 경우(A:자동, F:고정)
  2322. //e_vms_download_form = 0x9A,// Download Form 송신 Form download 센터 → VMS
  2323. //e_vms_file_download = 0x82,// 데이터 다운로드 송신 INI, CFG , Bitmap , Data파일송신 센터 → VMS
  2324. //e_vms_download_schedule_form = 0x96,// Display Schedule Form 송신 계획된 Form 표출 요구 센터 → VMS
  2325. //e_vms_blank = 0x9E,// Blank 송신 schedule 표출 센터 → VMS
  2326. AObj->FormDownload.IsDefault = false;
  2327. download_form_0x9A(); // Download Form (기본폼은 하나의 폼에 여러폼을 다운로드한다.)
  2328. }
  2329. }
  2330. return 1;
  2331. }
  2332. //---------------------------------------------------------------------------
  2333. // TODO: 20241220
  2334. int TClientSession::download_ftp_file()
  2335. {
  2336. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  2337. TCDSCtlr *AObj = FCDSCtlr;
  2338. if (!AObj) return -1;
  2339. //if (!AObj->RemainFtpFile()) return -2;
  2340. TFtpFile *pFtpFile = NULL;
  2341. FOR_STL(TFtpFile*, pInfo, AObj->FFtpFileLists)
  2342. {
  2343. if (!pInfo->IsFtpOk) {
  2344. pFtpFile = pInfo;
  2345. LINFO("download_ftp_file_0xA1: %s, try download.", pFtpFile->FtpFileName.c_str());
  2346. break;
  2347. }
  2348. else {
  2349. LINFO("download_ftp_file_0xA1: %s, already download.", pInfo->FtpFileName.c_str());
  2350. }
  2351. }
  2352. if (pFtpFile == NULL) {
  2353. LINFO("download_ftp_file_0xA1: ftp download completed.");
  2354. return -3;
  2355. }
  2356. BYTE *msgPtr;
  2357. VMS_HEAD *pHead;
  2358. VMS_FILE_FTP_DATA *pData;
  2359. WORD crc;
  2360. int nPktSize;
  2361. msgPtr = (BYTE*)pMsg->Buff;
  2362. pHead = (VMS_HEAD*)&msgPtr[0];
  2363. pData = (VMS_FILE_FTP_DATA*)&msgPtr[sizeof(VMS_HEAD)];
  2364. memset((char*)pData, 0x00, sizeof(VMS_FILE_FTP_DATA));
  2365. pHead->Dle = VMS_DLE;
  2366. pHead->Stx = VMS_STX;
  2367. pHead->Group = AObj->GROUP_NO;
  2368. pHead->Ctlr = AObj->CTLR_LOCAL_NO;
  2369. pHead->OpCode = e_vms_video_ftp_download_req;
  2370. pHead->Curr = 1;
  2371. pHead->Total = 1;
  2372. pHead->Length = 0;
  2373. sprintf(pData->FILE_NM, "%s", pFtpFile->FtpFileName.c_str());
  2374. LINFO("download_ftp_file_0xA1: %s, %s", pFtpFile->FtpFileName.c_str(), pData->FILE_NM);
  2375. pHead->Length = sizeof(VMS_FILE_FTP_DATA);
  2376. nPktSize = sizeof(VMS_HEAD)+pHead->Length-2; //DLE/STX
  2377. crc = GETCRC16((char*)&pHead->Group, nPktSize);
  2378. msgPtr[sizeof(VMS_HEAD)+pHead->Length+0] = VMS_DLE;
  2379. msgPtr[sizeof(VMS_HEAD)+pHead->Length+1] = VMS_ETX;
  2380. msgPtr[sizeof(VMS_HEAD)+pHead->Length+2] = HIBYTE(crc);
  2381. msgPtr[sizeof(VMS_HEAD)+pHead->Length+3] = LOBYTE(crc);
  2382. SendPacketDLE((char*)msgPtr, nPktSize+6, AObj->IsDle);
  2383. return 1;
  2384. }
  2385. //---------------------------------------------------------------------------
  2386. int TClientSession::download_default_form_0x9A()
  2387. {
  2388. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  2389. TCDSCtlr *AObj = FCDSCtlr;
  2390. if (!AObj) return -1;
  2391. BYTE *msgPtr;
  2392. // 파일다운로드
  2393. VMS_HEAD *pHead;
  2394. VMS_FILE_DATA *pFile;
  2395. // 폼다운로드
  2396. VMS_FORM_HEAD *pForm;
  2397. VMS_FORM_BMPID_DATA *pBmpIdData;
  2398. WORD crc;
  2399. int nPktSize;
  2400. int nPktIdx;
  2401. nPktIdx = sizeof(VMS_HEAD)+sizeof(VMS_FORM_HEAD);
  2402. msgPtr = (BYTE*)pMsg->Buff;
  2403. pHead = (VMS_HEAD*)&msgPtr[0];
  2404. pForm = (VMS_FORM_HEAD*)&msgPtr[sizeof(VMS_HEAD)];
  2405. pBmpIdData = (VMS_FORM_BMPID_DATA*)&msgPtr[nPktIdx];
  2406. pHead->Dle = VMS_DLE;
  2407. pHead->Stx = VMS_STX;
  2408. pHead->Group = AObj->GROUP_NO;
  2409. pHead->Ctlr = AObj->CTLR_LOCAL_NO;
  2410. pHead->OpCode = e_vms_download_form;
  2411. pHead->Curr = 1;
  2412. pHead->Total = 1;
  2413. pHead->Length = 0;
  2414. int nFormId = DEFAULT_FORMID;
  2415. int nFormCnt = AObj->FormDownload.MaxSchedule; // 폼정보는 하나만 내려보내야 한다. 제어기에서 수용하지 못함
  2416. if (nFormCnt > MAX_VMS_SCENARIO_FORM) {
  2417. nFormCnt = MAX_VMS_SCENARIO_FORM;
  2418. }
  2419. LDEBUG("download_default_form_0x9A: FormId: %d, FormCnt: %d", nFormId, nFormCnt);
  2420. pForm->FORM_ID = htons(nFormId);
  2421. pForm->FORM_CNT = htons(nFormCnt);
  2422. pHead->Length = sizeof(VMS_FORM_HEAD)+(sizeof(VMS_FORM_BMPID_INFO)*nFormCnt);
  2423. for (int ii = 0; ii < nFormCnt; ii++)
  2424. {
  2425. pBmpIdData = (VMS_FORM_BMPID_DATA*)&msgPtr[nPktIdx];
  2426. memset(pBmpIdData, 0x00, sizeof(VMS_FORM_BMPID_DATA));
  2427. pBmpIdData->INFO.data.FORM_SEQ = htons(ii); // 폼 표출 일련번호, 2Byte
  2428. pBmpIdData->INFO.data.DISPLAY_TIME = 4; // 폼의 표출시간을 지정, 1Byte( 0x00 이면 계속 표출 ) ==> 제어기에서 사용안함
  2429. pBmpIdData->INFO.data.DISPLAY_TYPE = e_static_normal; // 폼의 표출유형을 지정, 1Byte
  2430. pBmpIdData->INFO.data.BG_RGB = e_bg_black; // 폼의 배경색을 지정, 1Byte
  2431. pBmpIdData->INFO.data.OBJ_CNT = 1; // 표출할 오브젝트 전체 수, 1Byte
  2432. pBmpIdData->INFO.obj.OBJ_TYPE = e_obj_bitmapid; // 오브젝트 종류
  2433. pBmpIdData->INFO.obj.OBJ_SIZE = htons(sizeof(VMS_OBJ_BITMAPID)); // 오브젝트 데이터 크기
  2434. pBmpIdData->INFO.obj.FLASH = 0x00; // 점멸여부, 1Byte(0x00 : 고정, 0x01 : 점멸)
  2435. pBmpIdData->INFO.obj.X = htons(0); // 좌표 X
  2436. pBmpIdData->INFO.obj.Y = htons(0); // 좌표 Y
  2437. pBmpIdData->INFO.obj.TEXT_BG_RGB = e_bg_black; // 문자열 배경색을 지정
  2438. pBmpIdData->INFO.bmpid.WIDTH = htons(AObj->WIDTH); // 비트맵 표시 Width, 2 Byte, 0 ~ 1023 : 표출 비트맵 Width
  2439. pBmpIdData->INFO.bmpid.HEIGHT = htons(AObj->HEIGHT); // 비트맵 표시 Heitht, 2 Byte, 0 ~ 1023 : 표출 비트맵 Width
  2440. pBmpIdData->INFO.bmpid.IMG_TYPE = e_img_bitmap; // e_img_type
  2441. pBmpIdData->INFO.bmpid.BITMAP_ID = htons(AObj->FormDownload.Info[ii].BitmapId); // 표출할 비트맵 ID, 2 Byte, 0~ 9999 : 표출할 비트맵 ID
  2442. LDEBUG("download_default_form_0x9A: FormSeq: %d, FormId: %d", ii, AObj->FormDownload.Info[ii].BitmapId);
  2443. nPktIdx += sizeof(VMS_FORM_BMPID_DATA);
  2444. }
  2445. nPktSize = sizeof(VMS_HEAD)+pHead->Length-2; //DLE/STX
  2446. crc = GETCRC16((char*)&pHead->Group, nPktSize);
  2447. msgPtr[sizeof(VMS_HEAD)+pHead->Length+0] = VMS_DLE;
  2448. msgPtr[sizeof(VMS_HEAD)+pHead->Length+1] = VMS_ETX;
  2449. msgPtr[sizeof(VMS_HEAD)+pHead->Length+2] = HIBYTE(crc);
  2450. msgPtr[sizeof(VMS_HEAD)+pHead->Length+3] = LOBYTE(crc);
  2451. SendPacketDLE((char*)msgPtr, nPktSize+6, AObj->IsDle);
  2452. return 1;
  2453. }
  2454. //---------------------------------------------------------------------------
  2455. int TClientSession::download_form_0x9A()
  2456. {
  2457. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  2458. TCDSCtlr *AObj = FCDSCtlr;
  2459. if (!AObj) return -1;
  2460. if (AObj->FormDownload.DownloadCnt && AObj->FormDownload.MaxSchedule &&
  2461. AObj->FormDownload.DownloadCnt >= AObj->FormDownload.MaxSchedule)
  2462. {
  2463. // 폼정보를 모두 다운로드 했기때문에
  2464. // 폼파일을 다운로드 해야 한다.
  2465. AObj->FormDownload.DownloadCnt = 0; // 폼이미지파일을 다운로드해야 하기때문에 다운로드 인덱스를 다시 0으로 리셋
  2466. download_file_0x82();
  2467. return 1;
  2468. }
  2469. BYTE *msgPtr;
  2470. // 파일다운로드
  2471. VMS_HEAD *pHead;
  2472. VMS_FILE_DATA *pFile;
  2473. // 폼다운로드
  2474. VMS_FORM_HEAD *pForm;
  2475. VMS_FORM_BMPID_DATA *pBmpIdData;
  2476. VMS_FORM_VIDEO_DATA *pVideoData;
  2477. WORD crc;
  2478. int nPktSize;
  2479. int nPktIdx;
  2480. nPktIdx = sizeof(VMS_HEAD)+sizeof(VMS_FORM_HEAD);
  2481. msgPtr = (BYTE*)pMsg->Buff;
  2482. pHead = (VMS_HEAD*)&msgPtr[0];
  2483. pForm = (VMS_FORM_HEAD*)&msgPtr[sizeof(VMS_HEAD)];
  2484. pBmpIdData = (VMS_FORM_BMPID_DATA*)&msgPtr[nPktIdx];
  2485. pVideoData = (VMS_FORM_VIDEO_DATA*)&msgPtr[nPktIdx];
  2486. pHead->Dle = VMS_DLE;
  2487. pHead->Stx = VMS_STX;
  2488. pHead->Group = AObj->GROUP_NO;
  2489. pHead->Ctlr = AObj->CTLR_LOCAL_NO;
  2490. pHead->OpCode = e_vms_download_form;
  2491. pHead->Curr = 1;
  2492. pHead->Total = 1;
  2493. pHead->Length = 0;
  2494. // 폼아이디는 제어기가 최초에 접속했을때 한번만 내려보내기 때문에
  2495. // 폼아이디를 여기서 설정해 주어야 한다.
  2496. BYTE fileType = AObj->FormDownload.Info[AObj->FormDownload.DownloadCnt].fileType;
  2497. AnsiString STRM_ADDR = AObj->FormDownload.Info[AObj->FormDownload.DownloadCnt].STRM_ADDR;
  2498. int nFormId = AObj->FormDownload.Info[AObj->FormDownload.DownloadCnt].FormNo;
  2499. int nBitmapId = AObj->FormDownload.Info[AObj->FormDownload.DownloadCnt].BitmapId;
  2500. int nFormCnt = 1; // 폼정보는 하나만 내려보내야 한다. 제어기에서 수용하지 못함
  2501. pForm->FORM_ID = htons(nFormId);
  2502. pForm->FORM_CNT = htons(nFormCnt);
  2503. // TODO: 20241220
  2504. if (fileType == P_FILE_TYPE_VIDEO) {
  2505. // 동영상 표출
  2506. //LDEBUG("download_form_0x9A: DownloadCnt: %d, FormId: %d, VideoId: %s", AObj->FormDownload.DownloadCnt, nFormId, STRM_ADDR.c_str());
  2507. pHead->Length = sizeof(VMS_FORM_HEAD)+(sizeof(VMS_FORM_VIDEO_INFO)*nFormCnt);
  2508. }
  2509. else {
  2510. //LDEBUG("download_form_0x9A: DownloadCnt: %d, FormId: %d, BitmapId: %d", AObj->FormDownload.DownloadCnt, nFormId, nBitmapId);
  2511. pHead->Length = sizeof(VMS_FORM_HEAD)+(sizeof(VMS_FORM_BMPID_INFO)*nFormCnt);
  2512. }
  2513. //for (int ii = 0; ii < nFormCnt; ii++) {
  2514. if (fileType == P_FILE_TYPE_VIDEO) {
  2515. // 동영상 표출
  2516. pVideoData = (VMS_FORM_VIDEO_DATA*)&msgPtr[nPktIdx];
  2517. memset(pVideoData, 0x00, sizeof(VMS_FORM_VIDEO_DATA));
  2518. pVideoData->INFO.data.FORM_SEQ = htons(nFormId); // 폼 표출 일련번호, 2Byte
  2519. pVideoData->INFO.data.DISPLAY_TIME = 1; // 폼의 표출시간을 지정, 1Byte( 0x00 이면 계속 표출 ) ==> 제어기에서 사용안함
  2520. pVideoData->INFO.data.DISPLAY_TYPE = e_static_normal; // 폼의 표출유형을 지정, 1Byte
  2521. pVideoData->INFO.data.BG_RGB = e_bg_black; // 폼의 배경색을 지정, 1Byte
  2522. pVideoData->INFO.data.OBJ_CNT = 1; // 표출할 오브젝트 전체 수, 1Byte
  2523. pVideoData->INFO.obj.OBJ_TYPE = e_obj_video; // 오브젝트 종류
  2524. pVideoData->INFO.obj.OBJ_SIZE = htons(sizeof(VMS_OBJ_VIDEO)); // 오브젝트 데이터 크기
  2525. pVideoData->INFO.obj.FLASH = 0x00; // 점멸여부, 1Byte(0x00 : 고정, 0x01 : 점멸)
  2526. pVideoData->INFO.obj.X = htons(0); // 좌표 X
  2527. pVideoData->INFO.obj.Y = htons(0); // 좌표 Y
  2528. pVideoData->INFO.obj.TEXT_BG_RGB = e_bg_black; // 문자열 배경색을 지정
  2529. pVideoData->INFO.video.WIDTH = htons(AObj->WIDTH); // 비트맵 표시 Width, 2 Byte, 0 ~ 1023 : 표출 비트맵 Width
  2530. pVideoData->INFO.video.HEIGHT = htons(AObj->HEIGHT); // 비트맵 표시 Heitht, 2 Byte, 0 ~ 1023 : 표출 비트맵 Width
  2531. pVideoData->INFO.video.ETC = 0x00; // 기타
  2532. sprintf(pVideoData->INFO.video.FILE_NM, "%s", STRM_ADDR.c_str()); // 동영상 파일 이름
  2533. nPktIdx += sizeof(VMS_FORM_VIDEO_DATA);
  2534. LINFO("download_form_0x9A: DownloadCnt: %d, FormId: %d, VideoId: %s", AObj->FormDownload.DownloadCnt, nFormId, pVideoData->INFO.video.FILE_NM);
  2535. }
  2536. else {
  2537. pBmpIdData = (VMS_FORM_BMPID_DATA*)&msgPtr[nPktIdx];
  2538. memset(pBmpIdData, 0x00, sizeof(VMS_FORM_BMPID_DATA));
  2539. pBmpIdData->INFO.data.FORM_SEQ = htons(nFormId); // 폼 표출 일련번호, 2Byte
  2540. pBmpIdData->INFO.data.DISPLAY_TIME = 1; // 폼의 표출시간을 지정, 1Byte( 0x00 이면 계속 표출 ) ==> 제어기에서 사용안함
  2541. pBmpIdData->INFO.data.DISPLAY_TYPE = e_static_normal; // 폼의 표출유형을 지정, 1Byte
  2542. pBmpIdData->INFO.data.BG_RGB = e_bg_black; // 폼의 배경색을 지정, 1Byte
  2543. pBmpIdData->INFO.data.OBJ_CNT = 1; // 표출할 오브젝트 전체 수, 1Byte
  2544. pBmpIdData->INFO.obj.OBJ_TYPE = e_obj_bitmapid; // 오브젝트 종류
  2545. pBmpIdData->INFO.obj.OBJ_SIZE = htons(sizeof(VMS_OBJ_BITMAPID)); // 오브젝트 데이터 크기
  2546. pBmpIdData->INFO.obj.FLASH = 0x00; // 점멸여부, 1Byte(0x00 : 고정, 0x01 : 점멸)
  2547. pBmpIdData->INFO.obj.X = htons(0); // 좌표 X
  2548. pBmpIdData->INFO.obj.Y = htons(0); // 좌표 Y
  2549. pBmpIdData->INFO.obj.TEXT_BG_RGB = e_bg_black; // 문자열 배경색을 지정
  2550. pBmpIdData->INFO.bmpid.WIDTH = htons(AObj->WIDTH); // 비트맵 표시 Width, 2 Byte, 0 ~ 1023 : 표출 비트맵 Width
  2551. pBmpIdData->INFO.bmpid.HEIGHT = htons(AObj->HEIGHT); // 비트맵 표시 Heitht, 2 Byte, 0 ~ 1023 : 표출 비트맵 Width
  2552. pBmpIdData->INFO.bmpid.IMG_TYPE = e_img_bitmap; // e_img_type
  2553. pBmpIdData->INFO.bmpid.BITMAP_ID = htons(nBitmapId); // 표출할 비트맵 ID, 2 Byte, 0~ 9999 : 표출할 비트맵 ID
  2554. nPktIdx += sizeof(VMS_FORM_BMPID_DATA);
  2555. LINFO("download_form_0x9A: DownloadCnt: %d, FormId: %d, BitmapId: %d", AObj->FormDownload.DownloadCnt, nFormId, nBitmapId);
  2556. }
  2557. //}
  2558. nPktSize = sizeof(VMS_HEAD)+pHead->Length-2; //DLE/STX
  2559. crc = GETCRC16((char*)&pHead->Group, nPktSize);
  2560. msgPtr[sizeof(VMS_HEAD)+pHead->Length+0] = VMS_DLE;
  2561. msgPtr[sizeof(VMS_HEAD)+pHead->Length+1] = VMS_ETX;
  2562. msgPtr[sizeof(VMS_HEAD)+pHead->Length+2] = HIBYTE(crc);
  2563. msgPtr[sizeof(VMS_HEAD)+pHead->Length+3] = LOBYTE(crc);
  2564. AObj->FormDownload.DownloadCnt++;
  2565. SendPacketDLE((char*)msgPtr, nPktSize+6, AObj->IsDle);
  2566. return 1;
  2567. }
  2568. //---------------------------------------------------------------------------
  2569. int TClientSession::download_file_0x82()
  2570. {
  2571. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  2572. TCDSCtlr *AObj = FCDSCtlr;
  2573. if (!AObj) return -1;
  2574. if (AObj->FormDownload.MaxSchedule == 0)
  2575. {
  2576. // 여기 들어오면 안됌, 다운로드할 폼정보가 존해해야 여기 함수를 호출하게 돼있음
  2577. return 0;
  2578. }
  2579. int nDownloadCnt = AObj->FormDownload.DownloadCnt;
  2580. if (nDownloadCnt >= AObj->FormDownload.MaxSchedule)
  2581. {
  2582. // 폼파일이(폼이미지파일) 모두 다운로드 되었으므로 스케쥴 정보를 다운로드 한다.
  2583. download_schedule_form_0x96(); // Display Schedule Form
  2584. return 0;
  2585. }
  2586. bool bResult = true;
  2587. BYTE *msgPtr;
  2588. // 파일다운로드
  2589. VMS_HEAD *pHead;
  2590. VMS_FILE_DATA *pFile;
  2591. char *pStrm;
  2592. // 폼다운로드
  2593. VMS_FORM_HEAD *pForm;
  2594. VMS_FORM_BMPID_DATA *pData;
  2595. WORD crc;
  2596. int nPktSize;
  2597. int ii;
  2598. bool isEndDownload = true;
  2599. AObj->pForms->Lock();
  2600. try
  2601. {
  2602. for (ii = nDownloadCnt; ii < AObj->FormDownload.MaxSchedule; ii++)
  2603. {
  2604. AObj->FormDownload.DownloadCnt++;
  2605. int nFormId = AObj->FormDownload.Info[ii].FormNo;
  2606. int nBitmapId = AObj->FormDownload.Info[ii].BitmapId;
  2607. int nFormIdx = AObj->FormDownload.Info[ii].FormIdx;
  2608. if (g_AppCfg.IsCheckNewForm && AObj->FormDownload.Info[ii].IsDownload == false)
  2609. {
  2610. // 이미 다운로드 했기 때문에 다시 다운로드 하지 않는다.
  2611. LDEBUG("download_file_0x82: DownloadCnt: %d, FormId: %d, BitmapId: %d, already download...", ii, nFormId, nBitmapId);
  2612. continue;
  2613. }
  2614. TVmsForm *pForm = AObj->pForms->FLists.Find(nFormIdx);
  2615. if (!pForm)
  2616. {
  2617. continue;
  2618. }
  2619. if (!pForm->Success)
  2620. {
  2621. continue;
  2622. }
  2623. // TODO: 20241220
  2624. if (pForm->fileType == P_FILE_TYPE_STREAM)
  2625. {
  2626. continue;
  2627. }
  2628. if (!pForm->pStream || pForm->pStream->Size == 0)
  2629. {
  2630. continue;
  2631. }
  2632. if (pForm->fileType == P_FILE_TYPE_VIDEO)
  2633. {
  2634. // 필요에 따라서 동영상 FTP 다운로드 프로토콜을 여기서도 사용하자.....
  2635. continue;
  2636. }
  2637. isEndDownload = false;
  2638. AObj->DownloadFormId = AObj->FormDownload.Info[ii].VMS_FORM_ID;
  2639. LDEBUG("download_file_0x82: DownloadCnt: %d, FormId: %d, BitmapId: %d, VMS_FORM_ID: %s", ii, nFormId, nBitmapId, AObj->DownloadFormId.c_str());
  2640. // 다운로드
  2641. msgPtr = (BYTE*)pMsg->Buff;
  2642. pHead = (VMS_HEAD*)&msgPtr[0];
  2643. pFile = (VMS_FILE_DATA*)&msgPtr[sizeof(VMS_HEAD)];
  2644. pStrm = (char*)&msgPtr[sizeof(VMS_HEAD)+sizeof(VMS_FILE_DATA)];
  2645. pHead->Dle = VMS_DLE;
  2646. pHead->Stx = VMS_STX;
  2647. pHead->Group = AObj->GROUP_NO;
  2648. pHead->Ctlr = AObj->CTLR_LOCAL_NO;
  2649. pHead->OpCode = e_vms_file_download;
  2650. pHead->Curr = 1;
  2651. pHead->Total = 1;
  2652. pHead->Length = 0;
  2653. int nFileNameSize = 11;
  2654. int nFileSize = pForm->pStream->Size;
  2655. nFileNameSize = 11;
  2656. pHead->Length = sizeof(VMS_FILE_DATA)+nFileNameSize+nFileSize;
  2657. pFile->head.SAVE_LOC = e_download_prog_image; // Download Data 저장위치 Code, 1 Byte
  2658. pFile->head.NAME_SIZE = 11; // 파일명 길이, 1 Byte, 1~ 255
  2659. pFile->head.SIZE = nFileSize; // 저장하여야 할 데이터의 크기, 4 Byte
  2660. pForm->pStream->Position = 0;
  2661. try
  2662. {
  2663. sprintf((char*)&pStrm[0], "BID%04d.BMP", nBitmapId);
  2664. memcpy((char*)&pStrm[pFile->head.NAME_SIZE], (char*)pForm->pStream->Memory, nFileSize);
  2665. // 바이트 오더링 변환
  2666. pFile->head.SIZE = htonl(pFile->head.SIZE);
  2667. nPktSize = sizeof(VMS_HEAD)+pHead->Length-2; //DLE/STX
  2668. crc = GETCRC16((char*)&pHead->Group, nPktSize);
  2669. msgPtr[sizeof(VMS_HEAD)+pHead->Length+0] = VMS_DLE;
  2670. msgPtr[sizeof(VMS_HEAD)+pHead->Length+1] = VMS_ETX;
  2671. msgPtr[sizeof(VMS_HEAD)+pHead->Length+2] = HIBYTE(crc);
  2672. msgPtr[sizeof(VMS_HEAD)+pHead->Length+3] = LOBYTE(crc);
  2673. SendPacketDLE((char*)msgPtr, nPktSize+6, AObj->IsDle);
  2674. break;
  2675. }
  2676. catch(Exception &e)
  2677. {
  2678. bResult = false;
  2679. }
  2680. }
  2681. }
  2682. __finally
  2683. {
  2684. AObj->pForms->UnLock();
  2685. }
  2686. if (isEndDownload)
  2687. {
  2688. // 폼이미지 정보가 모두 다운로드 되었으므로 스케쥴 정보를 다운로드 한다.
  2689. download_schedule_form_0x96(); // Display Schedule Form
  2690. }
  2691. return 1;
  2692. }
  2693. //---------------------------------------------------------------------------
  2694. int TClientSession::download_schedule_form_0x96()
  2695. {
  2696. TCDSCtlr *AObj = FCDSCtlr;
  2697. if (!AObj) return -1;
  2698. char Buff[1024];
  2699. BYTE *msgPtr;
  2700. VMS_HEAD *pHead;
  2701. VMS_SCHEDULE_FORM *pSche;
  2702. WORD crc;
  2703. int nPktSize;
  2704. msgPtr = Buff;
  2705. pHead = (VMS_HEAD*)&msgPtr[0];
  2706. pSche = (VMS_SCHEDULE_FORM*)&msgPtr[sizeof(VMS_HEAD)];
  2707. pHead->Dle = VMS_DLE;
  2708. pHead->Stx = VMS_STX;
  2709. pHead->Group = AObj->GROUP_NO;
  2710. pHead->Ctlr = AObj->CTLR_LOCAL_NO;
  2711. pHead->OpCode = e_vms_download_schedule_form;
  2712. pHead->Curr = 1;
  2713. pHead->Total = 1;
  2714. pHead->Length = sizeof(VMS_SCHEDULE_FORM);
  2715. memset((char*)pSche, 0x00, sizeof(VMS_SCHEDULE_FORM));
  2716. if (AObj->FormDownload.IsDefault)
  2717. {
  2718. pSche->Form[0].FormNo = htons(DEFAULT_FORMID);
  2719. pSche->Form[0].DispSec = 4;
  2720. LINFO("download_schedule_form_0x96: 0, DEFAULT_FORMID: %d, DispSec: %d", DEFAULT_FORMID, pSche->Form[0].DispSec);
  2721. }
  2722. else
  2723. {
  2724. for (int ii = 0; ii < AObj->FormDownload.MaxSchedule && ii < MAX_VMS_SCENARIO_FORM; ii++)
  2725. {
  2726. pSche->Form[ii].FormNo = htons(AObj->FormDownload.Info[ii].FormNo);
  2727. pSche->Form[ii].DispSec = AObj->FormDownload.Info[ii].DispSec;
  2728. LINFO("download_schedule_form_0x96: %d, FormId: %d, DispSec: %d", ii, AObj->FormDownload.Info[ii].FormNo, AObj->FormDownload.Info[ii].DispSec);
  2729. }
  2730. }
  2731. nPktSize = sizeof(VMS_HEAD)+pHead->Length-2; //DLE/STX
  2732. crc = GETCRC16((char*)&pHead->Group, nPktSize);
  2733. msgPtr[sizeof(VMS_HEAD)+pHead->Length+0] = VMS_DLE;
  2734. msgPtr[sizeof(VMS_HEAD)+pHead->Length+1] = VMS_ETX;
  2735. msgPtr[sizeof(VMS_HEAD)+pHead->Length+2] = HIBYTE(crc);
  2736. msgPtr[sizeof(VMS_HEAD)+pHead->Length+3] = LOBYTE(crc);
  2737. SendPacketDLE((char*)msgPtr, nPktSize+6, AObj->IsDle);
  2738. return 1;
  2739. }
  2740. //---------------------------------------------------------------------------
  2741. int TClientSession::download_blank_0x9E()
  2742. {
  2743. TCDSCtlr *AObj = FCDSCtlr;
  2744. if (!AObj) return -1;
  2745. char Buff[1024];
  2746. BYTE *msgPtr;
  2747. VMS_HEAD *pHead;
  2748. WORD crc;
  2749. int nPktSize;
  2750. LDEBUG("download_blank_0x9E: .................");
  2751. msgPtr = Buff;
  2752. pHead = (VMS_HEAD*)&msgPtr[0];
  2753. pHead->Dle = VMS_DLE;
  2754. pHead->Stx = VMS_STX;
  2755. pHead->Group = AObj->GROUP_NO;
  2756. pHead->Ctlr = AObj->CTLR_LOCAL_NO;
  2757. pHead->OpCode = e_vms_blank;
  2758. pHead->Curr = 1;
  2759. pHead->Total = 1;
  2760. pHead->Length = 0;
  2761. nPktSize = sizeof(VMS_HEAD)+pHead->Length-2; //DLE/STX
  2762. crc = GETCRC16((char*)&pHead->Group, nPktSize);
  2763. msgPtr[sizeof(VMS_HEAD)+pHead->Length+0] = VMS_DLE;
  2764. msgPtr[sizeof(VMS_HEAD)+pHead->Length+1] = VMS_ETX;
  2765. msgPtr[sizeof(VMS_HEAD)+pHead->Length+2] = HIBYTE(crc);
  2766. msgPtr[sizeof(VMS_HEAD)+pHead->Length+3] = LOBYTE(crc);
  2767. SendPacketDLE((char*)msgPtr, nPktSize+6, AObj->IsDle);
  2768. return 1;
  2769. }
  2770. //---------------------------------------------------------------------------
  2771. int TClientSession::download_lib_form_0x0A()
  2772. {
  2773. IPC_JOB_MESSAGE *pMsg = g_jobBuff.GetBuff();
  2774. TCDSCtlr *AObj = FCDSCtlr;
  2775. if (!AObj) return -1;
  2776. if (AObj->FormDownload.MaxSchedule == 0)
  2777. {
  2778. // 여기 들어오면 안됌, 다운로드할 폼정보가 존해해야 여기 함수를 호출하게 돼있음
  2779. return 0;
  2780. }
  2781. int nDownloadCnt = AObj->FormDownload.DownloadCnt;
  2782. if (nDownloadCnt >= AObj->FormDownload.MaxSchedule)
  2783. {
  2784. // 폼파일이(폼이미지파일) 모두 다운로드 되었으므로 스케쥴 정보를 다운로드 한다.
  2785. download_schedule_form_0x0E(); // Display Schedule Form
  2786. return 0;
  2787. }
  2788. bool bResult = true;
  2789. BYTE *msgPtr;
  2790. // Download Graphics Library (Full Graphic Data)
  2791. VMS_HEAD *pHead;
  2792. VMS_FULL_GRAPHIC_LIB *pFile;
  2793. WORD crc;
  2794. int nPktSize;
  2795. int ii;
  2796. bool isEndDownload = true;
  2797. AObj->pForms->Lock();
  2798. try
  2799. {
  2800. for (ii = nDownloadCnt; ii < AObj->FormDownload.MaxSchedule; ii++)
  2801. {
  2802. AObj->FormDownload.DownloadCnt++;
  2803. int nFormId = AObj->FormDownload.Info[ii].FormNo;
  2804. int nBitmapId = AObj->FormDownload.Info[ii].BitmapId;
  2805. int nFormIdx = AObj->FormDownload.Info[ii].FormIdx;
  2806. if (g_AppCfg.IsCheckNewForm && AObj->FormDownload.Info[ii].IsDownload == false)
  2807. {
  2808. // 이미 다운로드 했기 때문에 다시 다운로드 하지 않는다.
  2809. LDEBUG("download_lib_form_0x0A: DownloadCnt: %d, FormId: %d, BitmapId: %d, already download...", ii, nFormId, nBitmapId);
  2810. continue;
  2811. }
  2812. TVmsForm *pForm = AObj->pForms->FLists.Find(nFormIdx);
  2813. if (!pForm)
  2814. {
  2815. continue;
  2816. }
  2817. if (!pForm->Success)
  2818. {
  2819. continue;
  2820. }
  2821. if (pForm->fileType == P_FILE_TYPE_VIDEO || pForm->fileType == P_FILE_TYPE_STREAM)
  2822. {
  2823. continue;
  2824. }
  2825. if (!pForm->pStream || pForm->pStream->Size == 0)
  2826. {
  2827. continue;
  2828. }
  2829. if (!pForm->pBitmap || pForm->pBitmap->Width == 0 || pForm->pBitmap->Height == 0)
  2830. {
  2831. continue;
  2832. }
  2833. // pForm->pBitmap->PixelFormat = pf24bit;
  2834. // 픽셀포멧이 24비트여야 ScanLine을 사용할 수 있다. 24비트가 아닌경우에는 다른 방법으로 처리해야 한다.
  2835. isEndDownload = false;
  2836. AObj->DownloadFormId = AObj->FormDownload.Info[ii].VMS_FORM_ID;
  2837. LDEBUG("download_lib_form_0x0A: DownloadCnt: %d, FormId: %d, BitmapId: %d, VMS_FORM_ID: %s", ii, nFormId, nBitmapId, AObj->DownloadFormId.c_str());
  2838. // 다운로드
  2839. msgPtr = (BYTE*)pMsg->Buff;
  2840. pHead = (VMS_HEAD*)&msgPtr[0];
  2841. pFile = (VMS_FULL_GRAPHIC_LIB*)&msgPtr[sizeof(VMS_HEAD)];
  2842. AObj->FTxtOpCode = e_txt_download_full_graphic_lib;
  2843. pHead->Dle = VMS_DLE;
  2844. pHead->Stx = VMS_STX;
  2845. pHead->Group = AObj->GROUP_NO;
  2846. pHead->Ctlr = AObj->CTLR_LOCAL_NO;
  2847. pHead->OpCode = e_txt_download_full_graphic_lib;
  2848. pHead->Curr = 1;
  2849. pHead->Total = 1;
  2850. pHead->Length = sizeof(VMS_FULL_GRAPHIC_LIB);
  2851. memset((char*)pFile, 0x00, sizeof(VMS_FULL_GRAPHIC_LIB));
  2852. pFile->Phase = 0x00; // 0x00(1phase), 0x01(2phase)
  2853. pFile->DispFunc = 0x07; // 0x07(static)
  2854. pFile->DispDir = 0x00; // 0x00(drop down)
  2855. pFile->MsgNmbr = (WORD)nBitmapId;
  2856. pFile->MsgNmbr = htons(pFile->MsgNmbr);
  2857. try
  2858. {
  2859. int idx = 0;
  2860. int ll, mm;
  2861. int r, g, b;
  2862. int nW = pForm->pBitmap->Width;
  2863. int nH = pForm->pBitmap->Height;
  2864. TPixelFormat PixelFormat = pForm->pBitmap->PixelFormat;
  2865. if (PixelFormat == pf24bit)
  2866. {
  2867. for (ll = 0; ll < nH; ll++)
  2868. {
  2869. TRGBTriple *p = reinterpret_cast<TRGBTriple *>(pForm->pBitmap->ScanLine[ll]);
  2870. for (mm = 0; mm < nW; mm++)
  2871. {
  2872. r = p[mm].rgbtRed;
  2873. g = p[mm].rgbtGreen;
  2874. //b = p[mm].rgbtBlue;
  2875. if (r > g_AppCfg.PixelValue) CComm_SetBitString(pFile->R_Data1, idx, 1);
  2876. if (g > g_AppCfg.PixelValue) CComm_SetBitString(pFile->G_Data1, idx, 1);
  2877. idx++;
  2878. }
  2879. }
  2880. }
  2881. else
  2882. if (PixelFormat == pf32bit)
  2883. {
  2884. for (ll = 0; ll < nH; ll++)
  2885. {
  2886. TRGBQuad *p = reinterpret_cast<TRGBQuad *>(pForm->pBitmap->ScanLine[ll]);
  2887. for (mm = 0; mm < nW; mm++)
  2888. {
  2889. r = p[mm].rgbRed;
  2890. g = p[mm].rgbGreen;
  2891. //b = p[mm].rgbBlue;
  2892. if (r > g_AppCfg.PixelValue) CComm_SetBitString(pFile->R_Data1, idx, 1);
  2893. if (g > g_AppCfg.PixelValue) CComm_SetBitString(pFile->G_Data1, idx, 1);
  2894. idx++;
  2895. }
  2896. }
  2897. }
  2898. else
  2899. if (PixelFormat == pf16bit)
  2900. {
  2901. //FILE *fp = fopen("C:\\temp.dat", "w+");
  2902. for (ll = 0; ll < nH; ll++)
  2903. {
  2904. WORD *p = reinterpret_cast<WORD *>(pForm->pBitmap->ScanLine[ll]);
  2905. for (mm = 0; mm < nW; mm++)
  2906. {
  2907. r = p[mm] >> 11 & 0x1F; // 5
  2908. g = p[mm] >> 5 & 0x3F; // 6
  2909. //b = p[mm] >> 0 & 0x1F; // 5
  2910. //((blue>>3)<<10) | ((green>>3)<<5) | (red>>3);
  2911. if (r > g_AppCfg.PixelValue) CComm_SetBitString(pFile->R_Data1, idx, 1);
  2912. if (g > g_AppCfg.PixelValue) CComm_SetBitString(pFile->G_Data1, idx, 1);
  2913. idx++;
  2914. //if (r > 0 || g > 0) fprintf(fp, "*"); else fprintf(fp, "-");
  2915. }
  2916. //fprintf(fp, "\n");
  2917. }
  2918. //fclose(fp);
  2919. }
  2920. else
  2921. if (PixelFormat == pf8bit)
  2922. {
  2923. PALETTEENTRY PalEntries[257];
  2924. if (pForm->pBitmap->Palette != 0)
  2925. {
  2926. GetPaletteEntries(pForm->pBitmap->Palette, 0, 256, (LPPALETTEENTRY)PalEntries);
  2927. //FILE *fp = fopen("C:\\temp.dat", "w+");
  2928. for (ll = 0; ll < nH; ll++)
  2929. {
  2930. BYTE *p = reinterpret_cast<BYTE *>(pForm->pBitmap->ScanLine[ll]);
  2931. for (mm = 0; mm < nW; mm++)
  2932. {
  2933. r = PalEntries[p[mm]].peRed;
  2934. g = PalEntries[p[mm]].peGreen;
  2935. b = PalEntries[p[mm]].peBlue;
  2936. if (r > g_AppCfg.PixelValue) CComm_SetBitString(pFile->R_Data1, idx, 1);
  2937. if (g > g_AppCfg.PixelValue) CComm_SetBitString(pFile->G_Data1, idx, 1);
  2938. idx++;
  2939. //if (r > 0 || g > 0) fprintf(fp, "*"); else fprintf(fp, "-");
  2940. }
  2941. //fprintf(fp, "\n");
  2942. }
  2943. //fclose(fp);
  2944. }
  2945. }
  2946. else
  2947. if (PixelFormat == pf4bit)
  2948. // PixelFormat == pf1bit)
  2949. {
  2950. PALETTEENTRY PalEntries[17];
  2951. if (pForm->pBitmap->Palette != 0)
  2952. {
  2953. int clrIdx;
  2954. GetPaletteEntries(pForm->pBitmap->Palette, 0, 16, (LPPALETTEENTRY)PalEntries);
  2955. //FILE *fp = fopen("C:\\temp.dat", "w+");
  2956. for (ll = 0; ll < nH; ll++)
  2957. {
  2958. BYTE *p = reinterpret_cast<BYTE *>(pForm->pBitmap->ScanLine[ll]);
  2959. for (mm = 0; mm < nW/2; mm++)
  2960. {
  2961. clrIdx = (p[mm] >> 4) & 0xF;
  2962. r = PalEntries[clrIdx].peRed;
  2963. g = PalEntries[clrIdx].peGreen;
  2964. b = PalEntries[clrIdx].peBlue;
  2965. if (r > g_AppCfg.PixelValue) CComm_SetBitString(pFile->R_Data1, idx, 1);
  2966. if (g > g_AppCfg.PixelValue) CComm_SetBitString(pFile->G_Data1, idx, 1);
  2967. idx++;
  2968. //if (r > 0 || g > 0) fprintf(fp, "*"); else fprintf(fp, "-");
  2969. clrIdx = p[mm] & 0xF;
  2970. r = PalEntries[clrIdx].peRed;
  2971. g = PalEntries[clrIdx].peGreen;
  2972. b = PalEntries[clrIdx].peBlue;
  2973. if (r > g_AppCfg.PixelValue) CComm_SetBitString(pFile->R_Data1, idx, 1);
  2974. if (g > g_AppCfg.PixelValue) CComm_SetBitString(pFile->G_Data1, idx, 1);
  2975. idx++;
  2976. //if (r > 0 || g > 0) fprintf(fp, "*"); else fprintf(fp, "-");
  2977. }
  2978. //fprintf(fp, "\n");
  2979. }
  2980. //fclose(fp);
  2981. }
  2982. }
  2983. nPktSize = sizeof(VMS_HEAD)+pHead->Length-2; //DLE/STX
  2984. crc = GETCRC16((char*)&pHead->Group, nPktSize);
  2985. msgPtr[sizeof(VMS_HEAD)+pHead->Length+0] = VMS_DLE;
  2986. msgPtr[sizeof(VMS_HEAD)+pHead->Length+1] = VMS_ETX;
  2987. msgPtr[sizeof(VMS_HEAD)+pHead->Length+2] = HIBYTE(crc);
  2988. msgPtr[sizeof(VMS_HEAD)+pHead->Length+3] = LOBYTE(crc);
  2989. SendPacketDLE((char*)msgPtr, nPktSize+6, AObj->IsDle);
  2990. break;
  2991. }
  2992. catch(Exception &e)
  2993. {
  2994. bResult = false;
  2995. }
  2996. }
  2997. }
  2998. __finally
  2999. {
  3000. AObj->pForms->UnLock();
  3001. }
  3002. if (isEndDownload)
  3003. {
  3004. // 폼이미지 정보가 모두 다운로드 되었으므로 스케쥴 정보를 다운로드 한다.
  3005. download_schedule_form_0x0E(); // Display Schedule Form
  3006. }
  3007. return 1;
  3008. }
  3009. //---------------------------------------------------------------------------
  3010. int TClientSession::download_schedule_form_0x0E()
  3011. {
  3012. TCDSCtlr *AObj = FCDSCtlr;
  3013. if (!AObj) return -1;
  3014. char Buff[1024];
  3015. BYTE *msgPtr;
  3016. VMS_HEAD *pHead;
  3017. VMS_SCHEDULE_FORM *pSche;
  3018. WORD crc;
  3019. int nPktSize;
  3020. AObj->FTxtOpCode = e_txt_display_schedule_msg;
  3021. msgPtr = Buff;
  3022. pHead = (VMS_HEAD*)&msgPtr[0];
  3023. pSche = (VMS_SCHEDULE_FORM*)&msgPtr[sizeof(VMS_HEAD)];
  3024. pHead->Dle = VMS_DLE;
  3025. pHead->Stx = VMS_STX;
  3026. pHead->Group = AObj->GROUP_NO;
  3027. pHead->Ctlr = AObj->CTLR_LOCAL_NO;
  3028. pHead->OpCode = e_txt_display_schedule_msg;
  3029. pHead->Curr = 1;
  3030. pHead->Total = 1;
  3031. pHead->Length = sizeof(VMS_SCHEDULE_FORM);
  3032. memset((char*)pSche, 0x00, sizeof(VMS_SCHEDULE_FORM));
  3033. for (int ii = 0; ii < AObj->FormDownload.MaxSchedule && ii < MAX_VMS_SCENARIO_FORM; ii++)
  3034. {
  3035. pSche->Form[ii].FormNo = htons(AObj->FormDownload.Info[ii].FormNo);
  3036. pSche->Form[ii].DispSec = AObj->FormDownload.Info[ii].DispSec;
  3037. LINFO("download_lib_form_0x0A: %d, FormId: %d, DispSec: %d", ii, AObj->FormDownload.Info[ii].FormNo, AObj->FormDownload.Info[ii].DispSec);
  3038. }
  3039. nPktSize = sizeof(VMS_HEAD)+pHead->Length-2; //DLE/STX
  3040. crc = GETCRC16((char*)&pHead->Group, nPktSize);
  3041. msgPtr[sizeof(VMS_HEAD)+pHead->Length+0] = VMS_DLE;
  3042. msgPtr[sizeof(VMS_HEAD)+pHead->Length+1] = VMS_ETX;
  3043. msgPtr[sizeof(VMS_HEAD)+pHead->Length+2] = HIBYTE(crc);
  3044. msgPtr[sizeof(VMS_HEAD)+pHead->Length+3] = LOBYTE(crc);
  3045. SendPacketDLE((char*)msgPtr, nPktSize+6, AObj->IsDle);
  3046. return 1;
  3047. }
  3048. //---------------------------------------------------------------------------
  3049. int TClientSession::download_blank_0x16()
  3050. {
  3051. TCDSCtlr *AObj = FCDSCtlr;
  3052. if (!AObj) return -1;
  3053. char Buff[1024];
  3054. BYTE *msgPtr;
  3055. VMS_HEAD *pHead;
  3056. WORD crc;
  3057. int nPktSize;
  3058. AObj->FTxtOpCode = e_txt_blank;
  3059. msgPtr = Buff;
  3060. pHead = (VMS_HEAD*)&msgPtr[0];
  3061. pHead->Dle = VMS_DLE;
  3062. pHead->Stx = VMS_STX;
  3063. pHead->Group = AObj->GROUP_NO;
  3064. pHead->Ctlr = AObj->CTLR_LOCAL_NO;
  3065. pHead->OpCode = e_txt_blank;
  3066. pHead->Curr = 1;
  3067. pHead->Total = 1;
  3068. pHead->Length = 0;
  3069. nPktSize = sizeof(VMS_HEAD)+pHead->Length-2; //DLE/STX
  3070. crc = GETCRC16((char*)&pHead->Group, nPktSize);
  3071. msgPtr[sizeof(VMS_HEAD)+pHead->Length+0] = VMS_DLE;
  3072. msgPtr[sizeof(VMS_HEAD)+pHead->Length+1] = VMS_ETX;
  3073. msgPtr[sizeof(VMS_HEAD)+pHead->Length+2] = HIBYTE(crc);
  3074. msgPtr[sizeof(VMS_HEAD)+pHead->Length+3] = LOBYTE(crc);
  3075. SendPacketDLE((char*)msgPtr, nPktSize+6, AObj->IsDle);
  3076. return 1;
  3077. }
  3078. //---------------------------------------------------------------------------
  3079. int TClientSession::ReqSendPacket(char *ACmd, int ALen)
  3080. {
  3081. VMS_HEAD *pHead = (VMS_HEAD*)ACmd;
  3082. if (ALen <= 0)
  3083. {
  3084. return -1;
  3085. }
  3086. if (!SendRequest(ACmd, ALen))
  3087. {
  3088. SERROR("+CLI ReqSendPacket send request faild: %s, 0x%02X will be closed.", FIpAddress.c_str(), pHead->OpCode);
  3089. MERROR("+CLI ReqSendPacket send request faild: %s, 0x%02X will be closed.", FIpAddress.c_str(), pHead->OpCode);
  3090. Disconnect();
  3091. return -2;
  3092. }
  3093. SendFlushComplete();
  3094. return 1;
  3095. }
  3096. //---------------------------------------------------------------------------