1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466 |
- /****************************************************************************
- * @source : VMSSThread.cpp
- * @description : VMS Server Socket Thread
- ****************************************************************************
- * DATE AUTHOR DESCRIPTION
- * --------------------------------------------------------------------------
- * 2012/03/09 CYM [100] First Cut
- *
- ****************************************************************************/
- //---------------------------------------------------------------------------
- #include "AppGlobalF.h"
- #include "VMSSThread.h"
- #include "VMSCThread.h"
- #include "FrmSysLogF.h"
- #include "FrmVmsInfoF.h"
- #include "FrmVmsLogF.h"
- #include <winsock.h>
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- //---------------------------------------------------------------------------
- // Important: Methods and properties of objects in VCL can only be
- // used in a method called using Synchronize, for example:
- //
- // Synchronize(&UpdateCaption);
- //
- // where UpdateCaption could look like:
- //
- // void __fastcall TVMSSThread::UpdateCaption()
- // {
- // Form1->Caption = "Updated in a thread";
- // }
- //---------------------------------------------------------------------------
- #define VMSID FVmsObj->VmsId
- __fastcall TVMSSThread::TVMSSThread(TServerSocketThread* ServerSocketThread, TCustomIpClient* ClientSocket, int Tag, bool *ActiveIndicator)
- : TClientSocketThread(ServerSocketThread)
- {
- try
- {
- FDupClose = false;
- m_InitFlag = false;
- FVmsObj = (TVmsCtlr*)Tag;
- FLogFile = FVmsObj->FSLog;
- ThreadActiveIndicator = ActiveIndicator;
- *ThreadActiveIndicator = true;
- FVmsObj->ConnectTm = Now().DateTimeString();
- // 정보 초기화
- ServerInitMem();
- ServerInitInfo();
- pClientSocket = ClientSocket;
- pClientSocket->BlockMode = bmBlocking;
- pClientSocket->OnError = TcpServerClientError;
- pClientSocket->OnDisconnect = TcpServerDisconnect;
- m_InitFlag = true;
- Priority = tpNormal;
- FreeOnTerminate = true;
- Resume();
- }
- catch(Exception &e)
- {
- SERROR("Thread Init Error");
- Terminate();
- }
- }
- //---------------------------------------------------------------------------
- __fastcall TVMSSThread::~TVMSSThread()
- {
- try
- {
- Close();
- SAFE_DELETE(pClientSocket);
- }
- catch(Exception &e)
- {
- }
- *ThreadActiveIndicator = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TVMSSThread::Close(void)
- {
- try
- {
- FVmsObj->DisconnectTm = Now().DateTimeString();
- FVmsObj->Server.Status == process_fail;
- if (pClientSocket)
- {
- //if (pClientSocket->Connected)
- {
- pClientSocket->Close();
- //Sleep(3000);
- }
- }
- }
- catch(Exception &e)
- {
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TVMSSThread::TcpServerClientError(TObject *Sender, int SocketError)
- {
- LPVOID lpMsgBuf = NULL;
- try
- {
- try
- {
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- //GetLastError(),
- //MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- SocketError,
- MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
- (LPTSTR) &lpMsgBuf,
- 0,
- NULL
- );
- char *pData = (char*)lpMsgBuf;
- if (strlen(pData) > 2)
- {
- pData[strlen(pData)-2] = 0x00;
- pData[strlen(pData)-1] = 0x00;
- }
- SERROR("SocketError: (%d: %s)", SocketError, pData);
- }
- __finally
- {
- if (lpMsgBuf) LocalFree(lpMsgBuf);
- lpMsgBuf = NULL;
- }
- }
- catch(Exception &e)
- {
- }
- Close();
- }
- //---------------------------------------------------------------------------
- bool __fastcall TVMSSThread::SocketActivity(bool &AError)
- {
- bool Error, ReadReady, WriteReady, ExcepFlag;
- ReadReady = false;
- AError = false;
- if (!pClientSocket) return ReadReady;
- try
- {
- Error = pClientSocket->Select(&ReadReady, &WriteReady, &ExcepFlag, 0);
- if ((Error == false))// || (ExcepFlag == true)) //exception flag == o.o.b(out of band data receive)
- {
- AError = true;
- ReadReady = false;
- }
- }
- catch(Exception &e)
- {
- AError = true;
- ReadReady = false;
- }
- return ReadReady;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TVMSSThread::SocketActivity()
- {
- bool bResult = false;
- bool Error, ReadReady, WriteReady, ExcepFlag;
- if (!pClientSocket) return bResult;
- try
- {
- Error = pClientSocket->Select(&ReadReady, &WriteReady, &ExcepFlag, 0);
- if ((Error == false) || (ReadReady == true) || (ExcepFlag == true))
- {
- bResult = true;
- }
- }
- catch(Exception &e)
- {
- }
- return bResult;
- }
- //---------------------------------------------------------------------------
- void __fastcall TVMSSThread::TcpServerDisconnect(TObject *Sender)
- {
- //SINFO("Client Disconnect");
- if (!APP_EXIT) {
- SINFO("Client Disconnect: %s %s", pClientSocket->RemoteHost.c_str(), pClientSocket->RemotePort.c_str());
- }
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TVMSSThread::Execute()
- {
- BYTE buffer[DEFAULT_TCP_PACKET_MAX_SIZE];
- int nError;
- int nResult;
- bool bError;
- int nReadLen;
- unsigned long nRecvLen;
- FErrLine = 0;
- SINFO("Thread start");
- try
- {
- while (!Terminated && !m_InitFlag);
- //NameThreadForDebugging(m_strName);
- FVmsObj->Server.Status = process_run;
- POST_MSG(MAINHANDLE, WM_VMS_THREAD, WM_VMS_SERVER_STTS, (int)FVmsObj);
- try
- {
- CheckClientThread(true);
- //TODO
- m_Server.State = ST_SECTION;
- while (!Terminated && pClientSocket->Connected && !FDupClose)
- {
- try
- {
- bError = false;
- if (pClientSocket->WaitForData(100) || SocketActivity())
- {
- bError = false;
- nRecvLen = 0;
- #if 0
- nResult = ioctlsocket(pClientSocket->Handle, FIONREAD, &nRecvLen);
- if (nResult != 0)
- {
- Close();
- }
- if (nRecvLen > 0)
- #endif
- {
- memset(buffer, 0, sizeof(buffer));
- nReadLen = pClientSocket->ReceiveBuf(buffer, sizeof(buffer));
- if (nReadLen > 0)
- {
- if ((nResult = RecvPacket(buffer, nReadLen)) != SYS_ERR_NONE)
- {
- ProcErrorState(TRUE, nResult);
- }
- }
- else
- {
- bError = true;
- }
- #if 0
- if ((int)nRecvLen != nReadLen)
- {
- SERROR("Receive data size false: %d, %d", nRecvLen, nReadLen);
- }
- #endif
- }
- }
- if (bError)
- {
- SERROR("Socket Error[Closed]....");
- nError = -3;
- Close();
- }
- else
- {
- CheckClientThread(true);
- ServerStateMachine();
- }
- if (g_AppCfg.bThrExit)
- {
- nError = 0;
- SINFO("Thread exit catched....");
- Close();
- }
- }
- catch(Exception &e)
- {
- SERROR("Thread execute exception: %s, Line: %d", AnsiString(e.Message).c_str(), FErrLine);
- nError = -2;
- Close();
- }
- }
- SERROR("Term: %d, Conn: %d, Dup: %d, Err: %d, Line: %d", Terminated, pClientSocket->Connected, FDupClose, nError, FErrLine);
- }
- __finally
- {
- Close();
- Terminate();
- }
- }
- catch(Exception &e)
- {
- SERROR("Thread execute error: %s", AnsiString(e.Message).c_str());
- Terminate();
- }
- ServerTerminate();
- }
- //---------------------------------------------------------------------------
- // VMS 제어기와의 상태정보 통신을 담당할 클라이언트 스레드를 체크한다.
- bool __fastcall TVMSSThread::CheckClientThread(bool ARun)
- {
- if (FVmsObj->Client.UseFlag != bit_enable) return false;
- if (ARun)
- {
- if ((FVmsObj->Client.pThread == NULL) &&
- (FVmsObj->Client.ActiveIndicator == false))
- {
- TVMSCThread *pVMSCThread = new TVMSCThread(true, (int)FVmsObj, &FVmsObj->Client.ActiveIndicator);
- FVmsObj->Client.pThread = pVMSCThread;
- if (FVmsObj->Client.pThread == NULL)
- {
- FVmsObj->Client.Status = process_fail;
- }
- else
- {
- FVmsObj->Client.wTimer = Now();
- }
- LINFO("Client Thread create: %d", FVmsObj->Client.pThread == NULL ? 0 : 1);
- }
- }
- return true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TVMSSThread::ServerTerminate(void)
- {
- try
- {
- FVmsObj->Server.Status = process_fail;
- if (!APP_EXIT) {
- POST_MSG(MAINHANDLE, WM_VMS_THREAD, WM_VMS_SERVER_STTS, (int)FVmsObj);
- SINFO("Thread stop");
- }
- }
- catch(Exception &e)
- {
- }
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::ServerInitMem(void)
- {
- return S_SUCC;
- }
- //---------------------------------------------------------------------------
- void __fastcall TVMSSThread::ServerInitInfo(void)
- {
- m_RxLen = 0;
- m_rTimer = Now();
- m_WatchDogTimer = Now();
- m_strName = "VMSS" + FVmsObj->VmsId;
- FWatchDogTime = g_AppCfg.comm.nWatchDogTime;
- m_pVmsFormList = FVmsObj->pForms;
- m_Server.VmsId = FVmsObj->VmsId;
- m_Server.Addr = FVmsObj->LocalNo;
- m_Server.IpAddress = FVmsObj->IpAddress;
- m_Server.Port = VMS_DEFAULT_PORT;
- m_Server.TimeOut = g_AppCfg.comm.nCmdTimeOut;
- m_Server.CycleTime = g_AppCfg.comm.nPollingTime;
- m_pState = &FVmsObj->RSTATE;
- //TODO
- m_Server.State = ST_IDLE;
- //m_Server.State = ST_INITIATE;
- m_Server.sTimer = Now();
- m_Server.iRetry = VMS_MAX_RETRY_COUNT;
- m_Server.cTimer = Now();
- m_Server.LocalCenterId = "";
- m_Server.CenterId = "";
- m_Server.LocalDomainNm = g_AppCfg.comm.sLocalDomain;
- m_Server.DomainNm = FVmsObj->VmsId;
- m_Server.UserName = g_AppCfg.comm.sLoginUser;
- m_Server.UserPasswd = g_AppCfg.comm.sLoginPswd;
- m_Server.MaxHeartbeatTime = VMS_MAX_HEARTBEAT_TIME;
- m_Server.DatagramSize = VMS_MAX_DATAGRAM_SIZE;
- m_DataPacketNumber = 0;
- m_FrEDConfirmPacketNumber = 0;
- m_LoginFlag = false;
- m_PublishSerialNbr = 0;
- m_Registered.GeneralStatus = false;
- m_Registered.ModuleStatus = false;
- m_Registered.PowerStatus = false;
- m_Registered.ScreenDataStatusMessage = false;
- m_Registered.RealTimeDisplayMessage = false;
- #if 0
- //VMS가 접속하는 경우 생성되어 있는 메시지를 바로 보내도록 플래그 설정
- AnsiString sSvcDate = Now().FormatString("yyyymmddhhnnss");
- if (sSvcDate == FVmsObj->CTLMODE->SvcDate)
- {
- Sleep(1000);
- sSvcDate = Now().FormatString("yyyymmddhhnnss");
- }
- FVmsObj->CTLMODE->Enable = object_enable;
- FVmsObj->CTLMODE->SvcDate = sSvcDate;
- FVmsObj->CTLMODE->SaveFlag = false;
- FVmsObj->CTLMODE->Result = false;
- #endif
- LINFO("ServerInitInfo ok");
- }
- //---------------------------------------------------------------------------
- void __fastcall TVMSSThread::LOG_WriteTime(Time_t *pTime)
- {
- FErrLine = 29;
- if (!pTime) return;
- if (pTime->time_Year_qty)
- {
- LDEBUG("time_Year_qty: %d", *pTime->time_Year_qty);
- }
- if (pTime->time_Month_qty)
- {
- LDEBUG("time_Month_qty: %d", *pTime->time_Month_qty);
- }
- if (pTime->time_Day_qty)
- {
- LDEBUG("time_Day_qty: %d", *pTime->time_Day_qty);
- }
- LDEBUG("time_Hour_qty : %d", pTime->time_Hour_qty);
- LDEBUG("time_Minute_qty: %d", pTime->time_Minute_qty);
- LDEBUG("time_Second_qty: %d", pTime->time_Second_qty);
- switch(pTime->time_SecondFractions_zz.present)
- {
- case time_SecondFractions_PR_deci_seconds:
- LDEBUG("deci_seconds: %d", pTime->time_SecondFractions_zz.choice.deci_seconds);
- break;
- case time_SecondFractions_PR_centi_seconds:
- LDEBUG("centi_seconds: %d", pTime->time_SecondFractions_zz.choice.centi_seconds);
- break;
- case time_SecondFractions_PR_milliseconds:
- LDEBUG("milliseconds: %d", pTime->time_SecondFractions_zz.choice.milliseconds);
- break;
- default:
- LDEBUG("Unknown time_SecondFractions %d", pTime->time_SecondFractions_zz.present);
- break;
- }
- if (pTime->time_Timezone)
- {
- LDEBUG("timezone_Hour_qty: %d", pTime->time_Timezone->timezone_Hour_qty);
- LDEBUG("time_Minute_qty: %d", pTime->time_Timezone->time_Minute_qty);
- }
- }
- /*--------------------------------------------------------------------------*/
- /*
- *
- * arguments
- * void
- * return
- * void
- */
- void __fastcall TVMSSThread::ClientResponse(int error)
- {
- #ifdef CENTERCOMM
- BYTE ErrCode;
- int sResult;
- int Flag;
- bool bSave = false;
- switch(error)
- {
- case SYS_ERR_NONE: break;
- case SYS_ERR_OTHER: ErrCode = INT_ERROR_OTHER; break;
- case SYS_ERR_INTERNAL: ErrCode = INT_ERROR_SYSTEM; break;
- case SYS_ERR_MEMORY: ErrCode = INT_ERROR_SYSTEM; break;
- case SYS_ERR_DATABASE: ErrCode = INT_ERROR_SYSTEM; break;
- case SYS_ERR_RESET: ErrCode = INT_ERROR_SYSTEM; break;
- case SYS_ERR_START: ErrCode = INT_ERROR_SYSTEM; break;
- case SYS_ERR_OFFLINE: ErrCode = INT_ERROR_OFFLINE; break;
- case SYS_ERR_NO_RES: ErrCode = INT_ERROR_NO_RESPONSE; break;
- case SYS_ERR_ACCESS: ErrCode = INT_ERROR_PROCESS; break;
- case SYS_ERR_INVALID: ErrCode = INT_ERROR_OTHER; break;
- case SYS_ERR_UNKNOWN: ErrCode = INT_ERROR_UNKNOWN_CODE; break;
- case SYS_ERR_WRITE_LENGTH: ErrCode = INT_ERROR_OTHER; break;
- case SYS_ERR_PACKET_SIZE_LARGE: ErrCode = INT_ERROR_OTHER; break;
- case SYS_ERR_INVALID_TAG: ErrCode = INT_ERROR_OTHER; break;
- case SYS_ERR_CRC: ErrCode = INT_ERROR_OTHER; break;
- case SYS_ERR_LENGTH: ErrCode = INT_ERROR_LENGTH; break;
- case SYS_ERR_ADDRESS: ErrCode = INT_ERROR_ADDRESS; break;
- case SYS_ERR_HEADER_OPTIONS: ErrCode = INT_ERROR_HEADER; break;
- case SYS_ERR_UNKNOWN_COMMAND: ErrCode = INT_ERROR_UNKNOWN_OPCODE; break;
- case SYS_ERR_RECEIVE_TIMEOUT: ErrCode = INT_ERROR_OTHER; break;
- case SYS_ERR_DATA_SIZE: ErrCode = INT_ERROR_DISCORD; break;
- case SYS_ERR_MISMATCH: ErrCode = INT_ERROR_OTHER; break;
- case SYS_ERR_INVALID_PARA: ErrCode = INT_ERROR_INVALID_DATA; break;
- case SYS_ERR_MOVEMENT: ErrCode = INT_ERROR_MOVEMENT; break;
- case SYS_ERR_UNAUTHORIZED: ErrCode = INT_ERROR_UNAUTHORIZED; break;
- default: ErrCode = INT_ERROR_OTHER; break;
- }
- switch (m_Req.OpCode)
- {
- case INT_OP_VMS_POWER_CTL: /* 0x0303 VMS 통신 서버, VMS 전광판 On/Off 제어 */
- if (error == SYS_ERR_NONE)
- {
- Flag = SEND_ACK;
- m_Set.Data.Control.Result = CTL_RESULT_SUCC;
- }
- else
- {
- Flag = SEND_NACK;
- }
- bSave = true;
- break;
- case INT_OP_VMS_PARA_SET: /* 0x0308 VMS 통신 서버, VMS 환경설정정보 전송 */
- if (error == SYS_ERR_NONE)
- {
- Flag = SEND_ACK;
- bSave = true;
- }
- else
- {
- Flag = SEND_NACK;
- }
- break;
- case INT_OP_VMS_RESET: /* 0x0309 VMS 통신 서버, VMS 제어기 리셋 전송 */
- if (error == SYS_ERR_NONE)
- {
- Flag = SEND_ACK;
- m_Set.Data.Control.Result = CTL_RESULT_SUCC;
- }
- else
- {
- Flag = SEND_NACK;
- }
- bSave = true;
- break;
- default:
- Flag = SEND_NONE;
- break;
- }
- if (bSave == true)
- {
- if ((sResult = SendDbThreadDataMessage(WM_DATA_SAVE, (void *)&m_Set, sizeof(m_Set))) != SYS_ERR_NONE)
- {
- }
- }
- if (Flag == SEND_ACK)
- {
- INT_ACK_RES Ack;
- memset(&Ack, 0x00, sizeof(Ack));
- Ack.OPCode.Type = INT_TYPE(m_Req.OpCode);
- Ack.OPCode.Kind = INT_KIND(m_Req.OpCode);
- Ack.MsgSeq = m_Req.MsgSeq;
- if ((sResult = AckRes(&Ack, m_Req.ProcessID)) != UDP_ERR_NONE)
- {
- }
- }
- else
- if (Flag == SEND_NACK)
- {
- INT_NACK_RES Nack;
- memset(&Nack, 0x00, sizeof(Nack));
- Nack.OPCode.Type = INT_TYPE(m_Req.OpCode);
- Nack.OPCode.Kind = INT_KIND(m_Req.OpCode);
- Nack.MsgSeq = m_Req.MsgSeq;
- Nack.ErrCode = ErrCode;
- if ((sResult = NackRes(&Nack, m_Req.ProcessID)) != UDP_ERR_NONE)
- {
- }
- }
- #endif
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::SendDbThreadMessage(UINT Msg, int wParam, int lParam)
- {
- int result;
- result = SYS_ERR_OTHER;
- if (g_SysInfo->State.CommThreadID != NULL)
- {
- if (PostThreadMessage(g_SysInfo->State.CommThreadID, Msg, (WPARAM)wParam, (LPARAM)lParam)){
- result = SYS_ERR_NONE;
- }else{
- result = SYS_ERR_INTERNAL;
- }
- }
- return result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::SendDbThreadDataMessage(UINT Msg, void *pData, int iLen)
- {
- int nResult;
- char *p;
- nResult = VERR_OTHER;
- if (g_SysInfo->State.CommThreadID != NULL)
- {
- p = new char[iLen];
- if (p != NULL)
- {
- try
- {
- memcpy(p, pData, iLen);
- if (PostThreadMessage(g_SysInfo->State.CommThreadID, Msg, (WPARAM)p, NULL))
- {
- nResult = VERR_NONE;
- Sleep(50);
- }
- else
- {
- nResult = VERR_INTERNAL;
- }
- }
- __finally
- {
- if (nResult != VERR_NONE)
- {
- delete []p;
- }
- }
- }
- else
- {
- nResult = VERR_MEMORY_ALLOC;
- }
- }
- return nResult;
- }
- //---------------------------------------------------------------------------
- /*
- * 한글을 UTF8 문자열로 변환
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::Hangul2UTF8String(char *pIn, char *pOut, int outSize)
- {
- FErrLine = 1;
- int result;
- UTF8String uStr;
- result = 0;
- memset(pOut, 0x00, outSize);
- if (!pIn)
- {
- SERROR("Hangul2UTF8String In Data is NULL");
- return result;
- }
- try
- {
- uStr = UTF8Encode(WideString(pIn));
- if (uStr.Length() > outSize)
- {
- return -1;
- }
- memcpy(pOut, uStr.c_str(), uStr.Length());
- }
- catch(Exception &e)
- {
- SERROR("Hangul2UTF8String exception: [%s], %s", pIn, AnsiString(e.Message).c_str());
- }
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * UTF8를 한글 문자열로 변환
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::UTF8String2Hangul(char *pIn, char *pOut, int outSize)
- {
- FErrLine = 2;
- int result;
- AnsiString AnsiStr;
- result = 0;
- memset(pOut, 0x00, outSize);
- if (!pIn)
- {
- SERROR("UTF8String2Hangul In Data is NULL");
- return result;
- }
- try
- {
- AnsiStr = (AnsiString)UTF8Decode(UTF8String(pIn));
- if (AnsiStr.Length() > outSize)
- {
- return -1;
- }
- memcpy(pOut, AnsiStr.c_str(), AnsiStr.Length());
- }
- catch(Exception &e)
- {
- SERROR("UTF8String2Hangul exception: [%s], %s", pIn, AnsiString(e.Message).c_str());
- }
- return result;
- }
- /*--------------------------------------------------------------------------*/
- /*
- * 패킷 수신
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::RecvPacket(void *Data, int Len)
- {
- FErrLine = 3;
- int result;
- ssize_t stat;
- ssize_t length;
- DatexDataPacket_t *pMsg = 0; /* Type to decode */
- asn_dec_rval_t rval; /* Decoder return value */
- long version;
- WORD crc;
- result = SYS_ERR_NONE;
- if (Len > 0)
- {
- LogData("RECV", (char*)Data, Len);
- }
- if (m_RxLen)
- {
- if ((m_RxLen + Len) > SERVER_MAX_PACKET_SIZE) m_RxLen = 0;
- memcpy(m_RxBuff + m_RxLen, Data, Len);
- m_RxLen += Len;
- }
- else
- {
- memcpy(m_RxBuff, Data, Len);
- m_RxLen = Len;
- m_rTimer = Now();
- }
- while (m_RxLen >= VMS_MIN_PACKET_SIZE)
- {
- stat = ASN1C_BerReadLength(m_RxBuff, m_RxLen, &length);
- if ((stat != RC_OK) || (length > VMS_MAX_PACKET_SIZE))
- {
- result = SYS_ERR_INVALID_TAGANDLEN;
- break;
- }
- LINFO("Recv: state[%d], length[%d/%d]", stat, length, m_RxLen);
- if (length > m_RxLen)
- {
- break;
- }
- /* Decode */
- #if 0
- rval = ber_decode(0, &asn_DEF_DatexDataPacket, (void **)&pMsg, m_RxBuff, m_RxLen);
- #else
- rval = ber_decode(0, &asn_DEF_DatexDataPacket, (void **)&pMsg, m_RxBuff, length);
- #endif
- switch(rval.code)
- {
- case RC_OK:
- if ((rval.consumed == 0) || (pMsg == 0))
- {
- result = SYS_ERR_DATEXDATAPACKET_DECODE;
- break;
- }
- asn_INTEGER2long(&pMsg->datex_Version_number, &version);
- if (version != datex_Version_number_version1)
- {
- LERROR("SYS_ERR_INVALID_VERSION_NUMBER: %d/%d", version, datex_Version_number_version1);
- result = SYS_ERR_INVALID_VERSION_NUMBER;
- break;
- }
- #if 1
- crc = ASN1C_MakeCrc16((void *)pMsg->datex_Data.buf, pMsg->datex_Data.size);
- if (pMsg->datex_Crc_nbr.size != 2 ||
- pMsg->datex_Crc_nbr.buf[0] != HIBYTE(crc) ||
- pMsg->datex_Crc_nbr.buf[1] != LOBYTE(crc))
- {
- result = ASN_ERR_CRC;
- break;
- }
- #endif
- /* 패킷 처리 */
- result = ProcessRecvPacket((BYTE *)pMsg->datex_Data.buf, pMsg->datex_Data.size);
- if (result != SYS_ERR_NONE)
- {
- SERROR("Receive Packet Error : %d", result);
- }
- break;
- case RC_WMORE:
- case RC_FAIL:
- default:
- result = SYS_ERR_DATEXDATAPACKET_DECODE;
- break;
- }
- if (pMsg)
- {
- ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
- pMsg = 0;
- }
- if (result != SYS_ERR_NONE)
- {
- m_RxLen = 0;
- break;
- }
- m_RxLen -= length;
- if (m_RxLen < 0) m_RxLen = 0;
- if (m_RxLen > 0)
- {
- memcpy(m_RxBuff, m_RxBuff + length, m_RxLen);
- }
- } /* end while */
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 수신 패킷 처리
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::ProcessRecvPacket(BYTE *pBuffer, int Len)
- {
- FErrLine = 4;
- int result, iResult;
- C2CAuthenticatedMessage_t *pMsg = 0; /* Type to decode */
- asn_dec_rval_t rval; /* Decoder return value */
- BYTE cmd;
- BYTE pdu;
- COMMAND_ARGUMENT arg;
- long DataPacket_number;
- result = SYS_ERR_OTHER;
- /* Decode */
- rval = ber_decode(0, &asn_DEF_C2CAuthenticatedMessage, (void **)&pMsg, pBuffer, Len);
- switch(rval.code)
- {
- case RC_OK:
- {
- if ((rval.consumed == 0) || (pMsg == 0))
- {
- LERROR("SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE");
- result = SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE;
- break;
- }
- /* 공통부분 */
- if (pMsg->datex_AuthenticationInfo_text.size != 1 ||
- /* pMsg->datex_DataPacket_number < 0 || */
- /* pMsg->datex_DataPacket_number > 4294967295 || */
- /* pMsg->datex_DataPacketPriority_number < 0 || */
- pMsg->datex_DataPacketPriority_number > 10)
- {
- LERROR("SYS_ERR_C2CAUTHENTICATEDMESSAGE: %d/%d", pMsg->datex_AuthenticationInfo_text.size, pMsg->datex_DataPacketPriority_number);
- result = SYS_ERR_C2CAUTHENTICATEDMESSAGE;
- break;
- }
- asn_INTEGER2long(&pMsg->datex_DataPacket_number, &DataPacket_number);
- pdu = pMsg->pdu.present;
- cmd = pMsg->datex_AuthenticationInfo_text.buf[0];
- #if 1
- if ((m_LoginFlag == false) && (pdu != PDUs_PR_login))
- {
- LWARN("SYS_ERR_NOT_LOGIN");
- m_Server.State = ST_SECTION;
- result = SYS_ERR_NOT_LOGIN;
- //break;
- }
- #endif
- #if 0
- HeaderOptions_t *options;
- /* Header Options */
- options = &pMsg->options;
- if (options->datex_OriginAddress_location->size == 0 ||
- options->datex_DestinationAddress_location->size == 0)
- {
- result = SYS_ERR_HEADER_OPTIONS;
- break;
- }
- // m_Server.CenterId = NULL
- // m_Server.LocalCenterId = NULL
- // datex_OriginAddress_location = VM10000002
- // datex_DestinationAddress_location = 00000000
- if (memcmp(options->datex_OriginAddress_location->buf, m_Server.CenterId.c_str(), options->datex_OriginAddress_location->size) ||
- memcmp(options->datex_DestinationAddress_location->buf, m_Server.LocalCenterId.c_str(), options->datex_DestinationAddress_location->size))
- {
- result = SYS_ERR_ADDRESS;
- break;
- }
- #endif
- /* options->datex_Origin_text */
- /* options->datex_Sender_text */
- /* options->datex_SenderAddress_location */
- /* options->datex_Destination_text */
- /* options->datex_Cost->amount_Currency_code */
- /* options->datex_Cost->amount_Factor_quantity */
- /* options->datex_Cost->amount_Quantity_quantity */
- /* options->datex_DataPacket_time->time_Year_qty */
- /* options->datex_DataPacket_time->time_Month_qty */
- /* options->datex_DataPacket_time->time_Day_qty */
- /* options->datex_DataPacket_time->time_Hour_qty */
- /* options->datex_DataPacket_time->time_Minute_qty */
- /* options->datex_DataPacket_time->time_Second_qty */
- /* options->datex_DataPacket_time->time_SecondFractions->present */
- /* options->datex_DataPacket_time->time_SecondFractions->choice.milliseconds */
- /* options->datex_DataPacket_time->time_Timezone->timezone_Hour_qty */
- /* options->datex_DataPacket_time->time_Timezone->time_Minute_qty */
- switch(pdu)
- {
- case PDUs_PR_NOTHING:
- //FOR YONGIN
- LINFO("<<< PDUs_PR_NOTHING 수신xxxxx");
- result = SYS_ERR_NONE;
- break;
- case PDUs_PR_datex_Initiate_null:
- //FOR YONGIN
- LINFO("<<< PDUs_PR_datex_Initiate_null 수신");
- result = SYS_ERR_NONE;
- break;
- case PDUs_PR_login: /* 서버에 접속하기 위한 클라이언트의 로그인 데이터 패킷 */
- LINFO("<<< PDUs_PR_login 수신");
- result = PacketLogin(&pMsg->pdu.choice.login, DataPacket_number);
- if (result == SYS_ERR_NONE)
- {
- m_LoginFlag = true;
- m_Server.State = ST_SECTION;
- }
- else
- {
- LERROR("PacketLogin result Error: %d", result);
- }
- break;
- case PDUs_PR_fred: /* 서버와 클라이언트의 연결을 유지하기 위한 확인 데이터 패킷 */
- {
- long fred;
- asn_INTEGER2long(&pMsg->pdu.choice.fred, &fred);
- result = SYS_ERR_NONE;
- LINFO("<<< PDUs_PR_fred 수신: %u", fred);
- {
- //TODO
- m_LoginFlag = true;
- //m_Server.State = ST_SECTION;
- }
- m_WatchDogTimer = Now();
- }
- if (m_FrEDConfirmPacketNumber > 65535) m_FrEDConfirmPacketNumber = 0;
- arg.FrED = m_FrEDConfirmPacketNumber++;
- if ((iResult = ProcessCommand(AI_FrED, &arg)) != SYS_ERR_NONE)
- {
- LERROR("AI_FrED Command failed: %d", iResult);
- }
- break;
- case PDUs_PR_terminate: /* 연결을 종료하고자 할 때, 서버에서 클라이언트에 요청하는 데이터 패킷 */
- {
- //여기는 들어오면 안됌(서버 모듈에서 보내는 메시지임)
- LINFO("<<< PDUs_PR_terminate 수신xxxxx");
- result = SYS_ERR_NONE;
- #if 0
- try
- {
- long terminate;
- asn_INTEGER2long(&pMsg->pdu.choice.terminate, &terminate);
- result = SYS_ERR_NONE;
- LINFO("<<< PDUs_PR_terminate 수신 %u", terminate);
- } catch(Exception &e) {}
- #endif
- }
- break;
- case PDUs_PR_logout: /* 접속을 종료하기 위한 클라이언트의 로그아웃 데이터 패킷 */
- {
- long logout;
- asn_INTEGER2long(&pMsg->pdu.choice.logout, &logout);
- result = SYS_ERR_NONE;
- LINFO("<<< PDUs_PR_logout 수신 %d", logout);
- }
- arg.FrED = m_FrEDConfirmPacketNumber++;
- if ((iResult = ProcessCommand(AI_FrED, &arg)) != SYS_ERR_NONE)
- {
- LERROR("Logout FrED Command failed: %d", iResult);
- }
- m_Server.State = ST_CLOSE;
- result = SYS_ERR_NONE;
- break;
- case PDUs_PR_subscripiton: /* 클라이언트가 서버에 정보를 요청할 경우 송신하는 데이터 패킷 */
- {
- LINFO("<<< PDUs_PR_subscripiton 수신");
- result = PacketSubscription(&pMsg->pdu.choice.subscripiton);
- bool bSubscript = false;
- int Message_id = 0;
- if (result == SYS_ERR_NONE)
- {
- long Serial_nbr;
- asn_INTEGER2long(&pMsg->pdu.choice.subscripiton.datexSubscribe_Serial_nbr, &Serial_nbr);
- arg.Accept.nbr = DataPacket_number;
- if (pMsg->pdu.choice.subscripiton.datexSubscribe_Type.present == SubscriptionType_PR_subscription)
- {
- if (pMsg->pdu.choice.subscripiton.datexSubscribe_Type.choice.subscription.datexSubscribe_Mode.present
- == SubscriptionMode_PR_single)
- {
- arg.Accept.type = datexAccept_Type_PR_single_subscription;
- }
- else
- { /* SubscriptionMode_PR_event_driven, SubscriptionMode_PR_periodic */
- arg.Accept.type = datexAccept_Type_PR_registered_subscription;
- arg.Accept.sub = Serial_nbr;
- Subscription_t *pSubscripiton = &pMsg->pdu.choice.subscripiton;
- SubscriptionData_t *pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
- if ((Message_id = ASN1C_GetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id)) != -1)
- {
- //bSubscript = true;
- switch(Message_id)
- {
- case OBJ_RealTimeDisplay: /* 실시간정보표출 */
- arg.Accept.nbr = 4;
- arg.Accept.sub = 1;
- break;
- case OBJ_ScheduledDisplay: /* 계획된정보표출 */
- arg.Accept.nbr = 5;
- arg.Accept.sub = 2;
- break;
- case OBJ_DownloadGraphicData: /* 그래픽데이터 다운로드 */
- arg.Accept.nbr = 6;
- arg.Accept.sub = 3;
- break;
- case OBJ_StatusControl: /* 상태제어 */
- arg.Accept.nbr = 7;
- arg.Accept.sub = 4;
- break;
- case OBJ_StatusSetting: /* 상태설정 */
- arg.Accept.nbr = 8;
- arg.Accept.sub = 5;
- break;
- }
- }
- }
- }
- else
- { /* SubscriptionType_PR_datexSubscribe_CancelReason_cd */
- arg.Accept.type = datexAccept_Type_PR_registered_subscription;
- arg.Accept.sub = Serial_nbr;
- }
- if (bSubscript)
- {
- SendSubscriptionAccept(Message_id);
- }
- else
- {
- if ((iResult = ProcessCommand(AI_Accept, &arg)) != SYS_ERR_NONE)
- {
- SERROR("Subscription Accept Command failed: %d", iResult);
- }
- }
- }
- else
- {
- int ErrCode;
- switch(result)
- {
- case SYS_ERR_SUBSCRIPTION_MODE_VALUE:
- ErrCode = datexReject_Subscription_cd_invalid_mode;
- break;
- case SYS_ERR_SUBSCRIPTION_FORMAT_VALUE:
- ErrCode = datexReject_Subscription_cd_publishFormatNotSupported;
- break;
- case SYS_ERR_UNKNOWN_MESSAGE_ID:
- ErrCode = datexReject_Subscription_cd_unknowSubscriptionMsgId;
- break;
- case SYS_ERR_MESSAGE_DECODE:
- ErrCode = datexReject_Subscription_cd_invalidSubscriptionContent;
- break;
- case SYS_ERR_SUBSCRIPTION_STATUS_VALUE:
- case SYS_ERR_SUBSCRIPTION_TYPE:
- default:
- ErrCode = datexReject_Subscription_cd_other;
- }
- /* datexReject_Subscription_cd_unknownSubscriptionNbr */
- /* datexReject_Subscription_cd_invalidTimes */
- /* datexReject_Subscription_cd_frequencyTooSmall */
- /* datexReject_Subscription_cd_frequencyTooLarge */
- /* datexReject_Subscription_cd_invalidSubscriptionMsgId */
- arg.Reject.nbr = DataPacket_number;
- arg.Reject.type = RejectType_PR_datexReject_Subscription_cd;
- arg.Reject.code = ErrCode;
- if((iResult = ProcessCommand(AI_Reject, &arg)) != SYS_ERR_NONE)
- {
- SERROR("Subscription Reject Command failed: %d", iResult);
- }
- }
- }
- break;
- case PDUs_PR_publication:
- // FOR YONGIN
- LINFO("<<< PDUs_PR_publication 수신");
- switch(cmd)
- {
- case AI_GeneralStatusMessage: LINFO(" *** AI_GeneralStatusMessage 수신"); break;
- case AI_PowerStatusMessage: LINFO(" *** AI_PowerStatusMessage 수신"); break;
- case AI_ModuleStatusMessage: LINFO(" *** AI_ModuleStatusMessage 수신"); break;
- case AI_DotStatusMessage: LINFO(" *** AI_DotStatusMessage 수신"); break;
- case AI_ScreenStatusMessage: LINFO(" *** AI_ScreenStatusMessage 수신"); break;
- case AI_DisplayingDataMessage:LINFO(" *** AI_DisplayingDataMessage 수신"); break;
- default: LINFO(" *** PDUs_PR_publication Unknown 수신: %d", cmd); break;
- }
- result = RecvPacketPublication(&pMsg->pdu.choice.publication);
- if (result == SYS_ERR_NONE)
- {
- #if 0
- m_WatchDogTimer = Now();
- arg.Accept = DataPacket_number;
- if((iResult = ProcessCommand(AI_Accept, &arg)) != SYS_ERR_NONE)
- {
- SERROR("Publication Accept Command failed: %d", iResult);
- }
- #endif
- }
- else
- {
- int ErrCode;
- switch(result)
- {
- case SYS_ERR_DATEXPUBLISH_FORMAT:
- ErrCode = datexReject_Publication_cd_invalidPublishFormat;
- break;
- case SYS_ERR_UNKNOWN_MESSAGE_ID:
- ErrCode = datexReject_Publication_cd_unknownPublicationMsgId;
- break;
- case SYS_ERR_DATEXPUBLISH_TYPE:
- ErrCode = datexReject_Publication_cd_invalidPublicationMsgContent;
- break;
- case SYS_ERR_MESSAGE_DECODE:
- ErrCode = datexReject_Publication_cd_invalidPublicationMsgContent;
- break;
- default:
- ErrCode = datexReject_Publication_cd_other;
- }
- /* datexReject_Publication_cd_unknownSubscription */
- /* datexReject_Publication_cd_unknownPublicationNbr */
- /* datexReject_Publication_cd_invalidPublicationMsgId */
- /* datexReject_Publication_cd_repeatedPublicationNbr */
- #if 0
- arg.Reject.nbr = DataPacket_number;
- arg.Reject.code = ErrCode;
- if ((iResult = ProcessCommand(AI_Reject, &arg)) != SYS_ERR_NONE)
- {
- SERROR("Publication Reject Command %d", iResult);
- }
- #endif
- }
- result = SYS_ERR_NONE;
- break;
- case PDUs_PR_transfer_done:
- LINFO("<<< PDUs_PR_transfer_done 수신");
- {
- AnsiString sFormImgId = "";
- TransferDone_t *pTrans = &pMsg->pdu.choice.transfer_done;
- long lv;
- asn_INTEGER2long(&pTrans->datexTransferDone_Publication_nbr, &lv);
- LDEBUG("datexTransferDone_Publication_nbr: %u", lv);
- sFormImgId.printf("%.*s", pTrans->datexTransferDone_FileName_txt.size, pTrans->datexTransferDone_FileName_txt.buf);
- LDEBUG(" datexTransferDone_FileName_txt: %s", sFormImgId.c_str());
- LDEBUG(" datexTransferDone_Sucess_bool: %d", pTrans->datexTransferDone_Sucess_bool);
- result = RecvFormDownResult(sFormImgId);
- if (result != SYS_ERR_NONE)
- {
- LERROR("RecvFormDownResult result Error: %d", result);
- }
- }
- break;
- case PDUs_PR_accept: /* 클라이언트의 요청에 대한 수용 */
- LINFO("<<< PDUs_PR_accept 수신");
- result = PacketAccept(&pMsg->pdu.choice.accept);
- if (result != SYS_ERR_NONE)
- {
- LERROR("PDUs_PR_accept result Error: %d", result);
- }
- break;
- case PDUs_PR_reject: /* 클라이언트의 요청에 대한 거부 */
- LINFO("<<< PDUs_PR_reject 수신");
- result = PacketReject(&pMsg->pdu.choice.reject);
- if (result != SYS_ERR_NONE)
- {
- LERROR("PacketReject result Error: %d", result);
- }
- break;
- default:
- LINFO("<<< Unknown PDUs 수신: pdu(%d), cmd(%d)", pdu, cmd);
- result = SYS_ERR_UNKNOWN_COMMAND;
- break;
- }/* end switch */
- }
- break;
- case RC_WMORE:
- case RC_FAIL:
- default:
- result = SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE;
- break;
- }/* end switch */
- if (pMsg)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- }
- if ((result == SYS_ERR_NONE) && (cmd != AI_Reject))
- {
- m_Server.iRetry = VMS_MAX_RETRY_COUNT;
- }
- if (pdu == PDUs_PR_login)
- {
- if (FVmsObj->FSymbolDownload)
- {
- if (FVmsObj->FIsOldProtocol && !FVmsObj->FBmpDownload)
- {
- DownloadSymbolImage();
- }
- }
- }
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 수신 패킷 처리
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::RecvPacketPublication(Publication_t *pPublication)
- {
- FErrLine = 47;
- int result;
- PublicationData_t *pData;
- int i;
- result = SYS_ERR_OTHER;
- /* pPublication->datexPublish_Guaranteed_bool */
- switch(pPublication->datexPublish_Format.present)
- {
- case Publish_Format_PR_datexPublish_Data:
- for(i = 0; i < pPublication->datexPublish_Format.choice.datexPublish_Data.list.count; i++)
- {
- pData = (PublicationData_t *)pPublication->datexPublish_Format.choice.datexPublish_Data.list.array[i];
- if ((result = RecvPacketPublicationData(pData)) != SYS_ERR_NONE)
- {
- break;
- }
- }
- break;
- case Publish_Format_PR_datexPublish_FileName_txt:
- result = SYS_ERR_NONE;
- break;
- default:
- result = SYS_ERR_DATEXPUBLISH_FORMAT;
- break;
- }/* end switch */
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 수신 패킷 처리
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::RecvPacketPublicationData(PublicationData_t *pData)
- {
- FErrLine = 48;
- int result;
- int Message_id;
- int i;
- result = SYS_ERR_OTHER;
- /* pData->datexPublish_SubscribeSerial_nbr */
- /* pData->datexPublish_Serial_nbr */
- /* pData->datexPublish_LatePublicationFlag */
- #if 0
- {
- long lv;
- asn_INTEGER2long(&pData->datexPublish_SubscribeSerial_nbr, &lv);
- LDEBUG("datexPublish_SubscribeSerial_nbr: %u", lv);
- asn_INTEGER2long(&pData->datexPublish_Serial_nbr, &lv);
- LDEBUG(" datexPublish_Serial_nbr: %u", lv);
- LDEBUG("datexPublish_LatePublicationFlag: %d", pData->datexPublish_LatePublicationFlag);
- }
- #endif
- switch(pData->datexPublish_Type.present)
- {
- case PublicationType_PR_datexPublication_Management_cd:
- result = SYS_ERR_NONE;
- break;
- case PublicationType_PR_datexPublish_Data:
- #if 0
- {
- int arcs[10];
- int count, j;
- count = OBJECT_IDENTIFIER_get_arcs(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id,
- arcs, sizeof(int), 10);
- LDEBUG("endApplication_Message_id: %d", count);
- for (j = 0; j < count && j < 10; j++)
- {
- LDEBUG("[%d]: %d", j, arcs[j]);
- }
- }
- #endif
- if ((Message_id = ASN1C_GetObjId(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id)) == -1)
- {
- return SYS_ERR_UNKNOWN_MESSAGE_ID;
- }
- /* pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg */
- switch(Message_id)
- {
- case OBJ_GeneralStatus: /* 기본상태정보 */
- {
- GeneralStatusMessage_t *pGS;
- MessageBodyGeneralStatusMessage_t *pMsg = 0; /* Type to decode */
- /* Decode */
- if (ANY_to_type(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
- &asn_DEF_MessageBodyGeneralStatusMessage,
- (void **)&pMsg) == ASN_ERR_NONE)
- {
- for(i = 0; i < pMsg->list.count; i++)
- {
- pGS = (GeneralStatusMessage_t *)pMsg->list.array[i];
- SaveStateData(pGS);
- }
- LINFO("GeneralStatus Publication Recv %d OK", pMsg->list.count);
- result = VERR_NONE;
- }
- else
- {
- result = SYS_ERR_MESSAGE_DECODE;
- }
- if(pMsg)
- {
- ASN1C_Free(&asn_DEF_MessageBodyGeneralStatusMessage, pMsg);
- }
- //FGenState = true;
- }
- break;
- case OBJ_PowerStatus: /* 전원상태정보 */
- {
- PowerStatusMessage_t *pMS;
- MessageBodyPowerStatusMessage_t *pMsg = 0; /* Type to decode */
- long PowerQty;
- int numbits, bit;
- /* Decode */
- if (ANY_to_type(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
- &asn_DEF_MessageBodyPowerStatusMessage,
- (void **)&pMsg) == ASN_ERR_NONE)
- {
- for(i = 0; i < pMsg->list.count; i++)
- {
- pMS = (PowerStatusMessage_t *)pMsg->list.array[i];
- asn_INTEGER2long(&pMS->power_Qty, &PowerQty);
- numbits = DATEX_NUMBITS(pMS->power_Status);
- LDEBUG("Power Module Count: %d, %d", PowerQty, numbits);
- if (PowerQty != numbits)
- {
- PowerQty = numbits;//양산거는 다르게 나타남
- }
- if (numbits >= INT_VMS_MAX_POWER)
- {
- numbits = INT_VMS_MAX_POWER;
- PowerQty = numbits;
- LERROR("Power size overflow: %d, %d", numbits, INT_VMS_MAX_POWER);
- }
- if (PowerQty == numbits)
- {
- #if 0
- memset((char*)m_pState->PowerStatus, 0x00, sizeof(m_pState->PowerStatus));
- for (bit = 0; bit < numbits; bit++)
- {
- int nOnOff = ASN1C_CheckBitString(&pMS->power_Status, bit);
- if (nOnOff == bit_enable)
- {
- VComm_SetBitString((char*)m_pState->PowerStatus, bit);
- }
- }
- m_pState->PowerCount = PowerQty;
- #endif
- }
- #if 0
- {
- LDEBUG(" module_PowerQty: %d", PowerQty);
- AnsiString sModule = "";
- for (int v = 0; v < PowerQty; v++)
- {
- int nM = VComm_GetBitString((char*)m_pState->PowerStatus, v);
- sModule += String(nM);
- }
- LDEBUG("%s", sModule.c_str());
- }
- #endif
- }/* end for */
- result = VERR_NONE;
- }
- else
- {
- result = SYS_ERR_MESSAGE_DECODE;
- }/* end if */
- if(pMsg)
- {
- ASN1C_Free(&asn_DEF_MessageBodyPowerStatusMessage, pMsg);
- }
- //FPowState = true;
- }
- break;
- case OBJ_ModuleStatus: /* 모듈상태정보 */
- {
- ModuleStatusMessage_t *pMS;
- MessageBodyModuleStatusMessage_t *pMsg = 0; /* Type to decode */
- long Horizontal, Vertical;
- int numbits, bit;
- BYTE ModuleState;
- /* Decode */
- if (ANY_to_type(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
- &asn_DEF_MessageBodyModuleStatusMessage,
- (void **)&pMsg) == ASN_ERR_NONE)
- {
- for(i = 0; i < pMsg->list.count; i++)
- {
- pMS = (ModuleStatusMessage_t *)pMsg->list.array[i];
- asn_INTEGER2long(&pMS->module_HorizontalQty, &Horizontal);
- asn_INTEGER2long(&pMS->module_VerticalQty, &Vertical);
- numbits = DATEX_NUMBITS(pMS->module_Status);
- if (numbits >= INT_VMS_MAX_MODULE)
- {
- numbits = INT_VMS_MAX_MODULE;
- LERROR("Module size overflow: %d, %d", numbits, INT_VMS_MAX_MODULE);
- }
- #if 0
- memset((char*)m_pState->ModuleStatus, 0x00, sizeof(m_pState->ModuleStatus));
- if ((Horizontal * Vertical) == numbits)
- {
- ModuleState = vms_normal;
- for (bit = 0; bit < numbits; bit++)
- {
- int nOnOff = ASN1C_CheckBitString(&pMS->module_Status, bit);
- if (nOnOff == bit_disable)
- {
- ModuleState = vms_error;
- }
- else
- {
- VComm_SetBitString((char*)m_pState->ModuleStatus, bit);
- }
- }
- if ((m_pState != NULL) && (numbits < INT_VMS_MAX_MODULE))
- {
- m_pState->ModuleHorizontal = Horizontal;
- m_pState->ModuleVertical = Vertical;
- }
- }
- else
- {
- ModuleState = vms_unknown;
- m_pState->ModuleHorizontal = 0;
- m_pState->ModuleVertical = 0;
- }
- m_pState->ModuleState = ModuleState;
- if (FLogFile->FLogCfg.Debug)
- {
- LDEBUG(" module_VerticalQty x HorizontalQty(Cnt): %d x %d (%d)", Vertical, Horizontal, numbits);
- //LDEBUG(" module_HorizontalQty: %d", Horizontal);
- //LDEBUG("module_Status numbits: %d", numbits);
- for (int v = 0, bit=0; v < Vertical; v++)
- {
- AnsiString sModule = "";
- for(int h = 0; h < Horizontal; h++)
- {
- int nM = VComm_GetBitString((char*)m_pState->ModuleStatus, v*h);
- sModule += String(nM);
- }
- LDEBUG("%d, %s", v, sModule.c_str());
- }
- }
- #endif
- }/* end for */
- result = SYS_ERR_NONE;
- }
- else
- {
- result = SYS_ERR_MESSAGE_DECODE;
- }/* end if */
- if(pMsg)
- {
- ASN1C_Free(&asn_DEF_MessageBodyModuleStatusMessage, pMsg);
- }
- //FModState = true;
- }
- break;
- case OBJ_DotStatus: /* 도트상태정보 */
- result = SYS_ERR_NONE;
- break;
- case OBJ_ScreenStatus: /* 표출상태정보 */
- result = SYS_ERR_NONE;
- break;
- case OBJ_DisplayingData: /* 표출정보 */
- result = SYS_ERR_NONE;
- break;
- default:
- result = SYS_ERR_UNKNOWN_MESSAGE_ID;
- break;
- }/* end switch */
- #if 0
- if (FGenState && FModState && FPowState)
- {
- FGenState = FModState = FPowState = false;
- POST_MSG(MAINHANDLE, WM_VMS_THREAD, WM_VMS_STATE_STTS, (int)FVmsObj);
- }
- #endif
- break;
- default:
- result = SYS_ERR_DATEXPUBLISH_TYPE;
- break;
- }
- return result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::SaveStateData(GeneralStatusMessage_t *pGS)
- {
- FErrLine = 42;
- int result;
- long lv;
- result = SYS_ERR_OTHER;
- // if (m_pState == NULL) return result;
- // m_pState->Cpsw.Enable = bit_enable;
- // m_pState->CollectDate = Now().FormatString("yyyymmddhhnnss");
- #if 0
- asn_INTEGER2long(&pGS->door_StatusCode, &lv);
- switch(lv)
- {
- case door_StatusCode_closed: m_pState->DoorStatus = vms_close; break;
- case door_StatusCode_open : m_pState->DoorStatus = vms_open; break;
- default : m_pState->DoorStatus = vms_unknown; break;
- }
- LDEBUG(" door_StatusCode: %u, %d", lv, m_pState->DoorStatus);
- asn_INTEGER2long(&pGS->modulePower_StatusCode, &lv);
- m_pState->ModulePowerStatus = lv;
- switch(lv)
- {
- case modulePower_StatusCode_off: m_pState->ModulePowerStatus = vms_off; break;
- case modulePower_StatusCode_on : m_pState->ModulePowerStatus = vms_on; break;
- default : m_pState->ModulePowerStatus = vms_unknown; break;
- }
- LDEBUG("modulePower_StatusCode: %u, %d", lv, m_pState->ModulePowerStatus);
- asn_INTEGER2long(&pGS->body_TemperatureQty, &lv);
- m_pState->BodyTemp = lv;
- LDEBUG(" body_TemperatureQty: %u, %d", lv, m_pState->BodyTemp);
- asn_INTEGER2long(&pGS->luminance_StatusQty, &lv);
- m_pState->LuminanceStatus = lv;
- LDEBUG(" luminance_StatusQty: %u, %d", lv, m_pState->LuminanceStatus);
- asn_INTEGER2long(&pGS->fan_StatusCode, &lv);
- m_pState->FanStatus = lv;
- switch(lv)
- {
- case fan_StatusCode_off: m_pState->FanStatus = vms_off; break;
- case fan_StatusCode_on : m_pState->FanStatus = vms_on; break;
- default : m_pState->FanStatus = vms_unknown; break;
- }
- LDEBUG(" fan_StatusCode: %u, %d", lv, m_pState->FanStatus);
- asn_INTEGER2long(&pGS->heater_StatusCode, &lv);
- m_pState->HeaterStatus = lv;
- switch(lv)
- {
- case heater_StatusCode_off: m_pState->HeaterStatus = vms_off; break;
- case heater_StatusCode_on : m_pState->HeaterStatus = vms_on; break;
- default : m_pState->HeaterStatus = vms_unknown; break;
- }
- LDEBUG(" heater_StatusCode: %u, %d", lv, m_pState->HeaterStatus);
- result = SYS_ERR_NONE;
- {
- if (pGS->externalLight_StatusCode) {
- asn_INTEGER2long(pGS->externalLight_StatusCode, &lv);
- m_pState->ExternalLightStatus = lv;
- LDEBUG("externalLight_StatusCode: %u", lv);
- }
- if (pGS->alarmLight_StatusCode) {
- asn_INTEGER2long(pGS->alarmLight_StatusCode, &lv);
- m_pState->AlarmLightStatus = lv;
- LDEBUG("alarmLight_StatusCode: %u", lv);
- }
- if (pGS->speaker_StatusCode) {
- asn_INTEGER2long(pGS->speaker_StatusCode, &lv);
- m_pState->SpeakerStatus = lv;
- LDEBUG("speaker_StatusCode: %u", lv);
- }
- if (pGS->controller_CurrentTime) {
- sprintf((char*)m_pState->ControllerCurrentTime, ".*s", pGS->controller_CurrentTime->size, pGS->controller_CurrentTime->buf);
- LDEBUG("controller_CurrentTime: %.*s", pGS->controller_CurrentTime->size, pGS->controller_CurrentTime->buf);
- }
- asn_INTEGER2long(&pGS->scheduledmessage_OperatingTime, &lv);
- m_pState->ScheduledMessageOperatingTime = lv;
- LDEBUG("scheduledmessage_OperatingTime: %u", lv);
- asn_INTEGER2long(&pGS->module_OperatingTemperatureQty, &lv);
- m_pState->ModuleOperatingTemperature = lv;
- LDEBUG("module_OperatingTemperatureQty: %u", lv);
- asn_INTEGER2long(&pGS->fan_OperatingTemperatureQty, &lv);
- m_pState->FanOperatingTemperature = lv;
- LDEBUG(" fan_OperatingTemperatureQty: %u", lv);
- asn_INTEGER2long(&pGS->heater_OperatingTemperatureQty, &lv);
- m_pState->HeaterOperatingTemperature = lv;
- LDEBUG("heater_OperatingTemperatureQty: %u", lv);
- if (pGS->externalLight_OperatingLuminanceQty) {
- asn_INTEGER2long(pGS->externalLight_OperatingLuminanceQty, &lv);
- m_pState->ExternalLightOperatingLuminance = lv;
- LDEBUG("externalLight_OperatingLuminanceQty: %u", lv);
- }
- //아래존재함
- if (pGS->module_BasicFailureRate) {
- asn_INTEGER2long(pGS->module_BasicFailureRate, &lv);
- m_pState->ModuleBasicFailureRate = lv;
- LDEBUG(" module_BasicFailureRate: %u", lv);
- }
- if (pGS->maximum_RetryQty) {
- asn_INTEGER2long(pGS->maximum_RetryQty, &lv);
- m_pState->MaximumRetry = lv;
- LDEBUG("maximum_RetryQty: %u", lv);
- }
- if (pGS->response_TimeOutQty) {
- asn_INTEGER2long(pGS->response_TimeOutQty, &lv);
- m_pState->ResponseTimeOut = lv;
- LDEBUG("response_TimeOutQty: %u", lv);
- }
- if (pGS->blinking_CycleTime) {
- asn_INTEGER2long(pGS->blinking_CycleTime, &lv);
- m_pState->BlinkingCycleTime = lv;
- LDEBUG("blinking_CycleTime: %u", lv);
- }
- }
- #endif
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 수신 패킷 처리
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::PacketLogin(Login_t *pLogin, DWORD nbr)
- {
- FErrLine = 5;
- int result, iResult;
- int ErrCode;
- COMMAND_ARGUMENT arg;
- result = SYS_ERR_NONE;
- ErrCode = datexReject_Login_cd_other;
- #if 0
- {
- long lv;
- int arcs[10];
- int count, i, j;
- OBJECT_IDENTIFIER_t *pOid;
- LDEBUG(" datex_Sender_txt : %s", pLogin->datex_Sender_txt.buf);
- LDEBUG(" datex_Destinatin_txt : %s", pLogin->datex_Destinatin_txt.buf);
- LDEBUG(" datexLogin_UserName_txt : %s", pLogin->datexLogin_UserName_txt.buf);
- LDEBUG(" datexLogin_Password_txt : %s", pLogin->datexLogin_Password_txt.buf);
- /*
- for (i = 0; i < pLogin->datexLogin_EncodingRules_id_zz.list.count; i++)
- {
- LDEBUG(" datexLogin_EncodingRules_id: [%d]", i);
- pOid = (OBJECT_IDENTIFIER_t *)pLogin->datexLogin_EncodingRules_id_zz.list.array[i];
- count = OBJECT_IDENTIFIER_get_arcs(pOid, arcs, sizeof(int), 10);
- for (j = 0; j < count && j < 10; j++)
- {
- LDEBUG("[%d]: %d", j, arcs[j]);
- }
- }
- */
- LDEBUG("datexLogin_HearteatDurationMax_qty : %d", pLogin->datexLogin_HearteatDurationMax_qty);
- LDEBUG(" datexLogin_ResponseTimeOut_qty : %d", pLogin->datexLogin_ResponseTimeOut_qty);
- asn_INTEGER2long(&pLogin->datexLogin_Initiator_cd, &lv);
- LDEBUG(" datexLogin_Initiator_cd : %d", lv);
- LDEBUG(" datexLogin_DatagramSize_qty : %d", pLogin->datexLogin_DatagramSize_qty);
- }
- #endif
- // m_Server.DomainNm = VMS ID
- // m_Server.LocalDomainNm = 00000000
- if (memcmp(pLogin->datex_Sender_txt.buf, m_Server.DomainNm.c_str(), m_Server.DomainNm.Length()) ||
- memcmp(pLogin->datex_Destinatin_txt.buf, m_Server.LocalDomainNm.c_str(), m_Server.LocalDomainNm.Length()))
- {
- LERROR("Login: Domain(%s - %s)", m_Server.DomainNm.c_str(), pLogin->datex_Sender_txt.buf);
- LERROR("Login: Destnation(%s - %s)", m_Server.LocalDomainNm.c_str(), pLogin->datex_Destinatin_txt.buf);
- if (LOGIN_CHECK)
- {
- result = SYS_ERR_MISMATCH_DESTINATION_TEXT;
- ErrCode = datexReject_Login_cd_unknownDomainName;
- }
- }
- // m_Server.UserName = 00000000
- // m_Server.UserPasswd = 00000000
- if (memcmp(pLogin->datexLogin_UserName_txt.buf, m_Server.UserName.c_str(), m_Server.UserName.Length()) ||
- memcmp(pLogin->datexLogin_Password_txt.buf, m_Server.UserPasswd.c_str(), m_Server.UserPasswd.Length()))
- {
- LERROR("Login: UserName(%s - %s)", m_Server.UserName.c_str(), pLogin->datexLogin_UserName_txt.buf);
- LERROR("Login: Password(%s - %s)", m_Server.UserPasswd.c_str(), pLogin->datexLogin_Password_txt.buf);
- if (LOGIN_CHECK)
- {
- result = SYS_ERR_DATEXLOGIN_VALUE;
- ErrCode = datexReject_Login_cd_invalidNamePassword;
- }
- }
- if (pLogin->datexLogin_HearteatDurationMax_qty < 10)
- {
- LERROR("HearteatDurationMax: [Require >= 10] ==> %d", pLogin->datexLogin_HearteatDurationMax_qty);
- if (LOGIN_CHECK)
- {
- result = SYS_ERR_DATEXLOGIN_VALUE;
- ErrCode = datexReject_Login_cd_heartbeatTooSmall;
- }
- else
- pLogin->datexLogin_HearteatDurationMax_qty = 10;
- }
- if (pLogin->datexLogin_HearteatDurationMax_qty > 1000)
- {
- LERROR("HearteatDurationMax_qty: [Require <= 1000] ==> %d", pLogin->datexLogin_HearteatDurationMax_qty);
- if (LOGIN_CHECK)
- {
- result = SYS_ERR_DATEXLOGIN_VALUE;
- ErrCode = datexReject_Login_cd_heartbeatTooLarge;
- }
- else
- pLogin->datexLogin_HearteatDurationMax_qty = 1000;
- }
- if (pLogin->datexLogin_HearteatDurationMax_qty > FWatchDogTime)
- {
- FWatchDogTime = pLogin->datexLogin_HearteatDurationMax_qty + 5;
- }
- if (pLogin->datexLogin_ResponseTimeOut_qty < 3)
- {
- LERROR("ResponseTimeOut_qty: [Require >= 3] ==> %d", pLogin->datexLogin_ResponseTimeOut_qty);
- if (LOGIN_CHECK)
- {
- result = SYS_ERR_DATEXLOGIN_VALUE;
- ErrCode = datexReject_Login_cd_timeoutTooSmall;
- }
- else
- pLogin->datexLogin_ResponseTimeOut_qty = 3;
- }
- if (pLogin->datexLogin_ResponseTimeOut_qty > 120)
- {
- LERROR("ResponseTimeOut_qty: [Require <= 120] ==> %d", pLogin->datexLogin_ResponseTimeOut_qty);
- if (LOGIN_CHECK)
- {
- result = SYS_ERR_DATEXLOGIN_VALUE;
- ErrCode = datexReject_Login_cd_timeoutTooLarge;
- }
- else
- pLogin->datexLogin_ResponseTimeOut_qty = 120;
- }
- #if 0
- if ((pLogin->datexLogin_Initiator_cd != datexLogin_Initiator_cd_clientInitiated) &&
- (pLogin->datexLogin_Initiator_cd != datexLogin_Initiator_cd_serverInitiated))
- {
- result = SYS_ERR_DATEXLOGIN_VALUE;
- ErrCode = datexReject_Login_cd_other;
- }
- if ((pLogin->datexLogin_DatagramSize_qty < 0) ||
- (pLogin->datexLogin_DatagramSize_qty > 65535))
- {
- result = SYS_ERR_DATEXLOGIN_VALUE;
- ErrCode = datexReject_Login_cd_other;
- }
- #endif
- if (result == SYS_ERR_NONE)
- {
- m_Server.MaxHeartbeatTime = pLogin->datexLogin_HearteatDurationMax_qty;
- m_Server.TimeOut = pLogin->datexLogin_ResponseTimeOut_qty;
- m_Server.DatagramSize = pLogin->datexLogin_DatagramSize_qty;
- arg.Accept.nbr = nbr;
- arg.Accept.type = datexAccept_Type_PR_logIn;
- if((iResult = ProcessCommand(AI_Accept, &arg)) != SYS_ERR_NONE)
- {
- SERROR("Login Accept Command failed: %d", iResult);
- }
- }
- else
- {
- arg.Reject.nbr = nbr;
- arg.Reject.type = RejectType_PR_datexReject_Login_cd;
- arg.Reject.code = ErrCode;
- if((iResult = ProcessCommand(AI_Reject, &arg)) != SYS_ERR_NONE)
- {
- SERROR("Login Reject Command failed: %d", iResult);
- }
- }
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 수신 패킷 처리
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::PacketSubscription(Subscription_t *pSubscripiton)
- {
- FErrLine = 6;
- int result;
- SubscriptionData_t *pData;
- long Serial_nbr;
- long Status;
- long PublishFormat;
- int flag;
- int Message_id;
- result = SYS_ERR_OTHER;
- #if 0
- {
- long lv;
- asn_INTEGER2long(&pSubscripiton->datexSubscribe_Serial_nbr, &lv);
- LDEBUG("datexSubscribe_Serial_nbr: %u", lv);
- LDEBUG("datexSubscribe_Type: %d", pSubscripiton->datexSubscribe_Type.present);
- switch(pSubscripiton->datexSubscribe_Type.present)
- {
- case SubscriptionType_PR_subscription:
- pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
- LDEBUG("datexSubscribe_Persistent_bool: %d", pData->datexSubscribe_Persistent_bool);
- asn_INTEGER2long(&pData->datexSubscribe_Status_cd, &lv);
- LDEBUG("datexSubscribe_Status_cd: %d", lv);
- LDEBUG("datexSubscribe_Mode: %d", pData->datexSubscribe_Mode.present);
- switch(pData->datexSubscribe_Mode.present){
- case SubscriptionMode_PR_single:
- break;
- case SubscriptionMode_PR_event_driven:
- case SubscriptionMode_PR_periodic:
- {
- Registered_t *pRegistered;
- int numbits, bit;
- if(pData->datexSubscribe_Mode.present == SubscriptionMode_PR_event_driven){
- pRegistered = &pData->datexSubscribe_Mode.choice.event_driven;
- }else{
- pRegistered = &pData->datexSubscribe_Mode.choice.periodic;
- }
- LDEBUG("Registered: %d", pRegistered->present);
- switch(pRegistered->present)
- {
- case Registered_PR_continuous:
- LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.continuous.datexRegistered_UpdateDelay_qty);
- if(pRegistered->choice.continuous.datexRegistered_StartTime){
- LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_StartTime);
- }
- if(pRegistered->choice.continuous.datexRegistered_EndTime){
- LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_EndTime);
- }
- break;
- case Registered_PR_daily:
- LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.daily.datexRegistered_UpdateDelay_qty);
- numbits = DATEX_NUMBITS(pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd);
- LDEBUG("datexRegistered_DaysOfWeek_cd numbits: %d", numbits);
- for (bit = 0; bit < numbits; bit++)
- {
- LDEBUG("[%d]: %d", bit, ASN1C_CheckBitString(&pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd, bit));
- }
- if (pRegistered->choice.daily.datexRegistered_StartDate)
- {
- LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartDate);
- }
- if (pRegistered->choice.daily.datexRegistered_EndDate)
- {
- LOG_WriteTime(pRegistered->choice.daily.datexRegistered_EndDate);
- }
- if (pRegistered->choice.daily.datexRegistered_StartTime)
- {
- LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartTime);
- }
- if (pRegistered->choice.daily.datexRegistered_Duration_qty)
- {
- LDEBUG("datexRegistered_Duration_qty: %u", *pRegistered->choice.daily.datexRegistered_Duration_qty);
- }
- break;
- default:
- LDEBUG("Unknown Registered %d", pRegistered->present);
- break;
- }/* end swtich */
- }
- break;
- default :
- LDEBUG("Unknown datexSubscribe_Mode %d", pData->datexSubscribe_Mode.present);
- break;
- }/* end switch */
- asn_INTEGER2long(&pData->datexSubscribe_PublishFormat_cd, &lv);
- LDEBUG("datexSubscribe_PublishFormat_cd: %d", lv);
- LDEBUG("datexSubscription_Priority_nbr: %d", pData->datexSubscription_Priority_nbr);
- LDEBUG("datexSubscribe_Guarantee_bool: %d", pData->datexSubscribe_Guarantee_bool);
- break;
- case SubscriptionType_PR_datexSubscribe_CancelReason_cd:
- LDEBUG("datexSubscribe_CancelReason_cd: %d", pSubscripiton->datexSubscribe_Type.choice.datexSubscribe_CancelReason_cd);
- break;
- default:
- LDEBUG("Unknown datexSubscribe_Type %d", pSubscripiton->datexSubscribe_Type.present);
- break;
- }/* end switch */
- }
- #endif
- asn_INTEGER2long(&pSubscripiton->datexSubscribe_Serial_nbr, &Serial_nbr);
- switch(pSubscripiton->datexSubscribe_Type.present)
- {
- case SubscriptionType_PR_subscription:
- pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
- /* pData->datexSubscribe_Persistent_bool */
- asn_INTEGER2long(&pData->datexSubscribe_Status_cd, &Status);
- switch(Status){
- case datexSubscribe_Status_cd_new:
- break;
- case datexSubscribe_Status_cd_update:
- break;
- default:
- return SYS_ERR_SUBSCRIPTION_STATUS_VALUE;
- }
- switch(pData->datexSubscribe_Mode.present){
- case SubscriptionMode_PR_single:
- flag = SubscriptionMode_PR_single;
- break;
- case SubscriptionMode_PR_event_driven:
- flag = SubscriptionMode_PR_event_driven;
- /* pData->datexSubscribe_Mode.choice.event_driven */
- break;
- case SubscriptionMode_PR_periodic:
- flag = SubscriptionMode_PR_periodic;
- /* pData->datexSubscribe_Mode.choice.periodic */
- break;
- default:
- return SYS_ERR_SUBSCRIPTION_MODE_VALUE;
- }
- asn_INTEGER2long(&pData->datexSubscribe_PublishFormat_cd, &PublishFormat);
- switch(PublishFormat)
- {
- #if 0
- case datexSubscribe_PublishFormat_cd_other:
- break;
- case datexSubscribe_PublishFormat_cd_ftp:
- break;
- case datexSubscribe_PublishFormat_cd_tftp:
- break;
- #endif
- case datexSubscribe_PublishFormat_cd_dataPacket:
- break;
- default:
- return SYS_ERR_SUBSCRIPTION_FORMAT_VALUE;
- }
- /* pData->datexSubscription_Priority_nbr */
- /* pData->datexSubscribe_Guarantee_bool */
- if ((Message_id = ASN1C_GetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id)) == -1)
- {
- return SYS_ERR_UNKNOWN_MESSAGE_ID;
- }
- switch(Message_id)
- {
- case OBJ_RealTimeDisplay: /* 실시간정보표출 */
- {
- LINFO(" *** OBJ_RealTimeDisplay 수신");
- result = SYS_ERR_NONE;
- }
- break;
- case OBJ_ScheduledDisplay: /* 계획된정보표출 */
- LINFO(" *** OBJ_ScheduledDisplay 수신");
- result = SYS_ERR_NONE;
- break;
- case OBJ_DownloadGraphicData: /* 그래픽데이터 다운로드 */
- LINFO(" *** OBJ_DownloadGraphicData 수신");
- result = SYS_ERR_NONE;
- break;
- case OBJ_StatusControl: /* 상태제어 */
- LINFO(" *** OBJ_StatusControl 수신");
- result = SYS_ERR_NONE;
- break;
- case OBJ_StatusSetting: /* 상태설정 */
- LINFO(" *** OBJ_StatusSetting 수신");
- result = SYS_ERR_NONE;
- break;
- //FOR YONGIN
- case OBJ_GeneralStatus:// = 6, /* 기본상태정보 */
- LINFO(" *** OBJ_GeneralStatus 수신");
- result = SYS_ERR_NONE;
- break;
- case OBJ_PowerStatus:// = 7, /* 전원상태정보 */
- LINFO(" *** OBJ_PowerStatus 수신");
- result = SYS_ERR_NONE;
- break;
- case OBJ_ModuleStatus:// = 8, /* 모듈상태정보 */
- LINFO(" *** OBJ_ModuleStatus 수신");
- result = SYS_ERR_NONE;
- break;
- case OBJ_DotStatus:// = 9, /* 도트상태정보 */
- LINFO(" *** OBJ_DotStatus 수신");
- result = SYS_ERR_NONE;
- break;
- case OBJ_ScreenStatus:// = 10, /* 표출상태정보 */
- LINFO(" *** OBJ_ScreenStatus 수신");
- result = SYS_ERR_NONE;
- break;
- case OBJ_DisplayingData:// = 11 /* 표출정보 */
- LINFO(" *** OBJ_DisplayingData 수신");
- result = SYS_ERR_NONE;
- break;
- //END YONGIN
- default:
- SERROR(" *** Unknown Subscription message: %d 수신", Message_id);
- result = SYS_ERR_UNKNOWN_MESSAGE_ID;
- break;
- }
- break;
- case SubscriptionType_PR_datexSubscribe_CancelReason_cd:
- result = SYS_ERR_NONE;
- break;
- default:
- SERROR(" *** Unknown Subscription Recv: %d", pSubscripiton->datexSubscribe_Type.present);
- result = SYS_ERR_SUBSCRIPTION_TYPE;
- break;
- }/* end switch */
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 수신 패킷 처리
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::PacketAccept(Accept_t *pAccept)
- {
- FErrLine = 7;
- int result, sResult;
- long nbr;
- result = VERR_OTHER;
- asn_INTEGER2long(&pAccept->datexAccept_Packet_nbr, &nbr);
- switch(pAccept->datexAccept_Type.present)
- {
- /*
- case datexAccept_Type_PR_logIn:
- break;
- case datexAccept_Type_PR_single_subscription:
- break;
- case datexAccept_Type_PR_registered_subscription:
- break;
- */
- case datexAccept_Type_PR_publication:
- #if 0
- if ((m_Server.State != ST_LOCAL_WAIT) &&
- (m_Server.State != ST_CLIENT_WAIT))
- {
- result = SYS_ERR_MISMATCH;
- break;
- }
- #endif
- /* if (nbr == (long)FSvrCtl.DataPacketNumber) */
- {
- if (FSvrCtl.obj == OBJ_RealTimeDisplay)
- {
- m_pVmsFormList->Lock();
- try
- {
- TVmsForm *pVmsForm = m_pVmsFormList->GetItem(FSvrCtl.Idx);
- if (pVmsForm)
- {
- pVmsForm->SvcRes = true;
- }
- else
- {
- //
- }
- }
- __finally
- {
- m_pVmsFormList->UnLock();
- }
- }
- else
- if (FSvrCtl.obj == OBJ_ScheduledDisplay)
- {
- SAVE_STRUCT ProvideSave;
- memset(&ProvideSave, 0x00, sizeof(ProvideSave));
- ProvideSave.Type = save_provide;
- ProvideSave.Count = 1;
- ProvideSave.pObj[0] = (void*)FVmsObj;
- FVmsObj->CTLMODE->Enable = object_disable;
- FVmsObj->CTLMODE->SvcDate = Now().FormatString("yyyymmddhhnnss");
- FVmsObj->CTLMODE->SaveFlag = true;
- FVmsObj->CTLMODE->Result = true;
- if ((sResult = SendDbThreadDataMessage(WM_PROVIDE_SAVE, &ProvideSave, sizeof(ProvideSave))) != VERR_NONE)
- {
- SERROR("SendDbThreadDataMessage Error %d", sResult);
- }
- }
- else
- if (FSvrCtl.obj == OBJ_DownloadGraphicData)
- {
- FVmsObj->DOWNLOAD->Unit[FSvrCtl.Idx].SendEndDate = Now().FormatString("yyyymmddhhnnss");
- FVmsObj->DOWNLOAD->Unit[FSvrCtl.Idx].SendStep = send_complete;
- FVmsObj->DOWNLOAD->Unit[FSvrCtl.Idx].SendResult = vms_download_succ;
- if ((FSvrCtl.Idx + 1) == FVmsObj->DOWNLOAD->Count)
- {
- SAVE_STRUCT DownLoadSave;
- memset(&DownLoadSave, 0x00, sizeof(DownLoadSave));
- DownLoadSave.Type = save_download;
- DownLoadSave.Count = 1;
- DownLoadSave.pObj[0] = (void*)FVmsObj;
- FVmsObj->DOWNLOAD->Enable = object_disable;
- FVmsObj->DOWNLOAD->SaveFlag = true;
- if ((sResult = SendDbThreadDataMessage(WM_PROVIDE_SAVE, &DownLoadSave, sizeof(DownLoadSave))) != VERR_NONE)
- {
- SERROR("SendDbThreadDataMessage Error %d", sResult);
- }
- }
- }
- }/* end if */
- SetServerState(SET_SERVER_SUCC);
- result = SYS_ERR_NONE;
- LINFO(" *** Accept_Type_PR_publication: %u", nbr);
- break;
- default:
- result = SYS_ERR_ACCEPT_TYPE;
- SERROR(" *** Unknown Accept_Type: %u, %d", nbr, pAccept->datexAccept_Type.present);
- break;
- }
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 수신 패킷 처리
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::PacketReject(Reject_t *pReject)
- {
- FErrLine = 8;
- int result;
- long nbr;
- long ErrCode;
- result = SYS_ERR_OTHER;
- asn_INTEGER2long(&pReject->datexReject_Packet_nbr, &nbr);
- switch(pReject->datexReject_Type.present){
- /*
- case RejectType_PR_datexReject_Login_cd:
- asn_INTEGER2long(&pReject->datexReject_Type.choice.datexReject_Login_cd, &ErrCode);
- break;
- case RejectType_PR_datexReject_Subscription_cd:
- asn_INTEGER2long(&pReject->datexReject_Type.choice.datexReject_Subscription_cd, &ErrCode);
- break;
- */
- case RejectType_PR_datexReject_Publication_cd:
- asn_INTEGER2long(&pReject->datexReject_Type.choice.datexReject_Publication_cd, &ErrCode);
- if ((m_Server.State != ST_LOCAL_WAIT) &&
- (m_Server.State != ST_CLIENT_WAIT))
- {
- result = SYS_ERR_MISMATCH;
- break;
- }
- SetServerState(SET_SERVER_FAIL);
- result = SYS_ERR_NONE;
- break;
- default:
- ErrCode = -1;
- break;
- }
- /* pReject->datexReject_AlternateRequest */
- LINFO("Reject 수신[%d %d %d]", nbr, pReject->datexReject_Type.present, ErrCode);
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 패킷 송신
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::SendPacket(void *Data, int Len, BYTE cmd)
- {
- FErrLine = 9;
- int result;
- DatexDataPacket_t *pMsg; /* Type to encode */
- asn_enc_rval_t er; /* Encoder return value */
- BYTE MsgBuf[SERVER_MSG_BUF_SIZE];
- WORD crc;
- int eLen, wLen;
- result = SYS_ERR_OTHER;
- pMsg = (DatexDataPacket_t *)ASN1C_Alloc(sizeof(DatexDataPacket_t));
- if(pMsg == NULL) {
- return SYS_ERR_INTERNAL;
- }
- if(asn_long2INTEGER(&pMsg->datex_Version_number, datex_Version_number_version1) != ASN_ERR_NONE){
- ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
- return -1;
- }
- if(OCTET_STRING_fromBuf(&pMsg->datex_Data, (char *)Data, Len) != ASN_ERR_NONE){
- ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
- return -2;
- }
- crc = ASN1C_MakeCrc16(Data, Len);
- crc = CommUtil_WordSwap(crc);
- if (OCTET_STRING_fromBuf(&pMsg->datex_Crc_nbr, (char *)&crc, sizeof(crc)) != ASN_ERR_NONE)
- {
- ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
- return -3;
- }
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_DatexDataPacket, pMsg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_DATEXDATAPACKET_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- wLen = pClientSocket->SendBuf(MsgBuf, eLen);
- LINFO("Send: %d/%d, cmd: %02X", eLen, wLen, cmd);
- if (eLen == wLen)
- {
- --m_Server.iRetry;
- m_Server.cTimer = Now();
- result = SYS_ERR_NONE;
- LogData("SEND", (char*)MsgBuf, eLen);
- }
- else
- {
- LERROR("TCP_Write(%d %d)", eLen, wLen);
- result = SYS_ERR_WRITE_LENGTH;
- LogData("SEND Fail", (char*)MsgBuf, eLen);
- }
- }
- ASN1C_Free(&asn_DEF_DatexDataPacket, pMsg);
- return result;
- }
- //---------------------------------------------------------------------------
- int UTF8String_fromBuf(UTF8String_t *st, const char *str, int len)
- {
- UTF8String uStr;
- uStr = UTF8Encode(WideString(str, len));
- return OCTET_STRING_fromBuf(st, uStr.c_str(), uStr.Length());
- }
- //---------------------------------------------------------------------------
- /*
- * 입력 파라미터에 따라 명령을 전송한다.
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::ProcessCommand(BYTE cmd, COMMAND_ARGUMENT *arg)
- {
- FErrLine = 10;
- C2CAuthenticatedMessage_t *pMsg; /* Type to encode */
- asn_enc_rval_t er; /* Encoder return value */
- BYTE MsgBuf[SERVER_MSG_BUF_SIZE];
- int eLen;
- int result;
- Word year, month, day;
- Word hour, min, sec, msec;
- result = SYS_ERR_OTHER;
- Now().DecodeDate(&year, &month, &day);
- Now().DecodeTime(&hour, &min, &sec, &msec);
- pMsg = (C2CAuthenticatedMessage_t *)ASN1C_Alloc(sizeof(C2CAuthenticatedMessage_t));
- if (pMsg == NULL)
- {
- return SYS_ERR_INTERNAL;
- }
- /* 공통부분 */
- if (OCTET_STRING_fromBuf(&pMsg->datex_AuthenticationInfo_text, (char *)&cmd, sizeof(cmd)) != ASN_ERR_NONE)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -1;
- }
- if (asn_long2INTEGER(&pMsg->datex_DataPacket_number, m_DataPacketNumber++) != ASN_ERR_NONE)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -2;
- }
- pMsg->datex_DataPacketPriority_number = 0;
- /* Header Options */
- /* pMsg->options.datex_Origin_text */
- pMsg->options.datex_OriginAddress_location = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t));
- if (pMsg->options.datex_OriginAddress_location == NULL)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -3;
- }
- //if (OCTET_STRING_fromString(pMsg->options.datex_OriginAddress_location, m_Server.LocalCenterId.c_str()) != ASN_ERR_NONE)
- if (OCTET_STRING_fromString(pMsg->options.datex_OriginAddress_location, m_Server.LocalDomainNm.c_str()) != ASN_ERR_NONE)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -4;
- }
- /* pMsg->options.datex_Sender_text */
- /* pMsg->options.datex_SenderAddress_location */
- /* pMsg->options.datex_Destination_text */
- #if 1
- pMsg->options.datex_SenderAddress_location = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t));
- if (pMsg->options.datex_SenderAddress_location == NULL)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -5;
- }
- if (OCTET_STRING_fromString(pMsg->options.datex_SenderAddress_location, m_Server.LocalDomainNm.c_str()) != ASN_ERR_NONE)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -6;
- }
- #endif
- pMsg->options.datex_DestinationAddress_location = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t));
- if (pMsg->options.datex_DestinationAddress_location == NULL)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -5;
- }
- //if (OCTET_STRING_fromString(pMsg->options.datex_DestinationAddress_location, m_Server.CenterId.c_str()) != ASN_ERR_NONE)
- if (OCTET_STRING_fromString(pMsg->options.datex_DestinationAddress_location, m_Server.DomainNm.c_str()) != ASN_ERR_NONE)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -6;
- }
- /* pMsg->options.datex_Cost->amount_Currency_code */
- /* pMsg->options.datex_Cost->amount_Factor_quantity */
- /* pMsg->options.datex_Cost->amount_Quantity_quantity */
- pMsg->options.datex_DataPacket_time = (Time_t *)ASN1C_Alloc(sizeof(Time_t));
- if (pMsg->options.datex_DataPacket_time == NULL)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -7;
- }
- pMsg->options.datex_DataPacket_time->time_Year_qty = (long *)ASN1C_Alloc(sizeof(long));
- if (pMsg->options.datex_DataPacket_time->time_Year_qty == NULL)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -8;
- }
- *pMsg->options.datex_DataPacket_time->time_Year_qty = year;
- pMsg->options.datex_DataPacket_time->time_Month_qty = (long *)ASN1C_Alloc(sizeof(long));
- if (pMsg->options.datex_DataPacket_time->time_Month_qty == NULL)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -9;
- }
- *pMsg->options.datex_DataPacket_time->time_Month_qty = month;
- pMsg->options.datex_DataPacket_time->time_Day_qty = (long *)ASN1C_Alloc(sizeof(long));
- if (pMsg->options.datex_DataPacket_time->time_Day_qty == NULL)
- {
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return -10;
- }
- *pMsg->options.datex_DataPacket_time->time_Day_qty = day;
- pMsg->options.datex_DataPacket_time->time_Hour_qty = hour;
- pMsg->options.datex_DataPacket_time->time_Minute_qty = min;
- pMsg->options.datex_DataPacket_time->time_Second_qty = sec;
- pMsg->options.datex_DataPacket_time->time_SecondFractions_zz.present = time_SecondFractions_PR_milliseconds;
- pMsg->options.datex_DataPacket_time->time_SecondFractions_zz.choice.milliseconds = 0;
- #if 0
- //TODO
- pMsg->options.datex_DataPacket_time->time_Timezone = (Timezone_t*)ASN1C_Alloc(sizeof(Timezone_t));
- if (pMsg->options.datex_DataPacket_time->time_Timezone)
- {
- pMsg->options.datex_DataPacket_time->time_Timezone->timezone_Hour_qty = 9;
- pMsg->options.datex_DataPacket_time->time_Timezone->time_Minute_qty = 0;
- }
- #endif
- /* pMsg->options.datex_DataPacket_time->time_Timezone->timezone_Hour_qty */
- /* pMsg->options.datex_DataPacket_time->time_Timezone->time_Minute_qty */
- switch(cmd)
- {
- case AI_Initiate: /* 초기 통신연결을 위한 개시 요청 데이터 패킷 */
- pMsg->pdu.present = PDUs_PR_datex_Initiate_null;
- if(OCTET_STRING_fromString(&pMsg->pdu.choice.datex_Initiate_null.datex_Sender_txt, m_Server.LocalDomainNm.c_str()) != ASN_ERR_NONE){
- result = -12;
- break;
- }
- if(OCTET_STRING_fromString(&pMsg->pdu.choice.datex_Initiate_null.datex_Destinatin_txt, m_Server.DomainNm.c_str()) != ASN_ERR_NONE){
- result = -13;
- break;
- }
- result = SYS_ERR_NONE;
- LINFO(">>> AI_Initiate 전송 Sender:%s Destinatin:%s", m_Server.LocalDomainNm.c_str(), m_Server.DomainNm.c_str());
- break;
- case AI_Accept: /* 클라이언트의 요청에 대한 수용 */
- LINFO(">>> AI_Accept 전송");
- pMsg->pdu.present = PDUs_PR_accept;
- if ((result = CommandAccept(&pMsg->pdu.choice.accept, arg->Accept.nbr, arg->Accept.type, arg->Accept.sub)) != SYS_ERR_NONE)
- {
- SERROR("CommandAccept result failed: %d", result);
- result = -14;
- }
- break;
- case AI_Reject: /* 클라이언트의 요청에 대한 거부 */
- LINFO(">>> AI_Reject 전송");
- pMsg->pdu.present = PDUs_PR_reject;
- if ((result = CommandReject(&pMsg->pdu.choice.reject, arg->Reject.nbr, arg->Reject.type, arg->Reject.code)) != SYS_ERR_NONE)
- {
- SERROR("CommandReject failed: %d", result);
- result = -15;
- }
- break;
- case AI_FrED: /* 서버와 클라이언트의 연결을 유지하기 위한 확인 데이터 패킷 */
- pMsg->pdu.present = PDUs_PR_fred;
- if (asn_long2INTEGER(&pMsg->pdu.choice.fred, arg->FrED) != ASN_ERR_NONE)
- {
- LINFO(">>> AI_FrED 전송 Failed");
- result = -16;
- break;
- }
- result = SYS_ERR_NONE;
- LINFO(">>> AI_FrED 전송: %u", arg->FrED);
- break;
- case AI_Terminate: /* 연결을 종료하고자 할 때, 서버에서 클라이언트에 요청하는 데이터 패킷 */
- pMsg->pdu.present = PDUs_PR_terminate;
- if (asn_long2INTEGER(&pMsg->pdu.choice.terminate, arg->Terminate) != ASN_ERR_NONE)
- {
- LINFO(">>> AI_Terminate 전송 Failed");
- result = -17;
- break;
- }
- result = SYS_ERR_NONE;
- LINFO(">>> AI_Terminate 전송 %u", arg->Terminate);
- break;
- case AI_RealTimeDisplayMessage: /* 실시간정보표출메시지 */
- case AI_ScheduledDisplayMessage: /* 계획된정보표출메시지 */
- case AI_DownloadGraphicDataMessage: /* 그래픽데이터 다운로드 메시지 */
- case AI_StatusControlMessage: /* 상태제어메시지 */
- case AI_StatusSettingMessage: /* 상태설정메시지 */
- {
- LINFO(">>> PublicationData 전송");
- PublicationData_t *pData;
- if ((pData = (PublicationData_t *)ASN1C_Alloc(sizeof(PublicationData_t))) == NULL)
- {
- result = -18;
- break;
- }
- pMsg->pdu.present = PDUs_PR_publication;
- pMsg->pdu.choice.publication.datexPublish_Guaranteed_bool = true;
- pMsg->pdu.choice.publication.datexPublish_Format.present = Publish_Format_PR_datexPublish_Data;
- if ((result = CommandPublicationData(pData, arg->Publication)) != SYS_ERR_NONE)
- {
- SERROR("CommandPublicationData failed: %d", result);
- result = -19;
- break;
- }
- if (ASN_SEQUENCE_ADD(&pMsg->pdu.choice.publication.datexPublish_Format.choice.datexPublish_Data, pData) != ASN_ERR_NONE)
- {
- result = -20;
- break;
- }
- result = SYS_ERR_NONE;
- }
- break;
- case AI_ScreenStatusMessage: /* 표출상태정보메시지 */
- {
- Subscription_t *pSubscripiton = &pMsg->pdu.choice.subscripiton;
- SubscriptionData_t *pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
- pMsg->pdu.present = PDUs_PR_subscripiton;
- if (asn_long2INTEGER(&pSubscripiton->datexSubscribe_Serial_nbr, arg->Publication.SubscribeSerialNbr) != ASN_ERR_NONE)
- {
- result = -31;
- break;
- }
- pSubscripiton->datexSubscribe_Type.present = SubscriptionType_PR_subscription;
- pData->datexSubscribe_Persistent_bool = false;
- if (asn_long2INTEGER(&pData->datexSubscribe_Status_cd, datexSubscribe_Status_cd_new) != ASN_ERR_NONE)
- {
- result = -32;
- break;
- }
- pData->datexSubscribe_Mode.present = SubscriptionMode_PR_single;
- if (asn_long2INTEGER(&pData->datexSubscribe_PublishFormat_cd, datexSubscribe_PublishFormat_cd_dataPacket) != ASN_ERR_NONE)
- {
- result = -33;
- break;
- }
- pData->datexSubscription_Priority_nbr = 1;
- pData->datexSubscribe_Guarantee_bool = true;
- ASN1C_SetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id, OBJ_ScreenStatus);
- //
- ScreenStatusMessage_t *pMS;
- MessageBodyScreenStatusMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyScreenStatusMessage_t));
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyScreenStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
- {
- result = -32;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -33;
- break;
- }
- result = SYS_ERR_NONE;
- LINFO("ScreenStatus Subscribe Send");
- }
- ASN1C_FreeC(&asn_DEF_MessageBodyScreenStatusMessage, &Msg);
- result = SYS_ERR_NONE;
- }
- break;
- case AI_DisplayingDataMessage: /* 표출정보메시지 */
- {
- //pMsg->pdu.present = PDUs_PR_subscripiton;
- //result = SYS_ERR_NONE;
- }
- break;
- case AI_TransferDone:
- {
- AnsiString sFileName = AnsiString(arg->Publication.szFormId);
- pMsg->pdu.present = PDUs_PR_publication;
- pMsg->pdu.choice.publication.datexPublish_Guaranteed_bool = true;
- pMsg->pdu.choice.publication.datexPublish_Format.present = Publish_Format_PR_datexPublish_FileName_txt;
- if (OCTET_STRING_fromString(&pMsg->pdu.choice.publication.datexPublish_Format.choice.datexPublish_FileName_txt, sFileName.c_str()) != ASN_ERR_NONE)
- {
- result = -41;
- break;
- }
- result = SYS_ERR_NONE;
- }
- break;
- #if 1
- // FOR Yongin
- case AI_Subscription:
- pMsg->pdu.present = PDUs_PR_subscripiton;
- #if 0
- if ((result = CommandSubscription(&pMsg->pdu.choice.subscripiton, arg->Subscription)) != SYS_ERR_NONE)
- {
- SERROR("CommandSubscription result %d", result);
- result = -15;
- }
- #endif
- break;
- // END Yongin
- #endif
- default:
- LERROR("ProcessCommand Unknown cmd: %d", cmd);
- result = SYS_ERR_UNKNOWN_COMMAND;
- break;
- }
- if (result == SYS_ERR_NONE)
- {
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_C2CAuthenticatedMessage, pMsg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_C2CAUTHENTICATEDMESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- result = SendPacket(MsgBuf, eLen, cmd);
- }
- }
- ASN1C_Free(&asn_DEF_C2CAuthenticatedMessage, pMsg);
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 송신 패킷 생성
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::CommandAccept(Accept_t *pAccept, DWORD nbr, int type, DWORD sub)
- {
- FErrLine = 11;
- int result;
- int oid[3] = {2, 1, 1};
- result = SYS_ERR_OTHER;
- if(asn_long2INTEGER(&pAccept->datexAccept_Packet_nbr, nbr) != ASN_ERR_NONE){
- return -1;
- }
- pAccept->datexAccept_Type.present = (datexAccept_Type_PR)type;
- switch(type)
- {
- case datexAccept_Type_PR_logIn:
- if (ASN1C_SetObjectIdentifier(&pAccept->datexAccept_Type.choice.logIn, oid, sizeof(oid)) != ASN_ERR_NONE)
- {
- LINFO(" *** Accept_Type_PR_logIn Failed");
- return -2;
- }
- result = SYS_ERR_NONE;
- LINFO(" *** Accept_Type_PR_logIn 전송: %u", nbr);
- break;
- case datexAccept_Type_PR_single_subscription:
- result = SYS_ERR_NONE;
- LINFO(" *** Accept_Type_PR_single_subscription 전송: %u", nbr);
- break;
- case datexAccept_Type_PR_registered_subscription:
- if (asn_long2INTEGER(&pAccept->datexAccept_Type.choice.registered_subscription, sub) != ASN_ERR_NONE)
- {
- LINFO(" *** Accept_Type_PR_registered_subscription Failed");
- return -3;
- }
- result = SYS_ERR_NONE;
- LINFO(" *** Accept_Type_PR_registered_subscription 전송: %u, %u", nbr, sub);
- break;
- case datexAccept_Type_PR_publication:
- result = SYS_ERR_NONE;
- LINFO(" *** Accept_Type_PR_publication 전송: %u", nbr);
- break;
- default:
- result = SYS_ERR_ACCEPT_TYPE;
- LINFO(" *** Unknown Accept_Type: %u, %d", nbr, type);
- break;
- }
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 송신 패킷 생성
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::CommandReject(Reject_t *pReject, DWORD nbr, int type, int code)
- {
- FErrLine = 12;
- int result;
- result = SYS_ERR_OTHER;
- if (asn_long2INTEGER(&pReject->datexReject_Packet_nbr, nbr) != ASN_ERR_NONE)
- {
- return -1;
- }
- pReject->datexReject_Type.present = (RejectType_PR)type;
- switch(type){
- case RejectType_PR_datexReject_Login_cd:
- if(asn_long2INTEGER(&pReject->datexReject_Type.choice.datexReject_Login_cd, code) != ASN_ERR_NONE){
- return -2;
- }
- result = SYS_ERR_NONE;
- LINFO("로그인 거부 전송 %u %d", nbr, code);
- break;
- case RejectType_PR_datexReject_Subscription_cd:
- if(asn_long2INTEGER(&pReject->datexReject_Type.choice.datexReject_Subscription_cd, code) != ASN_ERR_NONE){
- return -3;
- }
- result = SYS_ERR_NONE;
- LINFO("서브스크립션 거부 전송 %u %d", nbr, code);
- break;
- case RejectType_PR_datexReject_Publication_cd:
- if(asn_long2INTEGER(&pReject->datexReject_Type.choice.datexReject_Publication_cd, code) != ASN_ERR_NONE){
- return -4;
- }
- result = SYS_ERR_NONE;
- LINFO("Publication Reject 전송 %u %d", nbr, code);
- break;
- default:
- result = SYS_ERR_ACCEPT_TYPE;
- LINFO("Unknown Reject 전송 %u %d", nbr, type);
- break;
- }
- /* pReject->datexReject_AlternateRequest */
- return result;
- }
- //---------------------------------------------------------------------------
- /*
- * 송신 패킷 생성
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::CommandPublicationData(PublicationData_t *pData, PUBLICATION_ARGUMENT Arg)
- {
- FErrLine = 13;
- int result;
- asn_enc_rval_t er; /* Encoder return value */
- BYTE MsgBuf[SERVER_MSG_BUF_SIZE];
- int eLen;
- int i;
- result = SYS_ERR_OTHER;
- if (asn_long2INTEGER(&pData->datexPublish_SubscribeSerial_nbr, Arg.SubscribeSerialNbr) != ASN_ERR_NONE)
- {
- return -1;
- }
- pData->datexPublish_LatePublicationFlag = true;
- pData->datexPublish_Type.present = PublicationType_PR_datexPublish_Data;
- #if 0
- {
- long lv;
- asn_INTEGER2long(&pData->datexPublish_SubscribeSerial_nbr, &lv);
- LDEBUG("datexPublish_SubscribeSerial_nbr: %u", lv);
- asn_INTEGER2long(&pData->datexPublish_Serial_nbr, &lv);
- LDEBUG(" datexPublish_Serial_nbr: %u", lv);
- LDEBUG("datexPublish_LatePublicationFlag: %d", pData->datexPublish_LatePublicationFlag);
- }
- #endif
- if (FVmsObj->FIsOldProtocol)
- {
- int s_arcs[6];
- int *arcs = s_arcs;
- s_arcs[0] = 1;
- s_arcs[1] = 0;
- s_arcs[2] = 14827;
- s_arcs[3] = 2;
- s_arcs[4] = 0;
- s_arcs[5] = Arg.obj;
- int count = OBJECT_IDENTIFIER_set_arcs(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id, arcs, sizeof(*arcs), 6);
- }
- else
- {
- ASN1C_SetObjId(&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_id, Arg.obj);
- }
- switch(Arg.obj)
- {
- case OBJ_RealTimeDisplay: /* 실시간정보표출 */
- {
- LINFO(" *** OBJ_RealTimeDisplay");
- RealTimeDisplayMessage_t *pRTD;
- MessageBodyRealTimeDisplayMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyRealTimeDisplayMessage_t));
- for ( i = 0; i < 1; i++)
- {
- if ((pRTD = (RealTimeDisplayMessage_t *)ASN1C_Alloc(sizeof(RealTimeDisplayMessage_t))) == NULL)
- {
- result = -10;
- break;
- }
- if (FVmsObj->FBmpDownload)
- {
- //전체 이미지로 다운로드 하는 경우이거나
- //이전VMS중에 FTP로 다운로드 하는 경우임...
- result = RealTimeDisplayBitmap(pRTD, Arg);
- }
- else
- {
- result = RealTimeDisplayData(pRTD, Arg);
- }
- if (result != SYS_ERR_NONE)
- {
- SERROR("RealTimeDisplayData failed: %d", result);
- result = -11;
- break;
- }
- if (ASN_SEQUENCE_ADD(&Msg, pRTD)!= ASN_ERR_NONE)
- {
- result = -12;
- break;
- }
- #if 0
- {
- long lv;
- Object_t *pObj;
- char Utf8Buf[256+1];
- LDEBUG("[%d]", i);
- LDEBUG("message_serialID: %.*s", pRTD->message_serialID.size, pRTD->message_serialID.buf);
- asn_INTEGER2long(&pRTD->display_DurationQty, &lv);
- LDEBUG("display_DurationQty: %u", lv);
- asn_INTEGER2long(&pRTD->display_ModeCode, &lv);
- LDEBUG("display_ModeCode: %u", lv);
- asn_INTEGER2long(&pRTD->display_DirectionCode, &lv);
- LDEBUG("display_DirectionCode: %u", lv);
- asn_INTEGER2long(&pRTD->background_ColorCode, &lv);
- LDEBUG("background_ColorCode: %u", lv);
- asn_INTEGER2long(&pRTD->object_Nbr, &lv);
- LDEBUG("object_Nbr: %u", lv);
- for (int j = 0; j < pRTD->objects_zz.list.count; j++)
- {
- LDEBUG("objects: [%d]", j);
- pObj = (Object_t *)pRTD->objects_zz.list.array[j];
- asn_INTEGER2long(&pObj->object_TypeCode, &lv);
- LDEBUG("object_TypeCode: %u", lv);
- asn_INTEGER2long(&pObj->blinking_Code, &lv);
- LDEBUG("blinking_Code: %u", lv);
- asn_INTEGER2long(&pObj->x_Coordinate, &lv);
- LDEBUG("x_Coordinate: %u", lv);
- asn_INTEGER2long(&pObj->y_Coordinate, &lv);
- LDEBUG("y_Coordinate: %u", lv);
- asn_INTEGER2long(&pObj->data_BackgroundColor, &lv);
- LDEBUG("data_BackgroundColor: %u", lv);
- LDEBUG("object_Data: %d", pObj->object_Data.present);
- switch(pObj->object_Data.present)
- {
- case ObjectData_PR_text_object_data:
- asn_INTEGER2long(&pObj->object_Data.choice.text_object_data.font_ColorCode, &lv);
- LDEBUG("font_ColorCode: %u", lv);
- asn_INTEGER2long(&pObj->object_Data.choice.text_object_data.font_Size, &lv);
- LDEBUG("font_Size: %u", lv);
- LDEBUG("font_TypeCode: %.*s", pObj->object_Data.choice.text_object_data.font_TypeCode.size, pObj->object_Data.choice.text_object_data.font_TypeCode.buf);
- asn_INTEGER2long(&pObj->object_Data.choice.text_object_data.font_Thickness, &lv);
- LDEBUG("font_Thickness: %u", lv);
- UTF8String2Hangul((char *)pObj->object_Data.choice.text_object_data.text_Data.buf, Utf8Buf, sizeof(Utf8Buf));
- LDEBUG("text_Data: %.256s", Utf8Buf);
- break;
- case ObjectData_PR_graphic_object_data:
- asn_INTEGER2long(&pObj->object_Data.choice.graphic_object_data.graphic_Type, &lv);
- LDEBUG("graphic_Type: %u", lv);
- asn_INTEGER2long(&pObj->object_Data.choice.graphic_object_data.graphic_Width, &lv);
- LDEBUG("graphic_Width: %u", lv);
- asn_INTEGER2long(&pObj->object_Data.choice.graphic_object_data.graphic_Height, &lv);
- LDEBUG("graphic_Height: %u", lv);
- LDEBUG("graphic_Data:");
- //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);
- break;
- case ObjectData_PR_graphicID_object_data:
- asn_INTEGER2long(&pObj->object_Data.choice.graphicID_object_data.graphic_Type, &lv);
- LDEBUG("graphic_Type: %u", lv);
- asn_INTEGER2long(&pObj->object_Data.choice.graphicID_object_data.graphic_Width, &lv);
- LDEBUG("graphic_Width: %u", lv);
- asn_INTEGER2long(&pObj->object_Data.choice.graphicID_object_data.graphic_Height, &lv);
- LDEBUG("graphic_Height: %u", lv);
- LDEBUG("graphic_DataID: %.*s", pObj->object_Data.choice.graphicID_object_data.graphic_DataID.size, pObj->object_Data.choice.graphicID_object_data.graphic_DataID.buf);
- break;
- default:
- break;
- }
- }
- }
- #endif
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyRealTimeDisplayMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
- {
- result = -13;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -14;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyRealTimeDisplayMessage, &Msg);
- }
- break;
- case OBJ_ScheduledDisplay: /* 계획된정보표출 */
- {
- LINFO(" *** OBJ_ScheduledDisplay");
- ScheduledDisplayMessage_t *pSD;
- MessageBodyScheduledDisplayMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyScheduledDisplayMessage_t));
- for ( i = 0; i < 1; i++)
- {
- if ((pSD = (ScheduledDisplayMessage_t *)ASN1C_Alloc(sizeof(ScheduledDisplayMessage_t))) == NULL)
- {
- result = -20;
- break;
- }
- if ((result = ScheduledDisplayData(pSD, Arg)) != SYS_ERR_NONE)
- {
- SERROR("ScheduledDisplayData result %d", result);
- result = -21;
- break;
- }
- if (ASN_SEQUENCE_ADD(&Msg, pSD)!= ASN_ERR_NONE)
- {
- result = -22;
- break;
- }
- #if 0
- {
- long lv;
- OCTET_STRING_t *pSid;
- LDEBUG("[%d]", i);
- asn_INTEGER2long(&pSD->message_Nbr, &lv);
- LDEBUG("message_Nbr: %u", lv);
- for (int j = 0; j < pSD->message_serialIDs.list.count; j++)
- {
- LDEBUG("message_serialIDs: [%d]", j);
- pSid = (OCTET_STRING_t *)pSD->message_serialIDs.list.array[j];
- LDEBUG("serialIDs: %.*s", pSid->size, pSid->buf);
- }
- }
- #endif
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyScheduledDisplayMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
- {
- result = -23;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -24;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyScheduledDisplayMessage, &Msg);
- }
- break;
- case OBJ_DownloadGraphicData: /* 그래픽데이터 다운로드 */
- {
- LINFO(" *** OBJ_DownloadGraphicData");
- DownloadGraphicDataMessage_t *pDGD;
- MessageBodyDownloadGraphicDataMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyDownloadGraphicDataMessage_t));
- for ( i = 0; i < 1; i++)
- {
- if ((pDGD = (DownloadGraphicDataMessage_t *)ASN1C_Alloc(sizeof(DownloadGraphicDataMessage_t))) == NULL)
- {
- result = -30;
- break;
- }
- if ((result = DownloadGraphicData(pDGD, Arg)) != VERR_NONE)
- {
- SERROR("DownloadGraphicData result %d", result);
- result = -31;
- break;
- }
- if (ASN_SEQUENCE_ADD(&Msg, pDGD)!= ASN_ERR_NONE)
- {
- result = -32;
- break;
- }
- #if 0
- {
- LDEBUG("[%d]", i);
- LDEBUG("download_GraphicData_ID: %.*s", pDGD->download_GraphicData_ID.size, pDGD->download_GraphicData_ID.buf);
- LDEBUG("download_GraphicData:");
- //m_Log->WriteHex(LOG_DEBUG, (BYTE *)pDGD->download_GraphicData.buf, pDGD->download_GraphicData.size);
- }
- #endif
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyDownloadGraphicDataMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
- {
- result = -33;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -34;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyDownloadGraphicDataMessage, &Msg);
- }
- break;
- case OBJ_StatusControl: /* 상태제어 */
- {
- LINFO(" *** OBJ_StatusControl");
- StatusControlMessage_t *pSC;
- MessageBodyStatusControlMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyStatusControlMessage_t));
- for ( i = 0; i < 1; i++)
- {
- if ((pSC = (StatusControlMessage_t *)ASN1C_Alloc(sizeof(StatusControlMessage_t))) == NULL)
- {
- result = -40;
- break;
- }
- if ((result = StatusControlData(pSC, Arg)) != SYS_ERR_NONE)
- {
- SERROR("StatusControlData result %d", result);
- result = -41;
- break;
- }
- if (ASN_SEQUENCE_ADD(&Msg, pSC)!= ASN_ERR_NONE)
- {
- result = -42;
- break;
- }
- #if 0
- {
- long lv;
- //LDEBUG("[%d]", i);
- asn_INTEGER2long(&pSC->modulePower_ControlCode, &lv);
- LDEBUG(" modulePower_ControlCode: %u", lv);
- asn_INTEGER2long(&pSC->luminance_ControlCode, &lv);
- LDEBUG(" luminance_ControlCode: %u", lv);
- asn_INTEGER2long(&pSC->fan_ControlCode, &lv);
- LDEBUG(" fan_ControlCode: %u", lv);
- asn_INTEGER2long(&pSC->heater_ControlCode, &lv);
- LDEBUG(" heater_ControlCode: %u", lv);
- if (pSC->externalLight_ControlCode)
- {
- asn_INTEGER2long(pSC->externalLight_ControlCode, &lv);
- LDEBUG("externalLight_ControlCode: %u", lv);
- }
- if (pSC->alarmLight_ControlCode)
- {
- asn_INTEGER2long(pSC->alarmLight_ControlCode, &lv);
- LDEBUG(" alarmLight_ControlCode: %u", lv);
- }
- if (pSC->speaker_ControlCode)
- {
- asn_INTEGER2long(pSC->speaker_ControlCode, &lv);
- LDEBUG(" speaker_ControlCode: %u", lv);
- }
- if (pSC->controller_Reset)
- {
- LDEBUG(" controller_Reset: %d", *pSC->controller_Reset);
- }
- if (pSC->controllerTime_Reset)
- {
- LDEBUG(" controllerTime_Reset: %.*s", pSC->controllerTime_Reset->size, pSC->controllerTime_Reset->buf);
- }
- }
- #endif
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyStatusControlMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
- {
- result = -43;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -44;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyStatusControlMessage, &Msg);
- }
- break;
- case OBJ_StatusSetting: /* 상태설정 */
- {
- LINFO(" *** OBJ_StatusSetting");
- StatusSettingMessage_t *pSS;
- MessageBodyStatusSettingMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyStatusSettingMessage_t));
- for ( i = 0; i < 1; i++)
- {
- if ((pSS = (StatusSettingMessage_t *)ASN1C_Alloc(sizeof(StatusSettingMessage_t))) == NULL)
- {
- result = -50;
- break;
- }
- if ((result = StatusSettingData(pSS, Arg)) != SYS_ERR_NONE)
- {
- SERROR("StatusSettingData result: %d", result);
- result = -51;
- break;
- }
- if (ASN_SEQUENCE_ADD(&Msg, pSS)!= ASN_ERR_NONE)
- {
- result = -52;
- break;
- }
- #if 0
- {
- long lv;
- //LDEBUG("[%d]", i);
- asn_INTEGER2long(&pSS->scheduledMessage_OperatingTimeQty, &lv);
- LDEBUG(" scheduledMessage_OperatingTimeQty: %u", lv);
- asn_INTEGER2long(&pSS->module_OperatingTemperatureQty, &lv);
- LDEBUG(" module_OperatingTemperatureQty: %u", lv);
- asn_INTEGER2long(&pSS->fan_OperatingTemperatureQty, &lv);
- LDEBUG(" fan_OperatingTemperatureQty: %u", lv);
- asn_INTEGER2long(&pSS->heater_OperatingTemperatureQty, &lv);
- LDEBUG(" heater_OperatingTemperatureQty: %u", lv);
- if (pSS->externalLight_OperatingLuminanceQty)
- {
- asn_INTEGER2long(pSS->externalLight_OperatingLuminanceQty, &lv);
- LDEBUG("externalLight_OperatingLuminanceQty: %u", lv);
- }
- if (pSS->module_BasicFailureRate)
- {
- asn_INTEGER2long(pSS->module_BasicFailureRate, &lv);
- LDEBUG(" module_BasicFailureRate: %u", lv);
- }
- if (pSS->maximum_RetryQty)
- {
- asn_INTEGER2long(pSS->maximum_RetryQty, &lv);
- LDEBUG(" maximum_RetryQty: %u", lv);
- }
- if (pSS->response_TimeOutQty)
- {
- asn_INTEGER2long(pSS->response_TimeOutQty, &lv);
- LDEBUG(" response_TimeOutQty: %u", lv);
- }
- if (pSS->blinking_CycleTime)
- {
- asn_INTEGER2long(pSS->blinking_CycleTime, &lv);
- LDEBUG(" blinking_CycleTime: %u", lv);
- }
- }
- #endif
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyStatusSettingMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg.buf == NULL)
- {
- result = -53;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexPublish_Type.choice.datexPublish_Data.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -54;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyStatusSettingMessage, &Msg);
- }
- break;
- default:
- result = SYS_ERR_UNKNOWN_MESSAGE_ID;
- SERROR(" *** Unknown CommandPublicationData");
- break;
- }
- return result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::RecvFormDownResult(AnsiString AImageId)
- {
- if (AImageId.SubString(1,1) == "6" ||
- AImageId.SubString(1,1) == "7" ||
- AImageId.SubString(1,1) == "8" ) return VERR_NONE;
- AnsiString sImgId = AImageId;
- AnsiString sTmpId = AImageId.SubString(3,2);
- int nFormIdx;
- int nResult = VERR_NONE;
- COMMAND_ARGUMENT arg;
- BYTE CmdCode;
- //LINFO("FORM_IMAGE_ID: %s", AImageId.c_str());
- CmdCode = 0x00;
- memset(&arg, 0x00, sizeof(arg));
- memset(&FSvrCtl, 0x00, sizeof(FSvrCtl));
- #if 0
- if (FVmsObj->CTLMODE->Control == 'B')
- {
- sTmpId = AImageId.SubString(4,1);
- if (sTmpId == 'A') nFormIdx = 10;
- else if (sTmpId == 'B') nFormIdx = 11;
- else if (sTmpId == 'C') nFormIdx = 12;
- else if (sTmpId == 'D') nFormIdx = 13;
- else if (sTmpId == 'E') nFormIdx = 14;
- else if (sTmpId == 'F') nFormIdx = 15;
- else nFormIdx = sTmpId.ToIntDef(0);
- }
- else
- #endif
- {
- nFormIdx = sTmpId.ToIntDef(0);
- }
- m_pVmsFormList->Lock();
- try
- {
- try
- {
- int nFormCnt = m_pVmsFormList->Count();
- #if 0
- if ((nFormCnt-1) == nFormIdx)
- {
- arg.Publication.SubscribeSerialNbr = NBR_BASE_SCHEDULEDDISPLAY;
- //arg.Publication.SubscribeSerialNbr = 50;
- arg.Publication.obj = OBJ_ScheduledDisplay;
- FSvrCtl.obj = OBJ_ScheduledDisplay;
- FSvrCtl.DataPacketNumber = m_DataPacketNumber;
- CmdCode = AI_ScheduledDisplayMessage;
- }
- else
- #endif
- if (nFormIdx < nFormCnt)
- {
- TVmsForm *pVmsForm = m_pVmsFormList->GetItem(nFormIdx);
- if (pVmsForm)
- {
- pVmsForm->FtpRes = true;
- if (pVmsForm->SvcRes == false)
- {
- arg.Publication.SubscribeSerialNbr = NBR_BASE_REALTIMEDISPLAY + nFormIdx;
- //arg.Publication.SubscribeSerialNbr = 49;
- arg.Publication.obj = OBJ_RealTimeDisplay;
- arg.Publication.Data.Form.Idx = nFormIdx;
- sprintf(arg.Publication.szFormId, "%s", sImgId.c_str());
- FSvrCtl.obj = OBJ_RealTimeDisplay;
- FSvrCtl.DataPacketNumber = m_DataPacketNumber;
- FSvrCtl.Idx = nFormIdx;
- CmdCode = AI_RealTimeDisplayMessage;
- }
- }
- else
- {
- LERROR("Not found vms form: %s, %d", VMSID.c_str(), nFormIdx);
- }
- }
- arg.Publication.Data.Form.Mode = FVmsObj->CTLMODE->Control;
- }
- catch(Exception &e)
- {
- }
- }
- __finally
- {
- m_pVmsFormList->UnLock();
- if (nResult == VERR_NONE && CmdCode != 0x00)
- {
- nResult = ProcessCommand(CmdCode, &arg);
- }
- }
- return nResult;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::RealTimeDisplayData(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg)
- {
- //BBBBBBB
- TVmsForm *pVmsForm = NULL;
- TVmsFormObj *pVmsObj = NULL;
- Object_t *pObj = NULL;
- AnsiString MessageId;
- char Utf8Buf[256+1];
- int ii;
- bool bException = false;
- try
- {
- m_pVmsFormList->Lock();
- pVmsForm = m_pVmsFormList->GetItem(Arg.Data.Form.Idx);
- if (!pVmsForm)
- {
- SERROR("FormId Memory Not Found: %d", Arg.Data.Form.Idx);
- return SYS_ERR_NONE;
- }
- if (Arg.Data.Form.Mode == 'B') //기본운영모드
- {
- if (FVmsObj->FIsOldProtocol)
- MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
- else
- MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq);
- }
- else
- {
- MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
- }
- //LINFO("REALTIME: %s", MessageId.c_str());
- if (OCTET_STRING_fromString(&pRTD->message_serialID, MessageId.c_str()) != ASN_ERR_NONE){
- return -1;
- }
- if (asn_long2INTEGER(&pRTD->display_DurationQty, pVmsForm->DisplayTime) != ASN_ERR_NONE){
- return -2;
- }
- if (asn_long2INTEGER(&pRTD->display_ModeCode, pVmsForm->DisplayMode.ToIntDef(0)) != ASN_ERR_NONE){
- return -3;
- }
- if (asn_long2INTEGER(&pRTD->display_DirectionCode, pVmsForm->DisplayDir.ToIntDef(0)) != ASN_ERR_NONE){
- return -4;
- }
- if (asn_long2INTEGER(&pRTD->background_ColorCode, pVmsForm->BkColor) != ASN_ERR_NONE){
- return -5;
- }
- int nObjCnt = pVmsForm->Count();
- if (asn_long2INTEGER(&pRTD->object_Nbr, nObjCnt) != ASN_ERR_NONE){
- return -6;
- }
- for (ii = 0; ii < nObjCnt; ii++)
- {
- pVmsObj = pVmsForm->GetItem(ii);
- if ((pObj = (Object_t *)ASN1C_Alloc(sizeof(Object_t))) == NULL){
- return -10;
- }
- #if 0
- if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){
- return -11;
- }
- #endif
- if (asn_long2INTEGER(&pObj->blinking_Code, pVmsObj->IsBlinking) != ASN_ERR_NONE){
- return -12;
- }
- if (asn_long2INTEGER(&pObj->x_Coordinate, pVmsObj->PosX) != ASN_ERR_NONE){
- return -13;
- }
- if (asn_long2INTEGER(&pObj->y_Coordinate, pVmsObj->PosY) != ASN_ERR_NONE){
- return -14;
- }
- if (asn_long2INTEGER(&pObj->data_BackgroundColor, pVmsObj->BkColor) != ASN_ERR_NONE){
- return -15;
- }
- switch(pVmsObj->ObjectKind)
- {
- case text_object_data:
- pObj->object_Data.present = ObjectData_PR_text_object_data;
- if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){
- return -11;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.text_object_data.font_ColorCode, pVmsObj->TextFontColor) != ASN_ERR_NONE){
- return -100;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.text_object_data.font_Size, pVmsObj->TextFontSize) != ASN_ERR_NONE){
- return -101;
- }
- if (FVmsObj->FIsProtolFontName)
- {
- if (OCTET_STRING_fromString(&pObj->object_Data.choice.text_object_data.font_TypeCode, pVmsObj->StrTextFontName.c_str()) != ASN_ERR_NONE){
- return -102;
- }
- }
- else
- {
- if (OCTET_STRING_fromString(&pObj->object_Data.choice.text_object_data.font_TypeCode, AnsiString(pVmsObj->TextFontName).c_str()) != ASN_ERR_NONE){
- return -102;
- }
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.text_object_data.font_Thickness, pVmsObj->TextFontBold) != ASN_ERR_NONE){
- return -103;
- }
- Hangul2UTF8String(pVmsObj->TextData.c_str(), Utf8Buf, sizeof(Utf8Buf));
- if (OCTET_STRING_fromString(&pObj->object_Data.choice.text_object_data.text_Data, Utf8Buf) != ASN_ERR_NONE)
- {
- return -104;
- }
- break;
- case graphic_object_data:
- pObj->object_Data.present = ObjectData_PR_graphic_object_data;
- if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){
- return -11;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, pVmsObj->ImageType.ToIntDef(0)) != ASN_ERR_NONE){
- return -200;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsObj->Width) != ASN_ERR_NONE){
- return -201;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsObj->Height) != ASN_ERR_NONE){
- return -202;
- }
- try
- {
- pVmsObj->pImageStream->Position = 0;
- if (OCTET_STRING_fromBuf(&pObj->object_Data.choice.graphic_object_data.graphic_Data, (char *)pVmsObj->pImageStream->Memory, pVmsObj->pImageStream->Size) != ASN_ERR_NONE){
- return -203;
- }
- }
- catch(Exception &e)
- {
- bException = true;
- SERROR("MemoryStream Allocation error: %s, FormId: %s", AnsiString(e.Message).c_str(), pVmsForm->FormId.c_str());
- }
- break;
- case graphicID_object_data:
- if (FVmsObj->FIsOldProtocol)
- {
- pObj->object_Data.present = ObjectData_PR_graphicID_object_data;
- if (asn_long2INTEGER(&pObj->object_TypeCode, pVmsObj->ObjectKind) != ASN_ERR_NONE){
- return -11;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphicID_object_data.graphic_Type, pVmsObj->ImageType.ToIntDef(0)) != ASN_ERR_NONE){
- return -300;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphicID_object_data.graphic_Width, pVmsObj->Width) != ASN_ERR_NONE){
- return -301;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphicID_object_data.graphic_Height, pVmsObj->Height) != ASN_ERR_NONE){
- return -302;
- }
- AnsiString sFtpImgId = GetFtpImageId(pVmsObj->ImageId);
- //if (OCTET_STRING_fromString(&pObj->object_Data.choice.graphicID_object_data.graphic_DataID, pVmsObj->ImageId.c_str()) != ASN_ERR_NONE){
- if (OCTET_STRING_fromString(&pObj->object_Data.choice.graphicID_object_data.graphic_DataID, sFtpImgId.c_str()) != ASN_ERR_NONE){
- return -303;
- }
- }
- else
- {
- pObj->object_Data.present = ObjectData_PR_graphic_object_data;
- if (asn_long2INTEGER(&pObj->object_TypeCode, graphic_object_data) != ASN_ERR_NONE){
- return -11;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, pVmsObj->ImageType.ToIntDef(0)) != ASN_ERR_NONE){
- return -200;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsObj->Width) != ASN_ERR_NONE){
- return -201;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsObj->Height) != ASN_ERR_NONE){
- return -202;
- }
- try
- {
- pVmsObj->pImageStream->Position = 0;
- if (OCTET_STRING_fromBuf(&pObj->object_Data.choice.graphic_object_data.graphic_Data, (char *)pVmsObj->pImageStream->Memory, pVmsObj->pImageStream->Size) != ASN_ERR_NONE){
- return -203;
- }
- }
- catch(Exception &e)
- {
- bException = true;
- SERROR("MemoryStream Allocation error: %s, FormId: %s", AnsiString(e.Message).c_str(), pVmsForm->FormId.c_str());
- }
- }
- break;
- } //switch
- if (ASN_SEQUENCE_ADD(&pRTD->objects_zz, pObj)!= ASN_ERR_NONE)
- {
- return -16;
- }
- } //for
- }
- __finally
- {
- m_pVmsFormList->UnLock();
- if (bException)
- {
- SERROR("LockFree OK");
- }
- }
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::RealTimeDisplayBitmap(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg)
- {
- /* 모든 VMS를 이미지로 다운로드 하는 경우임
- 이전 VMS도 FTP를 이용하는 경우(도형식) 이거나 문자식 이거나 모두 FTP로 다운로드 함
- */
- int result;
- if (FVmsObj->FIsOldProtocol)
- {
- result = RealTimeDisplayBitmapOld(pRTD, Arg);
- }
- else
- {
- result = RealTimeDisplayBitmapNew(pRTD, Arg);
- }
- return result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::RealTimeDisplayBitmapOld(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg)
- {
- TVmsForm *pVmsForm = NULL;
- Object_t *pObj = NULL;
- AnsiString ImageId;
- AnsiString MessageId;
- int ii;
- bool bException = false;
- ImageId = String(Arg.szFormId);
- try
- {
- m_pVmsFormList->Lock();
- pVmsForm = m_pVmsFormList->GetItem(Arg.Data.Form.Idx);
- if (!pVmsForm)
- {
- SERROR("FormId Memory Not Found: %d", Arg.Data.Form.Idx);
- return SYS_ERR_NONE;
- }
- if (Arg.Data.Form.Mode == 'B') //기본운영모드
- {
- if (FVmsObj->FIsOldProtocol)
- MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
- else
- MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq);
- }
- else
- {
- MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
- }
- //LINFO("BMP_REALTIME(OLD): %s", MessageId.c_str());
- if (OCTET_STRING_fromString(&pRTD->message_serialID, MessageId.c_str()) != ASN_ERR_NONE){
- return -1;
- }
- if (asn_long2INTEGER(&pRTD->display_DurationQty, pVmsForm->DisplayTime) != ASN_ERR_NONE){
- return -2;
- }
- if (asn_long2INTEGER(&pRTD->display_ModeCode, pVmsForm->DisplayMode.ToIntDef(0)) != ASN_ERR_NONE){
- return -3;
- }
- if (asn_long2INTEGER(&pRTD->display_DirectionCode, pVmsForm->DisplayDir.ToIntDef(0)) != ASN_ERR_NONE){
- return -4;
- }
- if (asn_long2INTEGER(&pRTD->background_ColorCode, pVmsForm->BkColor) != ASN_ERR_NONE){
- return -5;
- }
- if (asn_long2INTEGER(&pRTD->object_Nbr, 1) != ASN_ERR_NONE){
- return -6;
- }
- //이미지 객체 정보 생성
- if ((pObj = (Object_t *)ASN1C_Alloc(sizeof(Object_t))) == NULL){
- return -10;
- }
- if (asn_long2INTEGER(&pObj->object_TypeCode, object_TypeCode_graphic_id_object) != ASN_ERR_NONE){
- return -11;
- }
- int IsBlinking = 0;
- if (asn_long2INTEGER(&pObj->blinking_Code, blinking_Code_off) != ASN_ERR_NONE){
- return -12;
- }
- if (asn_long2INTEGER(&pObj->x_Coordinate, 0) != ASN_ERR_NONE){
- return -13;
- }
- if (asn_long2INTEGER(&pObj->y_Coordinate, 0) != ASN_ERR_NONE){
- return -14;
- }
- int BkColor = 0;
- if (asn_long2INTEGER(&pObj->data_BackgroundColor, color_black) != ASN_ERR_NONE){
- return -15;
- }
- //이미지ID데이터
- pObj->object_Data.present = ObjectData_PR_graphicID_object_data;
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, graphic_Type_bitmap) != ASN_ERR_NONE){
- return -200;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsForm->Width) != ASN_ERR_NONE){
- return -201;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsForm->Height) != ASN_ERR_NONE){
- return -202;
- }
- if (OCTET_STRING_fromString(&pObj->object_Data.choice.graphicID_object_data.graphic_DataID, ImageId.c_str()) != ASN_ERR_NONE){
- return -303;
- }
- FErrLine = 33;
- if (ASN_SEQUENCE_ADD(&pRTD->objects_zz, pObj)!= ASN_ERR_NONE)
- {
- return -16;
- }
- }
- __finally
- {
- FErrLine = 34;
- m_pVmsFormList->UnLock();
- if (bException)
- {
- SERROR("LockFree OK");
- }
- }
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::RealTimeDisplayBitmapNew(RealTimeDisplayMessage_t *pRTD, PUBLICATION_ARGUMENT Arg)
- {
- TVmsForm *pVmsForm = NULL;
- Object_t *pObj = NULL;
- AnsiString MessageId;
- int ii;
- bool bException = false;
- try
- {
- m_pVmsFormList->Lock();
- pVmsForm = m_pVmsFormList->GetItem(Arg.Data.Form.Idx);
- if (!pVmsForm)
- {
- SERROR("FormId Memory Not Found: %d", Arg.Data.Form.Idx);
- return SYS_ERR_NONE;
- }
- if (Arg.Data.Form.Mode == 'B') //기본운영모드
- {
- if (FVmsObj->FIsOldProtocol)
- MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
- else
- MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq);
- }
- else
- {
- MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
- }
- //LINFO("BMP_REALTIME(NEW): %s", MessageId.c_str());
- if (OCTET_STRING_fromString(&pRTD->message_serialID, MessageId.c_str()) != ASN_ERR_NONE){
- return -1;
- }
- if (asn_long2INTEGER(&pRTD->display_DurationQty, pVmsForm->DisplayTime) != ASN_ERR_NONE){
- return -2;
- }
- if (asn_long2INTEGER(&pRTD->display_ModeCode, pVmsForm->DisplayMode.ToIntDef(0)) != ASN_ERR_NONE){
- return -3;
- }
- if (asn_long2INTEGER(&pRTD->display_DirectionCode, pVmsForm->DisplayDir.ToIntDef(0)) != ASN_ERR_NONE){
- return -4;
- }
- if (asn_long2INTEGER(&pRTD->background_ColorCode, pVmsForm->BkColor) != ASN_ERR_NONE){
- return -5;
- }
- if (asn_long2INTEGER(&pRTD->object_Nbr, 1) != ASN_ERR_NONE){
- return -6;
- }
- //이미지 객체 정보 생성
- if ((pObj = (Object_t *)ASN1C_Alloc(sizeof(Object_t))) == NULL){
- return -10;
- }
- if (asn_long2INTEGER(&pObj->object_TypeCode, object_TypeCode_graphic_object) != ASN_ERR_NONE){
- return -11;
- }
- int IsBlinking = 0;
- if (asn_long2INTEGER(&pObj->blinking_Code, blinking_Code_off) != ASN_ERR_NONE){
- return -12;
- }
- if (asn_long2INTEGER(&pObj->x_Coordinate, 0) != ASN_ERR_NONE){
- return -13;
- }
- if (asn_long2INTEGER(&pObj->y_Coordinate, 0) != ASN_ERR_NONE){
- return -14;
- }
- int BkColor = 0;
- if (asn_long2INTEGER(&pObj->data_BackgroundColor, color_black) != ASN_ERR_NONE){
- return -15;
- }
- //이미지데이터
- pObj->object_Data.present = ObjectData_PR_graphic_object_data;
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Type, graphic_Type_bitmap) != ASN_ERR_NONE){
- return -200;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Width, pVmsForm->Width) != ASN_ERR_NONE){
- return -201;
- }
- if (asn_long2INTEGER(&pObj->object_Data.choice.graphic_object_data.graphic_Height, pVmsForm->Height) != ASN_ERR_NONE){
- return -202;
- }
- try
- {
- pVmsForm->pStream->Position = 0;
- if (OCTET_STRING_fromBuf(&pObj->object_Data.choice.graphic_object_data.graphic_Data, (char *)pVmsForm->pStream->Memory, pVmsForm->pStream->Size) != ASN_ERR_NONE){
- return -203;
- }
- }
- catch(Exception &e)
- {
- bException = true;
- SERROR("MemoryStream Allocation error: %s, FormId: %s", AnsiString(e.Message).c_str(), pVmsForm->FormId.c_str());
- }
- if (ASN_SEQUENCE_ADD(&pRTD->objects_zz, pObj)!= ASN_ERR_NONE)
- {
- return -16;
- }
- }
- __finally
- {
- m_pVmsFormList->UnLock();
- if (bException)
- {
- SERROR("LockFree OK");
- }
- }
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::ScheduledDisplayData(ScheduledDisplayMessage_t *pSD, PUBLICATION_ARGUMENT Arg)
- {
- //AAAAAAAAAA
- FErrLine = 15;
- OCTET_STRING_t *pSid;
- AnsiString MessageId;
- int ii;
- try
- {
- m_pVmsFormList->Lock();
- int nFormCnt = m_pVmsFormList->Count();
- if (asn_long2INTEGER(&pSD->message_Nbr, nFormCnt) != ASN_ERR_NONE)
- {
- return -1;
- }
- for (ii = 0; ii < nFormCnt; ii++)
- {
- TVmsForm *pVmsForm = m_pVmsFormList->GetItem(ii);
- if (!pVmsForm) continue;
- if (Arg.Data.Form.Mode == 'B')
- {
- if (FVmsObj->FIsOldProtocol)
- MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
- else
- MessageId.sprintf("%d", VMS_BASE_MANUAL_ID + pVmsForm->ScenarioSeq);
- }
- else
- {
- MessageId.sprintf("%d", pVmsForm->ScenarioSeq);
- }
- //LINFO("SCHEDULE: %s", MessageId.c_str());
- if ((pSid = (OCTET_STRING_t *)ASN1C_Alloc(sizeof(OCTET_STRING_t))) == NULL)
- {
- return -10;
- }
- if (OCTET_STRING_fromString(pSid, MessageId.c_str()) != ASN_ERR_NONE)
- {
- return -11;
- }
- if (ASN_SEQUENCE_ADD(&pSD->message_serialIDs, pSid)!= ASN_ERR_NONE)
- {
- return -12;
- }
- }
- }
- __finally
- {
- m_pVmsFormList->UnLock();
- }
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::DownloadGraphicData(DownloadGraphicDataMessage_t *pDGD, PUBLICATION_ARGUMENT Arg)
- {
- FErrLine = 16;
- AnsiString sNmbr = FVmsObj->DOWNLOAD->Unit[Arg.Data.Down.Idx].FileId;
- TCDSImage *pVmsImage = ImageManager->FLists.Find(sNmbr+"0");
- if (!pVmsImage) return -10;
- TMemoryStream *pStream = new TMemoryStream;
- try
- {
- if (OCTET_STRING_fromString(&pDGD->download_GraphicData_ID, sNmbr.c_str()) != ASN_ERR_NONE)
- {
- return -1;
- }
- pStream->Clear();
- pStream->Position = 0;
- pVmsImage->pImage->Canvas->Lock();
- pVmsImage->pImage->Picture->Graphic->SaveToStream(pStream);
- pVmsImage->pImage->Canvas->Unlock();
- pStream->Position = 0;
- if (OCTET_STRING_fromBuf(&pDGD->download_GraphicData, (char *)pStream->Memory, pStream->Size) != ASN_ERR_NONE)
- {
- return -2;
- }
- }
- __finally
- {
- SAFE_DELETE(pStream);
- }
- return VERR_NONE;
- }
- //---------------------------------------------------------------------------
- /*
- * 송신 패킷 생성
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::StatusControlData(StatusControlMessage_t *pSC, PUBLICATION_ARGUMENT Arg)
- {
- FErrLine = 17;
- int modulePower;
- int luminance = 0;
- #if 0
- //TODO
- if (m_pState->Comm == vms_normal)
- {
- luminance = (int)m_pState->LuminanceStatus;
- }
- #endif
- if (Arg.Data.Ctl == CTL_MODULE_POWER_ON)
- {
- modulePower = modulePower_ControlCode_on;
- }
- else
- if (Arg.Data.Ctl == CTL_MODULE_POWER_OFF)
- {
- modulePower = modulePower_ControlCode_off;
- }
- else
- if (Arg.Data.Ctl == CTL_CONTROLLER_RESET)
- {
- modulePower = modulePower_ControlCode_on;
- }
- else
- if (Arg.Data.Ctl == CTL_LUMINANCE_SET)
- {
- modulePower = modulePower_ControlCode_on;
- luminance = (int)FCliCtl.CtlType;
- }
- else
- {
- return -1;
- }
- if (asn_long2INTEGER(&pSC->modulePower_ControlCode, modulePower) != ASN_ERR_NONE)
- {
- return -2;
- }
- #if 1
- if (asn_long2INTEGER(&pSC->luminance_ControlCode, luminance) != ASN_ERR_NONE)
- {
- return -3;
- }
- #else
- if (asn_long2INTEGER(&pSC->luminance_ControlCode, 0) != ASN_ERR_NONE)
- {
- return -3;
- }
- #endif
- if (asn_long2INTEGER(&pSC->fan_ControlCode, fan_ControlCode_auto) != ASN_ERR_NONE)
- {
- return -4;
- }
- if (asn_long2INTEGER(&pSC->heater_ControlCode, heater_ControlCode_auto) != ASN_ERR_NONE)
- {
- return -5;
- }
- pSC->externalLight_ControlCode = NULL;
- pSC->alarmLight_ControlCode = NULL;
- pSC->speaker_ControlCode = NULL;
- if (Arg.Data.Ctl == CTL_CONTROLLER_RESET)
- {
- if ((pSC->controller_Reset = (BOOLEAN_t *)ASN1C_Alloc(sizeof(BOOLEAN_t))) == NULL)
- {
- return -6;
- }
- *pSC->controller_Reset = true;
- }
- else
- {
- if ((pSC->controller_Reset = (BOOLEAN_t *)ASN1C_Alloc(sizeof(BOOLEAN_t))) == NULL)
- {
- return -6;
- }
- *pSC->controller_Reset = false;
- //pSC->controller_Reset = NULL;
- }
- pSC->controllerTime_Reset = NULL;
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- /*
- * 송신 패킷 생성
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::StatusSettingData(StatusSettingMessage_t *pSS, PUBLICATION_ARGUMENT Arg)
- {
- FErrLine = 18;
- //INTEGER_t scheduledMessage_OperatingTimeQty;
- //INTEGER_t module_OperatingTemperatureQty;
- //INTEGER_t fan_OperatingTemperatureQty;
- //INTEGER_t heater_OperatingTemperatureQty;
- INTEGER_t *externalLight_OperatingLuminanceQty /* OPTIONAL */;
- //INTEGER_t *module_BasicFailureRate /* OPTIONAL */;
- //INTEGER_t *maximum_RetryQty /* OPTIONAL */;
- //INTEGER_t *response_TimeOutQty /* OPTIONAL */;
- INTEGER_t *blinking_CycleTime /* OPTIONAL */;
- if(asn_long2INTEGER(&pSS->scheduledMessage_OperatingTimeQty, Arg.Data.Set.SchMsgTime) != ASN_ERR_NONE)
- {
- return -1;
- }
- if(asn_long2INTEGER(&pSS->module_OperatingTemperatureQty, Arg.Data.Set.ModuleTemp) != ASN_ERR_NONE)
- {
- return -2;
- }
- if(asn_long2INTEGER(&pSS->fan_OperatingTemperatureQty, Arg.Data.Set.FanTemp) != ASN_ERR_NONE)
- {
- return -3;
- }
- if(asn_long2INTEGER(&pSS->heater_OperatingTemperatureQty, Arg.Data.Set.HeaterTemp) != ASN_ERR_NONE)
- {
- return -4;
- }
- pSS->externalLight_OperatingLuminanceQty = NULL;
- if ((pSS->module_BasicFailureRate = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL)
- {
- return -5;
- }
- if(asn_long2INTEGER(pSS->module_BasicFailureRate, Arg.Data.Set.ModuleFail) != ASN_ERR_NONE)
- {
- return -6;
- }
- if ((pSS->maximum_RetryQty = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL)
- {
- return -7;
- }
- if(asn_long2INTEGER(pSS->maximum_RetryQty, Arg.Data.Set.RetryCount) != ASN_ERR_NONE)
- {
- return -8;
- }
- if ((pSS->response_TimeOutQty = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL)
- {
- return -9;
- }
- if(asn_long2INTEGER(pSS->response_TimeOutQty, Arg.Data.Set.TimeOut) != ASN_ERR_NONE)
- {
- return -10;
- }
- if (FVmsObj->FIsOldProtocol)
- {
- if ((pSS->blinking_CycleTime = (INTEGER_t *)ASN1C_Alloc(sizeof(INTEGER_t))) == NULL)
-
{
- return -5;
- }
- if(asn_long2INTEGER(pSS->blinking_CycleTime, 5) != ASN_ERR_NONE)
- {
- return -6;
- }
- }
-
else
-
{
-
pSS->blinking_CycleTime = NULL;
-
}
-
return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- /*
- * 서버 처리 루틴
- * arguments
- * void
- * return
- * void
- */
- void __fastcall TVMSSThread::ServerStateMachine(void)
- {
- FErrLine = 19;
- int result;
- bool flag;
- result = SYS_ERR_NONE;
- //timeout check
- if (m_RxLen && (CommUtil_TimeDiff(m_rTimer) > m_Server.TimeOut))
- {
- m_RxLen = 0;
- ProcErrorState(TRUE, SYS_ERR_RECEIVE_TIMEOUT);
- return;
- }
- #if 0
- {
- switch (m_Server.State)
- {
- #if 0
- case ST_IDLE: LDEBUG("IDLE"); break;
- case ST_INITIATE: LDEBUG("INITIATE"); break;
- case ST_SECTION: LDEBUG("SECTION"); break;
- case ST_CLOSE: LDEBUG("CLOSE"); break;
- #endif
- case ST_LOCAL_COMMAND: LDEBUG("LOCAL_COMMAND"); break;
- case ST_CLIENT_COMMAND: LDEBUG("CLIENT_COMMAND"); break;
- case ST_LOCAL_WAIT: LDEBUG("LOCAL_WAIT"); break;
- case ST_CLIENT_WAIT: LDEBUG("CLIENT_WAIT"); break;
- default: LDEBUG("Unknown State[%d]", m_Server.State); break;
- }
- }
- #endif
- switch(m_Server.State)
- {
- case ST_IDLE:
- if (CommUtil_TimeDiff(m_Server.sTimer) > SERVER_CONNECT_RETRY_TIME)
- {
- m_Server.sTimer = Now();
- if (m_Server.iRetry <= 0)
- {
- m_Server.State = ST_CLOSE;
- }
- else
- {
- m_Server.State = ST_INITIATE;
- }
- }
- break;
- case ST_INITIATE:
- if ((result = ProcessCommand(AI_Initiate, NULL)) == SYS_ERR_NONE)
- {
- m_Server.State = ST_IDLE;
- m_Server.iRetry = 0;
- }
- else
- {
- if (--m_Server.iRetry <= 0)
- {
- m_Server.State = ST_CLOSE;
- }
- }
- break;
- case ST_SECTION:
- if (CommUtil_TimeDiff(m_WatchDogTimer) > FWatchDogTime)
- {
- SERROR("WatchDogTime over");
- /* 통신 offline 종료 처리 */
- m_Server.State = ST_CLOSE;
- break;
- }
- /* 레지스터 정보 체크 */
- CheckRegistered();
- break;
- case ST_CLOSE:
- #if 0
- arg.Terminate = Logout_serverShutdown;
- ProcessCommand(AI_Terminate, &arg);
- #endif
- Terminate();
- break;
- case ST_LOCAL_COMMAND:
- result = CheckLocalData(&flag);
- if (flag)
- {
- if (result == VERR_NONE)
- {
- m_Server.State = ST_LOCAL_WAIT;
- }
- else
- {
- if (--m_Server.iRetry <= 0)
- {
- m_Server.State = ST_CLOSE;
- }
- }
- }
- else
- {
- m_Server.State = ST_CLIENT_COMMAND;
- }
- break;
- case ST_CLIENT_COMMAND:
- result = CheckClientData(&flag);
- if (flag)
- {
- if (result == VERR_NONE)
- {
- m_Server.State = ST_CLIENT_WAIT;
- }
- else
- {
- if (--m_Server.iRetry <= 0)
- {
- m_Server.State = ST_CLOSE;
- }
- }
- }
- else
- {
- m_Server.State = ST_SECTION;
- }
- break;
- case ST_LOCAL_WAIT:
- if (CommUtil_TimeDiff(m_Server.cTimer) > m_Server.TimeOut)
- {
- if (m_Server.iRetry > 0){
- m_Server.State = ST_LOCAL_COMMAND;
- }else{
- m_Server.State = ST_CLOSE;
- }
- }
- break;
- case ST_CLIENT_WAIT:
- if (CommUtil_TimeDiff(m_Server.cTimer) > m_Server.TimeOut)
- {
- if (m_Server.iRetry > 0)
- {
- ClientResponse(SYS_ERR_NO_RES);
- m_Server.State = ST_CLIENT_COMMAND;
- }
- else
- {
- m_Server.State = ST_CLOSE;
- }
- }
- break;
- default:
- m_Server.State = ST_IDLE;
- break;
- }/* end switch */
- if (result)
- {
- ProcErrorState(FALSE, result);
- }
- }
- //---------------------------------------------------------------------------
- /*
- * 에러 처리
- * arguments
- * void
- * return
- * void
- */
- void __fastcall TVMSSThread::ProcErrorState(bool flag, int result)
- {
- FErrLine = 20;
- #if 1
- {
- AnsiString strLog;
- switch(result)
- {
- case SYS_ERR_NONE: strLog.sprintf("no error [%d]", result); break;
- case SYS_ERR_OTHER: strLog.sprintf("other [%d]", result); break;
- case SYS_ERR_INTERNAL: strLog.sprintf("internal system error(kernel..) [%d]", result); break;
- case SYS_ERR_MEMORY: strLog.sprintf("memory overflow [%d]", result); break;
- case SYS_ERR_DATABASE: strLog.sprintf("system database error [%d]", result); break;
- case SYS_ERR_RESET: strLog.sprintf("system reset [%d]", result); break;
- case SYS_ERR_START: strLog.sprintf("system start [%d]", result); break;
- case SYS_ERR_OFFLINE: strLog.sprintf("offline [%d]", result); break;
- case SYS_ERR_NO_RES: strLog.sprintf("no response [%d]", result); break;
- case SYS_ERR_ACCESS: strLog.sprintf("access denied [%d]", result); break;
- case SYS_ERR_INVALID: strLog.sprintf("invalid data type [%d]", result); break;
- case SYS_ERR_UNKNOWN: strLog.sprintf("unknown data type [%d]", result); break;
- case SYS_ERR_WRITE_LENGTH: strLog.sprintf("write length [%d]", result); break;
- case SYS_ERR_PACKET_SIZE_LARGE: strLog.sprintf("packet size large [%d]", result); break;
- case SYS_ERR_INVALID_TAG: strLog.sprintf("invalid tag [%d]", result); break;
- case SYS_ERR_CRC: strLog.sprintf("crc [%d]", result); break;
- case SYS_ERR_LENGTH: strLog.sprintf("length [%d]", result); break;
- case SYS_ERR_ADDRESS: strLog.sprintf("address [%d]", result); break;
- case SYS_ERR_HEADER_OPTIONS: strLog.sprintf("header options [%d]", result); break;
- case SYS_ERR_UNKNOWN_COMMAND: strLog.sprintf("unknown command [%d]", result); break;
- case SYS_ERR_RECEIVE_TIMEOUT: strLog.sprintf("receive timeout [%d]", result); break;
- case SYS_ERR_DATA_SIZE: strLog.sprintf("data size [%d]", result); break;
- case SYS_ERR_MISMATCH: strLog.sprintf("mismatch command [%d]", result); break;
- case SYS_ERR_INVALID_PARA: strLog.sprintf("invalid parameter [%d]", result); break;
- case SYS_ERR_MOVEMENT: strLog.sprintf("movement [%d]", result); break;
- case SYS_ERR_UNAUTHORIZED: strLog.sprintf("unauthorized [%d]", result); break;
- case SYS_ERR_DATEXDATAPACKET_DECODE: strLog.sprintf("DatexDataPacket decode [%d]", result); break;
- case SYS_ERR_INVALID_VERSION_NUMBER: strLog.sprintf("invalid version number [%d]", result); break;
- case SYS_ERR_C2CAUTHENTICATEDMESSAGE_DECODE: strLog.sprintf("C2CAuthenticatedMessage decode [%d]", result); break;
- case SYS_ERR_C2CAUTHENTICATEDMESSAGE: strLog.sprintf("C2CAuthenticatedMessage [%d]", result); break;
- case SYS_ERR_NOT_LOGIN: strLog.sprintf("Not login [%d]", result); break;
- case SYS_ERR_ACCEPT_TYPE: strLog.sprintf("Accept Type [%d]", result); break;
- case SYS_ERR_DATEXPUBLISH_FORMAT: strLog.sprintf("datexPublish Format [%d]", result); break;
- case SYS_ERR_DATEXPUBLISH_TYPE: strLog.sprintf("datexPublish Type [%d]", result); break;
- case SYS_ERR_UNKNOWN_MESSAGE_ID: strLog.sprintf("unknown Message id [%d]", result); break;
- case SYS_ERR_MESSAGE_DECODE: strLog.sprintf("Message decode [%d]", result); break;
- case SYS_ERR_DATEXDATAPACKET_ENCODE: strLog.sprintf("DatexDataPacket encode [%d]", result); break;
- case SYS_ERR_C2CAUTHENTICATEDMESSAGE_ENCODE: strLog.sprintf("C2CAuthenticatedMessage encode [%d]", result); break;
- case SYS_ERR_MESSAGE_ENCODE: strLog.sprintf("Message encode [%d]", result); break;
- case SYS_ERR_PUBLICATIONDATA_ENCODE: strLog.sprintf("PublicationData encode [%d]", result); break;
- case SYS_ERR_MISMATCH_DESTINATION_TEXT: strLog.sprintf("mismatch Destination text [%d]", result); break;
- case SYS_ERR_DATEXLOGIN_VALUE: strLog.sprintf("Login Value [%d]", result); break;
- case SYS_ERR_SUBSCRIPTION_TYPE: strLog.sprintf("SubscriptionType Type [%d]", result); break;
- case SYS_ERR_SUBSCRIPTION_STATUS_VALUE: strLog.sprintf("SubscriptionType Status Value [%d]", result); break;
- case SYS_ERR_SUBSCRIPTION_MODE_VALUE: strLog.sprintf("SubscriptionType Mode Value [%d]", result); break;
- case SYS_ERR_SUBSCRIPTION_FORMAT_VALUE: strLog.sprintf("SubscriptionType Format Value [%d]", result); break;
- case SYS_ERR_HANGUL_CONVERSION: strLog.sprintf("Hangul Conversion [%d]", result); break;
- case SYS_ERR_INVALID_TAGANDLEN: strLog.sprintf("invalid Tag And Len [%d]", result); break;
- case SYS_ERR_PUBLICATIONDATA_DECODE: strLog.sprintf("PublicationData decode [%d]", result); break;
- default: strLog.sprintf("Unknown Error [%d]", result); break;
- }
- if (flag){
- SERROR("Recv Error %s", strLog.c_str());
- }else{
- SERROR("Send Error %s", strLog.c_str());
- }
- }
- #endif
- }
- //---------------------------------------------------------------------------
- /*
- * 상태 변경
- * arguments
- * void
- * return
- * void
- */
- void __fastcall TVMSSThread::SetServerState(int Case)
- {
- FErrLine = 21;
- switch(m_Server.State)
- {
- case ST_LOCAL_WAIT:
- if (Case == SET_SERVER_SUCC)
- {
- m_Server.State = ST_CLIENT_COMMAND;
- }
- else
- if (Case == SET_SERVER_FAIL)
- {
- m_Server.State = ST_LOCAL_COMMAND;
- }
- break;
- case ST_CLIENT_WAIT:
- if (Case == SET_SERVER_SUCC)
- {
- m_Server.State = ST_SECTION;
- }
- else
- if (Case == SET_SERVER_FAIL)
- {
- m_Server.State = ST_CLIENT_COMMAND;
- }
- break;
- default:
- break;
- }
- }
- //---------------------------------------------------------------------------
- /*
- *
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::CheckRegistered()
- {
- FErrLine = 22;
- int result;
- result = SYS_ERR_NONE;
- m_Server.State = ST_LOCAL_COMMAND;
- return result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::CheckLocalData(bool *AFlag)
- {
- FErrLine = 23;
- int nResult = VERR_NONE;
- COMMAND_ARGUMENT arg;
- BYTE CmdCode;
- *AFlag = false;
- CmdCode = 0x00;
- memset(&arg, 0x00, sizeof(arg));
- memset(&FSvrCtl, 0x00, sizeof(FSvrCtl));
- #if 0
- #if 0
- if (m_Registered.RealTimeDisplayMessage == false)
- {
- LINFO("**** RealTimeDisplayMessage 요청");
- arg.Publication.SubscribeSerialNbr = NBR_REALTIME_DISPLAY_REQ;
- arg.Publication.obj = OBJ_DisplayingData;
- arg.Publication.Data.Ctl = CTL_REALTIMEDISPLAY_REQ;
- CmdCode = AI_DisplayingDataMessage;
- nResult = ProcessCommand(CmdCode, &arg);
- *AFlag = true;
- return nResult;
- }
- #endif
- if (m_Registered.ScreenDataStatusMessage == false)
- {
- LINFO("**** ScreenDataStatusMessage 요청");
- arg.Publication.SubscribeSerialNbr = NBR_SCREEN_STATUS_REQ;
- arg.Publication.obj = OBJ_ScreenStatus;
- arg.Publication.Data.Ctl = CTL_SCREENSTATUS_REQ;
- CmdCode = AI_ScreenStatusMessage;
- nResult = ProcessCommand(CmdCode, &arg);
- *AFlag = true;
- return nResult;
- }
- #endif
- /* FORM */
- if (FVmsObj->CTLMODE->Enable == object_enable)
- {
- m_pVmsFormList->Lock();
- try
- {
- //pObj->FBmpDownload, Bitmap 전송여부와 상관없이
- //FTP다운로드가 필요한 경우임...
- if (FVmsObj->FIsFtpDownload)
- {
- int nFormCnt = m_pVmsFormList->Count();
- for (int ii = 0; ii < nFormCnt; ii++)
- {
- TVmsForm *pVmsForm = m_pVmsFormList->GetItem(ii);
- if (pVmsForm)
- {
- if (pVmsForm->FtpRes == false)
- {
- arg.Publication.SubscribeSerialNbr = NBR_BASE_REALTIMEDISPLAY + ii;
- arg.Publication.obj = OBJ_RealTimeDisplay;
- arg.Publication.Data.Form.Idx = ii;
- if (FVmsObj->CTLMODE->Control == 'B') //기본운영모드
- {
- if (FVmsObj->FIsOldProtocol)
- sprintf(arg.Publication.szFormId, "%s%02d", FVmsObj->VmsDownId.c_str(), ii);
- else
- sprintf(arg.Publication.szFormId, "%s9%d", FVmsObj->VmsDownId.c_str(), ii);
- }
- else
- {
- sprintf(arg.Publication.szFormId, "%s%02d", FVmsObj->VmsDownId.c_str(), ii);
- }
- FSvrCtl.obj = OBJ_RealTimeDisplay;
- FSvrCtl.DataPacketNumber = m_DataPacketNumber;
- FSvrCtl.Idx = ii;
- CmdCode = AI_TransferDone;
- break;
- }
- }
- }
- if (CmdCode == 0x00)
- {
- arg.Publication.SubscribeSerialNbr = NBR_BASE_SCHEDULEDDISPLAY;
- arg.Publication.obj = OBJ_ScheduledDisplay;
- FSvrCtl.obj = OBJ_ScheduledDisplay;
- FSvrCtl.DataPacketNumber = m_DataPacketNumber;
- CmdCode = AI_ScheduledDisplayMessage;
- }
- arg.Publication.Data.Form.Mode = FVmsObj->CTLMODE->Control;
- }
- else
- {
- int nFormCnt = m_pVmsFormList->Count();
- for (int ii = 0; ii < nFormCnt; ii++)
- {
- TVmsForm *pVmsForm = m_pVmsFormList->GetItem(ii);
- if (pVmsForm)
- {
- if (pVmsForm->SvcRes == false)
- {
- arg.Publication.SubscribeSerialNbr = NBR_BASE_REALTIMEDISPLAY + ii;
- arg.Publication.obj = OBJ_RealTimeDisplay;
- arg.Publication.Data.Form.Idx = ii;
- FSvrCtl.obj = OBJ_RealTimeDisplay;
- FSvrCtl.DataPacketNumber = m_DataPacketNumber;
- FSvrCtl.Idx = ii;
- CmdCode = AI_RealTimeDisplayMessage;
- break;
- }
- }
- }
- if (CmdCode == 0x00)
- {
- arg.Publication.SubscribeSerialNbr = NBR_BASE_SCHEDULEDDISPLAY;
- arg.Publication.obj = OBJ_ScheduledDisplay;
- FSvrCtl.obj = OBJ_ScheduledDisplay;
- FSvrCtl.DataPacketNumber = m_DataPacketNumber;
- CmdCode = AI_ScheduledDisplayMessage;
- }
- arg.Publication.Data.Form.Mode = FVmsObj->CTLMODE->Control;
- }
- }
- __finally
- {
- m_pVmsFormList->UnLock();
- if (nResult == VERR_NONE && CmdCode != 0x00)
- {
- nResult = ProcessCommand(CmdCode, &arg);
- }
- *AFlag = true;
- }
- }
- /* ON/OFF */
- if (FVmsObj->MODULE.PowerOnTime != FVmsObj->MODULE.PowerOffTime)
- {
- //On/Off 시각이 같지 않을 경우 On/Off 명령 수행
- if ((FVmsObj->MODULE.PowerOnTime == Now().FormatString("yyyymmddhhnn")) &&
- (FVmsObj->MODULE.Retry > 0))
- {
- arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER;
- arg.Publication.obj = OBJ_StatusControl;
- arg.Publication.Data.Ctl = CTL_MODULE_POWER_ON;
- CmdCode = AI_StatusControlMessage;
- nResult = ProcessCommand(CmdCode, &arg);
- if (nResult == SYS_ERR_NONE)
- {
- }
- LINFO("**** Module Power On: %d", FVmsObj->MODULE.Retry);
- --FVmsObj->MODULE.Retry; // 3회 전송
- *AFlag = true;
- return nResult;
- }
- if ((FVmsObj->MODULE.PowerOffTime == Now().FormatString("yyyymmddhhnn")) &&
- (FVmsObj->MODULE.Retry > 0))
- {
- arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER;
- arg.Publication.obj = OBJ_StatusControl;
- arg.Publication.Data.Ctl = CTL_MODULE_POWER_OFF;
- CmdCode = AI_StatusControlMessage;
- nResult = ProcessCommand(CmdCode, &arg);
- if (nResult == SYS_ERR_NONE)
- {
- }
- LINFO("**** Module Power Off: %d", FVmsObj->MODULE.Retry);
- --FVmsObj->MODULE.Retry; // 3회 전송
- *AFlag = true;
- return nResult;
- }
- }
- /* LUMINANCE */
- //LUMINANCE시각이 같을 경우 LUMINANCE 명령 수행
- if ((FVmsObj->LUMINANCE.SchTime == Now().FormatString("yyyymmddhhnn")) &&
- (FVmsObj->LUMINANCE.Retry > 0))
- {
- arg.Publication.SubscribeSerialNbr = NBR_LUMINANCE;
- arg.Publication.obj = OBJ_StatusControl;
- arg.Publication.Data.Ctl = CTL_LUMINANCE_SET;
- FCliCtl.CtlType = FVmsObj->LUMINANCE.Value;
- CmdCode = AI_StatusControlMessage;
- nResult = ProcessCommand(CmdCode, &arg);
- if (nResult == SYS_ERR_NONE)
- {
- }
- LINFO("**** Luminance control: %d", FVmsObj->LUMINANCE.Retry);
- --FVmsObj->LUMINANCE.Retry; // 3회 전송
- *AFlag = true;
- return nResult;
- }
- /* DOWNLOAD */
- if (FVmsObj->DOWNLOAD->Enable == vms_download_enable)
- {
- for (int ii = 0; ii < FVmsObj->DOWNLOAD->Count; ii++)
- {
- if (FVmsObj->DOWNLOAD->Unit[ii].SendResult == vms_download_fail)
- {
- arg.Publication.SubscribeSerialNbr = NBR_BASE_DOWNLOADGRAPHICDATA + ii;
- arg.Publication.obj = OBJ_DownloadGraphicData;
- arg.Publication.Data.Down.Idx = ii;
- FSvrCtl.obj = OBJ_DownloadGraphicData;
- FSvrCtl.DataPacketNumber = m_DataPacketNumber;
- FSvrCtl.Idx = ii;
- CmdCode = AI_DownloadGraphicDataMessage;
- break;
- }
- }
- if ((nResult == VERR_NONE) && (CmdCode != 0x00))
- {
- nResult = ProcessCommand(CmdCode, &arg);
- if (nResult == SYS_ERR_NONE)
- {
- }
- *AFlag = true;
- return nResult;
- }
- }
- return nResult;
- }
- //---------------------------------------------------------------------------
- /*
- *
- * arguments
- * void
- * return
- * void
- */
- int __fastcall TVMSSThread::CheckClientData(bool *AFlag)
- {
- FErrLine = 24;
- int nResult = VERR_NONE;
- IPCUDPPACKET *pPI = NULL;
- TList *pPackQueue;
- COMMAND_ARGUMENT arg;
- BYTE CmdCode;
- *AFlag = false;
- pPackQueue = FVmsObj->pPackQueue->LockList();
- try
- {
- for (int ii = 0; ii < pPackQueue->Count; ii++)
- {
- pPI = (IPCUDPPACKET *)pPackQueue->Items[ii];
- memcpy((char*)&FCliReq, pPI, sizeof(FCliReq));
- memset((char*)&FCliCtl, 0x00, sizeof(FCliCtl));
- memset((char*)&arg, 0x00, sizeof(arg));
- switch(pPI->OPCode)
- {
- case INT_OP_VMS_POWER_CTL:
- if (pPI->Data)
- {
- INT_VMS_POWER_CTL_REQ *pReq = (INT_VMS_POWER_CTL_REQ*)pPI->Data;
- memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID);
- memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID);
- memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME);
- FCliCtl.Result = CTL_RESULT_FAIL;
- if (pReq->Command == vms_board_power_on)
- {
- arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER;
- arg.Publication.obj = OBJ_StatusControl;
- arg.Publication.Data.Ctl = CTL_MODULE_POWER_ON;
- FCliCtl.CtlType = CTL_TYPE_MODULE_ON;
- CmdCode = AI_StatusControlMessage;
- }
- else
- if (pReq->Command == vms_board_power_off)
- {
- arg.Publication.SubscribeSerialNbr = NBR_MODULE_POWER;
- arg.Publication.obj = OBJ_StatusControl;
- arg.Publication.Data.Ctl = CTL_MODULE_POWER_OFF;
- FCliCtl.CtlType = CTL_TYPE_MODULE_OFF;
- CmdCode = AI_StatusControlMessage;
- }
- else
- {
- nResult = VERR_UNKNOWN;
- break;
- }
- }
- else
- {
- nResult = VERR_DATA_SIZE;
- }
- break;
- case INT_OP_VMS_LUMINANCE_CTL:
- if (pPI->Data)
- {
- INT_VMS_LUMINANCE_REQ *pReq = (INT_VMS_LUMINANCE_REQ*)pPI->Data;
- memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID);
- memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID);
- memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME);
- FCliCtl.Result = CTL_RESULT_FAIL;
- arg.Publication.SubscribeSerialNbr = NBR_LUMINANCE;
- arg.Publication.obj = OBJ_StatusControl;
- arg.Publication.Data.Ctl = CTL_LUMINANCE_SET;
- FCliCtl.CtlType = pReq->Luminance;
- CmdCode = AI_StatusControlMessage;
- }
- else
- {
- nResult = VERR_DATA_SIZE;
- }
- break;
- case INT_OP_VMS_RESET:
- if (pPI->Data)
- {
- INT_VMS_RESET_REQ *pReq = (INT_VMS_RESET_REQ*)pPI->Data;
- memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID);
- memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID);
- memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME);
- FCliCtl.Result = CTL_RESULT_FAIL;
- arg.Publication.SubscribeSerialNbr = NBR_CONTROLLER_RESET;
- arg.Publication.obj = OBJ_StatusControl;
- arg.Publication.Data.Ctl = CTL_CONTROLLER_RESET;
- FCliCtl.CtlType = CTL_TYPE_RESET;
- CmdCode = AI_StatusControlMessage;
- }
- else
- {
- nResult = VERR_DATA_SIZE;
- }
- break;
- case INT_OP_VMS_PARA_SET:
- if (pPI->Data)
- {
- INT_VMS_PARA_SET_REQ *pReq = (INT_VMS_PARA_SET_REQ*)pPI->Data;
- memcpy(FCliCtl.VmsId, pReq->VmsId, INT_VMS_MAX_ID);
- memcpy(FCliCtl.OperId, pReq->OperId, INT_VMS_MAX_OPER_ID);
- memcpy(FCliCtl.CmdTime, pReq->CmdTime, INT_VMS_MAX_DATETIME);
- FCliCtl.Result = CTL_RESULT_FAIL;
- arg.Publication.SubscribeSerialNbr = NBR_STATUS_SETTING;
- arg.Publication.obj = OBJ_StatusSetting;
- arg.Publication.Data.Set.SchMsgTime = (int)pReq->SchMsgTime;
- arg.Publication.Data.Set.ModuleTemp = (int)pReq->ModuleTemp;
- arg.Publication.Data.Set.FanTemp = (int)pReq->FanTemp;
- arg.Publication.Data.Set.HeaterTemp = (int)pReq->HeaterTemp;
- arg.Publication.Data.Set.ModuleFail = (int)pReq->ModuleFail;
- arg.Publication.Data.Set.RetryCount = (int)pReq->RetryCount;
- arg.Publication.Data.Set.TimeOut = (int)pReq->TimeOut;
- FCliCtl.Data.Para.SchMsgTime = (int)pReq->SchMsgTime;
- FCliCtl.Data.Para.ModuleTemp = (int)pReq->ModuleTemp;
- FCliCtl.Data.Para.FanTemp = (int)pReq->FanTemp;
- FCliCtl.Data.Para.HeaterTemp = (int)pReq->HeaterTemp;
- FCliCtl.Data.Para.ModuleFail = (int)pReq->ModuleFail;
- FCliCtl.Data.Para.RetryCount = (int)pReq->RetryCount;
- FCliCtl.Data.Para.TimeOut = (int)pReq->TimeOut;
- FCliCtl.CtlType = CTL_TYPE_PARA_SET;
- CmdCode = AI_StatusSettingMessage;
- }
- else
- {
- nResult = VERR_DATA_SIZE;
- }
- break;
- default:
- nResult = VERR_UNKNOWN_COMMAND;
- break;
- }
- if (nResult == VERR_NONE)
- {
- nResult = ProcessCommand(CmdCode, &arg);
- }
- //ClientResponse(nResult);
- if (pPI->Size > 0)
- {
- delete []pPI->Data;
- }
- delete pPI;
- pPI = NULL;
- pPackQueue->Delete(ii);
- *AFlag = true;
- break;
- }
- }
- __finally
- {
- FVmsObj->pPackQueue->UnlockList();
- }
- return nResult;
- }
- //---------------------------------------------------------------------------
- int TVMSSThread::LogData(char *ASndRcv, BYTE *AData, int ALen)
- {
- int result = -1;
- if (!FLogFile) return result;
- if (!FLogFile->FLogCfg.Data) return result;
- try
- {
- FLogFile->LogData(ASndRcv, AData, ALen);
- if (FVmsObj->FDispLog)
- {
- IPC_LOG_MESSAGE *pLog = &FLogMsg;//new IPC_LOG_MESSAGE;
- if (pLog)
- {
- pLog->Kind = eLOG_DATA;
- pLog->Flag = ASndRcv[0] == 'S' ? 1 : 2;
- pLog->Len = ALen > MAX_LOG_BUFFER ? MAX_LOG_BUFFER-1 : ALen;
- pLog->Tm = Now();
- pLog->Type = 'S';
- memset(pLog->Msg, 0x00, sizeof(pLog->Msg));
- memcpy(pLog->Msg, (char*)AData, pLog->Len);
- pLog->Obj = (void*)FVmsObj;
- DWORD dwResult = 0;
- LRESULT lResult = SEND_LOGMSG(FrmVmsLog->Handle, WM_LOG_DISPLAY, (WPARAM)pLog, NULL, SMTO_NORMAL, 2000, dwResult);
- if (lResult == 0)
- {
- dwResult = GetLastError();
- if (dwResult == ERROR_TIMEOUT)
- {
- }
- //SAFE_DELETE(pLog);
- }
- }
- }
- }
- catch(Exception &e)
- {
- }
- return result;
- }
- //---------------------------------------------------------------------------
- int TVMSSThread::SysLogWrite(int ALogKind, char *AFmt, ...)
- {
- va_list ap;
- int cnt = 0;
- char szFmtData[MAX_LOG_BUFFER];
- AnsiString sLogKind;
- int nStep = 0;
- if (!FLogFile) return cnt;
- bool bLog = false;
- switch(ALogKind)
- {
- case eLOG_INFO : bLog = FLogFile->FLogCfg.Info; sLogKind = " [INF] "; break;
- case eLOG_DATA : bLog = FLogFile->FLogCfg.Data; sLogKind = " [DAT] "; break;
- case eLOG_ERROR : bLog = FLogFile->FLogCfg.Error; sLogKind = " [ERR] "; break;
- case eLOG_WARNING: bLog = FLogFile->FLogCfg.Warning; sLogKind = " [WAN] "; break;
- case eLOG_DEBUG : bLog = FLogFile->FLogCfg.Debug; sLogKind = " [DBG] "; break;
- case eLOG_DETAIL : bLog = FLogFile->FLogCfg.Detail; sLogKind = " [DET] "; break;
- }
- if (!bLog) return -1;
- try
- {
- va_start(ap, AFmt);
- cnt = vsprintf(szFmtData, AFmt, ap);
- va_end(ap);
- FLogFile->LogWrite(NULL, ALogKind, szFmtData);
- IPC_LOG_MESSAGE *pLog = &FLogMsg;//new IPC_LOG_MESSAGE;
- if (pLog)
- {
- pLog->Kind = ALogKind;
- pLog->Flag = 0;
- pLog->Len = strlen(szFmtData);
- pLog->Tm = Now();
- pLog->Type = 'S';
- memset(pLog->Msg, 0x00, sizeof(pLog->Msg));
- sprintf(pLog->Msg, "%s+SVR %s, %s", sLogKind.c_str(), VMSID.c_str(), szFmtData);
- pLog->Obj = (void*)FVmsObj;
- DWORD dwResult = 0;
- LRESULT lResult = SEND_LOGMSG(FrmSysLog->Handle, WM_LOG_DISPLAY, pLog, NULL, SMTO_NORMAL, 2000, dwResult);
- if (lResult == 0)
- {
- dwResult = GetLastError();
- if (dwResult == ERROR_TIMEOUT)
- {
- }
- //SAFE_DELETE(pLog);
- }
- }
- if (FVmsObj->FDispLog)
- {
- IPC_LOG_MESSAGE *pLog2 = &FLogMsg;//new IPC_LOG_MESSAGE;
- if (pLog2)
- {
- pLog2->Kind = ALogKind;
- pLog2->Flag = 0;
- pLog2->Len = strlen(szFmtData);
- pLog2->Tm = Now();
- pLog2->Type = 'S';
- memset(pLog2->Msg, 0x00, sizeof(pLog2->Msg));
- sprintf(pLog2->Msg, "%s+SVR %s, %s", sLogKind.c_str(), VMSID.c_str(), szFmtData);
- pLog2->Obj = (void*)FVmsObj;
- DWORD dwResult = 0;
- LRESULT lResult = SEND_LOGMSG(FrmVmsLog->Handle, WM_LOG_DISPLAY, pLog2, NULL, SMTO_NORMAL, 2000, dwResult);
- if (lResult == 0)
- {
- dwResult = GetLastError();
- if (dwResult == ERROR_TIMEOUT)
- {
- }
- //SAFE_DELETE(pLog2);
- }
- }
- }
- }
- catch(Exception &e)
- {
- }
- return cnt;
- }
- //---------------------------------------------------------------------------
- int TVMSSThread::LogWrite(int ALogKind, char *AFmt, ...)
- {
- va_list ap;
- int cnt = 0;
- char szFmtData[MAX_LOG_BUFFER];
- AnsiString sLogKind;
- int nStep = 0;
- if (!FLogFile) return cnt;
- bool bLog = false;
- switch(ALogKind)
- {
- case eLOG_INFO : bLog = FLogFile->FLogCfg.Info; sLogKind = " [INF] "; break;
- case eLOG_DATA : bLog = FLogFile->FLogCfg.Data; sLogKind = " [DAT] "; break;
- case eLOG_ERROR : bLog = FLogFile->FLogCfg.Error; sLogKind = " [ERR] "; break;
- case eLOG_WARNING: bLog = FLogFile->FLogCfg.Warning; sLogKind = " [WAN] "; break;
- case eLOG_DEBUG : bLog = FLogFile->FLogCfg.Debug; sLogKind = " [DBG] "; break;
- case eLOG_DETAIL : bLog = FLogFile->FLogCfg.Detail; sLogKind = " [DET] "; break;
- }
- if (!bLog) return -1;
- try
- {
- va_start(ap, AFmt);
- cnt = vsprintf(szFmtData, AFmt, ap);
- va_end(ap);
- FLogFile->LogWrite(NULL, ALogKind, szFmtData);
- if (FVmsObj->FDispLog)
- {
- IPC_LOG_MESSAGE *pLog = &FLogMsg;//new IPC_LOG_MESSAGE;
- if (pLog)
- {
- pLog->Kind = ALogKind;
- pLog->Flag = 0;
- pLog->Len = strlen(szFmtData);
- pLog->Tm = Now();
- pLog->Type = 'S';
- memset(pLog->Msg, 0x00, sizeof(pLog->Msg));
- sprintf(pLog->Msg, "%s+SVR %s, %s", sLogKind.c_str(), VMSID.c_str(), szFmtData);
- pLog->Obj = (void*)FVmsObj;
- DWORD dwResult = 0;
- LRESULT lResult = SEND_LOGMSG(FrmVmsLog->Handle, WM_LOG_DISPLAY, pLog, NULL, SMTO_NORMAL, 2000, dwResult);
- if (lResult == 0)
- {
- dwResult = GetLastError();
- if (dwResult == ERROR_TIMEOUT)
- {
- }
- //SAFE_DELETE(pLog);
- }
- }
- }
- }
- catch(Exception &e)
- {
- }
- return cnt;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::CommandSubscription(Subscription_t *pSubscripiton, SUBSCRIPTION_ARGUMENT Arg)
- {
- FErrLine = 12;
- int result;
- SubscriptionData_t *pData;
- asn_enc_rval_t er; /* Encoder return value */
- BYTE MsgBuf[SERVER_MSG_BUF_SIZE];
- int eLen;
- int i, count = 0;
- result = SYS_ERR_OTHER;
- if (asn_long2INTEGER(&pSubscripiton->datexSubscribe_Serial_nbr, Arg.nbr) != ASN_ERR_NONE)
- {
- return -1;
- }
- pSubscripiton->datexSubscribe_Type.present = SubscriptionType_PR_subscription;
- pData = &pSubscripiton->datexSubscribe_Type.choice.subscription;
- pData->datexSubscribe_Persistent_bool = false;
- if (asn_long2INTEGER(&pData->datexSubscribe_Status_cd, datexSubscribe_Status_cd_new) != ASN_ERR_NONE)
- {
- return -3;
- }
- switch(Arg.mode)
- {
- case SubscriptionMode_PR_single:
- pData->datexSubscribe_Mode.present = SubscriptionMode_PR_single;
- break;
- case SubscriptionMode_PR_event_driven:
- pData->datexSubscribe_Mode.present = SubscriptionMode_PR_event_driven;
- /* Registered_PR_continuous 1 */
- /* Registered_PR_daily 2 */
- pData->datexSubscribe_Mode.choice.event_driven.present = Registered_PR_continuous;
- pData->datexSubscribe_Mode.choice.event_driven.choice.continuous.datexRegistered_UpdateDelay_qty = Arg.delay;
- /* pData->datexSubscribe_Mode.choice.event_driven.choice.continuous.datexRegistered_StartTime */
- /* pData->datexSubscribe_Mode.choice.event_driven.choice.continuous.datexRegistered_EndTime */
- break;
- case SubscriptionMode_PR_periodic:
- pData->datexSubscribe_Mode.present = SubscriptionMode_PR_periodic;
- /* Registered_PR_continuous 1 */
- /* Registered_PR_daily 2 */
- pData->datexSubscribe_Mode.choice.periodic.present = Registered_PR_continuous;
- pData->datexSubscribe_Mode.choice.periodic.choice.continuous.datexRegistered_UpdateDelay_qty = Arg.delay;
- /* pData->datexSubscribe_Mode.choice.periodic.choice.continuous.datexRegistered_StartTime */
- /* pData->datexSubscribe_Mode.choice.periodic.choice.continuous.datexRegistered_EndTime */
- break;
- default:
- pData->datexSubscribe_Mode.present = SubscriptionMode_PR_single;
- break;
- }
- if (asn_long2INTEGER(&pData->datexSubscribe_PublishFormat_cd, datexSubscribe_PublishFormat_cd_dataPacket) != ASN_ERR_NONE)
- {
- return -4;
- }
- pData->datexSubscription_Priority_nbr = 1;
- pData->datexSubscribe_Guarantee_bool = true;
- #if 0
- {
- long lv;
- asn_INTEGER2long(&pSubscripiton->datexSubscribe_Serial_nbr, &lv);
- LDEBUG(" SubscriptionMode: %d", Arg.mode);
- LDEBUG("datexSubscribe_Serial_nbr: %u", lv);
- LDEBUG(" datexSubscribe_Type: %d", pSubscripiton->datexSubscribe_Type.present);
- switch(pSubscripiton->datexSubscribe_Type.present)
- {
- case SubscriptionType_PR_subscription:
- asn_INTEGER2long(&pData->datexSubscribe_Status_cd, &lv);
- LDEBUG("datexSubscribe_Persistent_bool: %d", pData->datexSubscribe_Persistent_bool);
- LDEBUG(" datexSubscribe_Status_cd: %d", lv);
- LDEBUG(" datexSubscribe_Mode: %d", pData->datexSubscribe_Mode.present);
- switch(pData->datexSubscribe_Mode.present)
- {
- case SubscriptionMode_PR_single:
- break;
- case SubscriptionMode_PR_event_driven:
- case SubscriptionMode_PR_periodic:
- {
- Registered_t *pRegistered;
- int numbits, bit;
- if(pData->datexSubscribe_Mode.present == SubscriptionMode_PR_event_driven)
- {
- pRegistered = &pData->datexSubscribe_Mode.choice.event_driven;
- }
- else
- {
- pRegistered = &pData->datexSubscribe_Mode.choice.periodic;
- }
- LDEBUG("Registered: %d", pRegistered->present);
- switch(pRegistered->present)
- {
- case Registered_PR_continuous:
- LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.continuous.datexRegistered_UpdateDelay_qty);
- if (pRegistered->choice.continuous.datexRegistered_StartTime)
- {
- LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_StartTime);
- }
- if (pRegistered->choice.continuous.datexRegistered_EndTime)
- {
- LOG_WriteTime(pRegistered->choice.continuous.datexRegistered_EndTime);
- }
- break;
- case Registered_PR_daily:
- LDEBUG("datexRegistered_UpdateDelay_qty: %u", pRegistered->choice.daily.datexRegistered_UpdateDelay_qty);
- numbits = DATEX_NUMBITS(pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd);
- LDEBUG("datexRegistered_DaysOfWeek_cd numbits: %d", numbits);
- for (bit = 0; bit < numbits; bit++)
- {
- LDEBUG("[%d]: %d", bit, ASN1C_CheckBitString(&pRegistered->choice.daily.datexRegistered_DaysOfWeek_cd, bit));
- }
- if (pRegistered->choice.daily.datexRegistered_StartDate)
- {
- LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartDate);
- }
- if (pRegistered->choice.daily.datexRegistered_EndDate)
- {
- LOG_WriteTime(pRegistered->choice.daily.datexRegistered_EndDate);
- }
- if (pRegistered->choice.daily.datexRegistered_StartTime)
- {
- LOG_WriteTime(pRegistered->choice.daily.datexRegistered_StartTime);
- }
- if (pRegistered->choice.daily.datexRegistered_Duration_qty)
- {
- //LDEBUG("datexRegistered_Duration_qty: %u", *pRegistered->choice.daily.datexRegistered_Duration_qty);
- }
- break;
- default:
- LDEBUG("Unknown Registered %d", pRegistered->present);
- break;
- }/* end swtich */
- }
- break;
- default :
- LDEBUG("Unknown datexSubscribe_Mode %d", pData->datexSubscribe_Mode.present);
- break;
- }/* end switch */
- asn_INTEGER2long(&pData->datexSubscribe_PublishFormat_cd, &lv);
- LDEBUG("datexSubscribe_PublishFormat_cd: %d", lv);
- LDEBUG(" datexSubscription_Priority_nbr: %d", pData->datexSubscription_Priority_nbr);
- LDEBUG(" datexSubscribe_Guarantee_bool: %d", pData->datexSubscribe_Guarantee_bool);
- break;
- case SubscriptionType_PR_datexSubscribe_CancelReason_cd:
- LDEBUG("datexSubscribe_CancelReason_cd: %d", pSubscripiton->datexSubscribe_Type.choice.datexSubscribe_CancelReason_cd);
- break;
- default:
- LDEBUG("Unknown datexSubscribe_Type %d", pSubscripiton->datexSubscribe_Type.present);
- break;
- }/* end switch */
- }
- #endif
- ASN1C_SetObjId(&pData->datexSubscribe_Pdu.endApplication_Message_id, Arg.obj);
- switch(Arg.obj)
- {
- case OBJ_GeneralStatus: /* 기본상태정보 */
- {
- LINFO(" *** OBJ_GeneralStatus 전송");
- GeneralStatusMessage_t *pGS;
- MessageBodyGeneralStatusMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyGeneralStatusMessage_t));
- for ( i = 0; i < count; i++)
- {
- if ((pGS = (GeneralStatusMessage_t *)ASN1C_Alloc(sizeof(GeneralStatusMessage_t))) == NULL)
- {
- result = -10;
- break;
- }
- if(ASN_SEQUENCE_ADD(&Msg, pGS)!= ASN_ERR_NONE)
- {
- result = -11;
- break;
- }
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyGeneralStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
- {
- result = -12;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -13;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyGeneralStatusMessage, &Msg);
- }
- break;
- #if 1
- case OBJ_PowerStatus: /* 전원상태정보 */
- {
- LINFO(" *** OBJ_PowerStatus 전송");
- PowerStatusMessage_t *pMS;
- MessageBodyPowerStatusMessage_t Msg;
- memset((void *)&Msg, 0x00, sizeof(MessageBodyPowerStatusMessage_t));
- for ( i = 0; i < count; i++)
- {
- if ((pMS = (PowerStatusMessage_t *)ASN1C_Alloc(sizeof(PowerStatusMessage_t))) == NULL)
- {
- result = -30;
- break;
- }
- if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE)
- {
- result = -31;
- break;
- }
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyPowerStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
- {
- result = -32;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -33;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyPowerStatusMessage, &Msg);
- }
- break;
- #endif
- case OBJ_ModuleStatus: /* 모듈상태정보 */
- {
- LINFO(" *** OBJ_ModuleStatus 전송");
- ModuleStatusMessage_t *pMS;
- MessageBodyModuleStatusMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyModuleStatusMessage_t));
- for ( i = 0; i < count; i++)
- {
- if ((pMS = (ModuleStatusMessage_t *)ASN1C_Alloc(sizeof(ModuleStatusMessage_t))) == NULL)
- {
- result = -30;
- break;
- }
- if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE)
- {
- result = -31;
- break;
- }
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyModuleStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
- {
- result = -32;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -33;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyModuleStatusMessage, &Msg);
- }
- break;
- #if 0
- case OBJ_DotStatus: /* 도트상태정보 */
- break;
- #endif
- case OBJ_ScreenStatus: /* 표출상태정보 */
- {
- LINFO(" *** OBJ_ScreenStatus 전송");
- ScreenStatusMessage_t *pMS;
- MessageBodyScreenStatusMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyScreenStatusMessage_t));
- for ( i = 0; i < count; i++)
- {
- if ((pMS = (ScreenStatusMessage_t *)ASN1C_Alloc(sizeof(ScreenStatusMessage_t))) == NULL)
- {
- result = -30;
- break;
- }
- if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE)
- {
- result = -31;
- break;
- }
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyScreenStatusMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
- {
- result = -32;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -33;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyScreenStatusMessage, &Msg);
- }
- break;
- case OBJ_DisplayingData: /* 표출정보 */
- {
- LINFO(" *** OBJ_DisplayingData 전송");
- DisplayingDataMessage_t *pMS;
- MessageBodyDisplayingDataMessage_t Msg; /* Type to encode */
- memset((void *)&Msg, 0x00, sizeof(MessageBodyDisplayingDataMessage_t));
- for ( i = 0; i < count; i++)
- {
- if ((pMS = (DisplayingDataMessage_t *)ASN1C_Alloc(sizeof(DisplayingDataMessage_t))) == NULL)
- {
- result = -30;
- break;
- }
- if (ASN_SEQUENCE_ADD(&Msg, pMS)!= ASN_ERR_NONE)
- {
- result = -31;
- break;
- }
- }/* end for */
- /* Encode */
- memset(MsgBuf, 0x00, sizeof(MsgBuf));
- eLen = -1;
- er = der_encode_to_buffer(&asn_DEF_MessageBodyDisplayingDataMessage, &Msg, MsgBuf, sizeof(MsgBuf));
- if (er.encoded == -1)
- {
- /*
- * Failed to encode the data.
- */
- SERROR("Cannot encode %s", er.failed_type->name);
- result = SYS_ERR_MESSAGE_ENCODE;
- }
- else
- {
- /* Return the number of bytes */
- eLen = er.encoded;
- pData->datexSubscribe_Pdu.endApplication_Message_msg.buf = (uint8_t *)ASN1C_Alloc(eLen);
- if (pData->datexSubscribe_Pdu.endApplication_Message_msg.buf == NULL)
- {
- result = -32;
- break;
- }
- if (OCTET_STRING_fromBuf((OCTET_STRING_t *)&pData->datexSubscribe_Pdu.endApplication_Message_msg,
- (char *)MsgBuf, eLen) != ASN_ERR_NONE)
- {
- result = -33;
- break;
- }
- result = SYS_ERR_NONE;
- }/* end if */
- ASN1C_FreeC(&asn_DEF_MessageBodyDisplayingDataMessage, &Msg);
- }
- break;
- default:
- result = SYS_ERR_UNKNOWN_MESSAGE_ID;
- break;
- }
- return result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::SendLoginAccept()
- {
- TStringList *sl = NULL;
- //Data Dump: 104 Bytes
- String sMsg =
- "30 66 80 01 01 81 5D 30 5B 80 01 08 81 02 03 12 "
- "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
- "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
- "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
- "11 83 01 0D 84 01 08 85 01 19 A6 03 82 01 00 A7 "
- "06 80 01 09 81 01 00 A4 0B A8 09 80 01 01 A1 04 "
- "80 02 51 01 82 02 B3 EF ";
- try
- {
- sl = new TStringList;
- sl->Delimiter = ' ';
- sl->StrictDelimiter = true;
- sl->DelimitedText = sMsg;
- int ii;
- unsigned int hn, ln;
- BYTE chn, cln, val;
- char szData[2048];
- BYTE RxBuff[VMS_MAX_PACKET_SIZE];
- int RxLen;
- RxLen = 0;
- memset(RxBuff, 0x00, sizeof(RxBuff));
- for (ii = 0; ii < sl->Count; ii++)
- {
- AnsiString sTemp = sl->Strings[ii];
- if (sTemp.Trim() == "") continue;
- sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll);
- if (sTemp.Trim() == "\r\n") continue;
- memset(szData, 0x00, sizeof(szData));
- memcpy(szData, sTemp.c_str(), sTemp.Length());
- chn = (BYTE)szData[0];
- cln = (BYTE)szData[1];
- hn = chn > '9' ? chn - 'A' + 10 : chn - '0';
- ln = cln > '9' ? cln - 'A' + 10 : cln - '0';
- val = (BYTE)((hn << 4 ) | ln);
- RxBuff[RxLen] = val;
- RxLen++;
- }
- int nSends = pClientSocket->SendBuf(RxBuff, RxLen);
- LINFO("SendLoginAccept: %d/%d Bytes", RxLen, nSends);
- if (sl) delete sl;
- }
- catch(Exception &e)
- {
- //Application->ShowException(&e);
- }
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::SendSubscriptionAccept(int AMsgId)
- {
- TStringList *sl = NULL;
- String sMsg = "";
- String sRealTimeDisplay =
- "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 14 "
- "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
- "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
- "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
- "11 83 01 0D 84 01 08 85 01 19 A6 03 82 01 00 A7 "
- "06 80 01 09 81 01 00 A4 0A A8 08 80 01 04 A1 03 "
- "82 01 01 82 02 90 6A ";
- String sScheduledDisplay =
- "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 15 "
- "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
- "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
- "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
- "11 83 01 0D 84 01 08 85 01 1A A6 03 82 01 00 A7 "
- "06 80 01 09 81 01 00 A4 0A A8 08 80 01 05 A1 03 "
- "82 01 02 82 02 D5 7F ";
- String sDownloadGraphicData =
- "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 16 "
- "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
- "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
- "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
- "11 83 01 0D 84 01 08 85 01 1A A6 03 82 01 00 A7 "
- "06 80 01 09 81 01 00 A4 0A A8 08 80 01 06 A1 03 "
- "82 01 03 82 02 19 5C ";
- String sStatusControl =
- "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 17 "
- "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
- "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
- "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
- "11 83 01 0D 84 01 08 85 01 1A A6 03 82 01 00 A7 "
- "06 80 01 09 81 01 00 A4 0A A8 08 80 01 07 A1 03 "
- "82 01 04 82 02 DF 43 ";
- String sStatusSetting =
- "30 65 80 01 01 81 5C 30 5A 80 01 08 81 02 03 18 "
- "82 01 00 A3 42 81 08 30 30 30 30 30 30 30 30 83 "
- "08 30 30 30 30 30 30 30 30 85 0A 56 4D 53 31 30 "
- "30 30 30 31 33 A7 20 80 02 07 E0 81 01 0B 82 01 "
- "11 83 01 0D 84 01 08 85 01 1B A6 03 82 01 00 A7 "
- "06 80 01 09 81 01 00 A4 0A A8 08 80 01 08 A1 03 "
- "82 01 05 82 02 DF 10 ";
- switch(AMsgId)
- {
- case OBJ_RealTimeDisplay: /* 실시간정보표출 */
- sMsg = sRealTimeDisplay;
- //arg.Accept.nbr = 4;
- //arg.Accept.sub = 1;
- break;
- case OBJ_ScheduledDisplay: /* 계획된정보표출 */
- sMsg = sScheduledDisplay;
- //arg.Accept.nbr = 5;
- //arg.Accept.sub = 2;
- break;
- case OBJ_DownloadGraphicData: /* 그래픽데이터 다운로드 */
- sMsg = sDownloadGraphicData;
- //arg.Accept.nbr = 6;
- //arg.Accept.sub = 3;
- break;
- case OBJ_StatusControl: /* 상태제어 */
- sMsg = sStatusControl;
- //arg.Accept.nbr = 7;
- //arg.Accept.sub = 4;
- break;
- case OBJ_StatusSetting: /* 상태설정 */
- sMsg = sStatusSetting;
- //arg.Accept.nbr = 8;
- //arg.Accept.sub = 5;
- break;
- default:
- return SYS_ERR_OTHER;
- }
- try
- {
- sl = new TStringList;
- sl->Delimiter = ' ';
- sl->StrictDelimiter = true;
- sl->DelimitedText = sMsg;
- int ii;
- unsigned int hn, ln;
- BYTE chn, cln, val;
- char szData[2048];
- BYTE RxBuff[VMS_MAX_PACKET_SIZE];
- int RxLen;
- RxLen = 0;
- memset(RxBuff, 0x00, sizeof(RxBuff));
- for (ii = 0; ii < sl->Count; ii++)
- {
- AnsiString sTemp = sl->Strings[ii];
- if (sTemp.Trim() == "") continue;
- sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll);
- if (sTemp.Trim() == "\r\n") continue;
- memset(szData, 0x00, sizeof(szData));
- memcpy(szData, sTemp.c_str(), sTemp.Length());
- chn = (BYTE)szData[0];
- cln = (BYTE)szData[1];
- hn = chn > '9' ? chn - 'A' + 10 : chn - '0';
- ln = cln > '9' ? cln - 'A' + 10 : cln - '0';
- val = (BYTE)((hn << 4 ) | ln);
- RxBuff[RxLen] = val;
- RxLen++;
- }
- int nSends = pClientSocket->SendBuf(RxBuff, RxLen);
- LINFO("SendSubscriptionAccept: [%02X] %d/%d Bytes", AMsgId, RxLen, nSends);
- if (sl) delete sl;
- }
- catch(Exception &e)
- {
- //Application->ShowException(&e);
- }
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::SendRealTimeDisplay(int AIndex)
- {
- TStringList *sl = NULL;
- //Data Dump: 104 Bytes
- String sMsg = "";
- if (AIndex == 0)
- sMsg =
- "30 82 02 CE 80 01 01 81 82 02 C3 30 82 02 BF 80 "
- "01 00 81 02 03 8A 82 01 00 A3 42 81 08 30 30 30 "
- "30 30 30 30 30 83 08 30 30 30 30 30 30 30 30 85 "
- "0A 56 4D 53 31 30 30 30 30 31 33 A7 20 80 02 07 "
- "E0 81 01 0B 82 01 11 83 01 0D 84 01 0A 85 01 0C "
- "A6 03 82 01 00 A7 06 80 01 09 81 01 00 A4 82 02 "
- "6D A6 82 02 69 80 01 FF A1 82 02 62 A0 82 02 5E "
- "30 82 02 5A 80 01 31 81 01 01 82 01 00 A3 82 02 "
- "4D A1 82 02 49 80 06 28 F3 6B 02 00 01 A1 82 02 "
- "3D 30 82 02 39 30 82 02 35 80 01 31 81 01 0A 82 "
- "01 00 83 01 00 84 01 00 85 01 0C A6 82 02 1F 30 "
- "23 80 01 02 81 01 00 82 02 00 80 83 01 08 84 01 "
- "00 A5 11 A2 0F 80 01 00 81 01 1D 82 01 0F 83 04 "
- "30 30 30 32 30 23 80 01 02 81 01 00 82 02 00 80 "
- "83 01 2A 84 01 00 A5 11 A2 0F 80 01 00 81 01 1D "
- "82 01 0F 83 04 30 30 30 32 30 23 80 01 02 81 01 "
- "00 82 02 01 63 83 01 23 84 01 00 A5 11 A2 0F 80 "
- "01 00 81 01 15 82 01 19 83 04 30 30 30 38 30 23 "
- "80 01 02 81 01 00 82 02 01 63 83 01 05 84 01 00 "
- "A5 11 A2 0F 80 01 00 81 01 15 82 01 19 83 04 30 "
- "30 30 35 30 32 80 01 00 81 01 00 82 02 00 A9 83 "
- "01 25 84 01 00 A5 20 A0 1E 80 01 03 81 01 11 82 "
- "06 B1 BC B8 B2 C3 BC 83 01 02 84 0B EA B8 88 EA "
- "B3 A1 49 43 EC 95 9E 30 35 80 01 00 81 01 00 82 "
- "01 02 83 01 25 84 01 00 A5 24 A0 22 80 01 03 81 "
- "01 11 82 06 B1 BC B8 B2 C3 BC 83 01 02 84 0F EA "
- "B5 AC EC 84 B1 EC 9D B4 EB A7 88 ED 8A B8 30 2D "
- "80 01 00 81 01 00 82 02 01 27 83 01 05 84 01 00 "
- "A5 1B A0 19 80 01 03 81 01 11 82 06 B1 BC B8 B2 "
- "C3 BC 83 01 02 84 06 EC A7 80 EC B2 B4 30 36 80 "
- "01 00 81 01 00 82 02 00 9D 83 01 03 84 01 00 A5 "
- "24 A0 22 80 01 02 81 01 11 82 06 B1 BC B8 B2 C3 "
- "BC 83 01 02 84 0F EC A3 BD EC A0 84 EC 82 AC EA "
- "B1 B0 EB A6 AC 30 35 80 01 00 81 01 00 82 01 02 "
- "83 01 03 84 01 00 A5 24 A0 22 80 01 02 81 01 11 "
- "82 06 B1 BC B8 B2 C3 BC 83 01 02 84 0F EB B3 B4 "
- "EC A0 95 EA B5 90 EC B0 A8 EB A1 9C 30 2A 80 01 "
- "00 81 01 00 82 02 01 4A 83 01 25 84 01 00 A5 18 "
- "A0 16 80 01 02 81 01 11 82 06 B1 BC B8 B2 C3 BC "
- "83 01 02 84 03 EB B6 84 30 2A 80 01 00 81 01 00 "
- "82 02 01 1C 83 01 25 84 01 00 A5 18 A0 16 80 01 "
- "02 81 01 11 82 06 B1 BC B8 B2 C3 BC 83 01 02 84 "
- "03 EC 95 BD 30 28 80 01 00 81 01 00 82 02 01 39 "
- "83 01 25 84 01 00 A5 16 A0 14 80 01 02 81 01 11 "
- "82 06 B1 BC B8 B2 C3 BC 83 01 02 84 01 35 82 02 "
- "C1 95 ";
- else
- sMsg =
- "30 82 01 8B 80 01 01 81 82 01 80 30 82 01 7C 80 "
- "01 00 81 02 03 8B 82 01 00 A3 42 81 08 30 30 30 "
- "30 30 30 30 30 83 08 30 30 30 30 30 30 30 30 85 "
- "0A 56 4D 53 31 30 30 30 30 31 33 A7 20 80 02 07 "
- "E0 81 01 0B 82 01 11 83 01 0D 84 01 0A 85 01 0C "
- "A6 03 82 01 00 A7 06 80 01 09 81 01 00 A4 82 01 "
- "2A A6 82 01 26 80 01 FF A1 82 01 1F A0 82 01 1B "
- "30 82 01 17 80 01 31 81 01 01 82 01 00 A3 82 01 "
- "0A A1 82 01 06 80 06 28 F3 6B 02 00 01 A1 81 FB "
- "30 81 F8 30 81 F5 80 01 32 81 01 04 82 01 00 83 "
- "01 00 84 01 00 85 01 04 A6 81 E0 30 3F 80 01 00 "
- "81 01 00 82 01 11 83 01 23 84 01 00 A5 2E A0 2C "
- "80 01 02 81 01 13 82 06 B1 BC B8 B2 C3 BC 83 01 "
- "02 84 19 28 32 30 31 36 2E 30 36 2E 31 33 20 7E "
- "20 32 30 31 37 2E 31 32 2E 33 31 29 30 30 80 01 "
- "00 81 01 00 82 02 01 27 83 01 05 84 01 00 A5 1E "
- "A0 1C 80 01 01 81 01 14 82 06 B1 BC B8 B2 C3 BC "
- "83 01 02 84 09 EA B3 B5 EC 82 AC EC A4 91 30 34 "
- "80 01 00 81 01 00 82 02 00 9B 83 01 05 84 01 00 "
- "A5 22 A0 20 80 01 03 81 01 14 82 06 B1 BC B8 B2 "
- "C3 BC 83 01 02 84 0D EB B2 8C EB A7 90 7E EB A7 "
- "A4 EC 86 A1 30 35 80 01 00 81 01 00 82 01 0A 83 "
- "01 05 84 01 00 A5 24 A0 22 80 01 02 81 01 13 82 "
- "06 B1 BC B8 B2 C3 BC 83 01 02 84 0F EB B6 84 EB "
- "8B B9 EC 88 98 EC 84 9C EB A1 9C 82 02 73 03 ";
- try
- {
- sl = new TStringList;
- sl->Delimiter = ' ';
- sl->StrictDelimiter = true;
- sl->DelimitedText = sMsg;
- int ii;
- unsigned int hn, ln;
- BYTE chn, cln, val;
- char szData[2048];
- BYTE RxBuff[VMS_MAX_PACKET_SIZE];
- int RxLen;
- RxLen = 0;
- memset(RxBuff, 0x00, sizeof(RxBuff));
- for (ii = 0; ii < sl->Count; ii++)
- {
- AnsiString sTemp = sl->Strings[ii];
- if (sTemp.Trim() == "") continue;
- sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll);
- if (sTemp.Trim() == "\r\n") continue;
- memset(szData, 0x00, sizeof(szData));
- memcpy(szData, sTemp.c_str(), sTemp.Length());
- chn = (BYTE)szData[0];
- cln = (BYTE)szData[1];
- hn = chn > '9' ? chn - 'A' + 10 : chn - '0';
- ln = cln > '9' ? cln - 'A' + 10 : cln - '0';
- val = (BYTE)((hn << 4 ) | ln);
- RxBuff[RxLen] = val;
- RxLen++;
- }
- int nSends = pClientSocket->SendBuf(RxBuff, RxLen);
- LINFO("SendRealTimeDisplay: %d/%d Bytes", RxLen, nSends);
- if (sl) delete sl;
- }
- catch(Exception &e)
- {
- //Application->ShowException(&e);
- }
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::SendScheduledDisplay()
- {
- TStringList *sl = NULL;
- //Data Dump: 104 Bytes
- String sMsg =
- "30 81 8E 80 01 01 81 81 84 30 81 81 80 01 00 81 "
- "02 03 8C 82 01 00 A3 42 81 08 30 30 30 30 30 30 "
- "30 30 83 08 30 30 30 30 30 30 30 30 85 0A 56 4D "
- "53 31 30 30 30 30 31 33 A7 20 80 02 07 E0 81 01 "
- "0B 82 01 11 83 01 0D 84 01 0A 85 01 0C A6 03 82 "
- "01 00 A7 06 80 01 09 81 01 00 A4 31 A6 2F 80 01 "
- "FF A1 2A A0 28 30 26 80 01 32 81 01 02 82 01 00 "
- "A3 1B A1 19 80 06 28 F3 6B 02 00 02 A1 0F 30 0D "
- "30 0B 80 01 02 A1 06 04 01 31 04 01 32 82 02 10 "
- "5D ";
- try
- {
- sl = new TStringList;
- sl->Delimiter = ' ';
- sl->StrictDelimiter = true;
- sl->DelimitedText = sMsg;
- int ii;
- unsigned int hn, ln;
- BYTE chn, cln, val;
- char szData[2048];
- BYTE RxBuff[VMS_MAX_PACKET_SIZE];
- int RxLen;
- RxLen = 0;
- memset(RxBuff, 0x00, sizeof(RxBuff));
- for (ii = 0; ii < sl->Count; ii++)
- {
- AnsiString sTemp = sl->Strings[ii];
- if (sTemp.Trim() == "") continue;
- sTemp = StringReplace(sTemp, " ", "", TReplaceFlags() << rfReplaceAll);
- if (sTemp.Trim() == "\r\n") continue;
- memset(szData, 0x00, sizeof(szData));
- memcpy(szData, sTemp.c_str(), sTemp.Length());
- chn = (BYTE)szData[0];
- cln = (BYTE)szData[1];
- hn = chn > '9' ? chn - 'A' + 10 : chn - '0';
- ln = cln > '9' ? cln - 'A' + 10 : cln - '0';
- val = (BYTE)((hn << 4 ) | ln);
- RxBuff[RxLen] = val;
- RxLen++;
- }
- int nSends = pClientSocket->SendBuf(RxBuff, RxLen);
- LINFO("SendScheduledDisplay: %d/%d Bytes", RxLen, nSends);
- if (sl) delete sl;
- }
- catch(Exception &e)
- {
- //Application->ShowException(&e);
- }
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::SendFtpImage()
- {
- LINFO("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK");
- int result;
- result = ProcessCommand(AI_TransferDone, NULL);
- return SYS_ERR_NONE;
- }
- //---------------------------------------------------------------------------
- int __fastcall TVMSSThread::DownloadSymbolImage()
- {
- int nResult;
- COMMAND_ARGUMENT arg;
- BYTE CmdCode;
- CmdCode = 0x00;
- memset(&arg, 0x00, sizeof(arg));
- AnsiString sFtpImgId;
- try
- {
- CDSImageItr it;
- for(it=ImageManager->FLists.FMapObject.begin(); it != ImageManager->FLists.FMapObject.end(); ++it)
- {
- TCDSImage *pTmp = (TCDSImage*)it->second;
- //FOR_STL(TCDSImage*, pTmp, ImageManager->FLists)
- //{
- sFtpImgId = GetFtpImageId(pTmp->Nmbr);
- if (sFtpImgId.SubString(1,1) == "7" || pTmp->VmsType == "VMP1")
- continue; /* 도형식 배경이미지는 다운로드 할 필요 없음 */
- arg.Publication.SubscribeSerialNbr = 0;
- arg.Publication.obj = OBJ_RealTimeDisplay;
- arg.Publication.Data.Form.Idx = 0;
- sprintf(arg.Publication.szFormId, "%s", sFtpImgId.c_str());
- CmdCode = AI_TransferDone;
- nResult = ProcessCommand(CmdCode, &arg);
- Sleep(100);
- }
- }
- catch(Exception &e)
- {
- }
- FVmsObj->FSymbolDownload = false;
- return nResult;
- }
- //---------------------------------------------------------------------------
|