PacketHandllingF.cpp 138 KB

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