VMSSThread.cpp 210 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466
  1. /****************************************************************************
  2. * @source : VMSSThread.cpp
  3. * @description : VMS Server Socket Thread
  4. ****************************************************************************
  5. * DATE AUTHOR DESCRIPTION
  6. * --------------------------------------------------------------------------
  7. * 2012/03/09 CYM [100] First Cut
  8. *
  9. ****************************************************************************/
  10. //---------------------------------------------------------------------------
  11. #include "AppGlobalF.h"
  12. #include "VMSSThread.h"
  13. #include "VMSCThread.h"
  14. #include "FrmSysLogF.h"
  15. #include "FrmVmsInfoF.h"
  16. #include "FrmVmsLogF.h"
  17. #include <winsock.h>
  18. //---------------------------------------------------------------------------
  19. #pragma package(smart_init)
  20. //---------------------------------------------------------------------------
  21. // Important: Methods and properties of objects in VCL can only be
  22. // used in a method called using Synchronize, for example:
  23. //
  24. // Synchronize(&UpdateCaption);
  25. //
  26. // where UpdateCaption could look like:
  27. //
  28. // void __fastcall TVMSSThread::UpdateCaption()
  29. // {
  30. // Form1->Caption = "Updated in a thread";
  31. // }
  32. //---------------------------------------------------------------------------
  33. #define VMSID FVmsObj->VmsId
  34. __fastcall TVMSSThread::TVMSSThread(TServerSocketThread* ServerSocketThread, TCustomIpClient* ClientSocket, int Tag, bool *ActiveIndicator)
  35. : TClientSocketThread(ServerSocketThread)
  36. {
  37. try
  38. {
  39. FDupClose = false;
  40. m_InitFlag = false;
  41. FVmsObj = (TVmsCtlr*)Tag;
  42. FLogFile = FVmsObj->FSLog;
  43. ThreadActiveIndicator = ActiveIndicator;
  44. *ThreadActiveIndicator = true;
  45. FVmsObj->ConnectTm = Now().DateTimeString();
  46. // 정보 초기화
  47. ServerInitMem();
  48. ServerInitInfo();
  49. pClientSocket = ClientSocket;
  50. pClientSocket->BlockMode = bmBlocking;
  51. pClientSocket->OnError = TcpServerClientError;
  52. pClientSocket->OnDisconnect = TcpServerDisconnect;
  53. m_InitFlag = true;
  54. Priority = tpNormal;
  55. FreeOnTerminate = true;
  56. Resume();
  57. }
  58. catch(Exception &e)
  59. {
  60. SERROR("Thread Init Error");
  61. Terminate();
  62. }
  63. }
  64. //---------------------------------------------------------------------------
  65. __fastcall TVMSSThread::~TVMSSThread()
  66. {
  67. try
  68. {
  69. Close();
  70. SAFE_DELETE(pClientSocket);
  71. }
  72. catch(Exception &e)
  73. {
  74. }
  75. *ThreadActiveIndicator = false;
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TVMSSThread::Close(void)
  79. {
  80. try
  81. {
  82. FVmsObj->DisconnectTm = Now().DateTimeString();
  83. FVmsObj->Server.Status == process_fail;
  84. if (pClientSocket)
  85. {
  86. //if (pClientSocket->Connected)
  87. {
  88. pClientSocket->Close();
  89. //Sleep(3000);
  90. }
  91. }
  92. }
  93. catch(Exception &e)
  94. {
  95. }
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TVMSSThread::TcpServerClientError(TObject *Sender, int SocketError)
  99. {
  100. LPVOID lpMsgBuf = NULL;
  101. try
  102. {
  103. try
  104. {
  105. FormatMessage(
  106. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  107. NULL,
  108. //GetLastError(),
  109. //MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  110. SocketError,
  111. MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
  112. (LPTSTR) &lpMsgBuf,
  113. 0,
  114. NULL
  115. );
  116. char *pData = (char*)lpMsgBuf;
  117. if (strlen(pData) > 2)
  118. {
  119. pData[strlen(pData)-2] = 0x00;
  120. pData[strlen(pData)-1] = 0x00;
  121. }
  122. SERROR("SocketError: (%d: %s)", SocketError, pData);
  123. }
  124. __finally
  125. {
  126. if (lpMsgBuf) LocalFree(lpMsgBuf);
  127. lpMsgBuf = NULL;
  128. }
  129. }
  130. catch(Exception &e)
  131. {
  132. }
  133. Close();
  134. }
  135. //---------------------------------------------------------------------------
  136. bool __fastcall TVMSSThread::SocketActivity(bool &AError)
  137. {
  138. bool Error, ReadReady, WriteReady, ExcepFlag;
  139. ReadReady = false;
  140. AError = false;
  141. if (!pClientSocket) return ReadReady;
  142. try
  143. {
  144. Error = pClientSocket->Select(&ReadReady, &WriteReady, &ExcepFlag, 0);
  145. if ((Error == false))// || (ExcepFlag == true)) //exception flag == o.o.b(out of band data receive)
  146. {
  147. AError = true;
  148. ReadReady = false;
  149. }
  150. }
  151. catch(Exception &e)
  152. {
  153. AError = true;
  154. ReadReady = false;
  155. }
  156. return ReadReady;
  157. }
  158. //---------------------------------------------------------------------------
  159. bool __fastcall TVMSSThread::SocketActivity()
  160. {
  161. bool bResult = false;
  162. bool Error, ReadReady, WriteReady, ExcepFlag;
  163. if (!pClientSocket) return bResult;
  164. try
  165. {
  166. Error = pClientSocket->Select(&ReadReady, &WriteReady, &ExcepFlag, 0);
  167. if ((Error == false) || (ReadReady == true) || (ExcepFlag == true))
  168. {
  169. bResult = true;
  170. }
  171. }
  172. catch(Exception &e)
  173. {
  174. }
  175. return bResult;
  176. }
  177. //---------------------------------------------------------------------------
  178. void __fastcall TVMSSThread::TcpServerDisconnect(TObject *Sender)
  179. {
  180. //SINFO("Client Disconnect");
  181. if (!APP_EXIT) {
  182. SINFO("Client Disconnect: %s %s", pClientSocket->RemoteHost.c_str(), pClientSocket->RemotePort.c_str());
  183. }
  184. Close();
  185. }
  186. //---------------------------------------------------------------------------
  187. void __fastcall TVMSSThread::Execute()
  188. {
  189. BYTE buffer[DEFAULT_TCP_PACKET_MAX_SIZE];
  190. int nError;
  191. int nResult;
  192. bool bError;
  193. int nReadLen;
  194. unsigned long nRecvLen;
  195. FErrLine = 0;
  196. SINFO("Thread start");
  197. try
  198. {
  199. while (!Terminated && !m_InitFlag);
  200. //NameThreadForDebugging(m_strName);
  201. FVmsObj->Server.Status = process_run;
  202. POST_MSG(MAINHANDLE, WM_VMS_THREAD, WM_VMS_SERVER_STTS, (int)FVmsObj);
  203. try
  204. {
  205. CheckClientThread(true);
  206. //TODO
  207. m_Server.State = ST_SECTION;
  208. while (!Terminated && pClientSocket->Connected && !FDupClose)
  209. {
  210. try
  211. {
  212. bError = false;
  213. if (pClientSocket->WaitForData(100) || SocketActivity())
  214. {
  215. bError = false;
  216. nRecvLen = 0;
  217. #if 0
  218. nResult = ioctlsocket(pClientSocket->Handle, FIONREAD, &nRecvLen);
  219. if (nResult != 0)
  220. {
  221. Close();
  222. }
  223. if (nRecvLen > 0)
  224. #endif
  225. {
  226. memset(buffer, 0, sizeof(buffer));
  227. nReadLen = pClientSocket->ReceiveBuf(buffer, sizeof(buffer));
  228. if (nReadLen > 0)
  229. {
  230. if ((nResult = RecvPacket(buffer, nReadLen)) != SYS_ERR_NONE)
  231. {
  232. ProcErrorState(TRUE, nResult);
  233. }
  234. }
  235. else
  236. {
  237. bError = true;
  238. }
  239. #if 0
  240. if ((int)nRecvLen != nReadLen)
  241. {
  242. SERROR("Receive data size false: %d, %d", nRecvLen, nReadLen);
  243. }
  244. #endif
  245. }
  246. }
  247. if (bError)
  248. {
  249. SERROR("Socket Error[Closed]....");
  250. nError = -3;
  251. Close();
  252. }
  253. else
  254. {
  255. CheckClientThread(true);
  256. ServerStateMachine();
  257. }
  258. if (g_AppCfg.bThrExit)
  259. {
  260. nError = 0;
  261. SINFO("Thread exit catched....");
  262. Close();
  263. }
  264. }
  265. catch(Exception &e)
  266. {
  267. SERROR("Thread execute exception: %s, Line: %d", AnsiString(e.Message).c_str(), FErrLine);
  268. nError = -2;
  269. Close();
  270. }
  271. }
  272. SERROR("Term: %d, Conn: %d, Dup: %d, Err: %d, Line: %d", Terminated, pClientSocket->Connected, FDupClose, nError, FErrLine);
  273. }
  274. __finally
  275. {
  276. Close();
  277. Terminate();
  278. }
  279. }
  280. catch(Exception &e)
  281. {
  282. SERROR("Thread execute error: %s", AnsiString(e.Message).c_str());
  283. Terminate();
  284. }
  285. ServerTerminate();
  286. }
  287. //---------------------------------------------------------------------------
  288. // VMS 제어기와의 상태정보 통신을 담당할 클라이언트 스레드를 체크한다.
  289. bool __fastcall TVMSSThread::CheckClientThread(bool ARun)
  290. {
  291. if (FVmsObj->Client.UseFlag != bit_enable) return false;
  292. if (ARun)
  293. {
  294. if ((FVmsObj->Client.pThread == NULL) &&
  295. (FVmsObj->Client.ActiveIndicator == false))
  296. {
  297. TVMSCThread *pVMSCThread = new TVMSCThread(true, (int)FVmsObj, &FVmsObj->Client.ActiveIndicator);
  298. FVmsObj->Client.pThread = pVMSCThread;
  299. if (FVmsObj->Client.pThread == NULL)
  300. {
  301. FVmsObj->Client.Status = process_fail;
  302. }
  303. else
  304. {
  305. FVmsObj->Client.wTimer = Now();
  306. }
  307. LINFO("Client Thread create: %d", FVmsObj->Client.pThread == NULL ? 0 : 1);
  308. }
  309. }
  310. return true;
  311. }
  312. //---------------------------------------------------------------------------
  313. void __fastcall TVMSSThread::ServerTerminate(void)
  314. {
  315. try
  316. {
  317. FVmsObj->Server.Status = process_fail;
  318. if (!APP_EXIT) {
  319. POST_MSG(MAINHANDLE, WM_VMS_THREAD, WM_VMS_SERVER_STTS, (int)FVmsObj);
  320. SINFO("Thread stop");
  321. }
  322. }
  323. catch(Exception &e)
  324. {
  325. }
  326. }
  327. //---------------------------------------------------------------------------
  328. int __fastcall TVMSSThread::ServerInitMem(void)
  329. {
  330. return S_SUCC;
  331. }
  332. //---------------------------------------------------------------------------
  333. void __fastcall TVMSSThread::ServerInitInfo(void)
  334. {
  335. m_RxLen = 0;
  336. m_rTimer = Now();
  337. m_WatchDogTimer = Now();
  338. m_strName = "VMSS" + FVmsObj->VmsId;
  339. FWatchDogTime = g_AppCfg.comm.nWatchDogTime;
  340. m_pVmsFormList = FVmsObj->pForms;
  341. m_Server.VmsId = FVmsObj->VmsId;
  342. m_Server.Addr = FVmsObj->LocalNo;
  343. m_Server.IpAddress = FVmsObj->IpAddress;
  344. m_Server.Port = VMS_DEFAULT_PORT;
  345. m_Server.TimeOut = g_AppCfg.comm.nCmdTimeOut;
  346. m_Server.CycleTime = g_AppCfg.comm.nPollingTime;
  347. m_pState = &FVmsObj->RSTATE;
  348. //TODO
  349. m_Server.State = ST_IDLE;
  350. //m_Server.State = ST_INITIATE;
  351. m_Server.sTimer = Now();
  352. m_Server.iRetry = VMS_MAX_RETRY_COUNT;
  353. m_Server.cTimer = Now();
  354. m_Server.LocalCenterId = "";
  355. m_Server.CenterId = "";
  356. m_Server.LocalDomainNm = g_AppCfg.comm.sLocalDomain;
  357. m_Server.DomainNm = FVmsObj->VmsId;
  358. m_Server.UserName = g_AppCfg.comm.sLoginUser;
  359. m_Server.UserPasswd = g_AppCfg.comm.sLoginPswd;
  360. m_Server.MaxHeartbeatTime = VMS_MAX_HEARTBEAT_TIME;
  361. m_Server.DatagramSize = VMS_MAX_DATAGRAM_SIZE;
  362. m_DataPacketNumber = 0;
  363. m_FrEDConfirmPacketNumber = 0;
  364. m_LoginFlag = false;
  365. m_PublishSerialNbr = 0;
  366. m_Registered.GeneralStatus = false;
  367. m_Registered.ModuleStatus = false;
  368. m_Registered.PowerStatus = false;
  369. m_Registered.ScreenDataStatusMessage = false;
  370. m_Registered.RealTimeDisplayMessage = false;
  371. #if 0
  372. //VMS가 접속하는 경우 생성되어 있는 메시지를 바로 보내도록 플래그 설정
  373. AnsiString sSvcDate = Now().FormatString("yyyymmddhhnnss");
  374. if (sSvcDate == FVmsObj->CTLMODE->SvcDate)
  375. {
  376. Sleep(1000);
  377. sSvcDate = Now().FormatString("yyyymmddhhnnss");
  378. }
  379. FVmsObj->CTLMODE->Enable = object_enable;
  380. FVmsObj->CTLMODE->SvcDate = sSvcDate;
  381. FVmsObj->CTLMODE->SaveFlag = false;
  382. FVmsObj->CTLMODE->Result = false;
  383. #endif
  384. LINFO("ServerInitInfo ok");
  385. }
  386. //---------------------------------------------------------------------------
  387. void __fastcall TVMSSThread::LOG_WriteTime(Time_t *pTime)
  388. {
  389. FErrLine = 29;
  390. if (!pTime) return;
  391. if (pTime->time_Year_qty)
  392. {
  393. LDEBUG("time_Year_qty: %d", *pTime->time_Year_qty);
  394. }
  395. if (pTime->time_Month_qty)
  396. {
  397. LDEBUG("time_Month_qty: %d", *pTime->time_Month_qty);
  398. }
  399. if (pTime->time_Day_qty)
  400. {
  401. LDEBUG("time_Day_qty: %d", *pTime->time_Day_qty);
  402. }
  403. LDEBUG("time_Hour_qty : %d", pTime->time_Hour_qty);
  404. LDEBUG("time_Minute_qty: %d", pTime->time_Minute_qty);
  405. LDEBUG("time_Second_qty: %d", pTime->time_Second_qty);
  406. switch(pTime->time_SecondFractions_zz.present)
  407. {
  408. case time_SecondFractions_PR_deci_seconds:
  409. LDEBUG("deci_seconds: %d", pTime->time_SecondFractions_zz.choice.deci_seconds);
  410. break;
  411. case time_SecondFractions_PR_centi_seconds:
  412. LDEBUG("centi_seconds: %d", pTime->time_SecondFractions_zz.choice.centi_seconds);
  413. break;
  414. case time_SecondFractions_PR_milliseconds:
  415. LDEBUG("milliseconds: %d", pTime->time_SecondFractions_zz.choice.milliseconds);
  416. break;
  417. default:
  418. LDEBUG("Unknown time_SecondFractions %d", pTime->time_SecondFractions_zz.present);
  419. break;
  420. }
  421. if (pTime->time_Timezone)
  422. {
  423. LDEBUG("timezone_Hour_qty: %d", pTime->time_Timezone->timezone_Hour_qty);
  424. LDEBUG("time_Minute_qty: %d", pTime->time_Timezone->time_Minute_qty);
  425. }
  426. }
  427. /*--------------------------------------------------------------------------*/
  428. /*
  429. *
  430. * arguments
  431. * void
  432. * return
  433. * void
  434. */
  435. void __fastcall TVMSSThread::ClientResponse(int error)
  436. {
  437. #ifdef CENTERCOMM
  438. BYTE ErrCode;
  439. int sResult;
  440. int Flag;
  441. bool bSave = false;
  442. switch(error)
  443. {
  444. case SYS_ERR_NONE: break;
  445. case SYS_ERR_OTHER: ErrCode = INT_ERROR_OTHER; break;
  446. case SYS_ERR_INTERNAL: ErrCode = INT_ERROR_SYSTEM; break;
  447. case SYS_ERR_MEMORY: ErrCode = INT_ERROR_SYSTEM; break;
  448. case SYS_ERR_DATABASE: ErrCode = INT_ERROR_SYSTEM; break;
  449. case SYS_ERR_RESET: ErrCode = INT_ERROR_SYSTEM; break;
  450. case SYS_ERR_START: ErrCode = INT_ERROR_SYSTEM; break;
  451. case SYS_ERR_OFFLINE: ErrCode = INT_ERROR_OFFLINE; break;
  452. case SYS_ERR_NO_RES: ErrCode = INT_ERROR_NO_RESPONSE; break;
  453. case SYS_ERR_ACCESS: ErrCode = INT_ERROR_PROCESS; break;
  454. case SYS_ERR_INVALID: ErrCode = INT_ERROR_OTHER; break;
  455. case SYS_ERR_UNKNOWN: ErrCode = INT_ERROR_UNKNOWN_CODE; break;
  456. case SYS_ERR_WRITE_LENGTH: ErrCode = INT_ERROR_OTHER; break;
  457. case SYS_ERR_PACKET_SIZE_LARGE: ErrCode = INT_ERROR_OTHER; break;
  458. case SYS_ERR_INVALID_TAG: ErrCode = INT_ERROR_OTHER; break;
  459. case SYS_ERR_CRC: ErrCode = INT_ERROR_OTHER; break;
  460. case SYS_ERR_LENGTH: ErrCode = INT_ERROR_LENGTH; break;
  461. case SYS_ERR_ADDRESS: ErrCode = INT_ERROR_ADDRESS; break;
  462. case SYS_ERR_HEADER_OPTIONS: ErrCode = INT_ERROR_HEADER; break;
  463. case SYS_ERR_UNKNOWN_COMMAND: ErrCode = INT_ERROR_UNKNOWN_OPCODE; break;
  464. case SYS_ERR_RECEIVE_TIMEOUT: ErrCode = INT_ERROR_OTHER; break;
  465. case SYS_ERR_DATA_SIZE: ErrCode = INT_ERROR_DISCORD; break;
  466. case SYS_ERR_MISMATCH: ErrCode = INT_ERROR_OTHER; break;
  467. case SYS_ERR_INVALID_PARA: ErrCode = INT_ERROR_INVALID_DATA; break;
  468. case SYS_ERR_MOVEMENT: ErrCode = INT_ERROR_MOVEMENT; break;
  469. case SYS_ERR_UNAUTHORIZED: ErrCode = INT_ERROR_UNAUTHORIZED; break;
  470. default: ErrCode = INT_ERROR_OTHER; break;
  471. }
  472. switch (m_Req.OpCode)
  473. {
  474. case INT_OP_VMS_POWER_CTL: /* 0x0303 VMS 통신 서버, VMS 전광판 On/Off 제어 */
  475. if (error == SYS_ERR_NONE)
  476. {
  477. Flag = SEND_ACK;
  478. m_Set.Data.Control.Result = CTL_RESULT_SUCC;
  479. }
  480. else
  481. {
  482. Flag = SEND_NACK;
  483. }
  484. bSave = true;
  485. break;
  486. case INT_OP_VMS_PARA_SET: /* 0x0308 VMS 통신 서버, VMS 환경설정정보 전송 */
  487. if (error == SYS_ERR_NONE)
  488. {
  489. Flag = SEND_ACK;
  490. bSave = true;
  491. }
  492. else
  493. {
  494. Flag = SEND_NACK;
  495. }
  496. break;
  497. case INT_OP_VMS_RESET: /* 0x0309 VMS 통신 서버, VMS 제어기 리셋 전송 */
  498. if (error == SYS_ERR_NONE)
  499. {
  500. Flag = SEND_ACK;
  501. m_Set.Data.Control.Result = CTL_RESULT_SUCC;
  502. }
  503. else
  504. {
  505. Flag = SEND_NACK;
  506. }
  507. bSave = true;
  508. break;
  509. default:
  510. Flag = SEND_NONE;
  511. break;
  512. }
  513. if (bSave == true)
  514. {
  515. if ((sResult = SendDbThreadDataMessage(WM_DATA_SAVE, (void *)&m_Set, sizeof(m_Set))) != SYS_ERR_NONE)
  516. {
  517. }
  518. }
  519. if (Flag == SEND_ACK)
  520. {
  521. INT_ACK_RES Ack;
  522. memset(&Ack, 0x00, sizeof(Ack));
  523. Ack.OPCode.Type = INT_TYPE(m_Req.OpCode);
  524. Ack.OPCode.Kind = INT_KIND(m_Req.OpCode);
  525. Ack.MsgSeq = m_Req.MsgSeq;
  526. if ((sResult = AckRes(&Ack, m_Req.ProcessID)) != UDP_ERR_NONE)
  527. {
  528. }
  529. }
  530. else
  531. if (Flag == SEND_NACK)
  532. {
  533. INT_NACK_RES Nack;
  534. memset(&Nack, 0x00, sizeof(Nack));
  535. Nack.OPCode.Type = INT_TYPE(m_Req.OpCode);
  536. Nack.OPCode.Kind = INT_KIND(m_Req.OpCode);
  537. Nack.MsgSeq = m_Req.MsgSeq;
  538. Nack.ErrCode = ErrCode;
  539. if ((sResult = NackRes(&Nack, m_Req.ProcessID)) != UDP_ERR_NONE)
  540. {
  541. }
  542. }
  543. #endif
  544. }
  545. //---------------------------------------------------------------------------
  546. int __fastcall TVMSSThread::SendDbThreadMessage(UINT Msg, int wParam, int lParam)
  547. {
  548. int result;
  549. result = SYS_ERR_OTHER;
  550. if (g_SysInfo->State.CommThreadID != NULL)
  551. {
  552. if (PostThreadMessage(g_SysInfo->State.CommThreadID, Msg, (WPARAM)wParam, (LPARAM)lParam)){
  553. result = SYS_ERR_NONE;
  554. }else{
  555. result = SYS_ERR_INTERNAL;
  556. }
  557. }
  558. return result;
  559. }
  560. //---------------------------------------------------------------------------
  561. int __fastcall TVMSSThread::SendDbThreadDataMessage(UINT Msg, void *pData, int iLen)
  562. {
  563. int nResult;
  564. char *p;
  565. nResult = VERR_OTHER;
  566. if (g_SysInfo->State.CommThreadID != NULL)
  567. {
  568. p = new char[iLen];
  569. if (p != NULL)
  570. {
  571. try
  572. {
  573. memcpy(p, pData, iLen);
  574. if (PostThreadMessage(g_SysInfo->State.CommThreadID, Msg, (WPARAM)p, NULL))
  575. {
  576. nResult = VERR_NONE;
  577. Sleep(50);
  578. }
  579. else
  580. {
  581. nResult = VERR_INTERNAL;
  582. }
  583. }
  584. __finally
  585. {
  586. if (nResult != VERR_NONE)
  587. {
  588. delete []p;
  589. }
  590. }
  591. }
  592. else
  593. {
  594. nResult = VERR_MEMORY_ALLOC;
  595. }
  596. }
  597. return nResult;
  598. }
  599. //---------------------------------------------------------------------------
  600. /*
  601. * 한글을 UTF8 문자열로 변환
  602. * arguments
  603. * void
  604. * return
  605. * void
  606. */
  607. int __fastcall TVMSSThread::Hangul2UTF8String(char *pIn, char *pOut, int outSize)
  608. {
  609. FErrLine = 1;
  610. int result;
  611. UTF8String uStr;
  612. result = 0;
  613. memset(pOut, 0x00, outSize);
  614. if (!pIn)
  615. {
  616. SERROR("Hangul2UTF8String In Data is NULL");
  617. return result;
  618. }
  619. try
  620. {
  621. uStr = UTF8Encode(WideString(pIn));
  622. if (uStr.Length() > outSize)
  623. {
  624. return -1;
  625. }
  626. memcpy(pOut, uStr.c_str(), uStr.Length());
  627. }
  628. catch(Exception &e)
  629. {
  630. SERROR("Hangul2UTF8String exception: [%s], %s", pIn, AnsiString(e.Message).c_str());
  631. }
  632. return result;
  633. }
  634. //---------------------------------------------------------------------------
  635. /*
  636. * UTF8를 한글 문자열로 변환
  637. * arguments
  638. * void
  639. * return
  640. * void
  641. */
  642. int __fastcall TVMSSThread::UTF8String2Hangul(char *pIn, char *pOut, int outSize)
  643. {
  644. FErrLine = 2;
  645. int result;
  646. AnsiString AnsiStr;
  647. result = 0;
  648. memset(pOut, 0x00, outSize);
  649. if (!pIn)
  650. {
  651. SERROR("UTF8String2Hangul In Data is NULL");
  652. return result;
  653. }
  654. try
  655. {
  656. AnsiStr = (AnsiString)UTF8Decode(UTF8String(pIn));
  657. if (AnsiStr.Length() > outSize)
  658. {
  659. return -1;
  660. }
  661. memcpy(pOut, AnsiStr.c_str(), AnsiStr.Length());
  662. }
  663. catch(Exception &e)
  664. {
  665. SERROR("UTF8String2Hangul exception: [%s], %s", pIn, AnsiString(e.Message).c_str());
  666. }
  667. return result;
  668. }
  669. /*--------------------------------------------------------------------------*/
  670. /*
  671. * 패킷 수신
  672. * arguments
  673. * void
  674. * return
  675. * void
  676. */
  677. int __fastcall TVMSSThread::RecvPacket(void *Data, int Len)
  678. {
  679. FErrLine = 3;
  680. int result;
  681. ssize_t stat;
  682. ssize_t length;
  683. DatexDataPacket_t *pMsg = 0; /* Type to decode */
  684. asn_dec_rval_t rval; /* Decoder return value */
  685. long version;
  686. WORD crc;
  687. result = SYS_ERR_NONE;
  688. if (Len > 0)
  689. {
  690. LogData("RECV", (char*)Data, Len);
  691. }
  692. if (m_RxLen)
  693. {
  694. if ((m_RxLen + Len) > SERVER_MAX_PACKET_SIZE) m_RxLen = 0;
  695. memcpy(m_RxBuff + m_RxLen, Data, Len);
  696. m_RxLen += Len;
  697. }
  698. else
  699. {
  700. memcpy(m_RxBuff, Data, Len);
  701. m_RxLen = Len;
  702. m_rTimer = Now();
  703. }
  704. while (m_RxLen >= VMS_MIN_PACKET_SIZE)
  705. {
  706. stat = ASN1C_BerReadLength(m_RxBuff, m_RxLen, &length);
  707. if ((stat != RC_OK) || (length > VMS_MAX_PACKET_SIZE))
  708. {
  709. result = SYS_ERR_INVALID_TAGANDLEN;
  710. break;
  711. }
  712. LINFO("Recv: state[%d], length[%d/%d]", stat, length, m_RxLen);
  713. if (length > m_RxLen)
  714. {
  715. break;
  716. }
  717. /* Decode */
  718. #if 0
  719. rval = ber_decode(0, &asn_DEF_DatexDataPacket, (void **)&pMsg, m_RxBuff, m_RxLen);
  720. #else
  721. rval = ber_decode(0, &asn_DEF_DatexDataPacket, (void **)&pMsg, m_RxBuff, length);
  722. #endif
  723. switch(rval.code)
  724. {
  725. case RC_OK:
  726. if ((rval.consumed == 0) || (pMsg == 0))
  727. {
  728. result = SYS_ERR_DATEXDATAPACKET_DECODE;
  729. break;
  730. }
  731. asn_INTEGER2long(&pMsg->datex_Version_number, &version);
  732. if (version != datex_Version_number_version1)
  733. {
  734. LERROR("SYS_ERR_INVALID_VERSION_NUMBER: %d/%d", version, datex_Version_number_version1);
  735. result = SYS_ERR_INVALID_VERSION_NUMBER;
  736. break;
  737. }
  738. #if 1
  739. crc = ASN1C_MakeCrc16((void *)pMsg->datex_Data.buf, pMsg->datex_Data.size);
  740. if (pMsg->datex_Crc_nbr.size != 2 ||
  741. pMsg->datex_Crc_nbr.buf[0] != HIBYTE(crc) ||
  742. pMsg->datex_Crc_nbr.buf[1] != LOBYTE(crc))
  743. {
  744. result = ASN_ERR_CRC;
  745. break;
  746. }
  747. #endif
  748. /* 패킷 처리 */
  749. result = ProcessRecvPacket((BYTE *)pMsg->datex_Data.buf, pMsg->datex_Data.size);
  750. if (result != SYS_ERR_NONE)
  751. {
  752. SERROR("Receive Packet Error : %d", result);
  753. }
  754. break;
  755. case RC_WMORE:
  756. case RC_FAIL:
  757. default:
  758. result = SYS_ERR_DATEXDATAPACKET_DECODE;
  759. break;
  760. }
  761. if (pMsg)
  762. {
  763. ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
  764. pMsg = 0;
  765. }
  766. if (result != SYS_ERR_NONE)
  767. {
  768. m_RxLen = 0;
  769. break;
  770. }
  771. m_RxLen -= length;
  772. if (m_RxLen < 0) m_RxLen = 0;
  773. if (m_RxLen > 0)
  774. {
  775. memcpy(m_RxBuff, m_RxBuff + length, m_RxLen);
  776. }
  777. } /* end while */
  778. return result;
  779. }
  780. //---------------------------------------------------------------------------
  781. /*
  782. * 수신 패킷 처리
  783. * arguments
  784. * void
  785. * return
  786. * void
  787. */
  788. int __fastcall TVMSSThread::ProcessRecvPacket(BYTE *pBuffer, int Len)
  789. {
  790. FErrLine = 4;
  791. int result, iResult;
  792. C2CAuthenticatedMessage_t *pMsg = 0; /* Type to decode */
  793. asn_dec_rval_t rval; /* Decoder return value */
  794. BYTE cmd;
  795. BYTE pdu;
  796. COMMAND_ARGUMENT arg;
  797. long DataPacket_number;
  798. result = SYS_ERR_OTHER;
  799. /* Decode */
  800. rval = ber_decode(0, &asn_DEF_C2CAuthenticatedMessage, (void **)&pMsg, pBuffer, Len);
  801. switch(rval.code)
  802. {
  803. case RC_OK:
  804. {
  805. if ((rval.consumed == 0) || (pMsg == 0))
  806. {
  807. LERROR("SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE");
  808. result = SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE;
  809. break;
  810. }
  811. /* 공통부분 */
  812. if (pMsg->datex_AuthenticationInfo_text.size != 1 ||
  813. /* pMsg->datex_DataPacket_number < 0 || */
  814. /* pMsg->datex_DataPacket_number > 4294967295 || */
  815. /* pMsg->datex_DataPacketPriority_number < 0 || */
  816. pMsg->datex_DataPacketPriority_number > 10)
  817. {
  818. LERROR("SYS_ERR_C2CAUTHENTICATEDMESSAGE: %d/%d", pMsg->datex_AuthenticationInfo_text.size, pMsg->datex_DataPacketPriority_number);
  819. result = SYS_ERR_C2CAUTHENTICATEDMESSAGE;
  820. break;
  821. }
  822. asn_INTEGER2long(&pMsg->datex_DataPacket_number, &DataPacket_number);
  823. pdu = pMsg->pdu.present;
  824. cmd = pMsg->datex_AuthenticationInfo_text.buf[0];
  825. #if 1
  826. if ((m_LoginFlag == false) && (pdu != PDUs_PR_login))
  827. {
  828. LWARN("SYS_ERR_NOT_LOGIN");
  829. m_Server.State = ST_SECTION;
  830. result = SYS_ERR_NOT_LOGIN;
  831. //break;
  832. }
  833. #endif
  834. #if 0
  835. HeaderOptions_t *options;
  836. /* Header Options */
  837. options = &pMsg->options;
  838. if (options->datex_OriginAddress_location->size == 0 ||
  839. options->datex_DestinationAddress_location->size == 0)
  840. {
  841. result = SYS_ERR_HEADER_OPTIONS;
  842. break;
  843. }
  844. // m_Server.CenterId = NULL
  845. // m_Server.LocalCenterId = NULL
  846. // datex_OriginAddress_location = VM10000002
  847. // datex_DestinationAddress_location = 00000000
  848. if (memcmp(options->datex_OriginAddress_location->buf, m_Server.CenterId.c_str(), options->datex_OriginAddress_location->size) ||
  849. memcmp(options->datex_DestinationAddress_location->buf, m_Server.LocalCenterId.c_str(), options->datex_DestinationAddress_location->size))
  850. {
  851. result = SYS_ERR_ADDRESS;
  852. break;
  853. }
  854. #endif
  855. /* options->datex_Origin_text */
  856. /* options->datex_Sender_text */
  857. /* options->datex_SenderAddress_location */
  858. /* options->datex_Destination_text */
  859. /* options->datex_Cost->amount_Currency_code */
  860. /* options->datex_Cost->amount_Factor_quantity */
  861. /* options->datex_Cost->amount_Quantity_quantity */
  862. /* options->datex_DataPacket_time->time_Year_qty */
  863. /* options->datex_DataPacket_time->time_Month_qty */
  864. /* options->datex_DataPacket_time->time_Day_qty */
  865. /* options->datex_DataPacket_time->time_Hour_qty */
  866. /* options->datex_DataPacket_time->time_Minute_qty */
  867. /* options->datex_DataPacket_time->time_Second_qty */
  868. /* options->datex_DataPacket_time->time_SecondFractions->present */
  869. /* options->datex_DataPacket_time->time_SecondFractions->choice.milliseconds */
  870. /* options->datex_DataPacket_time->time_Timezone->timezone_Hour_qty */
  871. /* options->datex_DataPacket_time->time_Timezone->time_Minute_qty */
  872. switch(pdu)
  873. {
  874. case PDUs_PR_NOTHING:
  875. //FOR YONGIN
  876. LINFO("<<< PDUs_PR_NOTHING 수신xxxxx");
  877. result = SYS_ERR_NONE;
  878. break;
  879. case PDUs_PR_datex_Initiate_null:
  880. //FOR YONGIN
  881. LINFO("<<< PDUs_PR_datex_Initiate_null 수신");
  882. result = SYS_ERR_NONE;
  883. break;
  884. case PDUs_PR_login: /* 서버에 접속하기 위한 클라이언트의 로그인 데이터 패킷 */
  885. LINFO("<<< PDUs_PR_login 수신");
  886. result = PacketLogin(&pMsg->pdu.choice.login, DataPacket_number);
  887. if (result == SYS_ERR_NONE)
  888. {
  889. m_LoginFlag = true;
  890. m_Server.State = ST_SECTION;
  891. }
  892. else
  893. {
  894. LERROR("PacketLogin result Error: %d", result);
  895. }
  896. break;
  897. case PDUs_PR_fred: /* 서버와 클라이언트의 연결을 유지하기 위한 확인 데이터 패킷 */
  898. {
  899. long fred;
  900. asn_INTEGER2long(&pMsg->pdu.choice.fred, &fred);
  901. result = SYS_ERR_NONE;
  902. LINFO("<<< PDUs_PR_fred 수신: %u", fred);
  903. {
  904. //TODO
  905. m_LoginFlag = true;
  906. //m_Server.State = ST_SECTION;
  907. }
  908. m_WatchDogTimer = Now();
  909. }
  910. if (m_FrEDConfirmPacketNumber > 65535) m_FrEDConfirmPacketNumber = 0;
  911. arg.FrED = m_FrEDConfirmPacketNumber++;
  912. if ((iResult = ProcessCommand(AI_FrED, &arg)) != SYS_ERR_NONE)
  913. {
  914. LERROR("AI_FrED Command failed: %d", iResult);
  915. }
  916. break;
  917. case PDUs_PR_terminate: /* 연결을 종료하고자 할 때, 서버에서 클라이언트에 요청하는 데이터 패킷 */
  918. {
  919. //여기는 들어오면 안됌(서버 모듈에서 보내는 메시지임)
  920. LINFO("<<< PDUs_PR_terminate 수신xxxxx");
  921. result = SYS_ERR_NONE;
  922. #if 0
  923. try
  924. {
  925. long terminate;
  926. asn_INTEGER2long(&pMsg->pdu.choice.terminate, &terminate);
  927. result = SYS_ERR_NONE;
  928. LINFO("<<< PDUs_PR_terminate 수신 %u", terminate);
  929. } catch(Exception &e) {}
  930. #endif
  931. }
  932. break;
  933. case PDUs_PR_logout: /* 접속을 종료하기 위한 클라이언트의 로그아웃 데이터 패킷 */
  934. {
  935. long logout;
  936. asn_INTEGER2long(&pMsg->pdu.choice.logout, &logout);
  937. result = SYS_ERR_NONE;
  938. LINFO("<<< PDUs_PR_logout 수신 %d", logout);
  939. }
  940. arg.FrED = m_FrEDConfirmPacketNumber++;
  941. if ((iResult = ProcessCommand(AI_FrED, &arg)) != SYS_ERR_NONE)
  942. {
  943. LERROR("Logout FrED Command failed: %d", iResult);
  944. }
  945. m_Server.State = ST_CLOSE;
  946. result = SYS_ERR_NONE;
  947. break;
  948. case PDUs_PR_subscripiton: /* 클라이언트가 서버에 정보를 요청할 경우 송신하는 데이터 패킷 */
  949. {
  950. LINFO("<<< PDUs_PR_subscripiton 수신");
  951. result = PacketSubscription(&pMsg->pdu.choice.subscripiton);
  952. bool bSubscript = false;
  953. int Message_id = 0;
  954. if (result == SYS_ERR_NONE)
  955. {
  956. long Serial_nbr;
  957. asn_INTEGER2long(&pMsg->pdu.choice.subscripiton.datexSubscribe_Serial_nbr, &Serial_nbr);
  958. arg.Accept.nbr = DataPacket_number;
  959. if (pMsg->pdu.choice.subscripiton.datexSubscribe_Type.present == SubscriptionType_PR_subscription)
  960. {
  961. if (pMsg->pdu.choice.subscripiton.datexSubscribe_Type.choice.subscription.datexSubscribe_Mode.present
  962. == SubscriptionMode_PR_single)
  963. {
  964. arg.Accept.type = datexAccept_Type_PR_single_subscription;
  965. }
  966. else
  967. { /* SubscriptionMode_PR_event_driven, SubscriptionMode_PR_periodic */
  968. arg.Accept.type = datexAccept_Type_PR_registered_subscription;
  969. arg.Accept.sub = Serial_nbr;
  970. Subscription_t *pSubscripiton = &pMsg->pdu.choice.subscripiton;
  971. SubscriptionData_t *pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
  972. if ((Message_id = ASN1C_GetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id)) != -1)
  973. {
  974. //bSubscript = true;
  975. switch(Message_id)
  976. {
  977. case OBJ_RealTimeDisplay: /* 실시간정보표출 */
  978. arg.Accept.nbr = 4;
  979. arg.Accept.sub = 1;
  980. break;
  981. case OBJ_ScheduledDisplay: /* 계획된정보표출 */
  982. arg.Accept.nbr = 5;
  983. arg.Accept.sub = 2;
  984. break;
  985. case OBJ_DownloadGraphicData: /* 그래픽데이터 다운로드 */
  986. arg.Accept.nbr = 6;
  987. arg.Accept.sub = 3;
  988. break;
  989. case OBJ_StatusControl: /* 상태제어 */
  990. arg.Accept.nbr = 7;
  991. arg.Accept.sub = 4;
  992. break;
  993. case OBJ_StatusSetting: /* 상태설정 */
  994. arg.Accept.nbr = 8;
  995. arg.Accept.sub = 5;
  996. break;
  997. }
  998. }
  999. }
  1000. }
  1001. else
  1002. { /* SubscriptionType_PR_datexSubscribe_CancelReason_cd */
  1003. arg.Accept.type = datexAccept_Type_PR_registered_subscription;
  1004. arg.Accept.sub = Serial_nbr;
  1005. }
  1006. if (bSubscript)
  1007. {
  1008. SendSubscriptionAccept(Message_id);
  1009. }
  1010. else
  1011. {
  1012. if ((iResult = ProcessCommand(AI_Accept, &arg)) != SYS_ERR_NONE)
  1013. {
  1014. SERROR("Subscription Accept Command failed: %d", iResult);
  1015. }
  1016. }
  1017. }
  1018. else
  1019. {
  1020. int ErrCode;
  1021. switch(result)
  1022. {
  1023. case SYS_ERR_SUBSCRIPTION_MODE_VALUE:
  1024. ErrCode = datexReject_Subscription_cd_invalid_mode;
  1025. break;
  1026. case SYS_ERR_SUBSCRIPTION_FORMAT_VALUE:
  1027. ErrCode = datexReject_Subscription_cd_publishFormatNotSupported;
  1028. break;
  1029. case SYS_ERR_UNKNOWN_MESSAGE_ID:
  1030. ErrCode = datexReject_Subscription_cd_unknowSubscriptionMsgId;
  1031. break;
  1032. case SYS_ERR_MESSAGE_DECODE:
  1033. ErrCode = datexReject_Subscription_cd_invalidSubscriptionContent;
  1034. break;
  1035. case SYS_ERR_SUBSCRIPTION_STATUS_VALUE:
  1036. case SYS_ERR_SUBSCRIPTION_TYPE:
  1037. default:
  1038. ErrCode = datexReject_Subscription_cd_other;
  1039. }
  1040. /* datexReject_Subscription_cd_unknownSubscriptionNbr */
  1041. /* datexReject_Subscription_cd_invalidTimes */
  1042. /* datexReject_Subscription_cd_frequencyTooSmall */
  1043. /* datexReject_Subscription_cd_frequencyTooLarge */
  1044. /* datexReject_Subscription_cd_invalidSubscriptionMsgId */
  1045. arg.Reject.nbr = DataPacket_number;
  1046. arg.Reject.type = RejectType_PR_datexReject_Subscription_cd;
  1047. arg.Reject.code = ErrCode;
  1048. if((iResult = ProcessCommand(AI_Reject, &arg)) != SYS_ERR_NONE)
  1049. {
  1050. SERROR("Subscription Reject Command failed: %d", iResult);
  1051. }
  1052. }
  1053. }
  1054. break;
  1055. case PDUs_PR_publication:
  1056. // FOR YONGIN
  1057. LINFO("<<< PDUs_PR_publication 수신");
  1058. switch(cmd)
  1059. {
  1060. case AI_GeneralStatusMessage: LINFO(" *** AI_GeneralStatusMessage 수신"); break;
  1061. case AI_PowerStatusMessage: LINFO(" *** AI_PowerStatusMessage 수신"); break;
  1062. case AI_ModuleStatusMessage: LINFO(" *** AI_ModuleStatusMessage 수신"); break;
  1063. case AI_DotStatusMessage: LINFO(" *** AI_DotStatusMessage 수신"); break;
  1064. case AI_ScreenStatusMessage: LINFO(" *** AI_ScreenStatusMessage 수신"); break;
  1065. case AI_DisplayingDataMessage:LINFO(" *** AI_DisplayingDataMessage 수신"); break;
  1066. default: LINFO(" *** PDUs_PR_publication Unknown 수신: %d", cmd); break;
  1067. }
  1068. result = RecvPacketPublication(&pMsg->pdu.choice.publication);
  1069. if (result == SYS_ERR_NONE)
  1070. {
  1071. #if 0
  1072. m_WatchDogTimer = Now();
  1073. arg.Accept = DataPacket_number;
  1074. if((iResult = ProcessCommand(AI_Accept, &arg)) != SYS_ERR_NONE)
  1075. {
  1076. SERROR("Publication Accept Command failed: %d", iResult);
  1077. }
  1078. #endif
  1079. }
  1080. else
  1081. {
  1082. int ErrCode;
  1083. switch(result)
  1084. {
  1085. case SYS_ERR_DATEXPUBLISH_FORMAT:
  1086. ErrCode = datexReject_Publication_cd_invalidPublishFormat;
  1087. break;
  1088. case SYS_ERR_UNKNOWN_MESSAGE_ID:
  1089. ErrCode = datexReject_Publication_cd_unknownPublicationMsgId;
  1090. break;
  1091. case SYS_ERR_DATEXPUBLISH_TYPE:
  1092. ErrCode = datexReject_Publication_cd_invalidPublicationMsgContent;
  1093. break;
  1094. case SYS_ERR_MESSAGE_DECODE:
  1095. ErrCode = datexReject_Publication_cd_invalidPublicationMsgContent;
  1096. break;
  1097. default:
  1098. ErrCode = datexReject_Publication_cd_other;
  1099. }
  1100. /* datexReject_Publication_cd_unknownSubscription */
  1101. /* datexReject_Publication_cd_unknownPublicationNbr */
  1102. /* datexReject_Publication_cd_invalidPublicationMsgId */
  1103. /* datexReject_Publication_cd_repeatedPublicationNbr */
  1104. #if 0
  1105. arg.Reject.nbr = DataPacket_number;
  1106. arg.Reject.code = ErrCode;
  1107. if ((iResult = ProcessCommand(AI_Reject, &arg)) != SYS_ERR_NONE)
  1108. {
  1109. SERROR("Publication Reject Command %d", iResult);
  1110. }
  1111. #endif
  1112. }
  1113. result = SYS_ERR_NONE;
  1114. break;
  1115. case PDUs_PR_transfer_done:
  1116. LINFO("<<< PDUs_PR_transfer_done 수신");
  1117. {
  1118. AnsiString sFormImgId = "";
  1119. TransferDone_t *pTrans = &pMsg->pdu.choice.transfer_done;
  1120. long lv;
  1121. asn_INTEGER2long(&pTrans->datexTransferDone_Publication_nbr, &lv);
  1122. LDEBUG("datexTransferDone_Publication_nbr: %u", lv);
  1123. sFormImgId.printf("%.*s", pTrans->datexTransferDone_FileName_txt.size, pTrans->datexTransferDone_FileName_txt.buf);
  1124. LDEBUG(" datexTransferDone_FileName_txt: %s", sFormImgId.c_str());
  1125. LDEBUG(" datexTransferDone_Sucess_bool: %d", pTrans->datexTransferDone_Sucess_bool);
  1126. result = RecvFormDownResult(sFormImgId);
  1127. if (result != SYS_ERR_NONE)
  1128. {
  1129. LERROR("RecvFormDownResult result Error: %d", result);
  1130. }
  1131. }
  1132. break;
  1133. case PDUs_PR_accept: /* 클라이언트의 요청에 대한 수용 */
  1134. LINFO("<<< PDUs_PR_accept 수신");
  1135. result = PacketAccept(&pMsg->pdu.choice.accept);
  1136. if (result != SYS_ERR_NONE)
  1137. {
  1138. LERROR("PDUs_PR_accept result Error: %d", result);
  1139. }
  1140. break;
  1141. case PDUs_PR_reject: /* 클라이언트의 요청에 대한 거부 */
  1142. LINFO("<<< PDUs_PR_reject 수신");
  1143. result = PacketReject(&pMsg->pdu.choice.reject);
  1144. if (result != SYS_ERR_NONE)
  1145. {
  1146. LERROR("PacketReject result Error: %d", result);
  1147. }
  1148. break;
  1149. default:
  1150. LINFO("<<< Unknown PDUs 수신: pdu(%d), cmd(%d)", pdu, cmd);
  1151. result = SYS_ERR_UNKNOWN_COMMAND;
  1152. break;
  1153. }/* end switch */
  1154. }
  1155. break;
  1156. case RC_WMORE:
  1157. case RC_FAIL:
  1158. default:
  1159. result = SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE;
  1160. break;
  1161. }/* end switch */
  1162. if (pMsg)
  1163. {
  1164. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  1165. }
  1166. if ((result == SYS_ERR_NONE) && (cmd != AI_Reject))
  1167. {
  1168. m_Server.iRetry = VMS_MAX_RETRY_COUNT;
  1169. }
  1170. if (pdu == PDUs_PR_login)
  1171. {
  1172. if (FVmsObj->FSymbolDownload)
  1173. {
  1174. if (FVmsObj->FIsOldProtocol && !FVmsObj->FBmpDownload)
  1175. {
  1176. DownloadSymbolImage();
  1177. }
  1178. }
  1179. }
  1180. return result;
  1181. }
  1182. //---------------------------------------------------------------------------
  1183. /*
  1184. * 수신 패킷 처리
  1185. * arguments
  1186. * void
  1187. * return
  1188. * void
  1189. */
  1190. int __fastcall TVMSSThread::RecvPacketPublication(Publication_t *pPublication)
  1191. {
  1192. FErrLine = 47;
  1193. int result;
  1194. PublicationData_t *pData;
  1195. int i;
  1196. result = SYS_ERR_OTHER;
  1197. /* pPublication->datexPublish_Guaranteed_bool */
  1198. switch(pPublication->datexPublish_Format.present)
  1199. {
  1200. case Publish_Format_PR_datexPublish_Data:
  1201. for(i = 0; i < pPublication->datexPublish_Format.choice.datexPublish_Data.list.count; i++)
  1202. {
  1203. pData = (PublicationData_t *)pPublication->datexPublish_Format.choice.datexPublish_Data.list.array[i];
  1204. if ((result = RecvPacketPublicationData(pData)) != SYS_ERR_NONE)
  1205. {
  1206. break;
  1207. }
  1208. }
  1209. break;
  1210. case Publish_Format_PR_datexPublish_FileName_txt:
  1211. result = SYS_ERR_NONE;
  1212. break;
  1213. default:
  1214. result = SYS_ERR_DATEXPUBLISH_FORMAT;
  1215. break;
  1216. }/* end switch */
  1217. return result;
  1218. }
  1219. //---------------------------------------------------------------------------
  1220. /*
  1221. * 수신 패킷 처리
  1222. * arguments
  1223. * void
  1224. * return
  1225. * void
  1226. */
  1227. int __fastcall TVMSSThread::RecvPacketPublicationData(PublicationData_t *pData)
  1228. {
  1229. FErrLine = 48;
  1230. int result;
  1231. int Message_id;
  1232. int i;
  1233. result = SYS_ERR_OTHER;
  1234. /* pData->datexPublish_SubscribeSerial_nbr */
  1235. /* pData->datexPublish_Serial_nbr */
  1236. /* pData->datexPublish_LatePublicationFlag */
  1237. #if 0
  1238. {
  1239. long lv;
  1240. asn_INTEGER2long(&pData->datexPublish_SubscribeSerial_nbr, &lv);
  1241. LDEBUG("datexPublish_SubscribeSerial_nbr: %u", lv);
  1242. asn_INTEGER2long(&pData->datexPublish_Serial_nbr, &lv);
  1243. LDEBUG(" datexPublish_Serial_nbr: %u", lv);
  1244. LDEBUG("datexPublish_LatePublicationFlag: %d", pData->datexPublish_LatePublicationFlag);
  1245. }
  1246. #endif
  1247. switch(pData->datexPublish_Type.present)
  1248. {
  1249. case PublicationType_PR_datexPublication_Management_cd:
  1250. result = SYS_ERR_NONE;
  1251. break;
  1252. case PublicationType_PR_datexPublish_Data:
  1253. #if 0
  1254. {
  1255. int arcs[10];
  1256. int count, j;
  1257. count = OBJECT_IDENTIFIER_get_arcs(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id,
  1258. arcs, sizeof(int), 10);
  1259. LDEBUG("endApplication_Message_id: %d", count);
  1260. for (j = 0; j < count && j < 10; j++)
  1261. {
  1262. LDEBUG("[%d]: %d", j, arcs[j]);
  1263. }
  1264. }
  1265. #endif
  1266. if ((Message_id = ASN1C_GetObjId(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id)) == -1)
  1267. {
  1268. return SYS_ERR_UNKNOWN_MESSAGE_ID;
  1269. }
  1270. /* pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg */
  1271. switch(Message_id)
  1272. {
  1273. case OBJ_GeneralStatus: /* 기본상태정보 */
  1274. {
  1275. GeneralStatusMessage_t *pGS;
  1276. MessageBodyGeneralStatusMessage_t *pMsg = 0; /* Type to decode */
  1277. /* Decode */
  1278. if (ANY_to_type(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
  1279. &asn_DEF_MessageBodyGeneralStatusMessage,
  1280. (void **)&pMsg) == ASN_ERR_NONE)
  1281. {
  1282. for(i = 0; i < pMsg->list.count; i++)
  1283. {
  1284. pGS = (GeneralStatusMessage_t *)pMsg->list.array[i];
  1285. SaveStateData(pGS);
  1286. }
  1287. LINFO("GeneralStatus Publication Recv %d OK", pMsg->list.count);
  1288. result = VERR_NONE;
  1289. }
  1290. else
  1291. {
  1292. result = SYS_ERR_MESSAGE_DECODE;
  1293. }
  1294. if(pMsg)
  1295. {
  1296. ASN1C_Free(&asn_DEF_MessageBodyGeneralStatusMessage, pMsg);
  1297. }
  1298. //FGenState = true;
  1299. }
  1300. break;
  1301. case OBJ_PowerStatus: /* 전원상태정보 */
  1302. {
  1303. PowerStatusMessage_t *pMS;
  1304. MessageBodyPowerStatusMessage_t *pMsg = 0; /* Type to decode */
  1305. long PowerQty;
  1306. int numbits, bit;
  1307. /* Decode */
  1308. if (ANY_to_type(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
  1309. &asn_DEF_MessageBodyPowerStatusMessage,
  1310. (void **)&pMsg) == ASN_ERR_NONE)
  1311. {
  1312. for(i = 0; i < pMsg->list.count; i++)
  1313. {
  1314. pMS = (PowerStatusMessage_t *)pMsg->list.array[i];
  1315. asn_INTEGER2long(&pMS->power_Qty, &PowerQty);
  1316. numbits = DATEX_NUMBITS(pMS->power_Status);
  1317. LDEBUG("Power Module Count: %d, %d", PowerQty, numbits);
  1318. if (PowerQty != numbits)
  1319. {
  1320. PowerQty = numbits;//양산거는 다르게 나타남
  1321. }
  1322. if (numbits >= INT_VMS_MAX_POWER)
  1323. {
  1324. numbits = INT_VMS_MAX_POWER;
  1325. PowerQty = numbits;
  1326. LERROR("Power size overflow: %d, %d", numbits, INT_VMS_MAX_POWER);
  1327. }
  1328. if (PowerQty == numbits)
  1329. {
  1330. #if 0
  1331. memset((char*)m_pState->PowerStatus, 0x00, sizeof(m_pState->PowerStatus));
  1332. for (bit = 0; bit < numbits; bit++)
  1333. {
  1334. int nOnOff = ASN1C_CheckBitString(&pMS->power_Status, bit);
  1335. if (nOnOff == bit_enable)
  1336. {
  1337. VComm_SetBitString((char*)m_pState->PowerStatus, bit);
  1338. }
  1339. }
  1340. m_pState->PowerCount = PowerQty;
  1341. #endif
  1342. }
  1343. #if 0
  1344. {
  1345. LDEBUG(" module_PowerQty: %d", PowerQty);
  1346. AnsiString sModule = "";
  1347. for (int v = 0; v < PowerQty; v++)
  1348. {
  1349. int nM = VComm_GetBitString((char*)m_pState->PowerStatus, v);
  1350. sModule += String(nM);
  1351. }
  1352. LDEBUG("%s", sModule.c_str());
  1353. }
  1354. #endif
  1355. }/* end for */
  1356. result = VERR_NONE;
  1357. }
  1358. else
  1359. {
  1360. result = SYS_ERR_MESSAGE_DECODE;
  1361. }/* end if */
  1362. if(pMsg)
  1363. {
  1364. ASN1C_Free(&asn_DEF_MessageBodyPowerStatusMessage, pMsg);
  1365. }
  1366. //FPowState = true;
  1367. }
  1368. break;
  1369. case OBJ_ModuleStatus: /* 모듈상태정보 */
  1370. {
  1371. ModuleStatusMessage_t *pMS;
  1372. MessageBodyModuleStatusMessage_t *pMsg = 0; /* Type to decode */
  1373. long Horizontal, Vertical;
  1374. int numbits, bit;
  1375. BYTE ModuleState;
  1376. /* Decode */
  1377. if (ANY_to_type(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
  1378. &asn_DEF_MessageBodyModuleStatusMessage,
  1379. (void **)&pMsg) == ASN_ERR_NONE)
  1380. {
  1381. for(i = 0; i < pMsg->list.count; i++)
  1382. {
  1383. pMS = (ModuleStatusMessage_t *)pMsg->list.array[i];
  1384. asn_INTEGER2long(&pMS->module_HorizontalQty, &Horizontal);
  1385. asn_INTEGER2long(&pMS->module_VerticalQty, &Vertical);
  1386. numbits = DATEX_NUMBITS(pMS->module_Status);
  1387. if (numbits >= INT_VMS_MAX_MODULE)
  1388. {
  1389. numbits = INT_VMS_MAX_MODULE;
  1390. LERROR("Module size overflow: %d, %d", numbits, INT_VMS_MAX_MODULE);
  1391. }
  1392. #if 0
  1393. memset((char*)m_pState->ModuleStatus, 0x00, sizeof(m_pState->ModuleStatus));
  1394. if ((Horizontal * Vertical) == numbits)
  1395. {
  1396. ModuleState = vms_normal;
  1397. for (bit = 0; bit < numbits; bit++)
  1398. {
  1399. int nOnOff = ASN1C_CheckBitString(&pMS->module_Status, bit);
  1400. if (nOnOff == bit_disable)
  1401. {
  1402. ModuleState = vms_error;
  1403. }
  1404. else
  1405. {
  1406. VComm_SetBitString((char*)m_pState->ModuleStatus, bit);
  1407. }
  1408. }
  1409. if ((m_pState != NULL) && (numbits < INT_VMS_MAX_MODULE))
  1410. {
  1411. m_pState->ModuleHorizontal = Horizontal;
  1412. m_pState->ModuleVertical = Vertical;
  1413. }
  1414. }
  1415. else
  1416. {
  1417. ModuleState = vms_unknown;
  1418. m_pState->ModuleHorizontal = 0;
  1419. m_pState->ModuleVertical = 0;
  1420. }
  1421. m_pState->ModuleState = ModuleState;
  1422. if (FLogFile->FLogCfg.Debug)
  1423. {
  1424. LDEBUG(" module_VerticalQty x HorizontalQty(Cnt): %d x %d (%d)", Vertical, Horizontal, numbits);
  1425. //LDEBUG(" module_HorizontalQty: %d", Horizontal);
  1426. //LDEBUG("module_Status numbits: %d", numbits);
  1427. for (int v = 0, bit=0; v < Vertical; v++)
  1428. {
  1429. AnsiString sModule = "";
  1430. for(int h = 0; h < Horizontal; h++)
  1431. {
  1432. int nM = VComm_GetBitString((char*)m_pState->ModuleStatus, v*h);
  1433. sModule += String(nM);
  1434. }
  1435. LDEBUG("%d, %s", v, sModule.c_str());
  1436. }
  1437. }
  1438. #endif
  1439. }/* end for */
  1440. result = SYS_ERR_NONE;
  1441. }
  1442. else
  1443. {
  1444. result = SYS_ERR_MESSAGE_DECODE;
  1445. }/* end if */
  1446. if(pMsg)
  1447. {
  1448. ASN1C_Free(&asn_DEF_MessageBodyModuleStatusMessage, pMsg);
  1449. }
  1450. //FModState = true;
  1451. }
  1452. break;
  1453. case OBJ_DotStatus: /* 도트상태정보 */
  1454. result = SYS_ERR_NONE;
  1455. break;
  1456. case OBJ_ScreenStatus: /* 표출상태정보 */
  1457. result = SYS_ERR_NONE;
  1458. break;
  1459. case OBJ_DisplayingData: /* 표출정보 */
  1460. result = SYS_ERR_NONE;
  1461. break;
  1462. default:
  1463. result = SYS_ERR_UNKNOWN_MESSAGE_ID;
  1464. break;
  1465. }/* end switch */
  1466. #if 0
  1467. if (FGenState && FModState && FPowState)
  1468. {
  1469. FGenState = FModState = FPowState = false;
  1470. POST_MSG(MAINHANDLE, WM_VMS_THREAD, WM_VMS_STATE_STTS, (int)FVmsObj);
  1471. }
  1472. #endif
  1473. break;
  1474. default:
  1475. result = SYS_ERR_DATEXPUBLISH_TYPE;
  1476. break;
  1477. }
  1478. return result;
  1479. }
  1480. //---------------------------------------------------------------------------
  1481. int __fastcall TVMSSThread::SaveStateData(GeneralStatusMessage_t *pGS)
  1482. {
  1483. FErrLine = 42;
  1484. int result;
  1485. long lv;
  1486. result = SYS_ERR_OTHER;
  1487. // if (m_pState == NULL) return result;
  1488. // m_pState->Cpsw.Enable = bit_enable;
  1489. // m_pState->CollectDate = Now().FormatString("yyyymmddhhnnss");
  1490. #if 0
  1491. asn_INTEGER2long(&pGS->door_StatusCode, &lv);
  1492. switch(lv)
  1493. {
  1494. case door_StatusCode_closed: m_pState->DoorStatus = vms_close; break;
  1495. case door_StatusCode_open : m_pState->DoorStatus = vms_open; break;
  1496. default : m_pState->DoorStatus = vms_unknown; break;
  1497. }
  1498. LDEBUG(" door_StatusCode: %u, %d", lv, m_pState->DoorStatus);
  1499. asn_INTEGER2long(&pGS->modulePower_StatusCode, &lv);
  1500. m_pState->ModulePowerStatus = lv;
  1501. switch(lv)
  1502. {
  1503. case modulePower_StatusCode_off: m_pState->ModulePowerStatus = vms_off; break;
  1504. case modulePower_StatusCode_on : m_pState->ModulePowerStatus = vms_on; break;
  1505. default : m_pState->ModulePowerStatus = vms_unknown; break;
  1506. }
  1507. LDEBUG("modulePower_StatusCode: %u, %d", lv, m_pState->ModulePowerStatus);
  1508. asn_INTEGER2long(&pGS->body_TemperatureQty, &lv);
  1509. m_pState->BodyTemp = lv;
  1510. LDEBUG(" body_TemperatureQty: %u, %d", lv, m_pState->BodyTemp);
  1511. asn_INTEGER2long(&pGS->luminance_StatusQty, &lv);
  1512. m_pState->LuminanceStatus = lv;
  1513. LDEBUG(" luminance_StatusQty: %u, %d", lv, m_pState->LuminanceStatus);
  1514. asn_INTEGER2long(&pGS->fan_StatusCode, &lv);
  1515. m_pState->FanStatus = lv;
  1516. switch(lv)
  1517. {
  1518. case fan_StatusCode_off: m_pState->FanStatus = vms_off; break;
  1519. case fan_StatusCode_on : m_pState->FanStatus = vms_on; break;
  1520. default : m_pState->FanStatus = vms_unknown; break;
  1521. }
  1522. LDEBUG(" fan_StatusCode: %u, %d", lv, m_pState->FanStatus);
  1523. asn_INTEGER2long(&pGS->heater_StatusCode, &lv);
  1524. m_pState->HeaterStatus = lv;
  1525. switch(lv)
  1526. {
  1527. case heater_StatusCode_off: m_pState->HeaterStatus = vms_off; break;
  1528. case heater_StatusCode_on : m_pState->HeaterStatus = vms_on; break;
  1529. default : m_pState->HeaterStatus = vms_unknown; break;
  1530. }
  1531. LDEBUG(" heater_StatusCode: %u, %d", lv, m_pState->HeaterStatus);
  1532. result = SYS_ERR_NONE;
  1533. {
  1534. if (pGS->externalLight_StatusCode) {
  1535. asn_INTEGER2long(pGS->externalLight_StatusCode, &lv);
  1536. m_pState->ExternalLightStatus = lv;
  1537. LDEBUG("externalLight_StatusCode: %u", lv);
  1538. }
  1539. if (pGS->alarmLight_StatusCode) {
  1540. asn_INTEGER2long(pGS->alarmLight_StatusCode, &lv);
  1541. m_pState->AlarmLightStatus = lv;
  1542. LDEBUG("alarmLight_StatusCode: %u", lv);
  1543. }
  1544. if (pGS->speaker_StatusCode) {
  1545. asn_INTEGER2long(pGS->speaker_StatusCode, &lv);
  1546. m_pState->SpeakerStatus = lv;
  1547. LDEBUG("speaker_StatusCode: %u", lv);
  1548. }
  1549. if (pGS->controller_CurrentTime) {
  1550. sprintf((char*)m_pState->ControllerCurrentTime, ".*s", pGS->controller_CurrentTime->size, pGS->controller_CurrentTime->buf);
  1551. LDEBUG("controller_CurrentTime: %.*s", pGS->controller_CurrentTime->size, pGS->controller_CurrentTime->buf);
  1552. }
  1553. asn_INTEGER2long(&pGS->scheduledmessage_OperatingTime, &lv);
  1554. m_pState->ScheduledMessageOperatingTime = lv;
  1555. LDEBUG("scheduledmessage_OperatingTime: %u", lv);
  1556. asn_INTEGER2long(&pGS->module_OperatingTemperatureQty, &lv);
  1557. m_pState->ModuleOperatingTemperature = lv;
  1558. LDEBUG("module_OperatingTemperatureQty: %u", lv);
  1559. asn_INTEGER2long(&pGS->fan_OperatingTemperatureQty, &lv);
  1560. m_pState->FanOperatingTemperature = lv;
  1561. LDEBUG(" fan_OperatingTemperatureQty: %u", lv);
  1562. asn_INTEGER2long(&pGS->heater_OperatingTemperatureQty, &lv);
  1563. m_pState->HeaterOperatingTemperature = lv;
  1564. LDEBUG("heater_OperatingTemperatureQty: %u", lv);
  1565. if (pGS->externalLight_OperatingLuminanceQty) {
  1566. asn_INTEGER2long(pGS->externalLight_OperatingLuminanceQty, &lv);
  1567. m_pState->ExternalLightOperatingLuminance = lv;
  1568. LDEBUG("externalLight_OperatingLuminanceQty: %u", lv);
  1569. }
  1570. //아래존재함
  1571. if (pGS->module_BasicFailureRate) {
  1572. asn_INTEGER2long(pGS->module_BasicFailureRate, &lv);
  1573. m_pState->ModuleBasicFailureRate = lv;
  1574. LDEBUG(" module_BasicFailureRate: %u", lv);
  1575. }
  1576. if (pGS->maximum_RetryQty) {
  1577. asn_INTEGER2long(pGS->maximum_RetryQty, &lv);
  1578. m_pState->MaximumRetry = lv;
  1579. LDEBUG("maximum_RetryQty: %u", lv);
  1580. }
  1581. if (pGS->response_TimeOutQty) {
  1582. asn_INTEGER2long(pGS->response_TimeOutQty, &lv);
  1583. m_pState->ResponseTimeOut = lv;
  1584. LDEBUG("response_TimeOutQty: %u", lv);
  1585. }
  1586. if (pGS->blinking_CycleTime) {
  1587. asn_INTEGER2long(pGS->blinking_CycleTime, &lv);
  1588. m_pState->BlinkingCycleTime = lv;
  1589. LDEBUG("blinking_CycleTime: %u", lv);
  1590. }
  1591. }
  1592. #endif
  1593. return result;
  1594. }
  1595. //---------------------------------------------------------------------------
  1596. /*
  1597. * 수신 패킷 처리
  1598. * arguments
  1599. * void
  1600. * return
  1601. * void
  1602. */
  1603. int __fastcall TVMSSThread::PacketLogin(Login_t *pLogin, DWORD nbr)
  1604. {
  1605. FErrLine = 5;
  1606. int result, iResult;
  1607. int ErrCode;
  1608. COMMAND_ARGUMENT arg;
  1609. result = SYS_ERR_NONE;
  1610. ErrCode = datexReject_Login_cd_other;
  1611. #if 0
  1612. {
  1613. long lv;
  1614. int arcs[10];
  1615. int count, i, j;
  1616. OBJECT_IDENTIFIER_t *pOid;
  1617. LDEBUG(" datex_Sender_txt : %s", pLogin->datex_Sender_txt.buf);
  1618. LDEBUG(" datex_Destinatin_txt : %s", pLogin->datex_Destinatin_txt.buf);
  1619. LDEBUG(" datexLogin_UserName_txt : %s", pLogin->datexLogin_UserName_txt.buf);
  1620. LDEBUG(" datexLogin_Password_txt : %s", pLogin->datexLogin_Password_txt.buf);
  1621. /*
  1622. for (i = 0; i < pLogin->datexLogin_EncodingRules_id_zz.list.count; i++)
  1623. {
  1624. LDEBUG(" datexLogin_EncodingRules_id: [%d]", i);
  1625. pOid = (OBJECT_IDENTIFIER_t *)pLogin->datexLogin_EncodingRules_id_zz.list.array[i];
  1626. count = OBJECT_IDENTIFIER_get_arcs(pOid, arcs, sizeof(int), 10);
  1627. for (j = 0; j < count && j < 10; j++)
  1628. {
  1629. LDEBUG("[%d]: %d", j, arcs[j]);
  1630. }
  1631. }
  1632. */
  1633. LDEBUG("datexLogin_HearteatDurationMax_qty : %d", pLogin->datexLogin_HearteatDurationMax_qty);
  1634. LDEBUG(" datexLogin_ResponseTimeOut_qty : %d", pLogin->datexLogin_ResponseTimeOut_qty);
  1635. asn_INTEGER2long(&pLogin->datexLogin_Initiator_cd, &lv);
  1636. LDEBUG(" datexLogin_Initiator_cd : %d", lv);
  1637. LDEBUG(" datexLogin_DatagramSize_qty : %d", pLogin->datexLogin_DatagramSize_qty);
  1638. }
  1639. #endif
  1640. // m_Server.DomainNm = VMS ID
  1641. // m_Server.LocalDomainNm = 00000000
  1642. if (memcmp(pLogin->datex_Sender_txt.buf, m_Server.DomainNm.c_str(), m_Server.DomainNm.Length()) ||
  1643. memcmp(pLogin->datex_Destinatin_txt.buf, m_Server.LocalDomainNm.c_str(), m_Server.LocalDomainNm.Length()))
  1644. {
  1645. LERROR("Login: Domain(%s - %s)", m_Server.DomainNm.c_str(), pLogin->datex_Sender_txt.buf);
  1646. LERROR("Login: Destnation(%s - %s)", m_Server.LocalDomainNm.c_str(), pLogin->datex_Destinatin_txt.buf);
  1647. if (LOGIN_CHECK)
  1648. {
  1649. result = SYS_ERR_MISMATCH_DESTINATION_TEXT;
  1650. ErrCode = datexReject_Login_cd_unknownDomainName;
  1651. }
  1652. }
  1653. // m_Server.UserName = 00000000
  1654. // m_Server.UserPasswd = 00000000
  1655. if (memcmp(pLogin->datexLogin_UserName_txt.buf, m_Server.UserName.c_str(), m_Server.UserName.Length()) ||
  1656. memcmp(pLogin->datexLogin_Password_txt.buf, m_Server.UserPasswd.c_str(), m_Server.UserPasswd.Length()))
  1657. {
  1658. LERROR("Login: UserName(%s - %s)", m_Server.UserName.c_str(), pLogin->datexLogin_UserName_txt.buf);
  1659. LERROR("Login: Password(%s - %s)", m_Server.UserPasswd.c_str(), pLogin->datexLogin_Password_txt.buf);
  1660. if (LOGIN_CHECK)
  1661. {
  1662. result = SYS_ERR_DATEXLOGIN_VALUE;
  1663. ErrCode = datexReject_Login_cd_invalidNamePassword;
  1664. }
  1665. }
  1666. if (pLogin->datexLogin_HearteatDurationMax_qty < 10)
  1667. {
  1668. LERROR("HearteatDurationMax: [Require >= 10] ==> %d", pLogin->datexLogin_HearteatDurationMax_qty);
  1669. if (LOGIN_CHECK)
  1670. {
  1671. result = SYS_ERR_DATEXLOGIN_VALUE;
  1672. ErrCode = datexReject_Login_cd_heartbeatTooSmall;
  1673. }
  1674. else
  1675. pLogin->datexLogin_HearteatDurationMax_qty = 10;
  1676. }
  1677. if (pLogin->datexLogin_HearteatDurationMax_qty > 1000)
  1678. {
  1679. LERROR("HearteatDurationMax_qty: [Require <= 1000] ==> %d", pLogin->datexLogin_HearteatDurationMax_qty);
  1680. if (LOGIN_CHECK)
  1681. {
  1682. result = SYS_ERR_DATEXLOGIN_VALUE;
  1683. ErrCode = datexReject_Login_cd_heartbeatTooLarge;
  1684. }
  1685. else
  1686. pLogin->datexLogin_HearteatDurationMax_qty = 1000;
  1687. }
  1688. if (pLogin->datexLogin_HearteatDurationMax_qty > FWatchDogTime)
  1689. {
  1690. FWatchDogTime = pLogin->datexLogin_HearteatDurationMax_qty + 5;
  1691. }
  1692. if (pLogin->datexLogin_ResponseTimeOut_qty < 3)
  1693. {
  1694. LERROR("ResponseTimeOut_qty: [Require >= 3] ==> %d", pLogin->datexLogin_ResponseTimeOut_qty);
  1695. if (LOGIN_CHECK)
  1696. {
  1697. result = SYS_ERR_DATEXLOGIN_VALUE;
  1698. ErrCode = datexReject_Login_cd_timeoutTooSmall;
  1699. }
  1700. else
  1701. pLogin->datexLogin_ResponseTimeOut_qty = 3;
  1702. }
  1703. if (pLogin->datexLogin_ResponseTimeOut_qty > 120)
  1704. {
  1705. LERROR("ResponseTimeOut_qty: [Require <= 120] ==> %d", pLogin->datexLogin_ResponseTimeOut_qty);
  1706. if (LOGIN_CHECK)
  1707. {
  1708. result = SYS_ERR_DATEXLOGIN_VALUE;
  1709. ErrCode = datexReject_Login_cd_timeoutTooLarge;
  1710. }
  1711. else
  1712. pLogin->datexLogin_ResponseTimeOut_qty = 120;
  1713. }
  1714. #if 0
  1715. if ((pLogin->datexLogin_Initiator_cd != datexLogin_Initiator_cd_clientInitiated) &&
  1716. (pLogin->datexLogin_Initiator_cd != datexLogin_Initiator_cd_serverInitiated))
  1717. {
  1718. result = SYS_ERR_DATEXLOGIN_VALUE;
  1719. ErrCode = datexReject_Login_cd_other;
  1720. }
  1721. if ((pLogin->datexLogin_DatagramSize_qty < 0) ||
  1722. (pLogin->datexLogin_DatagramSize_qty > 65535))
  1723. {
  1724. result = SYS_ERR_DATEXLOGIN_VALUE;
  1725. ErrCode = datexReject_Login_cd_other;
  1726. }
  1727. #endif
  1728. if (result == SYS_ERR_NONE)
  1729. {
  1730. m_Server.MaxHeartbeatTime = pLogin->datexLogin_HearteatDurationMax_qty;
  1731. m_Server.TimeOut = pLogin->datexLogin_ResponseTimeOut_qty;
  1732. m_Server.DatagramSize = pLogin->datexLogin_DatagramSize_qty;
  1733. arg.Accept.nbr = nbr;
  1734. arg.Accept.type = datexAccept_Type_PR_logIn;
  1735. if((iResult = ProcessCommand(AI_Accept, &arg)) != SYS_ERR_NONE)
  1736. {
  1737. SERROR("Login Accept Command failed: %d", iResult);
  1738. }
  1739. }
  1740. else
  1741. {
  1742. arg.Reject.nbr = nbr;
  1743. arg.Reject.type = RejectType_PR_datexReject_Login_cd;
  1744. arg.Reject.code = ErrCode;
  1745. if((iResult = ProcessCommand(AI_Reject, &arg)) != SYS_ERR_NONE)
  1746. {
  1747. SERROR("Login Reject Command failed: %d", iResult);
  1748. }
  1749. }
  1750. return result;
  1751. }
  1752. //---------------------------------------------------------------------------
  1753. /*
  1754. * 수신 패킷 처리
  1755. * arguments
  1756. * void
  1757. * return
  1758. * void
  1759. */
  1760. int __fastcall TVMSSThread::PacketSubscription(Subscription_t *pSubscripiton)
  1761. {
  1762. FErrLine = 6;
  1763. int result;
  1764. SubscriptionData_t *pData;
  1765. long Serial_nbr;
  1766. long Status;
  1767. long PublishFormat;
  1768. int flag;
  1769. int Message_id;
  1770. result = SYS_ERR_OTHER;
  1771. #if 0
  1772. {
  1773. long lv;
  1774. asn_INTEGER2long(&pSubscripiton->datexSubscribe_Serial_nbr, &lv);
  1775. LDEBUG("datexSubscribe_Serial_nbr: %u", lv);
  1776. LDEBUG("datexSubscribe_Type: %d", pSubscripiton->datexSubscribe_Type.present);
  1777. switch(pSubscripiton->datexSubscribe_Type.present)
  1778. {
  1779. case SubscriptionType_PR_subscription:
  1780. pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
  1781. LDEBUG("datexSubscribe_Persistent_bool: %d", pData->datexSubscribe_Persistent_bool);
  1782. asn_INTEGER2long(&pData->datexSubscribe_Status_cd, &lv);
  1783. LDEBUG("datexSubscribe_Status_cd: %d", lv);
  1784. LDEBUG("datexSubscribe_Mode: %d", pData->datexSubscribe_Mode.present);
  1785. switch(pData->datexSubscribe_Mode.present){
  1786. case SubscriptionMode_PR_single:
  1787. break;
  1788. case SubscriptionMode_PR_event_driven:
  1789. case SubscriptionMode_PR_periodic:
  1790. {
  1791. Registered_t *pRegistered;
  1792. int numbits, bit;
  1793. if(pData->datexSubscribe_Mode.present == SubscriptionMode_PR_event_driven){
  1794. pRegistered = &pData->datexSubscribe_Mode.choice.event_driven;
  1795. }else{
  1796. pRegistered = &pData->datexSubscribe_Mode.choice.periodic;
  1797. }
  1798. LDEBUG("Registered: %d", pRegistered->present);
  1799. switch(pRegistered->present)
  1800. {
  1801. case Registered_PR_continuous:
  1802. LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.continuous.datexRegistered_UpdateDelay_qty);
  1803. if(pRegistered->choice.continuous.datexRegistered_StartTime){
  1804. LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_StartTime);
  1805. }
  1806. if(pRegistered->choice.continuous.datexRegistered_EndTime){
  1807. LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_EndTime);
  1808. }
  1809. break;
  1810. case Registered_PR_daily:
  1811. LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.daily.datexRegistered_UpdateDelay_qty);
  1812. numbits = DATEX_NUMBITS(pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd);
  1813. LDEBUG("datexRegistered_DaysOfWeek_cd numbits: %d", numbits);
  1814. for (bit = 0; bit < numbits; bit++)
  1815. {
  1816. LDEBUG("[%d]: %d", bit, ASN1C_CheckBitString(&pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd, bit));
  1817. }
  1818. if (pRegistered->choice.daily.datexRegistered_StartDate)
  1819. {
  1820. LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartDate);
  1821. }
  1822. if (pRegistered->choice.daily.datexRegistered_EndDate)
  1823. {
  1824. LOG_WriteTime(pRegistered->choice.daily.datexRegistered_EndDate);
  1825. }
  1826. if (pRegistered->choice.daily.datexRegistered_StartTime)
  1827. {
  1828. LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartTime);
  1829. }
  1830. if (pRegistered->choice.daily.datexRegistered_Duration_qty)
  1831. {
  1832. LDEBUG("datexRegistered_Duration_qty: %u", *pRegistered->choice.daily.datexRegistered_Duration_qty);
  1833. }
  1834. break;
  1835. default:
  1836. LDEBUG("Unknown Registered %d", pRegistered->present);
  1837. break;
  1838. }/* end swtich */
  1839. }
  1840. break;
  1841. default :
  1842. LDEBUG("Unknown datexSubscribe_Mode %d", pData->datexSubscribe_Mode.present);
  1843. break;
  1844. }/* end switch */
  1845. asn_INTEGER2long(&pData->datexSubscribe_PublishFormat_cd, &lv);
  1846. LDEBUG("datexSubscribe_PublishFormat_cd: %d", lv);
  1847. LDEBUG("datexSubscription_Priority_nbr: %d", pData->datexSubscription_Priority_nbr);
  1848. LDEBUG("datexSubscribe_Guarantee_bool: %d", pData->datexSubscribe_Guarantee_bool);
  1849. break;
  1850. case SubscriptionType_PR_datexSubscribe_CancelReason_cd:
  1851. LDEBUG("datexSubscribe_CancelReason_cd: %d", pSubscripiton->datexSubscribe_Type.choice.datexSubscribe_CancelReason_cd);
  1852. break;
  1853. default:
  1854. LDEBUG("Unknown datexSubscribe_Type %d", pSubscripiton->datexSubscribe_Type.present);
  1855. break;
  1856. }/* end switch */
  1857. }
  1858. #endif
  1859. asn_INTEGER2long(&pSubscripiton->datexSubscribe_Serial_nbr, &Serial_nbr);
  1860. switch(pSubscripiton->datexSubscribe_Type.present)
  1861. {
  1862. case SubscriptionType_PR_subscription:
  1863. pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
  1864. /* pData->datexSubscribe_Persistent_bool */
  1865. asn_INTEGER2long(&pData->datexSubscribe_Status_cd, &Status);
  1866. switch(Status){
  1867. case datexSubscribe_Status_cd_new:
  1868. break;
  1869. case datexSubscribe_Status_cd_update:
  1870. break;
  1871. default:
  1872. return SYS_ERR_SUBSCRIPTION_STATUS_VALUE;
  1873. }
  1874. switch(pData->datexSubscribe_Mode.present){
  1875. case SubscriptionMode_PR_single:
  1876. flag = SubscriptionMode_PR_single;
  1877. break;
  1878. case SubscriptionMode_PR_event_driven:
  1879. flag = SubscriptionMode_PR_event_driven;
  1880. /* pData->datexSubscribe_Mode.choice.event_driven */
  1881. break;
  1882. case SubscriptionMode_PR_periodic:
  1883. flag = SubscriptionMode_PR_periodic;
  1884. /* pData->datexSubscribe_Mode.choice.periodic */
  1885. break;
  1886. default:
  1887. return SYS_ERR_SUBSCRIPTION_MODE_VALUE;
  1888. }
  1889. asn_INTEGER2long(&pData->datexSubscribe_PublishFormat_cd, &PublishFormat);
  1890. switch(PublishFormat)
  1891. {
  1892. #if 0
  1893. case datexSubscribe_PublishFormat_cd_other:
  1894. break;
  1895. case datexSubscribe_PublishFormat_cd_ftp:
  1896. break;
  1897. case datexSubscribe_PublishFormat_cd_tftp:
  1898. break;
  1899. #endif
  1900. case datexSubscribe_PublishFormat_cd_dataPacket:
  1901. break;
  1902. default:
  1903. return SYS_ERR_SUBSCRIPTION_FORMAT_VALUE;
  1904. }
  1905. /* pData->datexSubscription_Priority_nbr */
  1906. /* pData->datexSubscribe_Guarantee_bool */
  1907. if ((Message_id = ASN1C_GetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id)) == -1)
  1908. {
  1909. return SYS_ERR_UNKNOWN_MESSAGE_ID;
  1910. }
  1911. switch(Message_id)
  1912. {
  1913. case OBJ_RealTimeDisplay: /* 실시간정보표출 */
  1914. {
  1915. LINFO(" *** OBJ_RealTimeDisplay 수신");
  1916. result = SYS_ERR_NONE;
  1917. }
  1918. break;
  1919. case OBJ_ScheduledDisplay: /* 계획된정보표출 */
  1920. LINFO(" *** OBJ_ScheduledDisplay 수신");
  1921. result = SYS_ERR_NONE;
  1922. break;
  1923. case OBJ_DownloadGraphicData: /* 그래픽데이터 다운로드 */
  1924. LINFO(" *** OBJ_DownloadGraphicData 수신");
  1925. result = SYS_ERR_NONE;
  1926. break;
  1927. case OBJ_StatusControl: /* 상태제어 */
  1928. LINFO(" *** OBJ_StatusControl 수신");
  1929. result = SYS_ERR_NONE;
  1930. break;
  1931. case OBJ_StatusSetting: /* 상태설정 */
  1932. LINFO(" *** OBJ_StatusSetting 수신");
  1933. result = SYS_ERR_NONE;
  1934. break;
  1935. //FOR YONGIN
  1936. case OBJ_GeneralStatus:// = 6, /* 기본상태정보 */
  1937. LINFO(" *** OBJ_GeneralStatus 수신");
  1938. result = SYS_ERR_NONE;
  1939. break;
  1940. case OBJ_PowerStatus:// = 7, /* 전원상태정보 */
  1941. LINFO(" *** OBJ_PowerStatus 수신");
  1942. result = SYS_ERR_NONE;
  1943. break;
  1944. case OBJ_ModuleStatus:// = 8, /* 모듈상태정보 */
  1945. LINFO(" *** OBJ_ModuleStatus 수신");
  1946. result = SYS_ERR_NONE;
  1947. break;
  1948. case OBJ_DotStatus:// = 9, /* 도트상태정보 */
  1949. LINFO(" *** OBJ_DotStatus 수신");
  1950. result = SYS_ERR_NONE;
  1951. break;
  1952. case OBJ_ScreenStatus:// = 10, /* 표출상태정보 */
  1953. LINFO(" *** OBJ_ScreenStatus 수신");
  1954. result = SYS_ERR_NONE;
  1955. break;
  1956. case OBJ_DisplayingData:// = 11 /* 표출정보 */
  1957. LINFO(" *** OBJ_DisplayingData 수신");
  1958. result = SYS_ERR_NONE;
  1959. break;
  1960. //END YONGIN
  1961. default:
  1962. SERROR(" *** Unknown Subscription message: %d 수신", Message_id);
  1963. result = SYS_ERR_UNKNOWN_MESSAGE_ID;
  1964. break;
  1965. }
  1966. break;
  1967. case SubscriptionType_PR_datexSubscribe_CancelReason_cd:
  1968. result = SYS_ERR_NONE;
  1969. break;
  1970. default:
  1971. SERROR(" *** Unknown Subscription Recv: %d", pSubscripiton->datexSubscribe_Type.present);
  1972. result = SYS_ERR_SUBSCRIPTION_TYPE;
  1973. break;
  1974. }/* end switch */
  1975. return result;
  1976. }
  1977. //---------------------------------------------------------------------------
  1978. /*
  1979. * 수신 패킷 처리
  1980. * arguments
  1981. * void
  1982. * return
  1983. * void
  1984. */
  1985. int __fastcall TVMSSThread::PacketAccept(Accept_t *pAccept)
  1986. {
  1987. FErrLine = 7;
  1988. int result, sResult;
  1989. long nbr;
  1990. result = VERR_OTHER;
  1991. asn_INTEGER2long(&pAccept->datexAccept_Packet_nbr, &nbr);
  1992. switch(pAccept->datexAccept_Type.present)
  1993. {
  1994. /*
  1995. case datexAccept_Type_PR_logIn:
  1996. break;
  1997. case datexAccept_Type_PR_single_subscription:
  1998. break;
  1999. case datexAccept_Type_PR_registered_subscription:
  2000. break;
  2001. */
  2002. case datexAccept_Type_PR_publication:
  2003. #if 0
  2004. if ((m_Server.State != ST_LOCAL_WAIT) &&
  2005. (m_Server.State != ST_CLIENT_WAIT))
  2006. {
  2007. result = SYS_ERR_MISMATCH;
  2008. break;
  2009. }
  2010. #endif
  2011. /* if (nbr == (long)FSvrCtl.DataPacketNumber) */
  2012. {
  2013. if (FSvrCtl.obj == OBJ_RealTimeDisplay)
  2014. {
  2015. m_pVmsFormList->Lock();
  2016. try
  2017. {
  2018. TVmsForm *pVmsForm = m_pVmsFormList->GetItem(FSvrCtl.Idx);
  2019. if (pVmsForm)
  2020. {
  2021. pVmsForm->SvcRes = true;
  2022. }
  2023. else
  2024. {
  2025. //
  2026. }
  2027. }
  2028. __finally
  2029. {
  2030. m_pVmsFormList->UnLock();
  2031. }
  2032. }
  2033. else
  2034. if (FSvrCtl.obj == OBJ_ScheduledDisplay)
  2035. {
  2036. SAVE_STRUCT ProvideSave;
  2037. memset(&ProvideSave, 0x00, sizeof(ProvideSave));
  2038. ProvideSave.Type = save_provide;
  2039. ProvideSave.Count = 1;
  2040. ProvideSave.pObj[0] = (void*)FVmsObj;
  2041. FVmsObj->CTLMODE->Enable = object_disable;
  2042. FVmsObj->CTLMODE->SvcDate = Now().FormatString("yyyymmddhhnnss");
  2043. FVmsObj->CTLMODE->SaveFlag = true;
  2044. FVmsObj->CTLMODE->Result = true;
  2045. if ((sResult = SendDbThreadDataMessage(WM_PROVIDE_SAVE, &ProvideSave, sizeof(ProvideSave))) != VERR_NONE)
  2046. {
  2047. SERROR("SendDbThreadDataMessage Error %d", sResult);
  2048. }
  2049. }
  2050. else
  2051. if (FSvrCtl.obj == OBJ_DownloadGraphicData)
  2052. {
  2053. FVmsObj->DOWNLOAD->Unit[FSvrCtl.Idx].SendEndDate = Now().FormatString("yyyymmddhhnnss");
  2054. FVmsObj->DOWNLOAD->Unit[FSvrCtl.Idx].SendStep = send_complete;
  2055. FVmsObj->DOWNLOAD->Unit[FSvrCtl.Idx].SendResult = vms_download_succ;
  2056. if ((FSvrCtl.Idx + 1) == FVmsObj->DOWNLOAD->Count)
  2057. {
  2058. SAVE_STRUCT DownLoadSave;
  2059. memset(&DownLoadSave, 0x00, sizeof(DownLoadSave));
  2060. DownLoadSave.Type = save_download;
  2061. DownLoadSave.Count = 1;
  2062. DownLoadSave.pObj[0] = (void*)FVmsObj;
  2063. FVmsObj->DOWNLOAD->Enable = object_disable;
  2064. FVmsObj->DOWNLOAD->SaveFlag = true;
  2065. if ((sResult = SendDbThreadDataMessage(WM_PROVIDE_SAVE, &DownLoadSave, sizeof(DownLoadSave))) != VERR_NONE)
  2066. {
  2067. SERROR("SendDbThreadDataMessage Error %d", sResult);
  2068. }
  2069. }
  2070. }
  2071. }/* end if */
  2072. SetServerState(SET_SERVER_SUCC);
  2073. result = SYS_ERR_NONE;
  2074. LINFO(" *** Accept_Type_PR_publication: %u", nbr);
  2075. break;
  2076. default:
  2077. result = SYS_ERR_ACCEPT_TYPE;
  2078. SERROR(" *** Unknown Accept_Type: %u, %d", nbr, pAccept->datexAccept_Type.present);
  2079. break;
  2080. }
  2081. return result;
  2082. }
  2083. //---------------------------------------------------------------------------
  2084. /*
  2085. * 수신 패킷 처리
  2086. * arguments
  2087. * void
  2088. * return
  2089. * void
  2090. */
  2091. int __fastcall TVMSSThread::PacketReject(Reject_t *pReject)
  2092. {
  2093. FErrLine = 8;
  2094. int result;
  2095. long nbr;
  2096. long ErrCode;
  2097. result = SYS_ERR_OTHER;
  2098. asn_INTEGER2long(&pReject->datexReject_Packet_nbr, &nbr);
  2099. switch(pReject->datexReject_Type.present){
  2100. /*
  2101. case RejectType_PR_datexReject_Login_cd:
  2102. asn_INTEGER2long(&pReject->datexReject_Type.choice.datexReject_Login_cd, &ErrCode);
  2103. break;
  2104. case RejectType_PR_datexReject_Subscription_cd:
  2105. asn_INTEGER2long(&pReject->datexReject_Type.choice.datexReject_Subscription_cd, &ErrCode);
  2106. break;
  2107. */
  2108. case RejectType_PR_datexReject_Publication_cd:
  2109. asn_INTEGER2long(&pReject->datexReject_Type.choice.datexReject_Publication_cd, &ErrCode);
  2110. if ((m_Server.State != ST_LOCAL_WAIT) &&
  2111. (m_Server.State != ST_CLIENT_WAIT))
  2112. {
  2113. result = SYS_ERR_MISMATCH;
  2114. break;
  2115. }
  2116. SetServerState(SET_SERVER_FAIL);
  2117. result = SYS_ERR_NONE;
  2118. break;
  2119. default:
  2120. ErrCode = -1;
  2121. break;
  2122. }
  2123. /* pReject->datexReject_AlternateRequest */
  2124. LINFO("Reject 수신[%d %d %d]", nbr, pReject->datexReject_Type.present, ErrCode);
  2125. return result;
  2126. }
  2127. //---------------------------------------------------------------------------
  2128. /*
  2129. * 패킷 송신
  2130. * arguments
  2131. * void
  2132. * return
  2133. * void
  2134. */
  2135. int __fastcall TVMSSThread::SendPacket(void *Data, int Len, BYTE cmd)
  2136. {
  2137. FErrLine = 9;
  2138. int result;
  2139. DatexDataPacket_t *pMsg; /* Type to encode */
  2140. asn_enc_rval_t er; /* Encoder return value */
  2141. BYTE MsgBuf[SERVER_MSG_BUF_SIZE];
  2142. WORD crc;
  2143. int eLen, wLen;
  2144. result = SYS_ERR_OTHER;
  2145. pMsg = (DatexDataPacket_t *)ASN1C_Alloc(sizeof(DatexDataPacket_t));
  2146. if(pMsg == NULL) {
  2147. return SYS_ERR_INTERNAL;
  2148. }
  2149. if(asn_long2INTEGER(&pMsg->datex_Version_number, datex_Version_number_version1) != ASN_ERR_NONE){
  2150. ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
  2151. return -1;
  2152. }
  2153. if(OCTET_STRING_fromBuf(&pMsg->datex_Data, (char *)Data, Len) != ASN_ERR_NONE){
  2154. ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
  2155. return -2;
  2156. }
  2157. crc = ASN1C_MakeCrc16(Data, Len);
  2158. crc = CommUtil_WordSwap(crc);
  2159. if (OCTET_STRING_fromBuf(&pMsg->datex_Crc_nbr, (char *)&crc, sizeof(crc)) != ASN_ERR_NONE)
  2160. {
  2161. ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
  2162. return -3;
  2163. }
  2164. /* Encode */
  2165. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  2166. eLen = -1;
  2167. er = der_encode_to_buffer(&asn_DEF_DatexDataPacket, pMsg, MsgBuf, sizeof(MsgBuf));
  2168. if (er.encoded == -1)
  2169. {
  2170. /*
  2171. * Failed to encode the data.
  2172. */
  2173. SERROR("Cannot encode %s", er.failed_type->name);
  2174. result = SYS_ERR_DATEXDATAPACKET_ENCODE;
  2175. }
  2176. else
  2177. {
  2178. /* Return the number of bytes */
  2179. eLen = er.encoded;
  2180. wLen = pClientSocket->SendBuf(MsgBuf, eLen);
  2181. LINFO("Send: %d/%d, cmd: %02X", eLen, wLen, cmd);
  2182. if (eLen == wLen)
  2183. {
  2184. --m_Server.iRetry;
  2185. m_Server.cTimer = Now();
  2186. result = SYS_ERR_NONE;
  2187. LogData("SEND", (char*)MsgBuf, eLen);
  2188. }
  2189. else
  2190. {
  2191. LERROR("TCP_Write(%d %d)", eLen, wLen);
  2192. result = SYS_ERR_WRITE_LENGTH;
  2193. LogData("SEND Fail", (char*)MsgBuf, eLen);
  2194. }
  2195. }
  2196. ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
  2197. return result;
  2198. }
  2199. //---------------------------------------------------------------------------
  2200. int UTF8String_fromBuf(UTF8String_t *st, const char *str, int len)
  2201. {
  2202. UTF8String uStr;
  2203. uStr = UTF8Encode(WideString(str, len));
  2204. return OCTET_STRING_fromBuf(st, uStr.c_str(), uStr.Length());
  2205. }
  2206. //---------------------------------------------------------------------------
  2207. /*
  2208. * 입력 파라미터에 따라 명령을 전송한다.
  2209. * arguments
  2210. * void
  2211. * return
  2212. * void
  2213. */
  2214. int __fastcall TVMSSThread::ProcessCommand(BYTE cmd, COMMAND_ARGUMENT *arg)
  2215. {
  2216. FErrLine = 10;
  2217. C2CAuthenticatedMessage_t *pMsg; /* Type to encode */
  2218. asn_enc_rval_t er; /* Encoder return value */
  2219. BYTE MsgBuf[SERVER_MSG_BUF_SIZE];
  2220. int eLen;
  2221. int result;
  2222. Word year, month, day;
  2223. Word hour, min, sec, msec;
  2224. result = SYS_ERR_OTHER;
  2225. Now().DecodeDate(&year, &month, &day);
  2226. Now().DecodeTime(&hour, &min, &sec, &msec);
  2227. pMsg = (C2CAuthenticatedMessage_t *)ASN1C_Alloc(sizeof(C2CAuthenticatedMessage_t));
  2228. if (pMsg == NULL)
  2229. {
  2230. return SYS_ERR_INTERNAL;
  2231. }
  2232. /* 공통부분 */
  2233. if (OCTET_STRING_fromBuf(&pMsg->datex_AuthenticationInfo_text, (char *)&cmd, sizeof(cmd)) != ASN_ERR_NONE)
  2234. {
  2235. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2236. return -1;
  2237. }
  2238. if (asn_long2INTEGER(&pMsg->datex_DataPacket_number, m_DataPacketNumber++) != ASN_ERR_NONE)
  2239. {
  2240. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2241. return -2;
  2242. }
  2243. pMsg->datex_DataPacketPriority_number = 0;
  2244. /* Header Options */
  2245. /* pMsg->options.datex_Origin_text */
  2246. pMsg->options.datex_OriginAddress_location = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t));
  2247. if (pMsg->options.datex_OriginAddress_location == NULL)
  2248. {
  2249. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2250. return -3;
  2251. }
  2252. //if (OCTET_STRING_fromString(pMsg->options.datex_OriginAddress_location, m_Server.LocalCenterId.c_str()) != ASN_ERR_NONE)
  2253. if (OCTET_STRING_fromString(pMsg->options.datex_OriginAddress_location, m_Server.LocalDomainNm.c_str()) != ASN_ERR_NONE)
  2254. {
  2255. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2256. return -4;
  2257. }
  2258. /* pMsg->options.datex_Sender_text */
  2259. /* pMsg->options.datex_SenderAddress_location */
  2260. /* pMsg->options.datex_Destination_text */
  2261. #if 1
  2262. pMsg->options.datex_SenderAddress_location = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t));
  2263. if (pMsg->options.datex_SenderAddress_location == NULL)
  2264. {
  2265. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2266. return -5;
  2267. }
  2268. if (OCTET_STRING_fromString(pMsg->options.datex_SenderAddress_location, m_Server.LocalDomainNm.c_str()) != ASN_ERR_NONE)
  2269. {
  2270. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2271. return -6;
  2272. }
  2273. #endif
  2274. pMsg->options.datex_DestinationAddress_location = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t));
  2275. if (pMsg->options.datex_DestinationAddress_location == NULL)
  2276. {
  2277. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2278. return -5;
  2279. }
  2280. //if (OCTET_STRING_fromString(pMsg->options.datex_DestinationAddress_location, m_Server.CenterId.c_str()) != ASN_ERR_NONE)
  2281. if (OCTET_STRING_fromString(pMsg->options.datex_DestinationAddress_location, m_Server.DomainNm.c_str()) != ASN_ERR_NONE)
  2282. {
  2283. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2284. return -6;
  2285. }
  2286. /* pMsg->options.datex_Cost->amount_Currency_code */
  2287. /* pMsg->options.datex_Cost->amount_Factor_quantity */
  2288. /* pMsg->options.datex_Cost->amount_Quantity_quantity */
  2289. pMsg->options.datex_DataPacket_time = (Time_t *)ASN1C_Alloc(sizeof(Time_t));
  2290. if (pMsg->options.datex_DataPacket_time == NULL)
  2291. {
  2292. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2293. return -7;
  2294. }
  2295. pMsg->options.datex_DataPacket_time->time_Year_qty = (long *)ASN1C_Alloc(sizeof(long));
  2296. if (pMsg->options.datex_DataPacket_time->time_Year_qty == NULL)
  2297. {
  2298. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2299. return -8;
  2300. }
  2301. *pMsg->options.datex_DataPacket_time->time_Year_qty = year;
  2302. pMsg->options.datex_DataPacket_time->time_Month_qty = (long *)ASN1C_Alloc(sizeof(long));
  2303. if (pMsg->options.datex_DataPacket_time->time_Month_qty == NULL)
  2304. {
  2305. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2306. return -9;
  2307. }
  2308. *pMsg->options.datex_DataPacket_time->time_Month_qty = month;
  2309. pMsg->options.datex_DataPacket_time->time_Day_qty = (long *)ASN1C_Alloc(sizeof(long));
  2310. if (pMsg->options.datex_DataPacket_time->time_Day_qty == NULL)
  2311. {
  2312. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2313. return -10;
  2314. }
  2315. *pMsg->options.datex_DataPacket_time->time_Day_qty = day;
  2316. pMsg->options.datex_DataPacket_time->time_Hour_qty = hour;
  2317. pMsg->options.datex_DataPacket_time->time_Minute_qty = min;
  2318. pMsg->options.datex_DataPacket_time->time_Second_qty = sec;
  2319. pMsg->options.datex_DataPacket_time->time_SecondFractions_zz.present = time_SecondFractions_PR_milliseconds;
  2320. pMsg->options.datex_DataPacket_time->time_SecondFractions_zz.choice.milliseconds = 0;
  2321. #if 0
  2322. //TODO
  2323. pMsg->options.datex_DataPacket_time->time_Timezone = (Timezone_t*)ASN1C_Alloc(sizeof(Timezone_t));
  2324. if (pMsg->options.datex_DataPacket_time->time_Timezone)
  2325. {
  2326. pMsg->options.datex_DataPacket_time->time_Timezone->timezone_Hour_qty = 9;
  2327. pMsg->options.datex_DataPacket_time->time_Timezone->time_Minute_qty = 0;
  2328. }
  2329. #endif
  2330. /* pMsg->options.datex_DataPacket_time->time_Timezone->timezone_Hour_qty */
  2331. /* pMsg->options.datex_DataPacket_time->time_Timezone->time_Minute_qty */
  2332. switch(cmd)
  2333. {
  2334. case AI_Initiate: /* 초기 통신연결을 위한 개시 요청 데이터 패킷 */
  2335. pMsg->pdu.present = PDUs_PR_datex_Initiate_null;
  2336. if(OCTET_STRING_fromString(&pMsg->pdu.choice.datex_Initiate_null.datex_Sender_txt, m_Server.LocalDomainNm.c_str()) != ASN_ERR_NONE){
  2337. result = -12;
  2338. break;
  2339. }
  2340. if(OCTET_STRING_fromString(&pMsg->pdu.choice.datex_Initiate_null.datex_Destinatin_txt, m_Server.DomainNm.c_str()) != ASN_ERR_NONE){
  2341. result = -13;
  2342. break;
  2343. }
  2344. result = SYS_ERR_NONE;
  2345. LINFO(">>> AI_Initiate 전송 Sender:%s Destinatin:%s", m_Server.LocalDomainNm.c_str(), m_Server.DomainNm.c_str());
  2346. break;
  2347. case AI_Accept: /* 클라이언트의 요청에 대한 수용 */
  2348. LINFO(">>> AI_Accept 전송");
  2349. pMsg->pdu.present = PDUs_PR_accept;
  2350. if ((result = CommandAccept(&pMsg->pdu.choice.accept, arg->Accept.nbr, arg->Accept.type, arg->Accept.sub)) != SYS_ERR_NONE)
  2351. {
  2352. SERROR("CommandAccept result failed: %d", result);
  2353. result = -14;
  2354. }
  2355. break;
  2356. case AI_Reject: /* 클라이언트의 요청에 대한 거부 */
  2357. LINFO(">>> AI_Reject 전송");
  2358. pMsg->pdu.present = PDUs_PR_reject;
  2359. if ((result = CommandReject(&pMsg->pdu.choice.reject, arg->Reject.nbr, arg->Reject.type, arg->Reject.code)) != SYS_ERR_NONE)
  2360. {
  2361. SERROR("CommandReject failed: %d", result);
  2362. result = -15;
  2363. }
  2364. break;
  2365. case AI_FrED: /* 서버와 클라이언트의 연결을 유지하기 위한 확인 데이터 패킷 */
  2366. pMsg->pdu.present = PDUs_PR_fred;
  2367. if (asn_long2INTEGER(&pMsg->pdu.choice.fred, arg->FrED) != ASN_ERR_NONE)
  2368. {
  2369. LINFO(">>> AI_FrED 전송 Failed");
  2370. result = -16;
  2371. break;
  2372. }
  2373. result = SYS_ERR_NONE;
  2374. LINFO(">>> AI_FrED 전송: %u", arg->FrED);
  2375. break;
  2376. case AI_Terminate: /* 연결을 종료하고자 할 때, 서버에서 클라이언트에 요청하는 데이터 패킷 */
  2377. pMsg->pdu.present = PDUs_PR_terminate;
  2378. if (asn_long2INTEGER(&pMsg->pdu.choice.terminate, arg->Terminate) != ASN_ERR_NONE)
  2379. {
  2380. LINFO(">>> AI_Terminate 전송 Failed");
  2381. result = -17;
  2382. break;
  2383. }
  2384. result = SYS_ERR_NONE;
  2385. LINFO(">>> AI_Terminate 전송 %u", arg->Terminate);
  2386. break;
  2387. case AI_RealTimeDisplayMessage: /* 실시간정보표출메시지 */
  2388. case AI_ScheduledDisplayMessage: /* 계획된정보표출메시지 */
  2389. case AI_DownloadGraphicDataMessage: /* 그래픽데이터 다운로드 메시지 */
  2390. case AI_StatusControlMessage: /* 상태제어메시지 */
  2391. case AI_StatusSettingMessage: /* 상태설정메시지 */
  2392. {
  2393. LINFO(">>> PublicationData 전송");
  2394. PublicationData_t *pData;
  2395. if ((pData = (PublicationData_t *)ASN1C_Alloc(sizeof(PublicationData_t))) == NULL)
  2396. {
  2397. result = -18;
  2398. break;
  2399. }
  2400. pMsg->pdu.present = PDUs_PR_publication;
  2401. pMsg->pdu.choice.publication.datexPublish_Guaranteed_bool = true;
  2402. pMsg->pdu.choice.publication.datexPublish_Format.present = Publish_Format_PR_datexPublish_Data;
  2403. if ((result = CommandPublicationData(pData, arg->Publication)) != SYS_ERR_NONE)
  2404. {
  2405. SERROR("CommandPublicationData failed: %d", result);
  2406. result = -19;
  2407. break;
  2408. }
  2409. if (ASN_SEQUENCE_ADD(&pMsg->pdu.choice.publication.datexPublish_Format.choice.datexPublish_Data, pData) != ASN_ERR_NONE)
  2410. {
  2411. result = -20;
  2412. break;
  2413. }
  2414. result = SYS_ERR_NONE;
  2415. }
  2416. break;
  2417. case AI_ScreenStatusMessage: /* 표출상태정보메시지 */
  2418. {
  2419. Subscription_t *pSubscripiton = &pMsg->pdu.choice.subscripiton;
  2420. SubscriptionData_t *pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
  2421. pMsg->pdu.present = PDUs_PR_subscripiton;
  2422. if (asn_long2INTEGER(&pSubscripiton->datexSubscribe_Serial_nbr, arg->Publication.SubscribeSerialNbr) != ASN_ERR_NONE)
  2423. {
  2424. result = -31;
  2425. break;
  2426. }
  2427. pSubscripiton->datexSubscribe_Type.present = SubscriptionType_PR_subscription;
  2428. pData->datexSubscribe_Persistent_bool = false;
  2429. if (asn_long2INTEGER(&pData->datexSubscribe_Status_cd, datexSubscribe_Status_cd_new) != ASN_ERR_NONE)
  2430. {
  2431. result = -32;
  2432. break;
  2433. }
  2434. pData->datexSubscribe_Mode.present = SubscriptionMode_PR_single;
  2435. if (asn_long2INTEGER(&pData->datexSubscribe_PublishFormat_cd, datexSubscribe_PublishFormat_cd_dataPacket) != ASN_ERR_NONE)
  2436. {
  2437. result = -33;
  2438. break;
  2439. }
  2440. pData->datexSubscription_Priority_nbr = 1;
  2441. pData->datexSubscribe_Guarantee_bool = true;
  2442. ASN1C_SetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id, OBJ_ScreenStatus);
  2443. //
  2444. ScreenStatusMessage_t *pMS;
  2445. MessageBodyScreenStatusMessage_t Msg; /* Type to encode */
  2446. memset((void *)&Msg, 0x00, sizeof(MessageBodyScreenStatusMessage_t));
  2447. /* Encode */
  2448. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  2449. eLen = -1;
  2450. er = der_encode_to_buffer(&asn_DEF_MessageBodyScreenStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  2451. if (er.encoded == -1)
  2452. {
  2453. /*
  2454. * Failed to encode the data.
  2455. */
  2456. SERROR("Cannot encode %s", er.failed_type->name);
  2457. result = SYS_ERR_MESSAGE_ENCODE;
  2458. }
  2459. else
  2460. {
  2461. /* Return the number of bytes */
  2462. eLen = er.encoded;
  2463. pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  2464. if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
  2465. {
  2466. result = -32;
  2467. break;
  2468. }
  2469. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
  2470. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  2471. {
  2472. result = -33;
  2473. break;
  2474. }
  2475. result = SYS_ERR_NONE;
  2476. LINFO("ScreenStatus Subscribe Send");
  2477. }
  2478. ASN1C_FreeC(&asn_DEF_MessageBodyScreenStatusMessage, &Msg);
  2479. result = SYS_ERR_NONE;
  2480. }
  2481. break;
  2482. case AI_DisplayingDataMessage: /* 표출정보메시지 */
  2483. {
  2484. //pMsg->pdu.present = PDUs_PR_subscripiton;
  2485. //result = SYS_ERR_NONE;
  2486. }
  2487. break;
  2488. case AI_TransferDone:
  2489. {
  2490. AnsiString sFileName = AnsiString(arg->Publication.szFormId);
  2491. pMsg->pdu.present = PDUs_PR_publication;
  2492. pMsg->pdu.choice.publication.datexPublish_Guaranteed_bool = true;
  2493. pMsg->pdu.choice.publication.datexPublish_Format.present = Publish_Format_PR_datexPublish_FileName_txt;
  2494. if (OCTET_STRING_fromString(&pMsg->pdu.choice.publication.datexPublish_Format.choice.datexPublish_FileName_txt, sFileName.c_str()) != ASN_ERR_NONE)
  2495. {
  2496. result = -41;
  2497. break;
  2498. }
  2499. result = SYS_ERR_NONE;
  2500. }
  2501. break;
  2502. #if 1
  2503. // FOR Yongin
  2504. case AI_Subscription:
  2505. pMsg->pdu.present = PDUs_PR_subscripiton;
  2506. #if 0
  2507. if ((result = CommandSubscription(&pMsg->pdu.choice.subscripiton, arg->Subscription)) != SYS_ERR_NONE)
  2508. {
  2509. SERROR("CommandSubscription result %d", result);
  2510. result = -15;
  2511. }
  2512. #endif
  2513. break;
  2514. // END Yongin
  2515. #endif
  2516. default:
  2517. LERROR("ProcessCommand Unknown cmd: %d", cmd);
  2518. result = SYS_ERR_UNKNOWN_COMMAND;
  2519. break;
  2520. }
  2521. if (result == SYS_ERR_NONE)
  2522. {
  2523. /* Encode */
  2524. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  2525. eLen = -1;
  2526. er = der_encode_to_buffer(&asn_DEF_C2CAuthenticatedMessage, pMsg, MsgBuf, sizeof(MsgBuf));
  2527. if (er.encoded == -1)
  2528. {
  2529. /*
  2530. * Failed to encode the data.
  2531. */
  2532. SERROR("Cannot encode %s", er.failed_type->name);
  2533. result = SYS_ERR_C2CAUTHENTICATEDMESSAGE_ENCODE;
  2534. }
  2535. else
  2536. {
  2537. /* Return the number of bytes */
  2538. eLen = er.encoded;
  2539. result = SendPacket(MsgBuf, eLen, cmd);
  2540. }
  2541. }
  2542. ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
  2543. return result;
  2544. }
  2545. //---------------------------------------------------------------------------
  2546. /*
  2547. * 송신 패킷 생성
  2548. * arguments
  2549. * void
  2550. * return
  2551. * void
  2552. */
  2553. int __fastcall TVMSSThread::CommandAccept(Accept_t *pAccept, DWORD nbr, int type, DWORD sub)
  2554. {
  2555. FErrLine = 11;
  2556. int result;
  2557. int oid[3] = {2, 1, 1};
  2558. result = SYS_ERR_OTHER;
  2559. if(asn_long2INTEGER(&pAccept->datexAccept_Packet_nbr, nbr) != ASN_ERR_NONE){
  2560. return -1;
  2561. }
  2562. pAccept->datexAccept_Type.present = (datexAccept_Type_PR)type;
  2563. switch(type)
  2564. {
  2565. case datexAccept_Type_PR_logIn:
  2566. if (ASN1C_SetObjectIdentifier(&pAccept->datexAccept_Type.choice.logIn, oid, sizeof(oid)) != ASN_ERR_NONE)
  2567. {
  2568. LINFO(" *** Accept_Type_PR_logIn Failed");
  2569. return -2;
  2570. }
  2571. result = SYS_ERR_NONE;
  2572. LINFO(" *** Accept_Type_PR_logIn 전송: %u", nbr);
  2573. break;
  2574. case datexAccept_Type_PR_single_subscription:
  2575. result = SYS_ERR_NONE;
  2576. LINFO(" *** Accept_Type_PR_single_subscription 전송: %u", nbr);
  2577. break;
  2578. case datexAccept_Type_PR_registered_subscription:
  2579. if (asn_long2INTEGER(&pAccept->datexAccept_Type.choice.registered_subscription, sub) != ASN_ERR_NONE)
  2580. {
  2581. LINFO(" *** Accept_Type_PR_registered_subscription Failed");
  2582. return -3;
  2583. }
  2584. result = SYS_ERR_NONE;
  2585. LINFO(" *** Accept_Type_PR_registered_subscription 전송: %u, %u", nbr, sub);
  2586. break;
  2587. case datexAccept_Type_PR_publication:
  2588. result = SYS_ERR_NONE;
  2589. LINFO(" *** Accept_Type_PR_publication 전송: %u", nbr);
  2590. break;
  2591. default:
  2592. result = SYS_ERR_ACCEPT_TYPE;
  2593. LINFO(" *** Unknown Accept_Type: %u, %d", nbr, type);
  2594. break;
  2595. }
  2596. return result;
  2597. }
  2598. //---------------------------------------------------------------------------
  2599. /*
  2600. * 송신 패킷 생성
  2601. * arguments
  2602. * void
  2603. * return
  2604. * void
  2605. */
  2606. int __fastcall TVMSSThread::CommandReject(Reject_t *pReject, DWORD nbr, int type, int code)
  2607. {
  2608. FErrLine = 12;
  2609. int result;
  2610. result = SYS_ERR_OTHER;
  2611. if (asn_long2INTEGER(&pReject->datexReject_Packet_nbr, nbr) != ASN_ERR_NONE)
  2612. {
  2613. return -1;
  2614. }
  2615. pReject->datexReject_Type.present = (RejectType_PR)type;
  2616. switch(type){
  2617. case RejectType_PR_datexReject_Login_cd:
  2618. if(asn_long2INTEGER(&pReject->datexReject_Type.choice.datexReject_Login_cd, code) != ASN_ERR_NONE){
  2619. return -2;
  2620. }
  2621. result = SYS_ERR_NONE;
  2622. LINFO("로그인 거부 전송 %u %d", nbr, code);
  2623. break;
  2624. case RejectType_PR_datexReject_Subscription_cd:
  2625. if(asn_long2INTEGER(&pReject->datexReject_Type.choice.datexReject_Subscription_cd, code) != ASN_ERR_NONE){
  2626. return -3;
  2627. }
  2628. result = SYS_ERR_NONE;
  2629. LINFO("서브스크립션 거부 전송 %u %d", nbr, code);
  2630. break;
  2631. case RejectType_PR_datexReject_Publication_cd:
  2632. if(asn_long2INTEGER(&pReject->datexReject_Type.choice.datexReject_Publication_cd, code) != ASN_ERR_NONE){
  2633. return -4;
  2634. }
  2635. result = SYS_ERR_NONE;
  2636. LINFO("Publication Reject 전송 %u %d", nbr, code);
  2637. break;
  2638. default:
  2639. result = SYS_ERR_ACCEPT_TYPE;
  2640. LINFO("Unknown Reject 전송 %u %d", nbr, type);
  2641. break;
  2642. }
  2643. /* pReject->datexReject_AlternateRequest */
  2644. return result;
  2645. }
  2646. //---------------------------------------------------------------------------
  2647. /*
  2648. * 송신 패킷 생성
  2649. * arguments
  2650. * void
  2651. * return
  2652. * void
  2653. */
  2654. int __fastcall TVMSSThread::CommandPublicationData(PublicationData_t *pData, PUBLICATION_ARGUMENT Arg)
  2655. {
  2656. FErrLine = 13;
  2657. int result;
  2658. asn_enc_rval_t er; /* Encoder return value */
  2659. BYTE MsgBuf[SERVER_MSG_BUF_SIZE];
  2660. int eLen;
  2661. int i;
  2662. result = SYS_ERR_OTHER;
  2663. if (asn_long2INTEGER(&pData->datexPublish_SubscribeSerial_nbr, Arg.SubscribeSerialNbr) != ASN_ERR_NONE)
  2664. {
  2665. return -1;
  2666. }
  2667. pData->datexPublish_LatePublicationFlag = true;
  2668. pData->datexPublish_Type.present = PublicationType_PR_datexPublish_Data;
  2669. #if 0
  2670. {
  2671. long lv;
  2672. asn_INTEGER2long(&pData->datexPublish_SubscribeSerial_nbr, &lv);
  2673. LDEBUG("datexPublish_SubscribeSerial_nbr: %u", lv);
  2674. asn_INTEGER2long(&pData->datexPublish_Serial_nbr, &lv);
  2675. LDEBUG(" datexPublish_Serial_nbr: %u", lv);
  2676. LDEBUG("datexPublish_LatePublicationFlag: %d", pData->datexPublish_LatePublicationFlag);
  2677. }
  2678. #endif
  2679. if (FVmsObj->FIsOldProtocol)
  2680. {
  2681. int s_arcs[6];
  2682. int *arcs = s_arcs;
  2683. s_arcs[0] = 1;
  2684. s_arcs[1] = 0;
  2685. s_arcs[2] = 14827;
  2686. s_arcs[3] = 2;
  2687. s_arcs[4] = 0;
  2688. s_arcs[5] = Arg.obj;
  2689. int count = OBJECT_IDENTIFIER_set_arcs(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id, arcs, sizeof(*arcs), 6);
  2690. }
  2691. else
  2692. {
  2693. ASN1C_SetObjId(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id, Arg.obj);
  2694. }
  2695. switch(Arg.obj)
  2696. {
  2697. case OBJ_RealTimeDisplay: /* 실시간정보표출 */
  2698. {
  2699. LINFO(" *** OBJ_RealTimeDisplay");
  2700. RealTimeDisplayMessage_t *pRTD;
  2701. MessageBodyRealTimeDisplayMessage_t Msg; /* Type to encode */
  2702. memset((void *)&Msg, 0x00, sizeof(MessageBodyRealTimeDisplayMessage_t));
  2703. for ( i = 0; i < 1; i++)
  2704. {
  2705. if ((pRTD = (RealTimeDisplayMessage_t *)ASN1C_Alloc(sizeof(RealTimeDisplayMessage_t))) == NULL)
  2706. {
  2707. result = -10;
  2708. break;
  2709. }
  2710. if (FVmsObj->FBmpDownload)
  2711. {
  2712. //전체 이미지로 다운로드 하는 경우이거나
  2713. //이전VMS중에 FTP로 다운로드 하는 경우임...
  2714. result = RealTimeDisplayBitmap(pRTD, Arg);
  2715. }
  2716. else
  2717. {
  2718. result = RealTimeDisplayData(pRTD, Arg);
  2719. }
  2720. if (result != SYS_ERR_NONE)
  2721. {
  2722. SERROR("RealTimeDisplayData failed: %d", result);
  2723. result = -11;
  2724. break;
  2725. }
  2726. if (ASN_SEQUENCE_ADD(&Msg, pRTD)!= ASN_ERR_NONE)
  2727. {
  2728. result = -12;
  2729. break;
  2730. }
  2731. #if 0
  2732. {
  2733. long lv;
  2734. Object_t *pObj;
  2735. char Utf8Buf[256+1];
  2736. LDEBUG("[%d]", i);
  2737. LDEBUG("message_serialID: %.*s", pRTD->message_serialID.size, pRTD->message_serialID.buf);
  2738. asn_INTEGER2long(&pRTD->display_DurationQty, &lv);
  2739. LDEBUG("display_DurationQty: %u", lv);
  2740. asn_INTEGER2long(&pRTD->display_ModeCode, &lv);
  2741. LDEBUG("display_ModeCode: %u", lv);
  2742. asn_INTEGER2long(&pRTD->display_DirectionCode, &lv);
  2743. LDEBUG("display_DirectionCode: %u", lv);
  2744. asn_INTEGER2long(&pRTD->background_ColorCode, &lv);
  2745. LDEBUG("background_ColorCode: %u", lv);
  2746. asn_INTEGER2long(&pRTD->object_Nbr, &lv);
  2747. LDEBUG("object_Nbr: %u", lv);
  2748. for (int j = 0; j < pRTD->objects_zz.list.count; j++)
  2749. {
  2750. LDEBUG("objects: [%d]", j);
  2751. pObj = (Object_t *)pRTD->objects_zz.list.array[j];
  2752. asn_INTEGER2long(&pObj->object_TypeCode, &lv);
  2753. LDEBUG("object_TypeCode: %u", lv);
  2754. asn_INTEGER2long(&pObj->blinking_Code, &lv);
  2755. LDEBUG("blinking_Code: %u", lv);
  2756. asn_INTEGER2long(&pObj->x_Coordinate, &lv);
  2757. LDEBUG("x_Coordinate: %u", lv);
  2758. asn_INTEGER2long(&pObj->y_Coordinate, &lv);
  2759. LDEBUG("y_Coordinate: %u", lv);
  2760. asn_INTEGER2long(&pObj->data_BackgroundColor, &lv);
  2761. LDEBUG("data_BackgroundColor: %u", lv);
  2762. LDEBUG("object_Data: %d", pObj->object_Data.present);
  2763. switch(pObj->object_Data.present)
  2764. {
  2765. case ObjectData_PR_text_object_data:
  2766. asn_INTEGER2long(&pObj->object_Data.choice.text_object_data.font_ColorCode, &lv);
  2767. LDEBUG("font_ColorCode: %u", lv);
  2768. asn_INTEGER2long(&pObj->object_Data.choice.text_object_data.font_Size, &lv);
  2769. LDEBUG("font_Size: %u", lv);
  2770. LDEBUG("font_TypeCode: %.*s", pObj->object_Data.choice.text_object_data.font_TypeCode.size, pObj->object_Data.choice.text_object_data.font_TypeCode.buf);
  2771. asn_INTEGER2long(&pObj->object_Data.choice.text_object_data.font_Thickness, &lv);
  2772. LDEBUG("font_Thickness: %u", lv);
  2773. UTF8String2Hangul((char *)pObj->object_Data.choice.text_object_data.text_Data.buf, Utf8Buf, sizeof(Utf8Buf));
  2774. LDEBUG("text_Data: %.256s", Utf8Buf);
  2775. break;
  2776. case ObjectData_PR_graphic_object_data:
  2777. asn_INTEGER2long(&pObj->object_Data.choice.graphic_object_data.graphic_Type, &lv);
  2778. LDEBUG("graphic_Type: %u", lv);
  2779. asn_INTEGER2long(&pObj->object_Data.choice.graphic_object_data.graphic_Width, &lv);
  2780. LDEBUG("graphic_Width: %u", lv);
  2781. asn_INTEGER2long(&pObj->object_Data.choice.graphic_object_data.graphic_Height, &lv);
  2782. LDEBUG("graphic_Height: %u", lv);
  2783. LDEBUG("graphic_Data:");
  2784. //m_Log->WriteHex(LOG_DEBUG, (BYTE *)pObj->object_Data.choice.graphic_object_data.graphic_Data.buf, pObj->object_Data.choice.graphic_object_data.graphic_Data.size);
  2785. break;
  2786. case ObjectData_PR_graphicID_object_data:
  2787. asn_INTEGER2long(&pObj->object_Data.choice.graphicID_object_data.graphic_Type, &lv);
  2788. LDEBUG("graphic_Type: %u", lv);
  2789. asn_INTEGER2long(&pObj->object_Data.choice.graphicID_object_data.graphic_Width, &lv);
  2790. LDEBUG("graphic_Width: %u", lv);
  2791. asn_INTEGER2long(&pObj->object_Data.choice.graphicID_object_data.graphic_Height, &lv);
  2792. LDEBUG("graphic_Height: %u", lv);
  2793. LDEBUG("graphic_DataID: %.*s", pObj->object_Data.choice.graphicID_object_data.graphic_DataID.size, pObj->object_Data.choice.graphicID_object_data.graphic_DataID.buf);
  2794. break;
  2795. default:
  2796. break;
  2797. }
  2798. }
  2799. }
  2800. #endif
  2801. }/* end for */
  2802. /* Encode */
  2803. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  2804. eLen = -1;
  2805. er = der_encode_to_buffer(&asn_DEF_MessageBodyRealTimeDisplayMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  2806. if (er.encoded == -1)
  2807. {
  2808. /*
  2809. * Failed to encode the data.
  2810. */
  2811. SERROR("Cannot encode %s", er.failed_type->name);
  2812. result = SYS_ERR_MESSAGE_ENCODE;
  2813. }
  2814. else
  2815. {
  2816. /* Return the number of bytes */
  2817. eLen = er.encoded;
  2818. pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  2819. if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
  2820. {
  2821. result = -13;
  2822. break;
  2823. }
  2824. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
  2825. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  2826. {
  2827. result = -14;
  2828. break;
  2829. }
  2830. result = SYS_ERR_NONE;
  2831. }/* end if */
  2832. ASN1C_FreeC(&asn_DEF_MessageBodyRealTimeDisplayMessage, &Msg);
  2833. }
  2834. break;
  2835. case OBJ_ScheduledDisplay: /* 계획된정보표출 */
  2836. {
  2837. LINFO(" *** OBJ_ScheduledDisplay");
  2838. ScheduledDisplayMessage_t *pSD;
  2839. MessageBodyScheduledDisplayMessage_t Msg; /* Type to encode */
  2840. memset((void *)&Msg, 0x00, sizeof(MessageBodyScheduledDisplayMessage_t));
  2841. for ( i = 0; i < 1; i++)
  2842. {
  2843. if ((pSD = (ScheduledDisplayMessage_t *)ASN1C_Alloc(sizeof(ScheduledDisplayMessage_t))) == NULL)
  2844. {
  2845. result = -20;
  2846. break;
  2847. }
  2848. if ((result = ScheduledDisplayData(pSD, Arg)) != SYS_ERR_NONE)
  2849. {
  2850. SERROR("ScheduledDisplayData result %d", result);
  2851. result = -21;
  2852. break;
  2853. }
  2854. if (ASN_SEQUENCE_ADD(&Msg, pSD)!= ASN_ERR_NONE)
  2855. {
  2856. result = -22;
  2857. break;
  2858. }
  2859. #if 0
  2860. {
  2861. long lv;
  2862. OCTET_STRING_t *pSid;
  2863. LDEBUG("[%d]", i);
  2864. asn_INTEGER2long(&pSD->message_Nbr, &lv);
  2865. LDEBUG("message_Nbr: %u", lv);
  2866. for (int j = 0; j < pSD->message_serialIDs.list.count; j++)
  2867. {
  2868. LDEBUG("message_serialIDs: [%d]", j);
  2869. pSid = (OCTET_STRING_t *)pSD->message_serialIDs.list.array[j];
  2870. LDEBUG("serialIDs: %.*s", pSid->size, pSid->buf);
  2871. }
  2872. }
  2873. #endif
  2874. }/* end for */
  2875. /* Encode */
  2876. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  2877. eLen = -1;
  2878. er = der_encode_to_buffer(&asn_DEF_MessageBodyScheduledDisplayMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  2879. if (er.encoded == -1)
  2880. {
  2881. /*
  2882. * Failed to encode the data.
  2883. */
  2884. SERROR("Cannot encode %s", er.failed_type->name);
  2885. result = SYS_ERR_MESSAGE_ENCODE;
  2886. }
  2887. else
  2888. {
  2889. /* Return the number of bytes */
  2890. eLen = er.encoded;
  2891. pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  2892. if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
  2893. {
  2894. result = -23;
  2895. break;
  2896. }
  2897. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
  2898. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  2899. {
  2900. result = -24;
  2901. break;
  2902. }
  2903. result = SYS_ERR_NONE;
  2904. }/* end if */
  2905. ASN1C_FreeC(&asn_DEF_MessageBodyScheduledDisplayMessage, &Msg);
  2906. }
  2907. break;
  2908. case OBJ_DownloadGraphicData: /* 그래픽데이터 다운로드 */
  2909. {
  2910. LINFO(" *** OBJ_DownloadGraphicData");
  2911. DownloadGraphicDataMessage_t *pDGD;
  2912. MessageBodyDownloadGraphicDataMessage_t Msg; /* Type to encode */
  2913. memset((void *)&Msg, 0x00, sizeof(MessageBodyDownloadGraphicDataMessage_t));
  2914. for ( i = 0; i < 1; i++)
  2915. {
  2916. if ((pDGD = (DownloadGraphicDataMessage_t *)ASN1C_Alloc(sizeof(DownloadGraphicDataMessage_t))) == NULL)
  2917. {
  2918. result = -30;
  2919. break;
  2920. }
  2921. if ((result = DownloadGraphicData(pDGD, Arg)) != VERR_NONE)
  2922. {
  2923. SERROR("DownloadGraphicData result %d", result);
  2924. result = -31;
  2925. break;
  2926. }
  2927. if (ASN_SEQUENCE_ADD(&Msg, pDGD)!= ASN_ERR_NONE)
  2928. {
  2929. result = -32;
  2930. break;
  2931. }
  2932. #if 0
  2933. {
  2934. LDEBUG("[%d]", i);
  2935. LDEBUG("download_GraphicData_ID: %.*s", pDGD->download_GraphicData_ID.size, pDGD->download_GraphicData_ID.buf);
  2936. LDEBUG("download_GraphicData:");
  2937. //m_Log->WriteHex(LOG_DEBUG, (BYTE *)pDGD->download_GraphicData.buf, pDGD->download_GraphicData.size);
  2938. }
  2939. #endif
  2940. }/* end for */
  2941. /* Encode */
  2942. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  2943. eLen = -1;
  2944. er = der_encode_to_buffer(&asn_DEF_MessageBodyDownloadGraphicDataMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  2945. if (er.encoded == -1)
  2946. {
  2947. /*
  2948. * Failed to encode the data.
  2949. */
  2950. SERROR("Cannot encode %s", er.failed_type->name);
  2951. result = SYS_ERR_MESSAGE_ENCODE;
  2952. }
  2953. else
  2954. {
  2955. /* Return the number of bytes */
  2956. eLen = er.encoded;
  2957. pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  2958. if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
  2959. {
  2960. result = -33;
  2961. break;
  2962. }
  2963. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
  2964. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  2965. {
  2966. result = -34;
  2967. break;
  2968. }
  2969. result = SYS_ERR_NONE;
  2970. }/* end if */
  2971. ASN1C_FreeC(&asn_DEF_MessageBodyDownloadGraphicDataMessage, &Msg);
  2972. }
  2973. break;
  2974. case OBJ_StatusControl: /* 상태제어 */
  2975. {
  2976. LINFO(" *** OBJ_StatusControl");
  2977. StatusControlMessage_t *pSC;
  2978. MessageBodyStatusControlMessage_t Msg; /* Type to encode */
  2979. memset((void *)&Msg, 0x00, sizeof(MessageBodyStatusControlMessage_t));
  2980. for ( i = 0; i < 1; i++)
  2981. {
  2982. if ((pSC = (StatusControlMessage_t *)ASN1C_Alloc(sizeof(StatusControlMessage_t))) == NULL)
  2983. {
  2984. result = -40;
  2985. break;
  2986. }
  2987. if ((result = StatusControlData(pSC, Arg)) != SYS_ERR_NONE)
  2988. {
  2989. SERROR("StatusControlData result %d", result);
  2990. result = -41;
  2991. break;
  2992. }
  2993. if (ASN_SEQUENCE_ADD(&Msg, pSC)!= ASN_ERR_NONE)
  2994. {
  2995. result = -42;
  2996. break;
  2997. }
  2998. #if 0
  2999. {
  3000. long lv;
  3001. //LDEBUG("[%d]", i);
  3002. asn_INTEGER2long(&pSC->modulePower_ControlCode, &lv);
  3003. LDEBUG(" modulePower_ControlCode: %u", lv);
  3004. asn_INTEGER2long(&pSC->luminance_ControlCode, &lv);
  3005. LDEBUG(" luminance_ControlCode: %u", lv);
  3006. asn_INTEGER2long(&pSC->fan_ControlCode, &lv);
  3007. LDEBUG(" fan_ControlCode: %u", lv);
  3008. asn_INTEGER2long(&pSC->heater_ControlCode, &lv);
  3009. LDEBUG(" heater_ControlCode: %u", lv);
  3010. if (pSC->externalLight_ControlCode)
  3011. {
  3012. asn_INTEGER2long(pSC->externalLight_ControlCode, &lv);
  3013. LDEBUG("externalLight_ControlCode: %u", lv);
  3014. }
  3015. if (pSC->alarmLight_ControlCode)
  3016. {
  3017. asn_INTEGER2long(pSC->alarmLight_ControlCode, &lv);
  3018. LDEBUG(" alarmLight_ControlCode: %u", lv);
  3019. }
  3020. if (pSC->speaker_ControlCode)
  3021. {
  3022. asn_INTEGER2long(pSC->speaker_ControlCode, &lv);
  3023. LDEBUG(" speaker_ControlCode: %u", lv);
  3024. }
  3025. if (pSC->controller_Reset)
  3026. {
  3027. LDEBUG(" controller_Reset: %d", *pSC->controller_Reset);
  3028. }
  3029. if (pSC->controllerTime_Reset)
  3030. {
  3031. LDEBUG(" controllerTime_Reset: %.*s", pSC->controllerTime_Reset->size, pSC->controllerTime_Reset->buf);
  3032. }
  3033. }
  3034. #endif
  3035. }/* end for */
  3036. /* Encode */
  3037. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  3038. eLen = -1;
  3039. er = der_encode_to_buffer(&asn_DEF_MessageBodyStatusControlMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  3040. if (er.encoded == -1)
  3041. {
  3042. /*
  3043. * Failed to encode the data.
  3044. */
  3045. SERROR("Cannot encode %s", er.failed_type->name);
  3046. result = SYS_ERR_MESSAGE_ENCODE;
  3047. }
  3048. else
  3049. {
  3050. /* Return the number of bytes */
  3051. eLen = er.encoded;
  3052. pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  3053. if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
  3054. {
  3055. result = -43;
  3056. break;
  3057. }
  3058. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
  3059. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  3060. {
  3061. result = -44;
  3062. break;
  3063. }
  3064. result = SYS_ERR_NONE;
  3065. }/* end if */
  3066. ASN1C_FreeC(&asn_DEF_MessageBodyStatusControlMessage, &Msg);
  3067. }
  3068. break;
  3069. case OBJ_StatusSetting: /* 상태설정 */
  3070. {
  3071. LINFO(" *** OBJ_StatusSetting");
  3072. StatusSettingMessage_t *pSS;
  3073. MessageBodyStatusSettingMessage_t Msg; /* Type to encode */
  3074. memset((void *)&Msg, 0x00, sizeof(MessageBodyStatusSettingMessage_t));
  3075. for ( i = 0; i < 1; i++)
  3076. {
  3077. if ((pSS = (StatusSettingMessage_t *)ASN1C_Alloc(sizeof(StatusSettingMessage_t))) == NULL)
  3078. {
  3079. result = -50;
  3080. break;
  3081. }
  3082. if ((result = StatusSettingData(pSS, Arg)) != SYS_ERR_NONE)
  3083. {
  3084. SERROR("StatusSettingData result: %d", result);
  3085. result = -51;
  3086. break;
  3087. }
  3088. if (ASN_SEQUENCE_ADD(&Msg, pSS)!= ASN_ERR_NONE)
  3089. {
  3090. result = -52;
  3091. break;
  3092. }
  3093. #if 0
  3094. {
  3095. long lv;
  3096. //LDEBUG("[%d]", i);
  3097. asn_INTEGER2long(&pSS->scheduledMessage_OperatingTimeQty, &lv);
  3098. LDEBUG(" scheduledMessage_OperatingTimeQty: %u", lv);
  3099. asn_INTEGER2long(&pSS->module_OperatingTemperatureQty, &lv);
  3100. LDEBUG(" module_OperatingTemperatureQty: %u", lv);
  3101. asn_INTEGER2long(&pSS->fan_OperatingTemperatureQty, &lv);
  3102. LDEBUG(" fan_OperatingTemperatureQty: %u", lv);
  3103. asn_INTEGER2long(&pSS->heater_OperatingTemperatureQty, &lv);
  3104. LDEBUG(" heater_OperatingTemperatureQty: %u", lv);
  3105. if (pSS->externalLight_OperatingLuminanceQty)
  3106. {
  3107. asn_INTEGER2long(pSS->externalLight_OperatingLuminanceQty, &lv);
  3108. LDEBUG("externalLight_OperatingLuminanceQty: %u", lv);
  3109. }
  3110. if (pSS->module_BasicFailureRate)
  3111. {
  3112. asn_INTEGER2long(pSS->module_BasicFailureRate, &lv);
  3113. LDEBUG(" module_BasicFailureRate: %u", lv);
  3114. }
  3115. if (pSS->maximum_RetryQty)
  3116. {
  3117. asn_INTEGER2long(pSS->maximum_RetryQty, &lv);
  3118. LDEBUG(" maximum_RetryQty: %u", lv);
  3119. }
  3120. if (pSS->response_TimeOutQty)
  3121. {
  3122. asn_INTEGER2long(pSS->response_TimeOutQty, &lv);
  3123. LDEBUG(" response_TimeOutQty: %u", lv);
  3124. }
  3125. if (pSS->blinking_CycleTime)
  3126. {
  3127. asn_INTEGER2long(pSS->blinking_CycleTime, &lv);
  3128. LDEBUG(" blinking_CycleTime: %u", lv);
  3129. }
  3130. }
  3131. #endif
  3132. }/* end for */
  3133. /* Encode */
  3134. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  3135. eLen = -1;
  3136. er = der_encode_to_buffer(&asn_DEF_MessageBodyStatusSettingMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  3137. if (er.encoded == -1)
  3138. {
  3139. /*
  3140. * Failed to encode the data.
  3141. */
  3142. SERROR("Cannot encode %s", er.failed_type->name);
  3143. result = SYS_ERR_MESSAGE_ENCODE;
  3144. }
  3145. else
  3146. {
  3147. /* Return the number of bytes */
  3148. eLen = er.encoded;
  3149. pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  3150. if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
  3151. {
  3152. result = -53;
  3153. break;
  3154. }
  3155. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
  3156. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  3157. {
  3158. result = -54;
  3159. break;
  3160. }
  3161. result = SYS_ERR_NONE;
  3162. }/* end if */
  3163. ASN1C_FreeC(&asn_DEF_MessageBodyStatusSettingMessage, &Msg);
  3164. }
  3165. break;
  3166. default:
  3167. result = SYS_ERR_UNKNOWN_MESSAGE_ID;
  3168. SERROR(" *** Unknown CommandPublicationData");
  3169. break;
  3170. }
  3171. return result;
  3172. }
  3173. //---------------------------------------------------------------------------
  3174. int __fastcall TVMSSThread::RecvFormDownResult(AnsiString AImageId)
  3175. {
  3176. if (AImageId.SubString(1,1) == "6" ||
  3177. AImageId.SubString(1,1) == "7" ||
  3178. AImageId.SubString(1,1) == "8" ) return VERR_NONE;
  3179. AnsiString sImgId = AImageId;
  3180. AnsiString sTmpId = AImageId.SubString(3,2);
  3181. int nFormIdx;
  3182. int nResult = VERR_NONE;
  3183. COMMAND_ARGUMENT arg;
  3184. BYTE CmdCode;
  3185. //LINFO("FORM_IMAGE_ID: %s", AImageId.c_str());
  3186. CmdCode = 0x00;
  3187. memset(&arg, 0x00, sizeof(arg));
  3188. memset(&FSvrCtl, 0x00, sizeof(FSvrCtl));
  3189. #if 0
  3190. if (FVmsObj->CTLMODE->Control == 'B')
  3191. {
  3192. sTmpId = AImageId.SubString(4,1);
  3193. if (sTmpId == 'A') nFormIdx = 10;
  3194. else if (sTmpId == 'B') nFormIdx = 11;
  3195. else if (sTmpId == 'C') nFormIdx = 12;
  3196. else if (sTmpId == 'D') nFormIdx = 13;
  3197. else if (sTmpId == 'E') nFormIdx = 14;
  3198. else if (sTmpId == 'F') nFormIdx = 15;
  3199. else nFormIdx = sTmpId.ToIntDef(0);
  3200. }
  3201. else
  3202. #endif
  3203. {
  3204. nFormIdx = sTmpId.ToIntDef(0);
  3205. }
  3206. m_pVmsFormList->Lock();
  3207. try
  3208. {
  3209. try
  3210. {
  3211. int nFormCnt = m_pVmsFormList->Count();
  3212. #if 0
  3213. if ((nFormCnt-1) == nFormIdx)
  3214. {
  3215. arg.Publication.SubscribeSerialNbr = NBR_BASE_SCHEDULEDDISPLAY;
  3216. //arg.Publication.SubscribeSerialNbr = 50;
  3217. arg.Publication.obj = OBJ_ScheduledDisplay;
  3218. FSvrCtl.obj = OBJ_ScheduledDisplay;
  3219. FSvrCtl.DataPacketNumber = m_DataPacketNumber;
  3220. CmdCode = AI_ScheduledDisplayMessage;
  3221. }
  3222. else
  3223. #endif
  3224. if (nFormIdx < nFormCnt)
  3225. {
  3226. TVmsForm *pVmsForm = m_pVmsFormList->GetItem(nFormIdx);
  3227. if (pVmsForm)
  3228. {
  3229. pVmsForm->FtpRes = true;
  3230. if (pVmsForm->SvcRes == false)
  3231. {
  3232. arg.Publication.SubscribeSerialNbr = NBR_BASE_REALTIMEDISPLAY + nFormIdx;
  3233. //arg.Publication.SubscribeSerialNbr = 49;
  3234. arg.Publication.obj = OBJ_RealTimeDisplay;
  3235. arg.Publication.Data.Form.Idx = nFormIdx;
  3236. sprintf(arg.Publication.szFormId, "%s", sImgId.c_str());
  3237. FSvrCtl.obj = OBJ_RealTimeDisplay;
  3238. FSvrCtl.DataPacketNumber = m_DataPacketNumber;
  3239. FSvrCtl.Idx = nFormIdx;
  3240. CmdCode = AI_RealTimeDisplayMessage;
  3241. }
  3242. }
  3243. else
  3244. {
  3245. LERROR("Not found vms form: %s, %d", VMSID.c_str(), nFormIdx);
  3246. }
  3247. }
  3248. arg.Publication.Data.Form.Mode = FVmsObj->CTLMODE->Control;
  3249. }
  3250. catch(Exception &e)
  3251. {
  3252. }
  3253. }
  3254. __finally
  3255. {
  3256. m_pVmsFormList->UnLock();
  3257. if (nResult == VERR_NONE && CmdCode != 0x00)
  3258. {
  3259. nResult = ProcessCommand(CmdCode, &arg);
  3260. }
  3261. }
  3262. return nResult;
  3263. }
  3264. //---------------------------------------------------------------------------
  3265. int __fastcall TVMSSThread::RealTimeDisplayData(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg)
  3266. {
  3267. //BBBBBBB
  3268. TVmsForm *pVmsForm = NULL;
  3269. TVmsFormObj *pVmsObj = NULL;
  3270. Object_t *pObj = NULL;
  3271. AnsiString MessageId;
  3272. char Utf8Buf[256+1];
  3273. int ii;
  3274. bool bException = false;
  3275. try
  3276. {
  3277. m_pVmsFormList->Lock();
  3278. pVmsForm = m_pVmsFormList->GetItem(Arg.Data.Form.Idx);
  3279. if (!pVmsForm)
  3280. {
  3281. SERROR("FormId Memory Not Found: %d", Arg.Data.Form.Idx);
  3282. return SYS_ERR_NONE;
  3283. }
  3284. if (Arg.Data.Form.Mode == 'B') //기본운영모드
  3285. {
  3286. if (FVmsObj->FIsOldProtocol)
  3287. MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
  3288. else
  3289. MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq);
  3290. }
  3291. else
  3292. {
  3293. MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
  3294. }
  3295. //LINFO("REALTIME: %s", MessageId.c_str());
  3296. if (OCTET_STRING_fromString(&pRTD->message_serialID, MessageId.c_str()) != ASN_ERR_NONE){
  3297. return -1;
  3298. }
  3299. if (asn_long2INTEGER(&pRTD->display_DurationQty, pVmsForm->DisplayTime) != ASN_ERR_NONE){
  3300. return -2;
  3301. }
  3302. if (asn_long2INTEGER(&pRTD->display_ModeCode, pVmsForm->DisplayMode.ToIntDef(0)) != ASN_ERR_NONE){
  3303. return -3;
  3304. }
  3305. if (asn_long2INTEGER(&pRTD->display_DirectionCode, pVmsForm->DisplayDir.ToIntDef(0)) != ASN_ERR_NONE){
  3306. return -4;
  3307. }
  3308. if (asn_long2INTEGER(&pRTD->background_ColorCode, pVmsForm->BkColor) != ASN_ERR_NONE){
  3309. return -5;
  3310. }
  3311. int nObjCnt = pVmsForm->Count();
  3312. if (asn_long2INTEGER(&pRTD->object_Nbr, nObjCnt) != ASN_ERR_NONE){
  3313. return -6;
  3314. }
  3315. for (ii = 0; ii < nObjCnt; ii++)
  3316. {
  3317. pVmsObj = pVmsForm->GetItem(ii);
  3318. if ((pObj = (Object_t *)ASN1C_Alloc(sizeof(Object_t))) == NULL){
  3319. return -10;
  3320. }
  3321. #if 0
  3322. if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){
  3323. return -11;
  3324. }
  3325. #endif
  3326. if (asn_long2INTEGER(&pObj->blinking_Code, pVmsObj->IsBlinking) != ASN_ERR_NONE){
  3327. return -12;
  3328. }
  3329. if (asn_long2INTEGER(&pObj->x_Coordinate, pVmsObj->PosX) != ASN_ERR_NONE){
  3330. return -13;
  3331. }
  3332. if (asn_long2INTEGER(&pObj->y_Coordinate, pVmsObj->PosY) != ASN_ERR_NONE){
  3333. return -14;
  3334. }
  3335. if (asn_long2INTEGER(&pObj->data_BackgroundColor, pVmsObj->BkColor) != ASN_ERR_NONE){
  3336. return -15;
  3337. }
  3338. switch(pVmsObj->ObjectKind)
  3339. {
  3340. case text_object_data:
  3341. pObj->object_Data.present = ObjectData_PR_text_object_data;
  3342. if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){
  3343. return -11;
  3344. }
  3345. if (asn_long2INTEGER(&pObj->object_Data.choice.text_object_data.font_ColorCode, pVmsObj->TextFontColor) != ASN_ERR_NONE){
  3346. return -100;
  3347. }
  3348. if (asn_long2INTEGER(&pObj->object_Data.choice.text_object_data.font_Size, pVmsObj->TextFontSize) != ASN_ERR_NONE){
  3349. return -101;
  3350. }
  3351. if (FVmsObj->FIsProtolFontName)
  3352. {
  3353. if (OCTET_STRING_fromString(&pObj->object_Data.choice.text_object_data.font_TypeCode, pVmsObj->StrTextFontName.c_str()) != ASN_ERR_NONE){
  3354. return -102;
  3355. }
  3356. }
  3357. else
  3358. {
  3359. if (OCTET_STRING_fromString(&pObj->object_Data.choice.text_object_data.font_TypeCode, AnsiString(pVmsObj->TextFontName).c_str()) != ASN_ERR_NONE){
  3360. return -102;
  3361. }
  3362. }
  3363. if (asn_long2INTEGER(&pObj->object_Data.choice.text_object_data.font_Thickness, pVmsObj->TextFontBold) != ASN_ERR_NONE){
  3364. return -103;
  3365. }
  3366. Hangul2UTF8String(pVmsObj->TextData.c_str(), Utf8Buf, sizeof(Utf8Buf));
  3367. if (OCTET_STRING_fromString(&pObj->object_Data.choice.text_object_data.text_Data, Utf8Buf) != ASN_ERR_NONE)
  3368. {
  3369. return -104;
  3370. }
  3371. break;
  3372. case graphic_object_data:
  3373. pObj->object_Data.present = ObjectData_PR_graphic_object_data;
  3374. if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){
  3375. return -11;
  3376. }
  3377. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, pVmsObj->ImageType.ToIntDef(0)) != ASN_ERR_NONE){
  3378. return -200;
  3379. }
  3380. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsObj->Width) != ASN_ERR_NONE){
  3381. return -201;
  3382. }
  3383. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsObj->Height) != ASN_ERR_NONE){
  3384. return -202;
  3385. }
  3386. try
  3387. {
  3388. pVmsObj->pImageStream->Position = 0;
  3389. if (OCTET_STRING_fromBuf(&pObj->object_Data.choice.graphic_object_data.graphic_Data, (char *)pVmsObj->pImageStream->Memory, pVmsObj->pImageStream->Size) != ASN_ERR_NONE){
  3390. return -203;
  3391. }
  3392. }
  3393. catch(Exception &e)
  3394. {
  3395. bException = true;
  3396. SERROR("MemoryStream Allocation error: %s, FormId: %s", AnsiString(e.Message).c_str(), pVmsForm->FormId.c_str());
  3397. }
  3398. break;
  3399. case graphicID_object_data:
  3400. if (FVmsObj->FIsOldProtocol)
  3401. {
  3402. pObj->object_Data.present = ObjectData_PR_graphicID_object_data;
  3403. if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){
  3404. return -11;
  3405. }
  3406. if (asn_long2INTEGER(&pObj->object_Data.choice.graphicID_object_data.graphic_Type, pVmsObj->ImageType.ToIntDef(0)) != ASN_ERR_NONE){
  3407. return -300;
  3408. }
  3409. if (asn_long2INTEGER(&pObj->object_Data.choice.graphicID_object_data.graphic_Width, pVmsObj->Width) != ASN_ERR_NONE){
  3410. return -301;
  3411. }
  3412. if (asn_long2INTEGER(&pObj->object_Data.choice.graphicID_object_data.graphic_Height, pVmsObj->Height) != ASN_ERR_NONE){
  3413. return -302;
  3414. }
  3415. AnsiString sFtpImgId = GetFtpImageId(pVmsObj->ImageId);
  3416. //if (OCTET_STRING_fromString(&pObj->object_Data.choice.graphicID_object_data.graphic_DataID, pVmsObj->ImageId.c_str()) != ASN_ERR_NONE){
  3417. if (OCTET_STRING_fromString(&pObj->object_Data.choice.graphicID_object_data.graphic_DataID, sFtpImgId.c_str()) != ASN_ERR_NONE){
  3418. return -303;
  3419. }
  3420. }
  3421. else
  3422. {
  3423. pObj->object_Data.present = ObjectData_PR_graphic_object_data;
  3424. if (asn_long2INTEGER(&pObj->object_TypeCode, graphic_object_data) != ASN_ERR_NONE){
  3425. return -11;
  3426. }
  3427. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, pVmsObj->ImageType.ToIntDef(0)) != ASN_ERR_NONE){
  3428. return -200;
  3429. }
  3430. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsObj->Width) != ASN_ERR_NONE){
  3431. return -201;
  3432. }
  3433. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsObj->Height) != ASN_ERR_NONE){
  3434. return -202;
  3435. }
  3436. try
  3437. {
  3438. pVmsObj->pImageStream->Position = 0;
  3439. if (OCTET_STRING_fromBuf(&pObj->object_Data.choice.graphic_object_data.graphic_Data, (char *)pVmsObj->pImageStream->Memory, pVmsObj->pImageStream->Size) != ASN_ERR_NONE){
  3440. return -203;
  3441. }
  3442. }
  3443. catch(Exception &e)
  3444. {
  3445. bException = true;
  3446. SERROR("MemoryStream Allocation error: %s, FormId: %s", AnsiString(e.Message).c_str(), pVmsForm->FormId.c_str());
  3447. }
  3448. }
  3449. break;
  3450. } //switch
  3451. if (ASN_SEQUENCE_ADD(&pRTD->objects_zz, pObj)!= ASN_ERR_NONE)
  3452. {
  3453. return -16;
  3454. }
  3455. } //for
  3456. }
  3457. __finally
  3458. {
  3459. m_pVmsFormList->UnLock();
  3460. if (bException)
  3461. {
  3462. SERROR("LockFree OK");
  3463. }
  3464. }
  3465. return SYS_ERR_NONE;
  3466. }
  3467. //---------------------------------------------------------------------------
  3468. int __fastcall TVMSSThread::RealTimeDisplayBitmap(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg)
  3469. {
  3470. /* 모든 VMS를 이미지로 다운로드 하는 경우임
  3471. 이전 VMS도 FTP를 이용하는 경우(도형식) 이거나 문자식 이거나 모두 FTP로 다운로드 함
  3472. */
  3473. int result;
  3474. if (FVmsObj->FIsOldProtocol)
  3475. {
  3476. result = RealTimeDisplayBitmapOld(pRTD, Arg);
  3477. }
  3478. else
  3479. {
  3480. result = RealTimeDisplayBitmapNew(pRTD, Arg);
  3481. }
  3482. return result;
  3483. }
  3484. //---------------------------------------------------------------------------
  3485. int __fastcall TVMSSThread::RealTimeDisplayBitmapOld(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg)
  3486. {
  3487. TVmsForm *pVmsForm = NULL;
  3488. Object_t *pObj = NULL;
  3489. AnsiString ImageId;
  3490. AnsiString MessageId;
  3491. int ii;
  3492. bool bException = false;
  3493. ImageId = String(Arg.szFormId);
  3494. try
  3495. {
  3496. m_pVmsFormList->Lock();
  3497. pVmsForm = m_pVmsFormList->GetItem(Arg.Data.Form.Idx);
  3498. if (!pVmsForm)
  3499. {
  3500. SERROR("FormId Memory Not Found: %d", Arg.Data.Form.Idx);
  3501. return SYS_ERR_NONE;
  3502. }
  3503. if (Arg.Data.Form.Mode == 'B') //기본운영모드
  3504. {
  3505. if (FVmsObj->FIsOldProtocol)
  3506. MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
  3507. else
  3508. MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq);
  3509. }
  3510. else
  3511. {
  3512. MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
  3513. }
  3514. //LINFO("BMP_REALTIME(OLD): %s", MessageId.c_str());
  3515. if (OCTET_STRING_fromString(&pRTD->message_serialID, MessageId.c_str()) != ASN_ERR_NONE){
  3516. return -1;
  3517. }
  3518. if (asn_long2INTEGER(&pRTD->display_DurationQty, pVmsForm->DisplayTime) != ASN_ERR_NONE){
  3519. return -2;
  3520. }
  3521. if (asn_long2INTEGER(&pRTD->display_ModeCode, pVmsForm->DisplayMode.ToIntDef(0)) != ASN_ERR_NONE){
  3522. return -3;
  3523. }
  3524. if (asn_long2INTEGER(&pRTD->display_DirectionCode, pVmsForm->DisplayDir.ToIntDef(0)) != ASN_ERR_NONE){
  3525. return -4;
  3526. }
  3527. if (asn_long2INTEGER(&pRTD->background_ColorCode, pVmsForm->BkColor) != ASN_ERR_NONE){
  3528. return -5;
  3529. }
  3530. if (asn_long2INTEGER(&pRTD->object_Nbr, 1) != ASN_ERR_NONE){
  3531. return -6;
  3532. }
  3533. //이미지 객체 정보 생성
  3534. if ((pObj = (Object_t *)ASN1C_Alloc(sizeof(Object_t))) == NULL){
  3535. return -10;
  3536. }
  3537. if (asn_long2INTEGER(&pObj->object_TypeCode, object_TypeCode_graphic_id_object) != ASN_ERR_NONE){
  3538. return -11;
  3539. }
  3540. int IsBlinking = 0;
  3541. if (asn_long2INTEGER(&pObj->blinking_Code, blinking_Code_off) != ASN_ERR_NONE){
  3542. return -12;
  3543. }
  3544. if (asn_long2INTEGER(&pObj->x_Coordinate, 0) != ASN_ERR_NONE){
  3545. return -13;
  3546. }
  3547. if (asn_long2INTEGER(&pObj->y_Coordinate, 0) != ASN_ERR_NONE){
  3548. return -14;
  3549. }
  3550. int BkColor = 0;
  3551. if (asn_long2INTEGER(&pObj->data_BackgroundColor, color_black) != ASN_ERR_NONE){
  3552. return -15;
  3553. }
  3554. //이미지ID데이터
  3555. pObj->object_Data.present = ObjectData_PR_graphicID_object_data;
  3556. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, graphic_Type_bitmap) != ASN_ERR_NONE){
  3557. return -200;
  3558. }
  3559. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsForm->Width) != ASN_ERR_NONE){
  3560. return -201;
  3561. }
  3562. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsForm->Height) != ASN_ERR_NONE){
  3563. return -202;
  3564. }
  3565. if (OCTET_STRING_fromString(&pObj->object_Data.choice.graphicID_object_data.graphic_DataID, ImageId.c_str()) != ASN_ERR_NONE){
  3566. return -303;
  3567. }
  3568. FErrLine = 33;
  3569. if (ASN_SEQUENCE_ADD(&pRTD->objects_zz, pObj)!= ASN_ERR_NONE)
  3570. {
  3571. return -16;
  3572. }
  3573. }
  3574. __finally
  3575. {
  3576. FErrLine = 34;
  3577. m_pVmsFormList->UnLock();
  3578. if (bException)
  3579. {
  3580. SERROR("LockFree OK");
  3581. }
  3582. }
  3583. return SYS_ERR_NONE;
  3584. }
  3585. //---------------------------------------------------------------------------
  3586. int __fastcall TVMSSThread::RealTimeDisplayBitmapNew(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg)
  3587. {
  3588. TVmsForm *pVmsForm = NULL;
  3589. Object_t *pObj = NULL;
  3590. AnsiString MessageId;
  3591. int ii;
  3592. bool bException = false;
  3593. try
  3594. {
  3595. m_pVmsFormList->Lock();
  3596. pVmsForm = m_pVmsFormList->GetItem(Arg.Data.Form.Idx);
  3597. if (!pVmsForm)
  3598. {
  3599. SERROR("FormId Memory Not Found: %d", Arg.Data.Form.Idx);
  3600. return SYS_ERR_NONE;
  3601. }
  3602. if (Arg.Data.Form.Mode == 'B') //기본운영모드
  3603. {
  3604. if (FVmsObj->FIsOldProtocol)
  3605. MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
  3606. else
  3607. MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq);
  3608. }
  3609. else
  3610. {
  3611. MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
  3612. }
  3613. //LINFO("BMP_REALTIME(NEW): %s", MessageId.c_str());
  3614. if (OCTET_STRING_fromString(&pRTD->message_serialID, MessageId.c_str()) != ASN_ERR_NONE){
  3615. return -1;
  3616. }
  3617. if (asn_long2INTEGER(&pRTD->display_DurationQty, pVmsForm->DisplayTime) != ASN_ERR_NONE){
  3618. return -2;
  3619. }
  3620. if (asn_long2INTEGER(&pRTD->display_ModeCode, pVmsForm->DisplayMode.ToIntDef(0)) != ASN_ERR_NONE){
  3621. return -3;
  3622. }
  3623. if (asn_long2INTEGER(&pRTD->display_DirectionCode, pVmsForm->DisplayDir.ToIntDef(0)) != ASN_ERR_NONE){
  3624. return -4;
  3625. }
  3626. if (asn_long2INTEGER(&pRTD->background_ColorCode, pVmsForm->BkColor) != ASN_ERR_NONE){
  3627. return -5;
  3628. }
  3629. if (asn_long2INTEGER(&pRTD->object_Nbr, 1) != ASN_ERR_NONE){
  3630. return -6;
  3631. }
  3632. //이미지 객체 정보 생성
  3633. if ((pObj = (Object_t *)ASN1C_Alloc(sizeof(Object_t))) == NULL){
  3634. return -10;
  3635. }
  3636. if (asn_long2INTEGER(&pObj->object_TypeCode, object_TypeCode_graphic_object) != ASN_ERR_NONE){
  3637. return -11;
  3638. }
  3639. int IsBlinking = 0;
  3640. if (asn_long2INTEGER(&pObj->blinking_Code, blinking_Code_off) != ASN_ERR_NONE){
  3641. return -12;
  3642. }
  3643. if (asn_long2INTEGER(&pObj->x_Coordinate, 0) != ASN_ERR_NONE){
  3644. return -13;
  3645. }
  3646. if (asn_long2INTEGER(&pObj->y_Coordinate, 0) != ASN_ERR_NONE){
  3647. return -14;
  3648. }
  3649. int BkColor = 0;
  3650. if (asn_long2INTEGER(&pObj->data_BackgroundColor, color_black) != ASN_ERR_NONE){
  3651. return -15;
  3652. }
  3653. //이미지데이터
  3654. pObj->object_Data.present = ObjectData_PR_graphic_object_data;
  3655. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, graphic_Type_bitmap) != ASN_ERR_NONE){
  3656. return -200;
  3657. }
  3658. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsForm->Width) != ASN_ERR_NONE){
  3659. return -201;
  3660. }
  3661. if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsForm->Height) != ASN_ERR_NONE){
  3662. return -202;
  3663. }
  3664. try
  3665. {
  3666. pVmsForm->pStream->Position = 0;
  3667. if (OCTET_STRING_fromBuf(&pObj->object_Data.choice.graphic_object_data.graphic_Data, (char *)pVmsForm->pStream->Memory, pVmsForm->pStream->Size) != ASN_ERR_NONE){
  3668. return -203;
  3669. }
  3670. }
  3671. catch(Exception &e)
  3672. {
  3673. bException = true;
  3674. SERROR("MemoryStream Allocation error: %s, FormId: %s", AnsiString(e.Message).c_str(), pVmsForm->FormId.c_str());
  3675. }
  3676. if (ASN_SEQUENCE_ADD(&pRTD->objects_zz, pObj)!= ASN_ERR_NONE)
  3677. {
  3678. return -16;
  3679. }
  3680. }
  3681. __finally
  3682. {
  3683. m_pVmsFormList->UnLock();
  3684. if (bException)
  3685. {
  3686. SERROR("LockFree OK");
  3687. }
  3688. }
  3689. return SYS_ERR_NONE;
  3690. }
  3691. //---------------------------------------------------------------------------
  3692. int __fastcall TVMSSThread::ScheduledDisplayData(ScheduledDisplayMessage_t *pSD, PUBLICATION_ARGUMENT Arg)
  3693. {
  3694. //AAAAAAAAAA
  3695. FErrLine = 15;
  3696. OCTET_STRING_t *pSid;
  3697. AnsiString MessageId;
  3698. int ii;
  3699. try
  3700. {
  3701. m_pVmsFormList->Lock();
  3702. int nFormCnt = m_pVmsFormList->Count();
  3703. if (asn_long2INTEGER(&pSD->message_Nbr, nFormCnt) != ASN_ERR_NONE)
  3704. {
  3705. return -1;
  3706. }
  3707. for (ii = 0; ii < nFormCnt; ii++)
  3708. {
  3709. TVmsForm *pVmsForm = m_pVmsFormList->GetItem(ii);
  3710. if (!pVmsForm) continue;
  3711. if (Arg.Data.Form.Mode == 'B')
  3712. {
  3713. if (FVmsObj->FIsOldProtocol)
  3714. MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
  3715. else
  3716. MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq);
  3717. }
  3718. else
  3719. {
  3720. MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
  3721. }
  3722. //LINFO("SCHEDULE: %s", MessageId.c_str());
  3723. if ((pSid = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t))) == NULL)
  3724. {
  3725. return -10;
  3726. }
  3727. if (OCTET_STRING_fromString(pSid, MessageId.c_str()) != ASN_ERR_NONE)
  3728. {
  3729. return -11;
  3730. }
  3731. if (ASN_SEQUENCE_ADD(&pSD->message_serialIDs, pSid)!= ASN_ERR_NONE)
  3732. {
  3733. return -12;
  3734. }
  3735. }
  3736. }
  3737. __finally
  3738. {
  3739. m_pVmsFormList->UnLock();
  3740. }
  3741. return SYS_ERR_NONE;
  3742. }
  3743. //---------------------------------------------------------------------------
  3744. int __fastcall TVMSSThread::DownloadGraphicData(DownloadGraphicDataMessage_t *pDGD, PUBLICATION_ARGUMENT Arg)
  3745. {
  3746. FErrLine = 16;
  3747. AnsiString sNmbr = FVmsObj->DOWNLOAD->Unit[Arg.Data.Down.Idx].FileId;
  3748. TCDSImage *pVmsImage = ImageManager->FLists.Find(sNmbr+"0");
  3749. if (!pVmsImage) return -10;
  3750. TMemoryStream *pStream = new TMemoryStream;
  3751. try
  3752. {
  3753. if (OCTET_STRING_fromString(&pDGD->download_GraphicData_ID, sNmbr.c_str()) != ASN_ERR_NONE)
  3754. {
  3755. return -1;
  3756. }
  3757. pStream->Clear();
  3758. pStream->Position = 0;
  3759. pVmsImage->pImage->Canvas->Lock();
  3760. pVmsImage->pImage->Picture->Graphic->SaveToStream(pStream);
  3761. pVmsImage->pImage->Canvas->Unlock();
  3762. pStream->Position = 0;
  3763. if (OCTET_STRING_fromBuf(&pDGD->download_GraphicData, (char *)pStream->Memory, pStream->Size) != ASN_ERR_NONE)
  3764. {
  3765. return -2;
  3766. }
  3767. }
  3768. __finally
  3769. {
  3770. SAFE_DELETE(pStream);
  3771. }
  3772. return VERR_NONE;
  3773. }
  3774. //---------------------------------------------------------------------------
  3775. /*
  3776. * 송신 패킷 생성
  3777. * arguments
  3778. * void
  3779. * return
  3780. * void
  3781. */
  3782. int __fastcall TVMSSThread::StatusControlData(StatusControlMessage_t *pSC, PUBLICATION_ARGUMENT Arg)
  3783. {
  3784. FErrLine = 17;
  3785. int modulePower;
  3786. int luminance = 0;
  3787. #if 0
  3788. //TODO
  3789. if (m_pState->Comm == vms_normal)
  3790. {
  3791. luminance = (int)m_pState->LuminanceStatus;
  3792. }
  3793. #endif
  3794. if (Arg.Data.Ctl == CTL_MODULE_POWER_ON)
  3795. {
  3796. modulePower = modulePower_ControlCode_on;
  3797. }
  3798. else
  3799. if (Arg.Data.Ctl == CTL_MODULE_POWER_OFF)
  3800. {
  3801. modulePower = modulePower_ControlCode_off;
  3802. }
  3803. else
  3804. if (Arg.Data.Ctl == CTL_CONTROLLER_RESET)
  3805. {
  3806. modulePower = modulePower_ControlCode_on;
  3807. }
  3808. else
  3809. if (Arg.Data.Ctl == CTL_LUMINANCE_SET)
  3810. {
  3811. modulePower = modulePower_ControlCode_on;
  3812. luminance = (int)FCliCtl.CtlType;
  3813. }
  3814. else
  3815. {
  3816. return -1;
  3817. }
  3818. if (asn_long2INTEGER(&pSC->modulePower_ControlCode, modulePower) != ASN_ERR_NONE)
  3819. {
  3820. return -2;
  3821. }
  3822. #if 1
  3823. if (asn_long2INTEGER(&pSC->luminance_ControlCode, luminance) != ASN_ERR_NONE)
  3824. {
  3825. return -3;
  3826. }
  3827. #else
  3828. if (asn_long2INTEGER(&pSC->luminance_ControlCode, 0) != ASN_ERR_NONE)
  3829. {
  3830. return -3;
  3831. }
  3832. #endif
  3833. if (asn_long2INTEGER(&pSC->fan_ControlCode, fan_ControlCode_auto) != ASN_ERR_NONE)
  3834. {
  3835. return -4;
  3836. }
  3837. if (asn_long2INTEGER(&pSC->heater_ControlCode, heater_ControlCode_auto) != ASN_ERR_NONE)
  3838. {
  3839. return -5;
  3840. }
  3841. pSC->externalLight_ControlCode = NULL;
  3842. pSC->alarmLight_ControlCode = NULL;
  3843. pSC->speaker_ControlCode = NULL;
  3844. if (Arg.Data.Ctl == CTL_CONTROLLER_RESET)
  3845. {
  3846. if ((pSC->controller_Reset = (BOOLEAN_t *)ASN1C_Alloc(sizeof(BOOLEAN_t))) == NULL)
  3847. {
  3848. return -6;
  3849. }
  3850. *pSC->controller_Reset = true;
  3851. }
  3852. else
  3853. {
  3854. if ((pSC->controller_Reset = (BOOLEAN_t *)ASN1C_Alloc(sizeof(BOOLEAN_t))) == NULL)
  3855. {
  3856. return -6;
  3857. }
  3858. *pSC->controller_Reset = false;
  3859. //pSC->controller_Reset = NULL;
  3860. }
  3861. pSC->controllerTime_Reset = NULL;
  3862. return SYS_ERR_NONE;
  3863. }
  3864. //---------------------------------------------------------------------------
  3865. /*
  3866. * 송신 패킷 생성
  3867. * arguments
  3868. * void
  3869. * return
  3870. * void
  3871. */
  3872. int __fastcall TVMSSThread::StatusSettingData(StatusSettingMessage_t *pSS, PUBLICATION_ARGUMENT Arg)
  3873. {
  3874. FErrLine = 18;
  3875. //INTEGER_t scheduledMessage_OperatingTimeQty;
  3876. //INTEGER_t module_OperatingTemperatureQty;
  3877. //INTEGER_t fan_OperatingTemperatureQty;
  3878. //INTEGER_t heater_OperatingTemperatureQty;
  3879. INTEGER_t *externalLight_OperatingLuminanceQty /* OPTIONAL */;
  3880. //INTEGER_t *module_BasicFailureRate /* OPTIONAL */;
  3881. //INTEGER_t *maximum_RetryQty /* OPTIONAL */;
  3882. //INTEGER_t *response_TimeOutQty /* OPTIONAL */;
  3883. INTEGER_t *blinking_CycleTime /* OPTIONAL */;
  3884. if(asn_long2INTEGER(&pSS->scheduledMessage_OperatingTimeQty, Arg.Data.Set.SchMsgTime) != ASN_ERR_NONE)
  3885. {
  3886. return -1;
  3887. }
  3888. if(asn_long2INTEGER(&pSS->module_OperatingTemperatureQty, Arg.Data.Set.ModuleTemp) != ASN_ERR_NONE)
  3889. {
  3890. return -2;
  3891. }
  3892. if(asn_long2INTEGER(&pSS->fan_OperatingTemperatureQty, Arg.Data.Set.FanTemp) != ASN_ERR_NONE)
  3893. {
  3894. return -3;
  3895. }
  3896. if(asn_long2INTEGER(&pSS->heater_OperatingTemperatureQty, Arg.Data.Set.HeaterTemp) != ASN_ERR_NONE)
  3897. {
  3898. return -4;
  3899. }
  3900. pSS->externalLight_OperatingLuminanceQty = NULL;
  3901. if ((pSS->module_BasicFailureRate = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL)
  3902. {
  3903. return -5;
  3904. }
  3905. if(asn_long2INTEGER(pSS->module_BasicFailureRate, Arg.Data.Set.ModuleFail) != ASN_ERR_NONE)
  3906. {
  3907. return -6;
  3908. }
  3909. if ((pSS->maximum_RetryQty = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL)
  3910. {
  3911. return -7;
  3912. }
  3913. if(asn_long2INTEGER(pSS->maximum_RetryQty, Arg.Data.Set.RetryCount) != ASN_ERR_NONE)
  3914. {
  3915. return -8;
  3916. }
  3917. if ((pSS->response_TimeOutQty = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL)
  3918. {
  3919. return -9;
  3920. }
  3921. if(asn_long2INTEGER(pSS->response_TimeOutQty, Arg.Data.Set.TimeOut) != ASN_ERR_NONE)
  3922. {
  3923. return -10;
  3924. }
  3925. if (FVmsObj->FIsOldProtocol)
  3926. {
  3927. if ((pSS->blinking_CycleTime = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL)
  3928. {
  3929. return -5;
  3930. }
  3931. if(asn_long2INTEGER(pSS->blinking_CycleTime, 5) != ASN_ERR_NONE)
  3932. {
  3933. return -6;
  3934. }
  3935. }
  3936. else
  3937. {
  3938. pSS->blinking_CycleTime = NULL;
  3939. }
  3940. return SYS_ERR_NONE;
  3941. }
  3942. //---------------------------------------------------------------------------
  3943. /*
  3944. * 서버 처리 루틴
  3945. * arguments
  3946. * void
  3947. * return
  3948. * void
  3949. */
  3950. void __fastcall TVMSSThread::ServerStateMachine(void)
  3951. {
  3952. FErrLine = 19;
  3953. int result;
  3954. bool flag;
  3955. result = SYS_ERR_NONE;
  3956. //timeout check
  3957. if (m_RxLen && (CommUtil_TimeDiff(m_rTimer) > m_Server.TimeOut))
  3958. {
  3959. m_RxLen = 0;
  3960. ProcErrorState(TRUE, SYS_ERR_RECEIVE_TIMEOUT);
  3961. return;
  3962. }
  3963. #if 0
  3964. {
  3965. switch (m_Server.State)
  3966. {
  3967. #if 0
  3968. case ST_IDLE: LDEBUG("IDLE"); break;
  3969. case ST_INITIATE: LDEBUG("INITIATE"); break;
  3970. case ST_SECTION: LDEBUG("SECTION"); break;
  3971. case ST_CLOSE: LDEBUG("CLOSE"); break;
  3972. #endif
  3973. case ST_LOCAL_COMMAND: LDEBUG("LOCAL_COMMAND"); break;
  3974. case ST_CLIENT_COMMAND: LDEBUG("CLIENT_COMMAND"); break;
  3975. case ST_LOCAL_WAIT: LDEBUG("LOCAL_WAIT"); break;
  3976. case ST_CLIENT_WAIT: LDEBUG("CLIENT_WAIT"); break;
  3977. default: LDEBUG("Unknown State[%d]", m_Server.State); break;
  3978. }
  3979. }
  3980. #endif
  3981. switch(m_Server.State)
  3982. {
  3983. case ST_IDLE:
  3984. if (CommUtil_TimeDiff(m_Server.sTimer) > SERVER_CONNECT_RETRY_TIME)
  3985. {
  3986. m_Server.sTimer = Now();
  3987. if (m_Server.iRetry <= 0)
  3988. {
  3989. m_Server.State = ST_CLOSE;
  3990. }
  3991. else
  3992. {
  3993. m_Server.State = ST_INITIATE;
  3994. }
  3995. }
  3996. break;
  3997. case ST_INITIATE:
  3998. if ((result = ProcessCommand(AI_Initiate, NULL)) == SYS_ERR_NONE)
  3999. {
  4000. m_Server.State = ST_IDLE;
  4001. m_Server.iRetry = 0;
  4002. }
  4003. else
  4004. {
  4005. if (--m_Server.iRetry <= 0)
  4006. {
  4007. m_Server.State = ST_CLOSE;
  4008. }
  4009. }
  4010. break;
  4011. case ST_SECTION:
  4012. if (CommUtil_TimeDiff(m_WatchDogTimer) > FWatchDogTime)
  4013. {
  4014. SERROR("WatchDogTime over");
  4015. /* 통신 offline 종료 처리 */
  4016. m_Server.State = ST_CLOSE;
  4017. break;
  4018. }
  4019. /* 레지스터 정보 체크 */
  4020. CheckRegistered();
  4021. break;
  4022. case ST_CLOSE:
  4023. #if 0
  4024. arg.Terminate = Logout_serverShutdown;
  4025. ProcessCommand(AI_Terminate, &arg);
  4026. #endif
  4027. Terminate();
  4028. break;
  4029. case ST_LOCAL_COMMAND:
  4030. result = CheckLocalData(&flag);
  4031. if (flag)
  4032. {
  4033. if (result == VERR_NONE)
  4034. {
  4035. m_Server.State = ST_LOCAL_WAIT;
  4036. }
  4037. else
  4038. {
  4039. if (--m_Server.iRetry <= 0)
  4040. {
  4041. m_Server.State = ST_CLOSE;
  4042. }
  4043. }
  4044. }
  4045. else
  4046. {
  4047. m_Server.State = ST_CLIENT_COMMAND;
  4048. }
  4049. break;
  4050. case ST_CLIENT_COMMAND:
  4051. result = CheckClientData(&flag);
  4052. if (flag)
  4053. {
  4054. if (result == VERR_NONE)
  4055. {
  4056. m_Server.State = ST_CLIENT_WAIT;
  4057. }
  4058. else
  4059. {
  4060. if (--m_Server.iRetry <= 0)
  4061. {
  4062. m_Server.State = ST_CLOSE;
  4063. }
  4064. }
  4065. }
  4066. else
  4067. {
  4068. m_Server.State = ST_SECTION;
  4069. }
  4070. break;
  4071. case ST_LOCAL_WAIT:
  4072. if (CommUtil_TimeDiff(m_Server.cTimer) > m_Server.TimeOut)
  4073. {
  4074. if (m_Server.iRetry > 0){
  4075. m_Server.State = ST_LOCAL_COMMAND;
  4076. }else{
  4077. m_Server.State = ST_CLOSE;
  4078. }
  4079. }
  4080. break;
  4081. case ST_CLIENT_WAIT:
  4082. if (CommUtil_TimeDiff(m_Server.cTimer) > m_Server.TimeOut)
  4083. {
  4084. if (m_Server.iRetry > 0)
  4085. {
  4086. ClientResponse(SYS_ERR_NO_RES);
  4087. m_Server.State = ST_CLIENT_COMMAND;
  4088. }
  4089. else
  4090. {
  4091. m_Server.State = ST_CLOSE;
  4092. }
  4093. }
  4094. break;
  4095. default:
  4096. m_Server.State = ST_IDLE;
  4097. break;
  4098. }/* end switch */
  4099. if (result)
  4100. {
  4101. ProcErrorState(FALSE, result);
  4102. }
  4103. }
  4104. //---------------------------------------------------------------------------
  4105. /*
  4106. * 에러 처리
  4107. * arguments
  4108. * void
  4109. * return
  4110. * void
  4111. */
  4112. void __fastcall TVMSSThread::ProcErrorState(bool flag, int result)
  4113. {
  4114. FErrLine = 20;
  4115. #if 1
  4116. {
  4117. AnsiString strLog;
  4118. switch(result)
  4119. {
  4120. case SYS_ERR_NONE: strLog.sprintf("no error [%d]", result); break;
  4121. case SYS_ERR_OTHER: strLog.sprintf("other [%d]", result); break;
  4122. case SYS_ERR_INTERNAL: strLog.sprintf("internal system error(kernel..) [%d]", result); break;
  4123. case SYS_ERR_MEMORY: strLog.sprintf("memory overflow [%d]", result); break;
  4124. case SYS_ERR_DATABASE: strLog.sprintf("system database error [%d]", result); break;
  4125. case SYS_ERR_RESET: strLog.sprintf("system reset [%d]", result); break;
  4126. case SYS_ERR_START: strLog.sprintf("system start [%d]", result); break;
  4127. case SYS_ERR_OFFLINE: strLog.sprintf("offline [%d]", result); break;
  4128. case SYS_ERR_NO_RES: strLog.sprintf("no response [%d]", result); break;
  4129. case SYS_ERR_ACCESS: strLog.sprintf("access denied [%d]", result); break;
  4130. case SYS_ERR_INVALID: strLog.sprintf("invalid data type [%d]", result); break;
  4131. case SYS_ERR_UNKNOWN: strLog.sprintf("unknown data type [%d]", result); break;
  4132. case SYS_ERR_WRITE_LENGTH: strLog.sprintf("write length [%d]", result); break;
  4133. case SYS_ERR_PACKET_SIZE_LARGE: strLog.sprintf("packet size large [%d]", result); break;
  4134. case SYS_ERR_INVALID_TAG: strLog.sprintf("invalid tag [%d]", result); break;
  4135. case SYS_ERR_CRC: strLog.sprintf("crc [%d]", result); break;
  4136. case SYS_ERR_LENGTH: strLog.sprintf("length [%d]", result); break;
  4137. case SYS_ERR_ADDRESS: strLog.sprintf("address [%d]", result); break;
  4138. case SYS_ERR_HEADER_OPTIONS: strLog.sprintf("header options [%d]", result); break;
  4139. case SYS_ERR_UNKNOWN_COMMAND: strLog.sprintf("unknown command [%d]", result); break;
  4140. case SYS_ERR_RECEIVE_TIMEOUT: strLog.sprintf("receive timeout [%d]", result); break;
  4141. case SYS_ERR_DATA_SIZE: strLog.sprintf("data size [%d]", result); break;
  4142. case SYS_ERR_MISMATCH: strLog.sprintf("mismatch command [%d]", result); break;
  4143. case SYS_ERR_INVALID_PARA: strLog.sprintf("invalid parameter [%d]", result); break;
  4144. case SYS_ERR_MOVEMENT: strLog.sprintf("movement [%d]", result); break;
  4145. case SYS_ERR_UNAUTHORIZED: strLog.sprintf("unauthorized [%d]", result); break;
  4146. case SYS_ERR_DATEXDATAPACKET_DECODE: strLog.sprintf("DatexDataPacket decode [%d]", result); break;
  4147. case SYS_ERR_INVALID_VERSION_NUMBER: strLog.sprintf("invalid version number [%d]", result); break;
  4148. case SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE: strLog.sprintf("C2CAuthenticatedMessage decode [%d]", result); break;
  4149. case SYS_ERR_C2CAUTHENTICATEDMESSAGE: strLog.sprintf("C2CAuthenticatedMessage [%d]", result); break;
  4150. case SYS_ERR_NOT_LOGIN: strLog.sprintf("Not login [%d]", result); break;
  4151. case SYS_ERR_ACCEPT_TYPE: strLog.sprintf("Accept Type [%d]", result); break;
  4152. case SYS_ERR_DATEXPUBLISH_FORMAT: strLog.sprintf("datexPublish Format [%d]", result); break;
  4153. case SYS_ERR_DATEXPUBLISH_TYPE: strLog.sprintf("datexPublish Type [%d]", result); break;
  4154. case SYS_ERR_UNKNOWN_MESSAGE_ID: strLog.sprintf("unknown Message id [%d]", result); break;
  4155. case SYS_ERR_MESSAGE_DECODE: strLog.sprintf("Message decode [%d]", result); break;
  4156. case SYS_ERR_DATEXDATAPACKET_ENCODE: strLog.sprintf("DatexDataPacket encode [%d]", result); break;
  4157. case SYS_ERR_C2CAUTHENTICATEDMESSAGE_ENCODE: strLog.sprintf("C2CAuthenticatedMessage encode [%d]", result); break;
  4158. case SYS_ERR_MESSAGE_ENCODE: strLog.sprintf("Message encode [%d]", result); break;
  4159. case SYS_ERR_PUBLICATIONDATA_ENCODE: strLog.sprintf("PublicationData encode [%d]", result); break;
  4160. case SYS_ERR_MISMATCH_DESTINATION_TEXT: strLog.sprintf("mismatch Destination text [%d]", result); break;
  4161. case SYS_ERR_DATEXLOGIN_VALUE: strLog.sprintf("Login Value [%d]", result); break;
  4162. case SYS_ERR_SUBSCRIPTION_TYPE: strLog.sprintf("SubscriptionType Type [%d]", result); break;
  4163. case SYS_ERR_SUBSCRIPTION_STATUS_VALUE: strLog.sprintf("SubscriptionType Status Value [%d]", result); break;
  4164. case SYS_ERR_SUBSCRIPTION_MODE_VALUE: strLog.sprintf("SubscriptionType Mode Value [%d]", result); break;
  4165. case SYS_ERR_SUBSCRIPTION_FORMAT_VALUE: strLog.sprintf("SubscriptionType Format Value [%d]", result); break;
  4166. case SYS_ERR_HANGUL_CONVERSION: strLog.sprintf("Hangul Conversion [%d]", result); break;
  4167. case SYS_ERR_INVALID_TAGANDLEN: strLog.sprintf("invalid Tag And Len [%d]", result); break;
  4168. case SYS_ERR_PUBLICATIONDATA_DECODE: strLog.sprintf("PublicationData decode [%d]", result); break;
  4169. default: strLog.sprintf("Unknown Error [%d]", result); break;
  4170. }
  4171. if (flag){
  4172. SERROR("Recv Error %s", strLog.c_str());
  4173. }else{
  4174. SERROR("Send Error %s", strLog.c_str());
  4175. }
  4176. }
  4177. #endif
  4178. }
  4179. //---------------------------------------------------------------------------
  4180. /*
  4181. * 상태 변경
  4182. * arguments
  4183. * void
  4184. * return
  4185. * void
  4186. */
  4187. void __fastcall TVMSSThread::SetServerState(int Case)
  4188. {
  4189. FErrLine = 21;
  4190. switch(m_Server.State)
  4191. {
  4192. case ST_LOCAL_WAIT:
  4193. if (Case == SET_SERVER_SUCC)
  4194. {
  4195. m_Server.State = ST_CLIENT_COMMAND;
  4196. }
  4197. else
  4198. if (Case == SET_SERVER_FAIL)
  4199. {
  4200. m_Server.State = ST_LOCAL_COMMAND;
  4201. }
  4202. break;
  4203. case ST_CLIENT_WAIT:
  4204. if (Case == SET_SERVER_SUCC)
  4205. {
  4206. m_Server.State = ST_SECTION;
  4207. }
  4208. else
  4209. if (Case == SET_SERVER_FAIL)
  4210. {
  4211. m_Server.State = ST_CLIENT_COMMAND;
  4212. }
  4213. break;
  4214. default:
  4215. break;
  4216. }
  4217. }
  4218. //---------------------------------------------------------------------------
  4219. /*
  4220. *
  4221. * arguments
  4222. * void
  4223. * return
  4224. * void
  4225. */
  4226. int __fastcall TVMSSThread::CheckRegistered()
  4227. {
  4228. FErrLine = 22;
  4229. int result;
  4230. result = SYS_ERR_NONE;
  4231. m_Server.State = ST_LOCAL_COMMAND;
  4232. return result;
  4233. }
  4234. //---------------------------------------------------------------------------
  4235. int __fastcall TVMSSThread::CheckLocalData(bool *AFlag)
  4236. {
  4237. FErrLine = 23;
  4238. int nResult = VERR_NONE;
  4239. COMMAND_ARGUMENT arg;
  4240. BYTE CmdCode;
  4241. *AFlag = false;
  4242. CmdCode = 0x00;
  4243. memset(&arg, 0x00, sizeof(arg));
  4244. memset(&FSvrCtl, 0x00, sizeof(FSvrCtl));
  4245. #if 0
  4246. #if 0
  4247. if (m_Registered.RealTimeDisplayMessage == false)
  4248. {
  4249. LINFO("**** RealTimeDisplayMessage 요청");
  4250. arg.Publication.SubscribeSerialNbr = NBR_REALTIME_DISPLAY_REQ;
  4251. arg.Publication.obj = OBJ_DisplayingData;
  4252. arg.Publication.Data.Ctl = CTL_REALTIMEDISPLAY_REQ;
  4253. CmdCode = AI_DisplayingDataMessage;
  4254. nResult = ProcessCommand(CmdCode, &arg);
  4255. *AFlag = true;
  4256. return nResult;
  4257. }
  4258. #endif
  4259. if (m_Registered.ScreenDataStatusMessage == false)
  4260. {
  4261. LINFO("**** ScreenDataStatusMessage 요청");
  4262. arg.Publication.SubscribeSerialNbr = NBR_SCREEN_STATUS_REQ;
  4263. arg.Publication.obj = OBJ_ScreenStatus;
  4264. arg.Publication.Data.Ctl = CTL_SCREENSTATUS_REQ;
  4265. CmdCode = AI_ScreenStatusMessage;
  4266. nResult = ProcessCommand(CmdCode, &arg);
  4267. *AFlag = true;
  4268. return nResult;
  4269. }
  4270. #endif
  4271. /* FORM */
  4272. if (FVmsObj->CTLMODE->Enable == object_enable)
  4273. {
  4274. m_pVmsFormList->Lock();
  4275. try
  4276. {
  4277. //pObj->FBmpDownload, Bitmap 전송여부와 상관없이
  4278. //FTP다운로드가 필요한 경우임...
  4279. if (FVmsObj->FIsFtpDownload)
  4280. {
  4281. int nFormCnt = m_pVmsFormList->Count();
  4282. for (int ii = 0; ii < nFormCnt; ii++)
  4283. {
  4284. TVmsForm *pVmsForm = m_pVmsFormList->GetItem(ii);
  4285. if (pVmsForm)
  4286. {
  4287. if (pVmsForm->FtpRes == false)
  4288. {
  4289. arg.Publication.SubscribeSerialNbr = NBR_BASE_REALTIMEDISPLAY + ii;
  4290. arg.Publication.obj = OBJ_RealTimeDisplay;
  4291. arg.Publication.Data.Form.Idx = ii;
  4292. if (FVmsObj->CTLMODE->Control == 'B') //기본운영모드
  4293. {
  4294. if (FVmsObj->FIsOldProtocol)
  4295. sprintf(arg.Publication.szFormId, "%s%02d", FVmsObj->VmsDownId.c_str(), ii);
  4296. else
  4297. sprintf(arg.Publication.szFormId, "%s9%d", FVmsObj->VmsDownId.c_str(), ii);
  4298. }
  4299. else
  4300. {
  4301. sprintf(arg.Publication.szFormId, "%s%02d", FVmsObj->VmsDownId.c_str(), ii);
  4302. }
  4303. FSvrCtl.obj = OBJ_RealTimeDisplay;
  4304. FSvrCtl.DataPacketNumber = m_DataPacketNumber;
  4305. FSvrCtl.Idx = ii;
  4306. CmdCode = AI_TransferDone;
  4307. break;
  4308. }
  4309. }
  4310. }
  4311. if (CmdCode == 0x00)
  4312. {
  4313. arg.Publication.SubscribeSerialNbr = NBR_BASE_SCHEDULEDDISPLAY;
  4314. arg.Publication.obj = OBJ_ScheduledDisplay;
  4315. FSvrCtl.obj = OBJ_ScheduledDisplay;
  4316. FSvrCtl.DataPacketNumber = m_DataPacketNumber;
  4317. CmdCode = AI_ScheduledDisplayMessage;
  4318. }
  4319. arg.Publication.Data.Form.Mode = FVmsObj->CTLMODE->Control;
  4320. }
  4321. else
  4322. {
  4323. int nFormCnt = m_pVmsFormList->Count();
  4324. for (int ii = 0; ii < nFormCnt; ii++)
  4325. {
  4326. TVmsForm *pVmsForm = m_pVmsFormList->GetItem(ii);
  4327. if (pVmsForm)
  4328. {
  4329. if (pVmsForm->SvcRes == false)
  4330. {
  4331. arg.Publication.SubscribeSerialNbr = NBR_BASE_REALTIMEDISPLAY + ii;
  4332. arg.Publication.obj = OBJ_RealTimeDisplay;
  4333. arg.Publication.Data.Form.Idx = ii;
  4334. FSvrCtl.obj = OBJ_RealTimeDisplay;
  4335. FSvrCtl.DataPacketNumber = m_DataPacketNumber;
  4336. FSvrCtl.Idx = ii;
  4337. CmdCode = AI_RealTimeDisplayMessage;
  4338. break;
  4339. }
  4340. }
  4341. }
  4342. if (CmdCode == 0x00)
  4343. {
  4344. arg.Publication.SubscribeSerialNbr = NBR_BASE_SCHEDULEDDISPLAY;
  4345. arg.Publication.obj = OBJ_ScheduledDisplay;
  4346. FSvrCtl.obj = OBJ_ScheduledDisplay;
  4347. FSvrCtl.DataPacketNumber = m_DataPacketNumber;
  4348. CmdCode = AI_ScheduledDisplayMessage;
  4349. }
  4350. arg.Publication.Data.Form.Mode = FVmsObj->CTLMODE->Control;
  4351. }
  4352. }
  4353. __finally
  4354. {
  4355. m_pVmsFormList->UnLock();
  4356. if (nResult == VERR_NONE && CmdCode != 0x00)
  4357. {
  4358. nResult = ProcessCommand(CmdCode, &arg);
  4359. }
  4360. *AFlag = true;
  4361. }
  4362. }
  4363. /* ON/OFF */
  4364. if (FVmsObj->MODULE.PowerOnTime != FVmsObj->MODULE.PowerOffTime)
  4365. {
  4366. //On/Off 시각이 같지 않을 경우 On/Off 명령 수행
  4367. if ((FVmsObj->MODULE.PowerOnTime == Now().FormatString("yyyymmddhhnn")) &&
  4368. (FVmsObj->MODULE.Retry > 0))
  4369. {
  4370. arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER;
  4371. arg.Publication.obj = OBJ_StatusControl;
  4372. arg.Publication.Data.Ctl = CTL_MODULE_POWER_ON;
  4373. CmdCode = AI_StatusControlMessage;
  4374. nResult = ProcessCommand(CmdCode, &arg);
  4375. if (nResult == SYS_ERR_NONE)
  4376. {
  4377. }
  4378. LINFO("**** Module Power On: %d", FVmsObj->MODULE.Retry);
  4379. --FVmsObj->MODULE.Retry; // 3회 전송
  4380. *AFlag = true;
  4381. return nResult;
  4382. }
  4383. if ((FVmsObj->MODULE.PowerOffTime == Now().FormatString("yyyymmddhhnn")) &&
  4384. (FVmsObj->MODULE.Retry > 0))
  4385. {
  4386. arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER;
  4387. arg.Publication.obj = OBJ_StatusControl;
  4388. arg.Publication.Data.Ctl = CTL_MODULE_POWER_OFF;
  4389. CmdCode = AI_StatusControlMessage;
  4390. nResult = ProcessCommand(CmdCode, &arg);
  4391. if (nResult == SYS_ERR_NONE)
  4392. {
  4393. }
  4394. LINFO("**** Module Power Off: %d", FVmsObj->MODULE.Retry);
  4395. --FVmsObj->MODULE.Retry; // 3회 전송
  4396. *AFlag = true;
  4397. return nResult;
  4398. }
  4399. }
  4400. /* LUMINANCE */
  4401. //LUMINANCE시각이 같을 경우 LUMINANCE 명령 수행
  4402. if ((FVmsObj->LUMINANCE.SchTime == Now().FormatString("yyyymmddhhnn")) &&
  4403. (FVmsObj->LUMINANCE.Retry > 0))
  4404. {
  4405. arg.Publication.SubscribeSerialNbr = NBR_LUMINANCE;
  4406. arg.Publication.obj = OBJ_StatusControl;
  4407. arg.Publication.Data.Ctl = CTL_LUMINANCE_SET;
  4408. FCliCtl.CtlType = FVmsObj->LUMINANCE.Value;
  4409. CmdCode = AI_StatusControlMessage;
  4410. nResult = ProcessCommand(CmdCode, &arg);
  4411. if (nResult == SYS_ERR_NONE)
  4412. {
  4413. }
  4414. LINFO("**** Luminance control: %d", FVmsObj->LUMINANCE.Retry);
  4415. --FVmsObj->LUMINANCE.Retry; // 3회 전송
  4416. *AFlag = true;
  4417. return nResult;
  4418. }
  4419. /* DOWNLOAD */
  4420. if (FVmsObj->DOWNLOAD->Enable == vms_download_enable)
  4421. {
  4422. for (int ii = 0; ii < FVmsObj->DOWNLOAD->Count; ii++)
  4423. {
  4424. if (FVmsObj->DOWNLOAD->Unit[ii].SendResult == vms_download_fail)
  4425. {
  4426. arg.Publication.SubscribeSerialNbr = NBR_BASE_DOWNLOADGRAPHICDATA + ii;
  4427. arg.Publication.obj = OBJ_DownloadGraphicData;
  4428. arg.Publication.Data.Down.Idx = ii;
  4429. FSvrCtl.obj = OBJ_DownloadGraphicData;
  4430. FSvrCtl.DataPacketNumber = m_DataPacketNumber;
  4431. FSvrCtl.Idx = ii;
  4432. CmdCode = AI_DownloadGraphicDataMessage;
  4433. break;
  4434. }
  4435. }
  4436. if ((nResult == VERR_NONE) && (CmdCode != 0x00))
  4437. {
  4438. nResult = ProcessCommand(CmdCode, &arg);
  4439. if (nResult == SYS_ERR_NONE)
  4440. {
  4441. }
  4442. *AFlag = true;
  4443. return nResult;
  4444. }
  4445. }
  4446. return nResult;
  4447. }
  4448. //---------------------------------------------------------------------------
  4449. /*
  4450. *
  4451. * arguments
  4452. * void
  4453. * return
  4454. * void
  4455. */
  4456. int __fastcall TVMSSThread::CheckClientData(bool *AFlag)
  4457. {
  4458. FErrLine = 24;
  4459. int nResult = VERR_NONE;
  4460. IPCUDPPACKET *pPI = NULL;
  4461. TList *pPackQueue;
  4462. COMMAND_ARGUMENT arg;
  4463. BYTE CmdCode;
  4464. *AFlag = false;
  4465. pPackQueue = FVmsObj->pPackQueue->LockList();
  4466. try
  4467. {
  4468. for (int ii = 0; ii < pPackQueue->Count; ii++)
  4469. {
  4470. pPI = (IPCUDPPACKET *)pPackQueue->Items[ii];
  4471. memcpy((char*)&FCliReq, pPI, sizeof(FCliReq));
  4472. memset((char*)&FCliCtl, 0x00, sizeof(FCliCtl));
  4473. memset((char*)&arg, 0x00, sizeof(arg));
  4474. switch(pPI->OPCode)
  4475. {
  4476. case INT_OP_VMS_POWER_CTL:
  4477. if (pPI->Data)
  4478. {
  4479. INT_VMS_POWER_CTL_REQ *pReq = (INT_VMS_POWER_CTL_REQ*)pPI->Data;
  4480. memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID);
  4481. memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID);
  4482. memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME);
  4483. FCliCtl.Result = CTL_RESULT_FAIL;
  4484. if (pReq->Command == vms_board_power_on)
  4485. {
  4486. arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER;
  4487. arg.Publication.obj = OBJ_StatusControl;
  4488. arg.Publication.Data.Ctl = CTL_MODULE_POWER_ON;
  4489. FCliCtl.CtlType = CTL_TYPE_MODULE_ON;
  4490. CmdCode = AI_StatusControlMessage;
  4491. }
  4492. else
  4493. if (pReq->Command == vms_board_power_off)
  4494. {
  4495. arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER;
  4496. arg.Publication.obj = OBJ_StatusControl;
  4497. arg.Publication.Data.Ctl = CTL_MODULE_POWER_OFF;
  4498. FCliCtl.CtlType = CTL_TYPE_MODULE_OFF;
  4499. CmdCode = AI_StatusControlMessage;
  4500. }
  4501. else
  4502. {
  4503. nResult = VERR_UNKNOWN;
  4504. break;
  4505. }
  4506. }
  4507. else
  4508. {
  4509. nResult = VERR_DATA_SIZE;
  4510. }
  4511. break;
  4512. case INT_OP_VMS_LUMINANCE_CTL:
  4513. if (pPI->Data)
  4514. {
  4515. INT_VMS_LUMINANCE_REQ *pReq = (INT_VMS_LUMINANCE_REQ*)pPI->Data;
  4516. memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID);
  4517. memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID);
  4518. memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME);
  4519. FCliCtl.Result = CTL_RESULT_FAIL;
  4520. arg.Publication.SubscribeSerialNbr = NBR_LUMINANCE;
  4521. arg.Publication.obj = OBJ_StatusControl;
  4522. arg.Publication.Data.Ctl = CTL_LUMINANCE_SET;
  4523. FCliCtl.CtlType = pReq->Luminance;
  4524. CmdCode = AI_StatusControlMessage;
  4525. }
  4526. else
  4527. {
  4528. nResult = VERR_DATA_SIZE;
  4529. }
  4530. break;
  4531. case INT_OP_VMS_RESET:
  4532. if (pPI->Data)
  4533. {
  4534. INT_VMS_RESET_REQ *pReq = (INT_VMS_RESET_REQ*)pPI->Data;
  4535. memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID);
  4536. memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID);
  4537. memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME);
  4538. FCliCtl.Result = CTL_RESULT_FAIL;
  4539. arg.Publication.SubscribeSerialNbr = NBR_CONTROLLER_RESET;
  4540. arg.Publication.obj = OBJ_StatusControl;
  4541. arg.Publication.Data.Ctl = CTL_CONTROLLER_RESET;
  4542. FCliCtl.CtlType = CTL_TYPE_RESET;
  4543. CmdCode = AI_StatusControlMessage;
  4544. }
  4545. else
  4546. {
  4547. nResult = VERR_DATA_SIZE;
  4548. }
  4549. break;
  4550. case INT_OP_VMS_PARA_SET:
  4551. if (pPI->Data)
  4552. {
  4553. INT_VMS_PARA_SET_REQ *pReq = (INT_VMS_PARA_SET_REQ*)pPI->Data;
  4554. memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID);
  4555. memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID);
  4556. memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME);
  4557. FCliCtl.Result = CTL_RESULT_FAIL;
  4558. arg.Publication.SubscribeSerialNbr = NBR_STATUS_SETTING;
  4559. arg.Publication.obj = OBJ_StatusSetting;
  4560. arg.Publication.Data.Set.SchMsgTime = (int)pReq->SchMsgTime;
  4561. arg.Publication.Data.Set.ModuleTemp = (int)pReq->ModuleTemp;
  4562. arg.Publication.Data.Set.FanTemp = (int)pReq->FanTemp;
  4563. arg.Publication.Data.Set.HeaterTemp = (int)pReq->HeaterTemp;
  4564. arg.Publication.Data.Set.ModuleFail = (int)pReq->ModuleFail;
  4565. arg.Publication.Data.Set.RetryCount = (int)pReq->RetryCount;
  4566. arg.Publication.Data.Set.TimeOut = (int)pReq->TimeOut;
  4567. FCliCtl.Data.Para.SchMsgTime = (int)pReq->SchMsgTime;
  4568. FCliCtl.Data.Para.ModuleTemp = (int)pReq->ModuleTemp;
  4569. FCliCtl.Data.Para.FanTemp = (int)pReq->FanTemp;
  4570. FCliCtl.Data.Para.HeaterTemp = (int)pReq->HeaterTemp;
  4571. FCliCtl.Data.Para.ModuleFail = (int)pReq->ModuleFail;
  4572. FCliCtl.Data.Para.RetryCount = (int)pReq->RetryCount;
  4573. FCliCtl.Data.Para.TimeOut = (int)pReq->TimeOut;
  4574. FCliCtl.CtlType = CTL_TYPE_PARA_SET;
  4575. CmdCode = AI_StatusSettingMessage;
  4576. }
  4577. else
  4578. {
  4579. nResult = VERR_DATA_SIZE;
  4580. }
  4581. break;
  4582. default:
  4583. nResult = VERR_UNKNOWN_COMMAND;
  4584. break;
  4585. }
  4586. if (nResult == VERR_NONE)
  4587. {
  4588. nResult = ProcessCommand(CmdCode, &arg);
  4589. }
  4590. //ClientResponse(nResult);
  4591. if (pPI->Size > 0)
  4592. {
  4593. delete []pPI->Data;
  4594. }
  4595. delete pPI;
  4596. pPI = NULL;
  4597. pPackQueue->Delete(ii);
  4598. *AFlag = true;
  4599. break;
  4600. }
  4601. }
  4602. __finally
  4603. {
  4604. FVmsObj->pPackQueue->UnlockList();
  4605. }
  4606. return nResult;
  4607. }
  4608. //---------------------------------------------------------------------------
  4609. int TVMSSThread::LogData(char *ASndRcv, BYTE *AData, int ALen)
  4610. {
  4611. int result = -1;
  4612. if (!FLogFile) return result;
  4613. if (!FLogFile->FLogCfg.Data) return result;
  4614. try
  4615. {
  4616. FLogFile->LogData(ASndRcv, AData, ALen);
  4617. if (FVmsObj->FDispLog)
  4618. {
  4619. IPC_LOG_MESSAGE *pLog = &FLogMsg;//new IPC_LOG_MESSAGE;
  4620. if (pLog)
  4621. {
  4622. pLog->Kind = eLOG_DATA;
  4623. pLog->Flag = ASndRcv[0] == 'S' ? 1 : 2;
  4624. pLog->Len = ALen > MAX_LOG_BUFFER ? MAX_LOG_BUFFER-1 : ALen;
  4625. pLog->Tm = Now();
  4626. pLog->Type = 'S';
  4627. memset(pLog->Msg, 0x00, sizeof(pLog->Msg));
  4628. memcpy(pLog->Msg, (char*)AData, pLog->Len);
  4629. pLog->Obj = (void*)FVmsObj;
  4630. DWORD dwResult = 0;
  4631. LRESULT lResult = SEND_LOGMSG(FrmVmsLog->Handle, WM_LOG_DISPLAY, (WPARAM)pLog, NULL, SMTO_NORMAL, 2000, dwResult);
  4632. if (lResult == 0)
  4633. {
  4634. dwResult = GetLastError();
  4635. if (dwResult == ERROR_TIMEOUT)
  4636. {
  4637. }
  4638. //SAFE_DELETE(pLog);
  4639. }
  4640. }
  4641. }
  4642. }
  4643. catch(Exception &e)
  4644. {
  4645. }
  4646. return result;
  4647. }
  4648. //---------------------------------------------------------------------------
  4649. int TVMSSThread::SysLogWrite(int ALogKind, char *AFmt, ...)
  4650. {
  4651. va_list ap;
  4652. int cnt = 0;
  4653. char szFmtData[MAX_LOG_BUFFER];
  4654. AnsiString sLogKind;
  4655. int nStep = 0;
  4656. if (!FLogFile) return cnt;
  4657. bool bLog = false;
  4658. switch(ALogKind)
  4659. {
  4660. case eLOG_INFO : bLog = FLogFile->FLogCfg.Info; sLogKind = " [INF] "; break;
  4661. case eLOG_DATA : bLog = FLogFile->FLogCfg.Data; sLogKind = " [DAT] "; break;
  4662. case eLOG_ERROR : bLog = FLogFile->FLogCfg.Error; sLogKind = " [ERR] "; break;
  4663. case eLOG_WARNING: bLog = FLogFile->FLogCfg.Warning; sLogKind = " [WAN] "; break;
  4664. case eLOG_DEBUG : bLog = FLogFile->FLogCfg.Debug; sLogKind = " [DBG] "; break;
  4665. case eLOG_DETAIL : bLog = FLogFile->FLogCfg.Detail; sLogKind = " [DET] "; break;
  4666. }
  4667. if (!bLog) return -1;
  4668. try
  4669. {
  4670. va_start(ap, AFmt);
  4671. cnt = vsprintf(szFmtData, AFmt, ap);
  4672. va_end(ap);
  4673. FLogFile->LogWrite(NULL, ALogKind, szFmtData);
  4674. IPC_LOG_MESSAGE *pLog = &FLogMsg;//new IPC_LOG_MESSAGE;
  4675. if (pLog)
  4676. {
  4677. pLog->Kind = ALogKind;
  4678. pLog->Flag = 0;
  4679. pLog->Len = strlen(szFmtData);
  4680. pLog->Tm = Now();
  4681. pLog->Type = 'S';
  4682. memset(pLog->Msg, 0x00, sizeof(pLog->Msg));
  4683. sprintf(pLog->Msg, "%s+SVR %s, %s", sLogKind.c_str(), VMSID.c_str(), szFmtData);
  4684. pLog->Obj = (void*)FVmsObj;
  4685. DWORD dwResult = 0;
  4686. LRESULT lResult = SEND_LOGMSG(FrmSysLog->Handle, WM_LOG_DISPLAY, pLog, NULL, SMTO_NORMAL, 2000, dwResult);
  4687. if (lResult == 0)
  4688. {
  4689. dwResult = GetLastError();
  4690. if (dwResult == ERROR_TIMEOUT)
  4691. {
  4692. }
  4693. //SAFE_DELETE(pLog);
  4694. }
  4695. }
  4696. if (FVmsObj->FDispLog)
  4697. {
  4698. IPC_LOG_MESSAGE *pLog2 = &FLogMsg;//new IPC_LOG_MESSAGE;
  4699. if (pLog2)
  4700. {
  4701. pLog2->Kind = ALogKind;
  4702. pLog2->Flag = 0;
  4703. pLog2->Len = strlen(szFmtData);
  4704. pLog2->Tm = Now();
  4705. pLog2->Type = 'S';
  4706. memset(pLog2->Msg, 0x00, sizeof(pLog2->Msg));
  4707. sprintf(pLog2->Msg, "%s+SVR %s, %s", sLogKind.c_str(), VMSID.c_str(), szFmtData);
  4708. pLog2->Obj = (void*)FVmsObj;
  4709. DWORD dwResult = 0;
  4710. LRESULT lResult = SEND_LOGMSG(FrmVmsLog->Handle, WM_LOG_DISPLAY, pLog2, NULL, SMTO_NORMAL, 2000, dwResult);
  4711. if (lResult == 0)
  4712. {
  4713. dwResult = GetLastError();
  4714. if (dwResult == ERROR_TIMEOUT)
  4715. {
  4716. }
  4717. //SAFE_DELETE(pLog2);
  4718. }
  4719. }
  4720. }
  4721. }
  4722. catch(Exception &e)
  4723. {
  4724. }
  4725. return cnt;
  4726. }
  4727. //---------------------------------------------------------------------------
  4728. int TVMSSThread::LogWrite(int ALogKind, char *AFmt, ...)
  4729. {
  4730. va_list ap;
  4731. int cnt = 0;
  4732. char szFmtData[MAX_LOG_BUFFER];
  4733. AnsiString sLogKind;
  4734. int nStep = 0;
  4735. if (!FLogFile) return cnt;
  4736. bool bLog = false;
  4737. switch(ALogKind)
  4738. {
  4739. case eLOG_INFO : bLog = FLogFile->FLogCfg.Info; sLogKind = " [INF] "; break;
  4740. case eLOG_DATA : bLog = FLogFile->FLogCfg.Data; sLogKind = " [DAT] "; break;
  4741. case eLOG_ERROR : bLog = FLogFile->FLogCfg.Error; sLogKind = " [ERR] "; break;
  4742. case eLOG_WARNING: bLog = FLogFile->FLogCfg.Warning; sLogKind = " [WAN] "; break;
  4743. case eLOG_DEBUG : bLog = FLogFile->FLogCfg.Debug; sLogKind = " [DBG] "; break;
  4744. case eLOG_DETAIL : bLog = FLogFile->FLogCfg.Detail; sLogKind = " [DET] "; break;
  4745. }
  4746. if (!bLog) return -1;
  4747. try
  4748. {
  4749. va_start(ap, AFmt);
  4750. cnt = vsprintf(szFmtData, AFmt, ap);
  4751. va_end(ap);
  4752. FLogFile->LogWrite(NULL, ALogKind, szFmtData);
  4753. if (FVmsObj->FDispLog)
  4754. {
  4755. IPC_LOG_MESSAGE *pLog = &FLogMsg;//new IPC_LOG_MESSAGE;
  4756. if (pLog)
  4757. {
  4758. pLog->Kind = ALogKind;
  4759. pLog->Flag = 0;
  4760. pLog->Len = strlen(szFmtData);
  4761. pLog->Tm = Now();
  4762. pLog->Type = 'S';
  4763. memset(pLog->Msg, 0x00, sizeof(pLog->Msg));
  4764. sprintf(pLog->Msg, "%s+SVR %s, %s", sLogKind.c_str(), VMSID.c_str(), szFmtData);
  4765. pLog->Obj = (void*)FVmsObj;
  4766. DWORD dwResult = 0;
  4767. LRESULT lResult = SEND_LOGMSG(FrmVmsLog->Handle, WM_LOG_DISPLAY, pLog, NULL, SMTO_NORMAL, 2000, dwResult);
  4768. if (lResult == 0)
  4769. {
  4770. dwResult = GetLastError();
  4771. if (dwResult == ERROR_TIMEOUT)
  4772. {
  4773. }
  4774. //SAFE_DELETE(pLog);
  4775. }
  4776. }
  4777. }
  4778. }
  4779. catch(Exception &e)
  4780. {
  4781. }
  4782. return cnt;
  4783. }
  4784. //---------------------------------------------------------------------------
  4785. int __fastcall TVMSSThread::CommandSubscription(Subscription_t *pSubscripiton, SUBSCRIPTION_ARGUMENT Arg)
  4786. {
  4787. FErrLine = 12;
  4788. int result;
  4789. SubscriptionData_t *pData;
  4790. asn_enc_rval_t er; /* Encoder return value */
  4791. BYTE MsgBuf[SERVER_MSG_BUF_SIZE];
  4792. int eLen;
  4793. int i, count = 0;
  4794. result = SYS_ERR_OTHER;
  4795. if (asn_long2INTEGER(&pSubscripiton->datexSubscribe_Serial_nbr, Arg.nbr) != ASN_ERR_NONE)
  4796. {
  4797. return -1;
  4798. }
  4799. pSubscripiton->datexSubscribe_Type.present = SubscriptionType_PR_subscription;
  4800. pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
  4801. pData->datexSubscribe_Persistent_bool = false;
  4802. if (asn_long2INTEGER(&pData->datexSubscribe_Status_cd, datexSubscribe_Status_cd_new) != ASN_ERR_NONE)
  4803. {
  4804. return -3;
  4805. }
  4806. switch(Arg.mode)
  4807. {
  4808. case SubscriptionMode_PR_single:
  4809. pData->datexSubscribe_Mode.present = SubscriptionMode_PR_single;
  4810. break;
  4811. case SubscriptionMode_PR_event_driven:
  4812. pData->datexSubscribe_Mode.present = SubscriptionMode_PR_event_driven;
  4813. /* Registered_PR_continuous 1 */
  4814. /* Registered_PR_daily 2 */
  4815. pData->datexSubscribe_Mode.choice.event_driven.present = Registered_PR_continuous;
  4816. pData->datexSubscribe_Mode.choice.event_driven.choice.continuous.datexRegistered_UpdateDelay_qty = Arg.delay;
  4817. /* pData->datexSubscribe_Mode.choice.event_driven.choice.continuous.datexRegistered_StartTime */
  4818. /* pData->datexSubscribe_Mode.choice.event_driven.choice.continuous.datexRegistered_EndTime */
  4819. break;
  4820. case SubscriptionMode_PR_periodic:
  4821. pData->datexSubscribe_Mode.present = SubscriptionMode_PR_periodic;
  4822. /* Registered_PR_continuous 1 */
  4823. /* Registered_PR_daily 2 */
  4824. pData->datexSubscribe_Mode.choice.periodic.present = Registered_PR_continuous;
  4825. pData->datexSubscribe_Mode.choice.periodic.choice.continuous.datexRegistered_UpdateDelay_qty = Arg.delay;
  4826. /* pData->datexSubscribe_Mode.choice.periodic.choice.continuous.datexRegistered_StartTime */
  4827. /* pData->datexSubscribe_Mode.choice.periodic.choice.continuous.datexRegistered_EndTime */
  4828. break;
  4829. default:
  4830. pData->datexSubscribe_Mode.present = SubscriptionMode_PR_single;
  4831. break;
  4832. }
  4833. if (asn_long2INTEGER(&pData->datexSubscribe_PublishFormat_cd, datexSubscribe_PublishFormat_cd_dataPacket) != ASN_ERR_NONE)
  4834. {
  4835. return -4;
  4836. }
  4837. pData->datexSubscription_Priority_nbr = 1;
  4838. pData->datexSubscribe_Guarantee_bool = true;
  4839. #if 0
  4840. {
  4841. long lv;
  4842. asn_INTEGER2long(&pSubscripiton->datexSubscribe_Serial_nbr, &lv);
  4843. LDEBUG(" SubscriptionMode: %d", Arg.mode);
  4844. LDEBUG("datexSubscribe_Serial_nbr: %u", lv);
  4845. LDEBUG(" datexSubscribe_Type: %d", pSubscripiton->datexSubscribe_Type.present);
  4846. switch(pSubscripiton->datexSubscribe_Type.present)
  4847. {
  4848. case SubscriptionType_PR_subscription:
  4849. asn_INTEGER2long(&pData->datexSubscribe_Status_cd, &lv);
  4850. LDEBUG("datexSubscribe_Persistent_bool: %d", pData->datexSubscribe_Persistent_bool);
  4851. LDEBUG(" datexSubscribe_Status_cd: %d", lv);
  4852. LDEBUG(" datexSubscribe_Mode: %d", pData->datexSubscribe_Mode.present);
  4853. switch(pData->datexSubscribe_Mode.present)
  4854. {
  4855. case SubscriptionMode_PR_single:
  4856. break;
  4857. case SubscriptionMode_PR_event_driven:
  4858. case SubscriptionMode_PR_periodic:
  4859. {
  4860. Registered_t *pRegistered;
  4861. int numbits, bit;
  4862. if(pData->datexSubscribe_Mode.present == SubscriptionMode_PR_event_driven)
  4863. {
  4864. pRegistered = &pData->datexSubscribe_Mode.choice.event_driven;
  4865. }
  4866. else
  4867. {
  4868. pRegistered = &pData->datexSubscribe_Mode.choice.periodic;
  4869. }
  4870. LDEBUG("Registered: %d", pRegistered->present);
  4871. switch(pRegistered->present)
  4872. {
  4873. case Registered_PR_continuous:
  4874. LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.continuous.datexRegistered_UpdateDelay_qty);
  4875. if (pRegistered->choice.continuous.datexRegistered_StartTime)
  4876. {
  4877. LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_StartTime);
  4878. }
  4879. if (pRegistered->choice.continuous.datexRegistered_EndTime)
  4880. {
  4881. LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_EndTime);
  4882. }
  4883. break;
  4884. case Registered_PR_daily:
  4885. LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.daily.datexRegistered_UpdateDelay_qty);
  4886. numbits = DATEX_NUMBITS(pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd);
  4887. LDEBUG("datexRegistered_DaysOfWeek_cd numbits: %d", numbits);
  4888. for (bit = 0; bit < numbits; bit++)
  4889. {
  4890. LDEBUG("[%d]: %d", bit, ASN1C_CheckBitString(&pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd, bit));
  4891. }
  4892. if (pRegistered->choice.daily.datexRegistered_StartDate)
  4893. {
  4894. LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartDate);
  4895. }
  4896. if (pRegistered->choice.daily.datexRegistered_EndDate)
  4897. {
  4898. LOG_WriteTime(pRegistered->choice.daily.datexRegistered_EndDate);
  4899. }
  4900. if (pRegistered->choice.daily.datexRegistered_StartTime)
  4901. {
  4902. LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartTime);
  4903. }
  4904. if (pRegistered->choice.daily.datexRegistered_Duration_qty)
  4905. {
  4906. //LDEBUG("datexRegistered_Duration_qty: %u", *pRegistered->choice.daily.datexRegistered_Duration_qty);
  4907. }
  4908. break;
  4909. default:
  4910. LDEBUG("Unknown Registered %d", pRegistered->present);
  4911. break;
  4912. }/* end swtich */
  4913. }
  4914. break;
  4915. default :
  4916. LDEBUG("Unknown datexSubscribe_Mode %d", pData->datexSubscribe_Mode.present);
  4917. break;
  4918. }/* end switch */
  4919. asn_INTEGER2long(&pData->datexSubscribe_PublishFormat_cd, &lv);
  4920. LDEBUG("datexSubscribe_PublishFormat_cd: %d", lv);
  4921. LDEBUG(" datexSubscription_Priority_nbr: %d", pData->datexSubscription_Priority_nbr);
  4922. LDEBUG(" datexSubscribe_Guarantee_bool: %d", pData->datexSubscribe_Guarantee_bool);
  4923. break;
  4924. case SubscriptionType_PR_datexSubscribe_CancelReason_cd:
  4925. LDEBUG("datexSubscribe_CancelReason_cd: %d", pSubscripiton->datexSubscribe_Type.choice.datexSubscribe_CancelReason_cd);
  4926. break;
  4927. default:
  4928. LDEBUG("Unknown datexSubscribe_Type %d", pSubscripiton->datexSubscribe_Type.present);
  4929. break;
  4930. }/* end switch */
  4931. }
  4932. #endif
  4933. ASN1C_SetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id, Arg.obj);
  4934. switch(Arg.obj)
  4935. {
  4936. case OBJ_GeneralStatus: /* 기본상태정보 */
  4937. {
  4938. LINFO(" *** OBJ_GeneralStatus 전송");
  4939. GeneralStatusMessage_t *pGS;
  4940. MessageBodyGeneralStatusMessage_t Msg; /* Type to encode */
  4941. memset((void *)&Msg, 0x00, sizeof(MessageBodyGeneralStatusMessage_t));
  4942. for ( i = 0; i < count; i++)
  4943. {
  4944. if ((pGS = (GeneralStatusMessage_t *)ASN1C_Alloc(sizeof(GeneralStatusMessage_t))) == NULL)
  4945. {
  4946. result = -10;
  4947. break;
  4948. }
  4949. if(ASN_SEQUENCE_ADD(&Msg, pGS)!= ASN_ERR_NONE)
  4950. {
  4951. result = -11;
  4952. break;
  4953. }
  4954. }/* end for */
  4955. /* Encode */
  4956. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  4957. eLen = -1;
  4958. er = der_encode_to_buffer(&asn_DEF_MessageBodyGeneralStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  4959. if (er.encoded == -1)
  4960. {
  4961. /*
  4962. * Failed to encode the data.
  4963. */
  4964. SERROR("Cannot encode %s", er.failed_type->name);
  4965. result = SYS_ERR_MESSAGE_ENCODE;
  4966. }
  4967. else
  4968. {
  4969. /* Return the number of bytes */
  4970. eLen = er.encoded;
  4971. pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  4972. if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
  4973. {
  4974. result = -12;
  4975. break;
  4976. }
  4977. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
  4978. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  4979. {
  4980. result = -13;
  4981. break;
  4982. }
  4983. result = SYS_ERR_NONE;
  4984. }/* end if */
  4985. ASN1C_FreeC(&asn_DEF_MessageBodyGeneralStatusMessage, &Msg);
  4986. }
  4987. break;
  4988. #if 1
  4989. case OBJ_PowerStatus: /* 전원상태정보 */
  4990. {
  4991. LINFO(" *** OBJ_PowerStatus 전송");
  4992. PowerStatusMessage_t *pMS;
  4993. MessageBodyPowerStatusMessage_t Msg;
  4994. memset((void *)&Msg, 0x00, sizeof(MessageBodyPowerStatusMessage_t));
  4995. for ( i = 0; i < count; i++)
  4996. {
  4997. if ((pMS = (PowerStatusMessage_t *)ASN1C_Alloc(sizeof(PowerStatusMessage_t))) == NULL)
  4998. {
  4999. result = -30;
  5000. break;
  5001. }
  5002. if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE)
  5003. {
  5004. result = -31;
  5005. break;
  5006. }
  5007. }/* end for */
  5008. /* Encode */
  5009. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  5010. eLen = -1;
  5011. er = der_encode_to_buffer(&asn_DEF_MessageBodyPowerStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  5012. if (er.encoded == -1)
  5013. {
  5014. /*
  5015. * Failed to encode the data.
  5016. */
  5017. SERROR("Cannot encode %s", er.failed_type->name);
  5018. result = SYS_ERR_MESSAGE_ENCODE;
  5019. }
  5020. else
  5021. {
  5022. /* Return the number of bytes */
  5023. eLen = er.encoded;
  5024. pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  5025. if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
  5026. {
  5027. result = -32;
  5028. break;
  5029. }
  5030. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
  5031. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  5032. {
  5033. result = -33;
  5034. break;
  5035. }
  5036. result = SYS_ERR_NONE;
  5037. }/* end if */
  5038. ASN1C_FreeC(&asn_DEF_MessageBodyPowerStatusMessage, &Msg);
  5039. }
  5040. break;
  5041. #endif
  5042. case OBJ_ModuleStatus: /* 모듈상태정보 */
  5043. {
  5044. LINFO(" *** OBJ_ModuleStatus 전송");
  5045. ModuleStatusMessage_t *pMS;
  5046. MessageBodyModuleStatusMessage_t Msg; /* Type to encode */
  5047. memset((void *)&Msg, 0x00, sizeof(MessageBodyModuleStatusMessage_t));
  5048. for ( i = 0; i < count; i++)
  5049. {
  5050. if ((pMS = (ModuleStatusMessage_t *)ASN1C_Alloc(sizeof(ModuleStatusMessage_t))) == NULL)
  5051. {
  5052. result = -30;
  5053. break;
  5054. }
  5055. if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE)
  5056. {
  5057. result = -31;
  5058. break;
  5059. }
  5060. }/* end for */
  5061. /* Encode */
  5062. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  5063. eLen = -1;
  5064. er = der_encode_to_buffer(&asn_DEF_MessageBodyModuleStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  5065. if (er.encoded == -1)
  5066. {
  5067. /*
  5068. * Failed to encode the data.
  5069. */
  5070. SERROR("Cannot encode %s", er.failed_type->name);
  5071. result = SYS_ERR_MESSAGE_ENCODE;
  5072. }
  5073. else
  5074. {
  5075. /* Return the number of bytes */
  5076. eLen = er.encoded;
  5077. pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  5078. if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
  5079. {
  5080. result = -32;
  5081. break;
  5082. }
  5083. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
  5084. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  5085. {
  5086. result = -33;
  5087. break;
  5088. }
  5089. result = SYS_ERR_NONE;
  5090. }/* end if */
  5091. ASN1C_FreeC(&asn_DEF_MessageBodyModuleStatusMessage, &Msg);
  5092. }
  5093. break;
  5094. #if 0
  5095. case OBJ_DotStatus: /* 도트상태정보 */
  5096. break;
  5097. #endif
  5098. case OBJ_ScreenStatus: /* 표출상태정보 */
  5099. {
  5100. LINFO(" *** OBJ_ScreenStatus 전송");
  5101. ScreenStatusMessage_t *pMS;
  5102. MessageBodyScreenStatusMessage_t Msg; /* Type to encode */
  5103. memset((void *)&Msg, 0x00, sizeof(MessageBodyScreenStatusMessage_t));
  5104. for ( i = 0; i < count; i++)
  5105. {
  5106. if ((pMS = (ScreenStatusMessage_t *)ASN1C_Alloc(sizeof(ScreenStatusMessage_t))) == NULL)
  5107. {
  5108. result = -30;
  5109. break;
  5110. }
  5111. if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE)
  5112. {
  5113. result = -31;
  5114. break;
  5115. }
  5116. }/* end for */
  5117. /* Encode */
  5118. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  5119. eLen = -1;
  5120. er = der_encode_to_buffer(&asn_DEF_MessageBodyScreenStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  5121. if (er.encoded == -1)
  5122. {
  5123. /*
  5124. * Failed to encode the data.
  5125. */
  5126. SERROR("Cannot encode %s", er.failed_type->name);
  5127. result = SYS_ERR_MESSAGE_ENCODE;
  5128. }
  5129. else
  5130. {
  5131. /* Return the number of bytes */
  5132. eLen = er.encoded;
  5133. pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  5134. if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
  5135. {
  5136. result = -32;
  5137. break;
  5138. }
  5139. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
  5140. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  5141. {
  5142. result = -33;
  5143. break;
  5144. }
  5145. result = SYS_ERR_NONE;
  5146. }/* end if */
  5147. ASN1C_FreeC(&asn_DEF_MessageBodyScreenStatusMessage, &Msg);
  5148. }
  5149. break;
  5150. case OBJ_DisplayingData: /* 표출정보 */
  5151. {
  5152. LINFO(" *** OBJ_DisplayingData 전송");
  5153. DisplayingDataMessage_t *pMS;
  5154. MessageBodyDisplayingDataMessage_t Msg; /* Type to encode */
  5155. memset((void *)&Msg, 0x00, sizeof(MessageBodyDisplayingDataMessage_t));
  5156. for ( i = 0; i < count; i++)
  5157. {
  5158. if ((pMS = (DisplayingDataMessage_t *)ASN1C_Alloc(sizeof(DisplayingDataMessage_t))) == NULL)
  5159. {
  5160. result = -30;
  5161. break;
  5162. }
  5163. if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE)
  5164. {
  5165. result = -31;
  5166. break;
  5167. }
  5168. }/* end for */
  5169. /* Encode */
  5170. memset(MsgBuf, 0x00, sizeof(MsgBuf));
  5171. eLen = -1;
  5172. er = der_encode_to_buffer(&asn_DEF_MessageBodyDisplayingDataMessage, &Msg, MsgBuf, sizeof(MsgBuf));
  5173. if (er.encoded == -1)
  5174. {
  5175. /*
  5176. * Failed to encode the data.
  5177. */
  5178. SERROR("Cannot encode %s", er.failed_type->name);
  5179. result = SYS_ERR_MESSAGE_ENCODE;
  5180. }
  5181. else
  5182. {
  5183. /* Return the number of bytes */
  5184. eLen = er.encoded;
  5185. pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
  5186. if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
  5187. {
  5188. result = -32;
  5189. break;
  5190. }
  5191. if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
  5192. (char *)MsgBuf, eLen) != ASN_ERR_NONE)
  5193. {
  5194. result = -33;
  5195. break;
  5196. }
  5197. result = SYS_ERR_NONE;
  5198. }/* end if */
  5199. ASN1C_FreeC(&asn_DEF_MessageBodyDisplayingDataMessage, &Msg);
  5200. }
  5201. break;
  5202. default:
  5203. result = SYS_ERR_UNKNOWN_MESSAGE_ID;
  5204. break;
  5205. }
  5206. return result;
  5207. }
  5208. //---------------------------------------------------------------------------
  5209. int __fastcall TVMSSThread::SendLoginAccept()
  5210. {
  5211. TStringList *sl = NULL;
  5212. //Data Dump: 104 Bytes
  5213. String sMsg =
  5214. "30 66 80 01 01 81 5D 30 5B 80 01 08 81 02 03 12 "
  5215. "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
  5216. "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
  5217. "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
  5218. "11 83 01 0D 84 01 08 85 01 19 A6 03 82 01 00 A7 "
  5219. "06 80 01 09 81 01 00 A4 0B A8 09 80 01 01 A1 04 "
  5220. "80 02 51 01 82 02 B3 EF ";
  5221. try
  5222. {
  5223. sl = new TStringList;
  5224. sl->Delimiter = ' ';
  5225. sl->StrictDelimiter = true;
  5226. sl->DelimitedText = sMsg;
  5227. int ii;
  5228. unsigned int hn, ln;
  5229. BYTE chn, cln, val;
  5230. char szData[2048];
  5231. BYTE RxBuff[VMS_MAX_PACKET_SIZE];
  5232. int RxLen;
  5233. RxLen = 0;
  5234. memset(RxBuff, 0x00, sizeof(RxBuff));
  5235. for (ii = 0; ii < sl->Count; ii++)
  5236. {
  5237. AnsiString sTemp = sl->Strings[ii];
  5238. if (sTemp.Trim() == "") continue;
  5239. sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll);
  5240. if (sTemp.Trim() == "\r\n") continue;
  5241. memset(szData, 0x00, sizeof(szData));
  5242. memcpy(szData, sTemp.c_str(), sTemp.Length());
  5243. chn = (BYTE)szData[0];
  5244. cln = (BYTE)szData[1];
  5245. hn = chn > '9' ? chn - 'A' + 10 : chn - '0';
  5246. ln = cln > '9' ? cln - 'A' + 10 : cln - '0';
  5247. val = (BYTE)((hn << 4 ) | ln);
  5248. RxBuff[RxLen] = val;
  5249. RxLen++;
  5250. }
  5251. int nSends = pClientSocket->SendBuf(RxBuff, RxLen);
  5252. LINFO("SendLoginAccept: %d/%d Bytes", RxLen, nSends);
  5253. if (sl) delete sl;
  5254. }
  5255. catch(Exception &e)
  5256. {
  5257. //Application->ShowException(&e);
  5258. }
  5259. return SYS_ERR_NONE;
  5260. }
  5261. //---------------------------------------------------------------------------
  5262. int __fastcall TVMSSThread::SendSubscriptionAccept(int AMsgId)
  5263. {
  5264. TStringList *sl = NULL;
  5265. String sMsg = "";
  5266. String sRealTimeDisplay =
  5267. "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 14 "
  5268. "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
  5269. "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
  5270. "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
  5271. "11 83 01 0D 84 01 08 85 01 19 A6 03 82 01 00 A7 "
  5272. "06 80 01 09 81 01 00 A4 0A A8 08 80 01 04 A1 03 "
  5273. "82 01 01 82 02 90 6A ";
  5274. String sScheduledDisplay =
  5275. "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 15 "
  5276. "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
  5277. "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
  5278. "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
  5279. "11 83 01 0D 84 01 08 85 01 1A A6 03 82 01 00 A7 "
  5280. "06 80 01 09 81 01 00 A4 0A A8 08 80 01 05 A1 03 "
  5281. "82 01 02 82 02 D5 7F ";
  5282. String sDownloadGraphicData =
  5283. "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 16 "
  5284. "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
  5285. "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
  5286. "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
  5287. "11 83 01 0D 84 01 08 85 01 1A A6 03 82 01 00 A7 "
  5288. "06 80 01 09 81 01 00 A4 0A A8 08 80 01 06 A1 03 "
  5289. "82 01 03 82 02 19 5C ";
  5290. String sStatusControl =
  5291. "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 17 "
  5292. "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
  5293. "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
  5294. "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
  5295. "11 83 01 0D 84 01 08 85 01 1A A6 03 82 01 00 A7 "
  5296. "06 80 01 09 81 01 00 A4 0A A8 08 80 01 07 A1 03 "
  5297. "82 01 04 82 02 DF 43 ";
  5298. String sStatusSetting =
  5299. "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 18 "
  5300. "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
  5301. "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
  5302. "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
  5303. "11 83 01 0D 84 01 08 85 01 1B A6 03 82 01 00 A7 "
  5304. "06 80 01 09 81 01 00 A4 0A A8 08 80 01 08 A1 03 "
  5305. "82 01 05 82 02 DF 10 ";
  5306. switch(AMsgId)
  5307. {
  5308. case OBJ_RealTimeDisplay: /* 실시간정보표출 */
  5309. sMsg = sRealTimeDisplay;
  5310. //arg.Accept.nbr = 4;
  5311. //arg.Accept.sub = 1;
  5312. break;
  5313. case OBJ_ScheduledDisplay: /* 계획된정보표출 */
  5314. sMsg = sScheduledDisplay;
  5315. //arg.Accept.nbr = 5;
  5316. //arg.Accept.sub = 2;
  5317. break;
  5318. case OBJ_DownloadGraphicData: /* 그래픽데이터 다운로드 */
  5319. sMsg = sDownloadGraphicData;
  5320. //arg.Accept.nbr = 6;
  5321. //arg.Accept.sub = 3;
  5322. break;
  5323. case OBJ_StatusControl: /* 상태제어 */
  5324. sMsg = sStatusControl;
  5325. //arg.Accept.nbr = 7;
  5326. //arg.Accept.sub = 4;
  5327. break;
  5328. case OBJ_StatusSetting: /* 상태설정 */
  5329. sMsg = sStatusSetting;
  5330. //arg.Accept.nbr = 8;
  5331. //arg.Accept.sub = 5;
  5332. break;
  5333. default:
  5334. return SYS_ERR_OTHER;
  5335. }
  5336. try
  5337. {
  5338. sl = new TStringList;
  5339. sl->Delimiter = ' ';
  5340. sl->StrictDelimiter = true;
  5341. sl->DelimitedText = sMsg;
  5342. int ii;
  5343. unsigned int hn, ln;
  5344. BYTE chn, cln, val;
  5345. char szData[2048];
  5346. BYTE RxBuff[VMS_MAX_PACKET_SIZE];
  5347. int RxLen;
  5348. RxLen = 0;
  5349. memset(RxBuff, 0x00, sizeof(RxBuff));
  5350. for (ii = 0; ii < sl->Count; ii++)
  5351. {
  5352. AnsiString sTemp = sl->Strings[ii];
  5353. if (sTemp.Trim() == "") continue;
  5354. sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll);
  5355. if (sTemp.Trim() == "\r\n") continue;
  5356. memset(szData, 0x00, sizeof(szData));
  5357. memcpy(szData, sTemp.c_str(), sTemp.Length());
  5358. chn = (BYTE)szData[0];
  5359. cln = (BYTE)szData[1];
  5360. hn = chn > '9' ? chn - 'A' + 10 : chn - '0';
  5361. ln = cln > '9' ? cln - 'A' + 10 : cln - '0';
  5362. val = (BYTE)((hn << 4 ) | ln);
  5363. RxBuff[RxLen] = val;
  5364. RxLen++;
  5365. }
  5366. int nSends = pClientSocket->SendBuf(RxBuff, RxLen);
  5367. LINFO("SendSubscriptionAccept: [%02X] %d/%d Bytes", AMsgId, RxLen, nSends);
  5368. if (sl) delete sl;
  5369. }
  5370. catch(Exception &e)
  5371. {
  5372. //Application->ShowException(&e);
  5373. }
  5374. return SYS_ERR_NONE;
  5375. }
  5376. //---------------------------------------------------------------------------
  5377. int __fastcall TVMSSThread::SendRealTimeDisplay(int AIndex)
  5378. {
  5379. TStringList *sl = NULL;
  5380. //Data Dump: 104 Bytes
  5381. String sMsg = "";
  5382. if (AIndex == 0)
  5383. sMsg =
  5384. "30 82 02 CE 80 01 01 81 82 02 C3 30 82 02 BF 80 "
  5385. "01 00 81 02 03 8A 82 01 00 A3 42 81 08 30 30 30 "
  5386. "30 30 30 30 30 83 08 30 30 30 30 30 30 30 30 85 "
  5387. "0A 56 4D 53 31 30 30 30 30 31 33 A7 20 80 02 07 "
  5388. "E0 81 01 0B 82 01 11 83 01 0D 84 01 0A 85 01 0C "
  5389. "A6 03 82 01 00 A7 06 80 01 09 81 01 00 A4 82 02 "
  5390. "6D A6 82 02 69 80 01 FF A1 82 02 62 A0 82 02 5E "
  5391. "30 82 02 5A 80 01 31 81 01 01 82 01 00 A3 82 02 "
  5392. "4D A1 82 02 49 80 06 28 F3 6B 02 00 01 A1 82 02 "
  5393. "3D 30 82 02 39 30 82 02 35 80 01 31 81 01 0A 82 "
  5394. "01 00 83 01 00 84 01 00 85 01 0C A6 82 02 1F 30 "
  5395. "23 80 01 02 81 01 00 82 02 00 80 83 01 08 84 01 "
  5396. "00 A5 11 A2 0F 80 01 00 81 01 1D 82 01 0F 83 04 "
  5397. "30 30 30 32 30 23 80 01 02 81 01 00 82 02 00 80 "
  5398. "83 01 2A 84 01 00 A5 11 A2 0F 80 01 00 81 01 1D "
  5399. "82 01 0F 83 04 30 30 30 32 30 23 80 01 02 81 01 "
  5400. "00 82 02 01 63 83 01 23 84 01 00 A5 11 A2 0F 80 "
  5401. "01 00 81 01 15 82 01 19 83 04 30 30 30 38 30 23 "
  5402. "80 01 02 81 01 00 82 02 01 63 83 01 05 84 01 00 "
  5403. "A5 11 A2 0F 80 01 00 81 01 15 82 01 19 83 04 30 "
  5404. "30 30 35 30 32 80 01 00 81 01 00 82 02 00 A9 83 "
  5405. "01 25 84 01 00 A5 20 A0 1E 80 01 03 81 01 11 82 "
  5406. "06 B1 BC B8 B2 C3 BC 83 01 02 84 0B EA B8 88 EA "
  5407. "B3 A1 49 43 EC 95 9E 30 35 80 01 00 81 01 00 82 "
  5408. "01 02 83 01 25 84 01 00 A5 24 A0 22 80 01 03 81 "
  5409. "01 11 82 06 B1 BC B8 B2 C3 BC 83 01 02 84 0F EA "
  5410. "B5 AC EC 84 B1 EC 9D B4 EB A7 88 ED 8A B8 30 2D "
  5411. "80 01 00 81 01 00 82 02 01 27 83 01 05 84 01 00 "
  5412. "A5 1B A0 19 80 01 03 81 01 11 82 06 B1 BC B8 B2 "
  5413. "C3 BC 83 01 02 84 06 EC A7 80 EC B2 B4 30 36 80 "
  5414. "01 00 81 01 00 82 02 00 9D 83 01 03 84 01 00 A5 "
  5415. "24 A0 22 80 01 02 81 01 11 82 06 B1 BC B8 B2 C3 "
  5416. "BC 83 01 02 84 0F EC A3 BD EC A0 84 EC 82 AC EA "
  5417. "B1 B0 EB A6 AC 30 35 80 01 00 81 01 00 82 01 02 "
  5418. "83 01 03 84 01 00 A5 24 A0 22 80 01 02 81 01 11 "
  5419. "82 06 B1 BC B8 B2 C3 BC 83 01 02 84 0F EB B3 B4 "
  5420. "EC A0 95 EA B5 90 EC B0 A8 EB A1 9C 30 2A 80 01 "
  5421. "00 81 01 00 82 02 01 4A 83 01 25 84 01 00 A5 18 "
  5422. "A0 16 80 01 02 81 01 11 82 06 B1 BC B8 B2 C3 BC "
  5423. "83 01 02 84 03 EB B6 84 30 2A 80 01 00 81 01 00 "
  5424. "82 02 01 1C 83 01 25 84 01 00 A5 18 A0 16 80 01 "
  5425. "02 81 01 11 82 06 B1 BC B8 B2 C3 BC 83 01 02 84 "
  5426. "03 EC 95 BD 30 28 80 01 00 81 01 00 82 02 01 39 "
  5427. "83 01 25 84 01 00 A5 16 A0 14 80 01 02 81 01 11 "
  5428. "82 06 B1 BC B8 B2 C3 BC 83 01 02 84 01 35 82 02 "
  5429. "C1 95 ";
  5430. else
  5431. sMsg =
  5432. "30 82 01 8B 80 01 01 81 82 01 80 30 82 01 7C 80 "
  5433. "01 00 81 02 03 8B 82 01 00 A3 42 81 08 30 30 30 "
  5434. "30 30 30 30 30 83 08 30 30 30 30 30 30 30 30 85 "
  5435. "0A 56 4D 53 31 30 30 30 30 31 33 A7 20 80 02 07 "
  5436. "E0 81 01 0B 82 01 11 83 01 0D 84 01 0A 85 01 0C "
  5437. "A6 03 82 01 00 A7 06 80 01 09 81 01 00 A4 82 01 "
  5438. "2A A6 82 01 26 80 01 FF A1 82 01 1F A0 82 01 1B "
  5439. "30 82 01 17 80 01 31 81 01 01 82 01 00 A3 82 01 "
  5440. "0A A1 82 01 06 80 06 28 F3 6B 02 00 01 A1 81 FB "
  5441. "30 81 F8 30 81 F5 80 01 32 81 01 04 82 01 00 83 "
  5442. "01 00 84 01 00 85 01 04 A6 81 E0 30 3F 80 01 00 "
  5443. "81 01 00 82 01 11 83 01 23 84 01 00 A5 2E A0 2C "
  5444. "80 01 02 81 01 13 82 06 B1 BC B8 B2 C3 BC 83 01 "
  5445. "02 84 19 28 32 30 31 36 2E 30 36 2E 31 33 20 7E "
  5446. "20 32 30 31 37 2E 31 32 2E 33 31 29 30 30 80 01 "
  5447. "00 81 01 00 82 02 01 27 83 01 05 84 01 00 A5 1E "
  5448. "A0 1C 80 01 01 81 01 14 82 06 B1 BC B8 B2 C3 BC "
  5449. "83 01 02 84 09 EA B3 B5 EC 82 AC EC A4 91 30 34 "
  5450. "80 01 00 81 01 00 82 02 00 9B 83 01 05 84 01 00 "
  5451. "A5 22 A0 20 80 01 03 81 01 14 82 06 B1 BC B8 B2 "
  5452. "C3 BC 83 01 02 84 0D EB B2 8C EB A7 90 7E EB A7 "
  5453. "A4 EC 86 A1 30 35 80 01 00 81 01 00 82 01 0A 83 "
  5454. "01 05 84 01 00 A5 24 A0 22 80 01 02 81 01 13 82 "
  5455. "06 B1 BC B8 B2 C3 BC 83 01 02 84 0F EB B6 84 EB "
  5456. "8B B9 EC 88 98 EC 84 9C EB A1 9C 82 02 73 03 ";
  5457. try
  5458. {
  5459. sl = new TStringList;
  5460. sl->Delimiter = ' ';
  5461. sl->StrictDelimiter = true;
  5462. sl->DelimitedText = sMsg;
  5463. int ii;
  5464. unsigned int hn, ln;
  5465. BYTE chn, cln, val;
  5466. char szData[2048];
  5467. BYTE RxBuff[VMS_MAX_PACKET_SIZE];
  5468. int RxLen;
  5469. RxLen = 0;
  5470. memset(RxBuff, 0x00, sizeof(RxBuff));
  5471. for (ii = 0; ii < sl->Count; ii++)
  5472. {
  5473. AnsiString sTemp = sl->Strings[ii];
  5474. if (sTemp.Trim() == "") continue;
  5475. sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll);
  5476. if (sTemp.Trim() == "\r\n") continue;
  5477. memset(szData, 0x00, sizeof(szData));
  5478. memcpy(szData, sTemp.c_str(), sTemp.Length());
  5479. chn = (BYTE)szData[0];
  5480. cln = (BYTE)szData[1];
  5481. hn = chn > '9' ? chn - 'A' + 10 : chn - '0';
  5482. ln = cln > '9' ? cln - 'A' + 10 : cln - '0';
  5483. val = (BYTE)((hn << 4 ) | ln);
  5484. RxBuff[RxLen] = val;
  5485. RxLen++;
  5486. }
  5487. int nSends = pClientSocket->SendBuf(RxBuff, RxLen);
  5488. LINFO("SendRealTimeDisplay: %d/%d Bytes", RxLen, nSends);
  5489. if (sl) delete sl;
  5490. }
  5491. catch(Exception &e)
  5492. {
  5493. //Application->ShowException(&e);
  5494. }
  5495. return SYS_ERR_NONE;
  5496. }
  5497. //---------------------------------------------------------------------------
  5498. int __fastcall TVMSSThread::SendScheduledDisplay()
  5499. {
  5500. TStringList *sl = NULL;
  5501. //Data Dump: 104 Bytes
  5502. String sMsg =
  5503. "30 81 8E 80 01 01 81 81 84 30 81 81 80 01 00 81 "
  5504. "02 03 8C 82 01 00 A3 42 81 08 30 30 30 30 30 30 "
  5505. "30 30 83 08 30 30 30 30 30 30 30 30 85 0A 56 4D "
  5506. "53 31 30 30 30 30 31 33 A7 20 80 02 07 E0 81 01 "
  5507. "0B 82 01 11 83 01 0D 84 01 0A 85 01 0C A6 03 82 "
  5508. "01 00 A7 06 80 01 09 81 01 00 A4 31 A6 2F 80 01 "
  5509. "FF A1 2A A0 28 30 26 80 01 32 81 01 02 82 01 00 "
  5510. "A3 1B A1 19 80 06 28 F3 6B 02 00 02 A1 0F 30 0D "
  5511. "30 0B 80 01 02 A1 06 04 01 31 04 01 32 82 02 10 "
  5512. "5D ";
  5513. try
  5514. {
  5515. sl = new TStringList;
  5516. sl->Delimiter = ' ';
  5517. sl->StrictDelimiter = true;
  5518. sl->DelimitedText = sMsg;
  5519. int ii;
  5520. unsigned int hn, ln;
  5521. BYTE chn, cln, val;
  5522. char szData[2048];
  5523. BYTE RxBuff[VMS_MAX_PACKET_SIZE];
  5524. int RxLen;
  5525. RxLen = 0;
  5526. memset(RxBuff, 0x00, sizeof(RxBuff));
  5527. for (ii = 0; ii < sl->Count; ii++)
  5528. {
  5529. AnsiString sTemp = sl->Strings[ii];
  5530. if (sTemp.Trim() == "") continue;
  5531. sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll);
  5532. if (sTemp.Trim() == "\r\n") continue;
  5533. memset(szData, 0x00, sizeof(szData));
  5534. memcpy(szData, sTemp.c_str(), sTemp.Length());
  5535. chn = (BYTE)szData[0];
  5536. cln = (BYTE)szData[1];
  5537. hn = chn > '9' ? chn - 'A' + 10 : chn - '0';
  5538. ln = cln > '9' ? cln - 'A' + 10 : cln - '0';
  5539. val = (BYTE)((hn << 4 ) | ln);
  5540. RxBuff[RxLen] = val;
  5541. RxLen++;
  5542. }
  5543. int nSends = pClientSocket->SendBuf(RxBuff, RxLen);
  5544. LINFO("SendScheduledDisplay: %d/%d Bytes", RxLen, nSends);
  5545. if (sl) delete sl;
  5546. }
  5547. catch(Exception &e)
  5548. {
  5549. //Application->ShowException(&e);
  5550. }
  5551. return SYS_ERR_NONE;
  5552. }
  5553. //---------------------------------------------------------------------------
  5554. int __fastcall TVMSSThread::SendFtpImage()
  5555. {
  5556. LINFO("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK");
  5557. int result;
  5558. result = ProcessCommand(AI_TransferDone, NULL);
  5559. return SYS_ERR_NONE;
  5560. }
  5561. //---------------------------------------------------------------------------
  5562. int __fastcall TVMSSThread::DownloadSymbolImage()
  5563. {
  5564. int nResult;
  5565. COMMAND_ARGUMENT arg;
  5566. BYTE CmdCode;
  5567. CmdCode = 0x00;
  5568. memset(&arg, 0x00, sizeof(arg));
  5569. AnsiString sFtpImgId;
  5570. try
  5571. {
  5572. CDSImageItr it;
  5573. for(it=ImageManager->FLists.FMapObject.begin(); it != ImageManager->FLists.FMapObject.end(); ++it)
  5574. {
  5575. TCDSImage *pTmp = (TCDSImage*)it->second;
  5576. //FOR_STL(TCDSImage*, pTmp, ImageManager->FLists)
  5577. //{
  5578. sFtpImgId = GetFtpImageId(pTmp->Nmbr);
  5579. if (sFtpImgId.SubString(1,1) == "7" || pTmp->VmsType == "VMP1")
  5580. continue; /* 도형식 배경이미지는 다운로드 할 필요 없음 */
  5581. arg.Publication.SubscribeSerialNbr = 0;
  5582. arg.Publication.obj = OBJ_RealTimeDisplay;
  5583. arg.Publication.Data.Form.Idx = 0;
  5584. sprintf(arg.Publication.szFormId, "%s", sFtpImgId.c_str());
  5585. CmdCode = AI_TransferDone;
  5586. nResult = ProcessCommand(CmdCode, &arg);
  5587. Sleep(100);
  5588. }
  5589. }
  5590. catch(Exception &e)
  5591. {
  5592. }
  5593. FVmsObj->FSymbolDownload = false;
  5594. return nResult;
  5595. }
  5596. //---------------------------------------------------------------------------