PacketHandllingF.cpp 128 KB

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