PacketHandllingF.cpp 136 KB

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