PacketHandllingF.cpp 138 KB

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