MessageHandler.c 965 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  56. //========================================
  57. // OCPP status/previous related variables
  58. //========================================
  59. static int GunStatusInterval = 10;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  118. }clientTime;
  119. typedef union
  120. {
  121. //Operations Initiated by Central System
  122. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  123. struct
  124. {
  125. //CsMsgValue[0]
  126. unsigned char StatusNotificationReq:1; //bit 0,
  127. unsigned char StatusNotificationConf:1; //bit 1,
  128. unsigned char TriggerMeterValue:1; //bit 2,
  129. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  130. unsigned char isOnCharging:1; //bit 4.
  131. unsigned char :3; //bit 5~7
  132. }bits[CONNECTOR_QUANTITY];
  133. }CpinitiateMsg;
  134. CpinitiateMsg cpinitateMsg;
  135. //GetConfiguration Array
  136. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  139. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  140. static char *ChargePointErrorCodeStr[] = {
  141. MACROSTR(ConnectorLockFailure),
  142. MACROSTR(EVCommunicationError),
  143. MACROSTR(GroundFailure),
  144. MACROSTR(HighTemperature),
  145. MACROSTR(InternalError),
  146. MACROSTR(LocalListConflict),
  147. MACROSTR(NoError),
  148. MACROSTR(OtherError),
  149. MACROSTR(OverCurrentFailure),
  150. MACROSTR(OverVoltage),
  151. MACROSTR(PowerMeterFailure),
  152. MACROSTR(PowerSwitchFailure),
  153. MACROSTR(ReaderFailure),
  154. MACROSTR(ResetFailure),
  155. MACROSTR(UnderVoltage),
  156. MACROSTR(WeakSignal)
  157. };
  158. static char * ChargePointStatusStr[] = {
  159. MACROSTR(Available),
  160. MACROSTR(Preparing),
  161. MACROSTR(Charging),
  162. MACROSTR(SuspendedEVSE),
  163. MACROSTR(SuspendedEV),
  164. MACROSTR(Finishing),
  165. MACROSTR(Reserved),
  166. MACROSTR(Unavailable),
  167. MACROSTR(Faulted)
  168. };
  169. static char *RegistrationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Pending),
  172. MACROSTR(Rejected)
  173. };
  174. static char *AvailabilityTypeStr[] = {
  175. MACROSTR(Inoperative),
  176. MACROSTR(Operative)
  177. };
  178. static char *AvailabilityStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(Scheduled)
  182. };
  183. static char *ConfigurationStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected),
  186. MACROSTR(RebootRequired),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearCacheStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Rejected)
  192. };
  193. static char *ChargingProfilePurposeTypeStr[] = {
  194. MACROSTR(ChargePointMaxProfile),
  195. MACROSTR(TxDefaultProfile),
  196. MACROSTR(TxProfile)
  197. };
  198. static char *ChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Rejected),
  201. MACROSTR(NotSupported)
  202. };
  203. static char *ClearChargingProfileStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Unknown)
  206. };
  207. static char *GetCompositeScheduleStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *UpdateTypeStr[] = {
  212. MACROSTR(Differential),
  213. MACROSTR(Full)
  214. };
  215. static char *UpdateStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Failed),
  218. MACROSTR(NotSupported),
  219. MACROSTR(VersionMismatch)
  220. };
  221. static char *RemoteStartStopStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Rejected)
  224. };
  225. static char *ReservationStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Faulted),
  228. MACROSTR(Occupied),
  229. MACROSTR(Rejected),
  230. MACROSTR(Unavailable)
  231. };
  232. static char *ResetTypeStr[] = {
  233. MACROSTR(Hard),
  234. MACROSTR(Soft)
  235. };
  236. static char *ResetStatusStr[] = {
  237. MACROSTR(Accepted),
  238. MACROSTR(Rejected)
  239. };
  240. static char * DiagnosticsStatusStr[] = {
  241. MACROSTR(Idle),
  242. MACROSTR(Uploaded),
  243. MACROSTR(UploadFailed),
  244. MACROSTR(Uploading)
  245. };
  246. static char * FirmwareStatusStr[] = {
  247. MACROSTR(Downloaded),
  248. MACROSTR(DownloadFailed),
  249. MACROSTR(Downloading),
  250. MACROSTR(Idle),
  251. MACROSTR(InstallationFailed),
  252. MACROSTR(Installing),
  253. MACROSTR(Installed)
  254. };
  255. static char * MessageTriggerStr[] = {
  256. MACROSTR(BootNotification),
  257. MACROSTR(DiagnosticsStatusNotification),
  258. MACROSTR(FirmwareStatusNotification),
  259. MACROSTR(Heartbeat),
  260. MACROSTR(MeterValues),
  261. MACROSTR(StatusNotification)
  262. };
  263. static char * TriggerMessageStatusStr[] = {
  264. MACROSTR(Accepted),
  265. MACROSTR(Rejected),
  266. MACROSTR(NotImplemented)
  267. };
  268. static char * UnlockStatusStr[] = {
  269. MACROSTR(Unlocked),
  270. MACROSTR(UnlockFailed),
  271. MACROSTR(NotSupported)
  272. };
  273. #if 0
  274. static char * StopTransactionReasonStr[] = {
  275. MACROSTR(EmergencyStop),
  276. MACROSTR(EVDisconnected),
  277. MACROSTR(HardReset),
  278. MACROSTR(Local),
  279. MACROSTR(Other),
  280. MACROSTR(PowerLoss),
  281. MACROSTR(Reboot),
  282. MACROSTR(Remote),
  283. MACROSTR(SoftReset),
  284. MACROSTR(UnlockCommand),
  285. MACROSTR(DeAuthorized)
  286. };
  287. #endif
  288. static char * CancelReservationStatusStr[] = {
  289. MACROSTR(Accepted),
  290. MACROSTR(Rejected)
  291. };
  292. static char * ReadingContextStr[] = {
  293. MACROSTR(Interruption.Begin),
  294. MACROSTR(Interruption.End),
  295. MACROSTR(Other),
  296. MACROSTR(Sample.Clock),
  297. MACROSTR(Sample.Periodic),
  298. MACROSTR(Transaction.Begin),
  299. MACROSTR(Transaction.End),
  300. MACROSTR(Trigger)
  301. };
  302. static char * ValueFormatStr[] = {
  303. MACROSTR(Raw),
  304. MACROSTR(SignedData)
  305. };
  306. static char * MeasurandStr[] = {
  307. MACROSTR(Current.Export),
  308. MACROSTR(Current.Import),
  309. MACROSTR(Current.Offered),
  310. MACROSTR(Energy.Active.Export.Register),
  311. MACROSTR(Energy.Active.Import.Register),
  312. MACROSTR(Energy.Reactive.Export.Register),
  313. MACROSTR(Energy.Reactive.Import.Register),
  314. MACROSTR(Energy.Active.Export.Interval),
  315. MACROSTR(Energy.Active.Import.Interval),
  316. MACROSTR(Energy.Reactive.Export.Interval),
  317. MACROSTR(Energy.Reactive.Import.Interval),
  318. MACROSTR(Frequency),
  319. MACROSTR(Power.Active.Export),
  320. MACROSTR(Power.Active.Import),
  321. MACROSTR(Power.Factor),
  322. MACROSTR(Power.Offered),
  323. MACROSTR(Power.Reactive.ExportMACROSTR),
  324. MACROSTR(Power.Reactive.Import),
  325. MACROSTR(RPM),
  326. MACROSTR(SoC),
  327. MACROSTR(Temperature),
  328. MACROSTR(Voltage)
  329. };
  330. static char * LocationStr[] = {
  331. MACROSTR(Body),
  332. MACROSTR(Cable),
  333. MACROSTR(EV),
  334. MACROSTR(Inlet),
  335. MACROSTR(Outlet)
  336. };
  337. static char * PhaseStr[] = {
  338. MACROSTR(L1),
  339. MACROSTR(L2),
  340. MACROSTR(L3),
  341. MACROSTR(N),
  342. MACROSTR(L1-N),
  343. MACROSTR(L2-N),
  344. MACROSTR(L3-N),
  345. MACROSTR(L1-L2),
  346. MACROSTR(L2-L3),
  347. MACROSTR(L3-L1)
  348. };
  349. static char * UnitOfMeasureStr[] = {
  350. MACROSTR(Wh),
  351. MACROSTR(kWh),
  352. MACROSTR(varh),
  353. MACROSTR(kvarh),
  354. MACROSTR(W),
  355. MACROSTR(kW),
  356. MACROSTR(VA),
  357. MACROSTR(kVA),
  358. MACROSTR(var),
  359. MACROSTR(kvar),
  360. MACROSTR(A),
  361. MACROSTR(V),
  362. MACROSTR(Celsius),
  363. MACROSTR(Fahrenheit),
  364. MACROSTR(K),
  365. MACROSTR(Percent)
  366. };
  367. //=========================================
  368. // Save configuration
  369. //=========================================
  370. int runShellCmd(const char*cmd)
  371. {
  372. int result = FAIL;
  373. char buf[256];
  374. FILE *fp;
  375. fp = popen(cmd, "r");
  376. if(fp != NULL)
  377. {
  378. while(fgets(buf, sizeof(buf), fp) != NULL)
  379. {
  380. DEBUG_INFO("%s\n", buf);
  381. }
  382. result = PASS;
  383. }
  384. pclose(fp);
  385. return result;
  386. }
  387. int StoreUsrConfigData(struct SysConfigData *UsrData)
  388. {
  389. int result = PASS;
  390. int fd,wrd;
  391. unsigned int i,Chk;
  392. unsigned char *ptr, *BufTmp;
  393. int MtdBlockSize = 0x300000;
  394. Chk=0;
  395. ptr=(unsigned char *)UsrData;
  396. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  397. {
  398. memset(BufTmp,0,MtdBlockSize);
  399. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  400. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  401. Chk+=*(BufTmp+i);
  402. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  403. // Output configuration to file.
  404. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  405. if (fd < 0)
  406. {
  407. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  408. free(BufTmp);
  409. return 0;
  410. }
  411. wrd=write(fd, BufTmp, MtdBlockSize);
  412. close(fd);
  413. if(wrd<MtdBlockSize)
  414. {
  415. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  416. free(BufTmp);
  417. return 0;
  418. }
  419. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  420. DEBUG_INFO("Erase /dev/mtd10.\n");
  421. runShellCmd("flash_erase /dev/mtd10 0 0");
  422. DEBUG_INFO("Write /dev/mtd10.\n");
  423. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  424. DEBUG_INFO("Erase /dev/mtd11.\n");
  425. runShellCmd("flash_erase /dev/mtd11 0 0");
  426. DEBUG_INFO("Write /dev/mtd11.\n");
  427. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  428. system("rm -f /mnt/EvseConfig.bin");
  429. DEBUG_INFO("EvseConfig write to flash OK\n");
  430. }
  431. else
  432. {
  433. DEBUG_ERROR("alloc BlockSize NG\r\n");
  434. result = FAIL;
  435. }
  436. if(BufTmp!=NULL)
  437. free(BufTmp);
  438. return result;
  439. }
  440. //=========================================
  441. // Sqlite3 related function
  442. //=========================================
  443. static int selectSqlCount = 0;
  444. static int callback(void *data, int argc, char **argv, char **azColName){
  445. int i;
  446. //printf("%s: ", (const char*)data);
  447. selectSqlCount = argc;
  448. for(i = 0; i<argc; i++){
  449. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  450. }
  451. //printf("\n");
  452. return 0;
  453. }
  454. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  455. //int i;
  456. //printf("%s:\n", (const char*)data);
  457. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  458. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  459. return 0;
  460. }
  461. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  462. //printf("%s:\n", (const char*)data);
  463. //idTag
  464. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  465. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  466. //parentIdTag
  467. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  468. //expir_date
  469. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  470. //status
  471. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  472. //version
  473. if(columenCount > 5)
  474. idTagQuery.listVersionInt = atoi(columnValue[5]);
  475. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  476. return 0;
  477. }
  478. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  479. {
  480. // localversion = argv[5] ? atoi(argv[5]) : 0;
  481. // printf("localversion=%d\n", localversion);
  482. return 0;
  483. }
  484. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  485. {
  486. for (int i = 0; i < n_columns; i++)
  487. {
  488. DEBUG_INFO("%s\t", col_values[i]);
  489. }
  490. DEBUG_INFO("\n");
  491. return 0;
  492. }
  493. int OCPP_cleanLocalCache()
  494. {
  495. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  496. char *errMsg = 0;
  497. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  498. if (SQLITE_OK != rc)
  499. {
  500. DEBUG_INFO("SQL error: %s\n",errMsg);
  501. return FALSE;
  502. }
  503. return TRUE;
  504. }
  505. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  506. {
  507. int isSuccess = TRUE;
  508. int ret = 0;
  509. //const char* data = "Callback function called";
  510. char sql[300];
  511. char zErrMsg[200];
  512. memset(sql, 0, 300);
  513. memset(zErrMsg, 0, 200);
  514. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  515. //* Execute SQL statement */
  516. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  517. if( ret != SQLITE_OK )
  518. {
  519. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  520. isSuccess = FALSE;
  521. }
  522. return isSuccess;
  523. }
  524. void OCPP_getIdTagFromLocalCache(char idTag[])
  525. {
  526. int rc = 0;
  527. char sql[100];
  528. char zErrMsg[100];
  529. memset(sql, 0, 100);
  530. memset(zErrMsg, 0, 100);
  531. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  532. memset(&idTagQuery, 0, sizeof(idTagQuery));
  533. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  534. /* Execute SQL statement */
  535. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  536. if( rc != SQLITE_OK )
  537. {
  538. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  539. }
  540. }
  541. void OCPP_getListVerion()
  542. {
  543. int rc = 0;
  544. // const char* data = "Callback function called";
  545. char sql[100];
  546. char zErrMsg[100];
  547. memset(sql, 0, 100);
  548. memset(zErrMsg, 0, 100);
  549. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  550. /* Execute SQL statement */
  551. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  552. if( rc != SQLITE_OK )
  553. {
  554. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  555. }
  556. }
  557. void OCPP_get_TableAuthlocalAllData(void)
  558. {
  559. int rc = 0;
  560. char sql[100];
  561. char zErrMsg[100];
  562. memset(sql, 0, 100);
  563. memset(zErrMsg, 0, 100);
  564. sprintf(sql,"select * from ocpp_auth_local ");
  565. /* Execute SQL statement */
  566. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  567. if( rc != SQLITE_OK )
  568. {
  569. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  570. }
  571. //return ver;
  572. }
  573. int OCPP_cleanLocalList()
  574. {
  575. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  576. char *errMsg = 0;
  577. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  578. if (SQLITE_OK != rc)
  579. {
  580. DEBUG_INFO("%s\n",errMsg);
  581. return FALSE;
  582. }
  583. return TRUE;
  584. }
  585. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  586. {
  587. int isSuccess = FALSE;
  588. int ret = 0;
  589. //const char* data = "Callback function called";
  590. char sql[300];
  591. char zErrMsg[200];
  592. memset(sql, 0, 300);
  593. memset(zErrMsg, 0, 200);
  594. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  595. //* Execute SQL statement */
  596. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  597. if( ret != SQLITE_OK )
  598. {
  599. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  600. return isSuccess;
  601. }
  602. memset(sql, 0, 300);
  603. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  604. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  605. if( ret != SQLITE_OK )
  606. {
  607. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  608. return isSuccess;
  609. }
  610. isSuccess = TRUE;
  611. return isSuccess;
  612. }
  613. void OCPP_getIdTagFromLocalList(char idTag[])
  614. {
  615. int rc = 0;
  616. // const char* data = "Callback function called";
  617. char sql[100];
  618. char zErrMsg[100];
  619. memset(sql, 0, 100);
  620. memset(zErrMsg, 0, 100);
  621. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  622. memset(&idTagQuery, 0, sizeof(idTagQuery));
  623. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  624. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  625. /* Execute SQL statement */
  626. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  627. if( rc != SQLITE_OK )
  628. {
  629. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  630. }
  631. //return ver;
  632. }
  633. void OCPP_deleteIdTagFromLocalList(char idTag[])
  634. {
  635. //int ver = 0;
  636. //int isSuccess = FALSE;
  637. int rc = 0;
  638. char sql[100];
  639. char zErrMsg[100];
  640. memset(sql, 0, 100);
  641. memset(zErrMsg, 0, 100);
  642. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  643. //* Execute SQL statement */
  644. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  645. if( rc != SQLITE_OK )
  646. {
  647. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  648. }
  649. }
  650. int getCurrentYear()
  651. {
  652. int result = 0;
  653. time_t CurrentTime;
  654. struct tm *tm;
  655. CurrentTime = time(NULL);
  656. tm=localtime(&CurrentTime);
  657. result = (tm->tm_year + 1900);
  658. return result;
  659. }
  660. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  661. {
  662. int result = PASS;
  663. char* errMsg = NULL;
  664. char sqlStr[8192];
  665. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  666. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  667. {
  668. result = FAIL;
  669. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  670. }
  671. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  672. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  673. {
  674. result = FAIL;
  675. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  676. }
  677. return result;
  678. }
  679. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  680. {
  681. int result = PASS;
  682. char* errMsg = NULL;
  683. char sqlStr[8192];
  684. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  685. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  686. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  687. {
  688. result = FAIL;
  689. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  690. }
  691. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  692. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  693. {
  694. result = FAIL;
  695. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  696. }
  697. return result;
  698. }
  699. int OCPP_update_deduct_info(int txId, char *creditNo)
  700. {
  701. int result = PASS;
  702. char* errMsg = NULL;
  703. char sqlStr[8192];
  704. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  705. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  706. {
  707. result = FAIL;
  708. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  709. }
  710. return result;
  711. }
  712. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  713. {
  714. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  715. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  716. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  717. atoi(columnValue[1]),
  718. columnValue[2],
  719. atoi(columnValue[3])==1?"true":"false",
  720. atoi(columnValue[4])==1?"true":"false",
  721. columnValue[5],
  722. columnValue[9]);
  723. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  724. return 0;
  725. }
  726. void OCPP_query_deduct_info()
  727. {
  728. int rc = 0;
  729. char sql[100];
  730. char zErrMsg[100];
  731. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  732. /* Execute SQL statement */
  733. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  734. if( rc != SQLITE_OK )
  735. {
  736. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  737. }
  738. }
  739. void reportReaderStatus(int gun_index)
  740. {
  741. struct timeval tmnow;
  742. struct tm *tm;
  743. char buf[28];//, usec_buf[6];
  744. gettimeofday(&tmnow, NULL);
  745. time_t t;
  746. t = time(NULL);
  747. /*UTC time and date*/
  748. tm = gmtime(&t);
  749. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  750. #if 0 // remove temporally
  751. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  752. strcat(buf,".");
  753. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  754. strcat(buf,usec_buf);
  755. #endif
  756. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  757. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  758. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  759. (gun_index+1),
  760. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  761. buf,
  762. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  763. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  764. ShmOCPP16DataPH->TcciCustomData.VEMData[gun_index]);
  765. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  766. }
  767. //==========================================
  768. // Check time passed since today
  769. //==========================================
  770. long long DiffTimebWithNow(struct timeb ST)
  771. {
  772. //return milli-second
  773. struct timeb ET;
  774. long long StartTime,StopTime;
  775. ftime(&ET);
  776. StartTime=(long long)ST.time;
  777. StopTime=(long long)ET.time;
  778. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  779. }
  780. int getTimePassSinceToday(uint8_t gun_index)
  781. {
  782. int result = -1;
  783. static time_t lastTime[4];
  784. time_t t;
  785. struct tm *tmStartToday;
  786. struct timeb tbStartToday;
  787. t=time(NULL);
  788. if(difftime(t, lastTime[gun_index])>0)
  789. {
  790. tmStartToday=localtime(&t);
  791. tmStartToday->tm_hour = 0;
  792. tmStartToday->tm_min = 0;
  793. tmStartToday->tm_sec = 0;
  794. tbStartToday.time = mktime(tmStartToday);
  795. tbStartToday.millitm = 0;
  796. result = DiffTimebWithNow(tbStartToday)/1000;
  797. lastTime[gun_index] = t;
  798. }
  799. return result;
  800. }
  801. void getNowDatetime(uint8_t *data)
  802. {
  803. time_t t = time(NULL);
  804. struct tm tm = *localtime(&t);
  805. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  806. }
  807. int syncDateTimeRTC(uint8_t *data)
  808. {
  809. struct ParsingResult
  810. {
  811. int result;
  812. int scanedElement;
  813. int year;
  814. int month;
  815. int mday;
  816. int hour;
  817. int min;
  818. int sec;
  819. int tz_hour;
  820. int tz_min;
  821. float minSec;
  822. }result;
  823. struct tm tmOrg;
  824. struct tm *tmTarget;
  825. struct timeb tbTarget;
  826. char buf[128];
  827. memset(&result, 0x00, sizeof(struct ParsingResult));
  828. result.result = PASS;
  829. if(strstr((char*)data, ".") != NULL)
  830. {
  831. // Original data with mini second
  832. if(strstr((char*)data, "Z") != NULL)
  833. {
  834. // Original data with Z
  835. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  836. &result.year,
  837. &result.month,
  838. &result.mday,
  839. &result.hour,
  840. &result.min,
  841. &result.sec,
  842. &result.minSec);
  843. }
  844. else
  845. {
  846. // Original data without Z
  847. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  848. &result.year,
  849. &result.month,
  850. &result.mday,
  851. &result.hour,
  852. &result.min,
  853. &result.sec,
  854. &result.minSec,
  855. &result.tz_hour,
  856. &result.tz_min);
  857. }
  858. }
  859. else
  860. {
  861. // Original data without mini second
  862. if(strstr((char*)data, "Z") != NULL)
  863. {
  864. // Original data with Z
  865. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  866. &result.year,
  867. &result.month,
  868. &result.mday,
  869. &result.hour,
  870. &result.min,
  871. &result.sec);
  872. }
  873. else
  874. {
  875. // Original data without Z
  876. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  877. &result.year,
  878. &result.month,
  879. &result.mday,
  880. &result.hour,
  881. &result.min,
  882. &result.sec,
  883. &result.tz_hour,
  884. &result.tz_min);
  885. }
  886. }
  887. tmOrg.tm_year = result.year - 1900;
  888. tmOrg.tm_mon = result.month - 1;
  889. tmOrg.tm_mday = result.mday;
  890. tmOrg.tm_hour = result.hour;
  891. tmOrg.tm_min = result.min;
  892. tmOrg.tm_sec = result.sec;
  893. tmOrg.tm_gmtoff = 0;
  894. tbTarget.time = mktime(&tmOrg);
  895. tbTarget.timezone = 0;
  896. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  897. tmTarget = gmtime(&tbTarget.time);
  898. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  899. //DEBUG_INFO(" org date time: %s\n", data);
  900. //DEBUG_INFO("parse date time: %s\n", buf);
  901. system(buf);
  902. system("/sbin/hwclock -w --systohc");
  903. if(result.scanedElement < 6)
  904. result.result = FAIL;
  905. return result.result;
  906. }
  907. //==========================================
  908. // GetCompositeSchedule logic related function
  909. //==========================================
  910. int DiffTimebSec(struct timeb ST, struct timeb ET)
  911. {
  912. //return milli-second
  913. unsigned int StartTime,StopTime;
  914. StartTime=(unsigned int)ST.time;
  915. StopTime=(unsigned int)ET.time;
  916. return (StopTime-StartTime);
  917. }
  918. int DiffTimebWithNowSec(struct timeb ST)
  919. {
  920. //return milli-second
  921. struct timeb ET;
  922. unsigned int StartTime,StopTime;
  923. ftime(&ET);
  924. StartTime=(unsigned int)ST.time;
  925. StopTime=(unsigned int)ET.time;
  926. return (StopTime-StartTime);
  927. }
  928. int getStartStop(uint8_t *start, uint8_t *stop)
  929. {
  930. struct ParsingResult
  931. {
  932. int result;
  933. int scanedElement;
  934. int year;
  935. int month;
  936. int mday;
  937. int hour;
  938. int min;
  939. int sec;
  940. int tz_hour;
  941. int tz_min;
  942. float minSec;
  943. };
  944. struct ParsingResult parseStart;
  945. struct ParsingResult parseStop;
  946. int result = -1;
  947. struct tm tmStart;
  948. struct timeb tbStart;
  949. struct tm tmStop;
  950. struct timeb tbStop;
  951. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  952. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  953. // Scan start & stop date time
  954. if(strstr((char*)start, ".") != NULL)
  955. {
  956. // Original data with mini second
  957. if(strstr((char*)start, "Z") != NULL)
  958. {
  959. // Original data with Z
  960. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  961. &parseStart.year,
  962. &parseStart.month,
  963. &parseStart.mday,
  964. &parseStart.hour,
  965. &parseStart.min,
  966. &parseStart.sec,
  967. &parseStart.minSec);
  968. }
  969. else
  970. {
  971. // Original data without Z
  972. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  973. &parseStart.year,
  974. &parseStart.month,
  975. &parseStart.mday,
  976. &parseStart.hour,
  977. &parseStart.min,
  978. &parseStart.sec,
  979. &parseStart.minSec,
  980. &parseStart.tz_hour,
  981. &parseStart.tz_min);
  982. }
  983. }
  984. else
  985. {
  986. // Original data without mini second
  987. if(strstr((char*)start, "Z") != NULL)
  988. {
  989. // Original data with Z
  990. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  991. &parseStart.year,
  992. &parseStart.month,
  993. &parseStart.mday,
  994. &parseStart.hour,
  995. &parseStart.min,
  996. &parseStart.sec);
  997. }
  998. else
  999. {
  1000. // Original data without Z
  1001. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1002. &parseStart.year,
  1003. &parseStart.month,
  1004. &parseStart.mday,
  1005. &parseStart.hour,
  1006. &parseStart.min,
  1007. &parseStart.sec,
  1008. &parseStart.tz_hour,
  1009. &parseStart.tz_min);
  1010. }
  1011. }
  1012. if(strstr((char*)stop, ".") != NULL)
  1013. {
  1014. // Original data with mini second
  1015. if(strstr((char*)stop, "Z") != NULL)
  1016. {
  1017. // Original data with Z
  1018. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1019. &parseStop.year,
  1020. &parseStop.month,
  1021. &parseStop.mday,
  1022. &parseStop.hour,
  1023. &parseStop.min,
  1024. &parseStop.sec,
  1025. &parseStop.minSec);
  1026. }
  1027. else
  1028. {
  1029. // Original data without Z
  1030. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1031. &parseStop.year,
  1032. &parseStop.month,
  1033. &parseStop.mday,
  1034. &parseStop.hour,
  1035. &parseStop.min,
  1036. &parseStop.sec,
  1037. &parseStop.minSec,
  1038. &parseStop.tz_hour,
  1039. &parseStop.tz_min);
  1040. }
  1041. }
  1042. else
  1043. {
  1044. // Original data without mini second
  1045. if(strstr((char*)stop, "Z") != NULL)
  1046. {
  1047. // Original data with Z
  1048. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1049. &parseStop.year,
  1050. &parseStop.month,
  1051. &parseStop.mday,
  1052. &parseStop.hour,
  1053. &parseStop.min,
  1054. &parseStop.sec);
  1055. }
  1056. else
  1057. {
  1058. // Original data without Z
  1059. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1060. &parseStop.year,
  1061. &parseStop.month,
  1062. &parseStop.mday,
  1063. &parseStop.hour,
  1064. &parseStop.min,
  1065. &parseStop.sec,
  1066. &parseStop.tz_hour,
  1067. &parseStop.tz_min);
  1068. }
  1069. }
  1070. // Calculate date time difference
  1071. if((parseStart.scanedElement >=6) &&
  1072. (parseStop.scanedElement >=6))
  1073. {
  1074. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1075. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1076. tmStart.tm_year = parseStart.year - 1900;
  1077. tmStart.tm_mon = parseStart.month - 1;
  1078. tmStart.tm_mday = parseStart.mday;
  1079. tmStart.tm_hour = parseStart.hour;
  1080. tmStart.tm_min = parseStart.min;
  1081. tmStart.tm_sec = parseStart.sec;
  1082. tmStart.tm_gmtoff = 0;
  1083. tbStart.time = mktime(&tmStart);
  1084. tbStart.timezone = 0;
  1085. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1086. tmStop.tm_year = parseStop.year - 1900;
  1087. tmStop.tm_mon = parseStop.month - 1;
  1088. tmStop.tm_mday = parseStop.mday;
  1089. tmStop.tm_hour = parseStop.hour;
  1090. tmStop.tm_min = parseStop.min;
  1091. tmStop.tm_sec = parseStop.sec;
  1092. tmStop.tm_gmtoff = 0;
  1093. tbStop.time = mktime(&tmStop);
  1094. tbStop.timezone = 0;
  1095. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1096. result = DiffTimebSec(tbStart, tbStop);
  1097. //DEBUG_INFO("getStartStop(): %d\n", result);
  1098. }
  1099. else
  1100. {
  1101. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1102. }
  1103. return result;
  1104. }
  1105. int isOvertNow(uint8_t *start)
  1106. {
  1107. int result = NO;
  1108. struct ParsingResult
  1109. {
  1110. int result;
  1111. int scanedElement;
  1112. int year;
  1113. int month;
  1114. int mday;
  1115. int hour;
  1116. int min;
  1117. int sec;
  1118. int tz_hour;
  1119. int tz_min;
  1120. float minSec;
  1121. }parsingResult;
  1122. struct tm tmStart;
  1123. struct timeb tbStart;
  1124. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1125. if(strstr((char*)start, ".") != NULL)
  1126. {
  1127. // Original data with mini second
  1128. if(strstr((char*)start, "Z") != NULL)
  1129. {
  1130. // Original data with Z
  1131. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1132. &parsingResult.year,
  1133. &parsingResult.month,
  1134. &parsingResult.mday,
  1135. &parsingResult.hour,
  1136. &parsingResult.min,
  1137. &parsingResult.sec,
  1138. &parsingResult.minSec);
  1139. }
  1140. else
  1141. {
  1142. // Original data without Z
  1143. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1144. &parsingResult.year,
  1145. &parsingResult.month,
  1146. &parsingResult.mday,
  1147. &parsingResult.hour,
  1148. &parsingResult.min,
  1149. &parsingResult.sec,
  1150. &parsingResult.minSec,
  1151. &parsingResult.tz_hour,
  1152. &parsingResult.tz_min);
  1153. }
  1154. }
  1155. else
  1156. {
  1157. // Original data without mini second
  1158. if(strstr((char*)start, "Z") != NULL)
  1159. {
  1160. // Original data with Z
  1161. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1162. &parsingResult.year,
  1163. &parsingResult.month,
  1164. &parsingResult.mday,
  1165. &parsingResult.hour,
  1166. &parsingResult.min,
  1167. &parsingResult.sec);
  1168. }
  1169. else
  1170. {
  1171. // Original data without Z
  1172. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1173. &parsingResult.year,
  1174. &parsingResult.month,
  1175. &parsingResult.mday,
  1176. &parsingResult.hour,
  1177. &parsingResult.min,
  1178. &parsingResult.sec,
  1179. &parsingResult.tz_hour,
  1180. &parsingResult.tz_min);
  1181. }
  1182. }
  1183. if(parsingResult.scanedElement >= 6)
  1184. {
  1185. tmStart.tm_year = parsingResult.year - 1900;
  1186. tmStart.tm_mon = parsingResult.month - 1;
  1187. tmStart.tm_mday = parsingResult.mday;
  1188. tmStart.tm_hour = parsingResult.hour;
  1189. tmStart.tm_min = parsingResult.min;
  1190. tmStart.tm_sec = parsingResult.sec;
  1191. tmStart.tm_gmtoff = 0;
  1192. tbStart.time = mktime(&tmStart);
  1193. tbStart.timezone = 0;
  1194. tbStart.millitm = 0;
  1195. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1196. if(DiffTimebWithNowSec(tbStart) <= 0)
  1197. result = NO;
  1198. else
  1199. result = YES;
  1200. }
  1201. else
  1202. {
  1203. DEBUG_WARN("Start date parsing error.\n");
  1204. }
  1205. return result;
  1206. }
  1207. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1208. {
  1209. struct ParsingResult
  1210. {
  1211. int result;
  1212. int scanedElement;
  1213. int year;
  1214. int month;
  1215. int mday;
  1216. int hour;
  1217. int min;
  1218. int sec;
  1219. int tz_hour;
  1220. int tz_min;
  1221. float minSec;
  1222. };
  1223. struct ParsingResult parseStart;
  1224. struct ParsingResult parseStop;
  1225. int result = -1;
  1226. struct tm tmStart;
  1227. struct timeb tbStart;
  1228. struct tm tmStop;
  1229. struct timeb tbStop;
  1230. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1231. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1232. // Scan start & stop date time
  1233. if(strstr((char*)start, ".") != NULL)
  1234. {
  1235. // Original data with mini second
  1236. if(strstr((char*)start, "Z") != NULL)
  1237. {
  1238. // Original data with Z
  1239. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1240. &parseStart.year,
  1241. &parseStart.month,
  1242. &parseStart.mday,
  1243. &parseStart.hour,
  1244. &parseStart.min,
  1245. &parseStart.sec,
  1246. &parseStart.minSec);
  1247. }
  1248. else
  1249. {
  1250. // Original data without Z
  1251. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1252. &parseStart.year,
  1253. &parseStart.month,
  1254. &parseStart.mday,
  1255. &parseStart.hour,
  1256. &parseStart.min,
  1257. &parseStart.sec,
  1258. &parseStart.minSec,
  1259. &parseStart.tz_hour,
  1260. &parseStart.tz_min);
  1261. }
  1262. }
  1263. else
  1264. {
  1265. // Original data without mini second
  1266. if(strstr((char*)start, "Z") != NULL)
  1267. {
  1268. // Original data with Z
  1269. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1270. &parseStart.year,
  1271. &parseStart.month,
  1272. &parseStart.mday,
  1273. &parseStart.hour,
  1274. &parseStart.min,
  1275. &parseStart.sec);
  1276. }
  1277. else
  1278. {
  1279. // Original data without Z
  1280. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1281. &parseStart.year,
  1282. &parseStart.month,
  1283. &parseStart.mday,
  1284. &parseStart.hour,
  1285. &parseStart.min,
  1286. &parseStart.sec,
  1287. &parseStart.tz_hour,
  1288. &parseStart.tz_min);
  1289. }
  1290. }
  1291. if(strstr((char*)stop, ".") != NULL)
  1292. {
  1293. // Original data with mini second
  1294. if(strstr((char*)stop, "Z") != NULL)
  1295. {
  1296. // Original data with Z
  1297. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1298. &parseStop.year,
  1299. &parseStop.month,
  1300. &parseStop.mday,
  1301. &parseStop.hour,
  1302. &parseStop.min,
  1303. &parseStop.sec,
  1304. &parseStop.minSec);
  1305. }
  1306. else
  1307. {
  1308. // Original data without Z
  1309. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1310. &parseStop.year,
  1311. &parseStop.month,
  1312. &parseStop.mday,
  1313. &parseStop.hour,
  1314. &parseStop.min,
  1315. &parseStop.sec,
  1316. &parseStop.minSec,
  1317. &parseStop.tz_hour,
  1318. &parseStop.tz_min);
  1319. }
  1320. }
  1321. else
  1322. {
  1323. // Original data without mini second
  1324. if(strstr((char*)stop, "Z") != NULL)
  1325. {
  1326. // Original data with Z
  1327. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1328. &parseStop.year,
  1329. &parseStop.month,
  1330. &parseStop.mday,
  1331. &parseStop.hour,
  1332. &parseStop.min,
  1333. &parseStop.sec);
  1334. }
  1335. else
  1336. {
  1337. // Original data without Z
  1338. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1339. &parseStop.year,
  1340. &parseStop.month,
  1341. &parseStop.mday,
  1342. &parseStop.hour,
  1343. &parseStop.min,
  1344. &parseStop.sec,
  1345. &parseStop.tz_hour,
  1346. &parseStop.tz_min);
  1347. }
  1348. }
  1349. // Calculate date time difference
  1350. if((parseStart.scanedElement >=6) &&
  1351. (parseStop.scanedElement >=6))
  1352. {
  1353. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1354. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1355. tmStart.tm_year = parseStart.year - 1900;
  1356. tmStart.tm_mon = parseStart.month - 1;
  1357. tmStart.tm_mday = parseStart.mday;
  1358. tmStart.tm_hour = parseStart.hour;
  1359. tmStart.tm_min = parseStart.min;
  1360. tmStart.tm_sec = parseStart.sec;
  1361. tmStart.tm_gmtoff = 0;
  1362. tbStart.time = mktime(&tmStart);
  1363. tbStart.timezone = 0;
  1364. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1365. tmStop.tm_year = parseStop.year - 1900;
  1366. tmStop.tm_mon = parseStop.month - 1;
  1367. tmStop.tm_mday = parseStop.mday;
  1368. tmStop.tm_hour = parseStop.hour;
  1369. tmStop.tm_min = parseStop.min;
  1370. tmStop.tm_sec = parseStop.sec;
  1371. tmStop.tm_gmtoff = 0;
  1372. tbStop.time = mktime(&tmStop);
  1373. tbStop.timezone = 0;
  1374. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1375. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1376. //DEBUG_INFO("getStartStop(): %d\n", result);
  1377. }
  1378. else
  1379. {
  1380. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1381. }
  1382. return result;
  1383. }
  1384. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1385. {
  1386. FILE *fp;
  1387. char profileFileName[128];
  1388. char *line = NULL;
  1389. size_t len = 0;
  1390. time_t CurrentTime;
  1391. struct tm *tmComposite;
  1392. struct StructChargingProfile maxProfile;
  1393. struct StructChargingProfile compositeProfile;
  1394. uint8_t limitMax=0;
  1395. int compositePeriodIdx = 0;
  1396. //uint8_t isDurationNull = FALSE;
  1397. CurrentTime = time(NULL);
  1398. tmComposite=localtime(&CurrentTime);
  1399. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1400. if(isUnitA)
  1401. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1402. else
  1403. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1404. compositeProfile.ChargingSchedule.Duration = durationReq;
  1405. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1406. {
  1407. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1408. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1409. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1410. }
  1411. compositeProfile.ChargingProfileId = 0;
  1412. compositeProfile.StackLevel = 99 ;
  1413. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1414. maxProfile.ChargingProfileId = -1;
  1415. maxProfile.ChargingSchedule.Duration = -1;
  1416. system("rm -f /tmp/*.json");
  1417. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1418. // Search max profile
  1419. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1420. if((access(profileFileName, F_OK))!=-1)
  1421. {
  1422. fp = fopen(profileFileName, "r");
  1423. while(getline(&line, &len, fp) != -1)
  1424. {
  1425. json_object *obj = NULL;
  1426. obj = json_tokener_parse(line);
  1427. if(is_error(obj))
  1428. {
  1429. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1430. }
  1431. else
  1432. {
  1433. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1434. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1435. )
  1436. {
  1437. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1438. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1439. )
  1440. {
  1441. struct tm tmFrom, tmTo;
  1442. struct timeb tbFrom, tbTo;
  1443. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1444. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1445. {
  1446. tmFrom.tm_year -= 1900;
  1447. tmFrom.tm_mon -= 1;
  1448. tbFrom.time = mktime(&tmFrom);
  1449. tmTo.tm_year -= 1900;
  1450. tmTo.tm_mon -= 1;
  1451. tbTo.time = mktime(&tmTo);
  1452. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1453. {
  1454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1455. {
  1456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1457. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1458. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1459. }
  1460. if(maxProfile.ChargingProfileId == -1)
  1461. DEBUG_INFO("MaxProfile found.\n");
  1462. else
  1463. DEBUG_INFO("MaxProfile updated.\n");
  1464. // Required item
  1465. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1466. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1467. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1468. if(isUnitA)
  1469. {
  1470. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1471. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1472. {
  1473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1474. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1475. 3:
  1476. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1478. }
  1479. }
  1480. else
  1481. {
  1482. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1483. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1484. {
  1485. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1486. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1487. 3:
  1488. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1489. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1490. }
  1491. }
  1492. // Optional item
  1493. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1494. {
  1495. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1496. }
  1497. else
  1498. {
  1499. sprintf((char*)maxProfile.ValidFrom, " ");
  1500. }
  1501. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1502. {
  1503. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1504. }
  1505. else
  1506. {
  1507. sprintf((char*)maxProfile.ValidTo, " ");
  1508. }
  1509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1510. {
  1511. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1512. }
  1513. else
  1514. {
  1515. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1516. }
  1517. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1518. {
  1519. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1520. }
  1521. else
  1522. {
  1523. maxProfile.TransactionId = -1;
  1524. }
  1525. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1526. {
  1527. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1528. }
  1529. else
  1530. {
  1531. maxProfile.ChargingSchedule.Duration = 86400;
  1532. //isDurationNull = TRUE;
  1533. }
  1534. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1535. {
  1536. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1537. }
  1538. else
  1539. {
  1540. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1541. }
  1542. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1543. {
  1544. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1545. }
  1546. else
  1547. {
  1548. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1549. }
  1550. }
  1551. }
  1552. }
  1553. else
  1554. {
  1555. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1556. {
  1557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1559. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1560. }
  1561. if(maxProfile.ChargingProfileId == -1)
  1562. DEBUG_INFO("MaxProfile found.\n");
  1563. else
  1564. DEBUG_INFO("MaxProfile updated.\n");
  1565. // Required item
  1566. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1567. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1568. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1569. if(isUnitA)
  1570. {
  1571. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1572. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1573. {
  1574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1576. 3:
  1577. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1579. }
  1580. }
  1581. else
  1582. {
  1583. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1584. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1585. {
  1586. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1587. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1588. 3:
  1589. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1590. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1591. }
  1592. }
  1593. // Optional item
  1594. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1595. {
  1596. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1597. }
  1598. else
  1599. {
  1600. sprintf((char*)maxProfile.ValidFrom, " ");
  1601. }
  1602. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1603. {
  1604. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1605. }
  1606. else
  1607. {
  1608. sprintf((char*)maxProfile.ValidTo, " ");
  1609. }
  1610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1611. {
  1612. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1613. }
  1614. else
  1615. {
  1616. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1617. }
  1618. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1619. {
  1620. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1621. }
  1622. else
  1623. {
  1624. maxProfile.TransactionId = -1;
  1625. }
  1626. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1627. {
  1628. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1629. }
  1630. else
  1631. {
  1632. maxProfile.ChargingSchedule.Duration = 86400;
  1633. //isDurationNull = TRUE;
  1634. }
  1635. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1636. {
  1637. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1638. }
  1639. else
  1640. {
  1641. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1642. }
  1643. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1644. {
  1645. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1646. }
  1647. else
  1648. {
  1649. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1650. }
  1651. }
  1652. }
  1653. }
  1654. json_object_put(obj);
  1655. }
  1656. fclose(fp);
  1657. /*
  1658. if(maxProfile.ChargingProfileId !=-1)
  1659. {
  1660. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1661. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1662. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1663. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1664. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1665. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1666. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1667. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1668. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1669. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1670. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1671. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1672. {
  1673. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1674. {
  1675. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1676. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1677. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1678. }
  1679. }
  1680. }
  1681. else
  1682. DEBUG_INFO("MaxProfile not found.\n");
  1683. DEBUG_INFO("------------------------------------\n");*/
  1684. }
  1685. if(maxProfile.ChargingProfileId != -1)
  1686. {
  1687. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1688. {
  1689. if(maxProfile.ChargingSchedule.Duration != -1)
  1690. {
  1691. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1692. 0:
  1693. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1694. }
  1695. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1696. {
  1697. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1698. {
  1699. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1700. 0:
  1701. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1702. if(idxPeriod > 0)
  1703. {
  1704. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1705. {
  1706. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1707. }
  1708. }
  1709. }
  1710. }
  1711. }
  1712. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1713. {
  1714. if(maxProfile.ChargingSchedule.Duration != -1)
  1715. {
  1716. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1717. }
  1718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1719. {
  1720. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1721. {
  1722. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1723. if(idxPeriod > 0)
  1724. {
  1725. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1726. {
  1727. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1728. }
  1729. }
  1730. }
  1731. }
  1732. }
  1733. else
  1734. {
  1735. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1736. {
  1737. if(maxProfile.ChargingSchedule.Duration != -1)
  1738. {
  1739. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1740. 0:
  1741. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1742. }
  1743. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1744. {
  1745. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1746. {
  1747. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1748. 0:
  1749. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1750. if(idxPeriod > 0)
  1751. {
  1752. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1753. {
  1754. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1755. }
  1756. }
  1757. }
  1758. }
  1759. }
  1760. else
  1761. {
  1762. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  1763. {
  1764. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1765. 0:
  1766. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1767. }
  1768. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1769. {
  1770. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1771. {
  1772. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1773. 0:
  1774. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1775. if(idxPeriod > 0)
  1776. {
  1777. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1778. {
  1779. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. }
  1786. /*
  1787. DEBUG_INFO("MaxProfile after align.\n");
  1788. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1789. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1790. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1791. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1792. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1793. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1794. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1795. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1796. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1797. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1798. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1799. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1800. {
  1801. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1802. {
  1803. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1804. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1805. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1806. }
  1807. }
  1808. DEBUG_INFO("------------------------------------\n");*/
  1809. }
  1810. // Find each profile period quantity
  1811. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1812. {
  1813. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1814. limitMax = idx+1;
  1815. }
  1816. if(maxProfile.ChargingProfileId != -1)
  1817. {
  1818. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1819. {
  1820. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1821. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1822. (maxProfile.ChargingSchedule.Duration > 0))
  1823. {
  1824. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1825. {
  1826. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1827. compositePeriodIdx++;
  1828. }
  1829. else
  1830. {
  1831. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1832. }
  1833. }
  1834. }
  1835. }
  1836. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1837. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1838. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1839. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1841. {
  1842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1843. {
  1844. compositeProfile.ChargingProfileId = 1;
  1845. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1846. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1847. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1848. }
  1849. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1850. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1851. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1852. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1853. }
  1854. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1855. if(line)
  1856. free(line);
  1857. }
  1858. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1859. {
  1860. FILE *fp;
  1861. char profileFileName[128];
  1862. char *line = NULL;
  1863. size_t len = 0;
  1864. time_t CurrentTime;
  1865. struct tm *tmComposite;
  1866. struct StructChargingProfile maxProfile;
  1867. struct StructChargingProfile defaultTxProfile;
  1868. struct StructChargingProfile txProfile;
  1869. struct StructChargingProfile compositeProfile;
  1870. struct StructChargingSchedulePeriod tmpPeriod;
  1871. uint8_t limitMax=0;
  1872. uint8_t limitDef=0;
  1873. uint8_t limitTx=0;
  1874. int compositePeriodIdx = 0;
  1875. CurrentTime = time(NULL);
  1876. tmComposite=localtime(&CurrentTime);
  1877. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  1878. if(isUnitA)
  1879. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1880. else
  1881. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1882. compositeProfile.ChargingSchedule.Duration = durationReq;
  1883. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1884. {
  1885. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1886. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1887. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1888. }
  1889. compositeProfile.ChargingProfileId = 0;
  1890. compositeProfile.StackLevel = 99 ;
  1891. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1892. maxProfile.ChargingProfileId = -1;
  1893. defaultTxProfile.ChargingProfileId = -1;
  1894. txProfile.ChargingProfileId = -1;
  1895. maxProfile.ChargingSchedule.Duration = -1;
  1896. defaultTxProfile.ChargingSchedule.Duration = -1;
  1897. txProfile.ChargingSchedule.Duration = -1;
  1898. system("rm -f /tmp/*.json");
  1899. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1900. /*
  1901. * Search valid charging profile
  1902. */
  1903. //DEBUG_INFO("====================================\n");
  1904. // Search tx profile
  1905. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1906. if((access(profileFileName, F_OK))!=-1)
  1907. {
  1908. fp = fopen(profileFileName, "r");
  1909. while(getline(&line, &len, fp) != -1)
  1910. {
  1911. json_object *obj = NULL;
  1912. obj = json_tokener_parse(line);
  1913. if(is_error(obj))
  1914. {
  1915. DEBUG_ERROR("Parse txProfile from file error.\n");
  1916. }
  1917. else
  1918. {
  1919. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1920. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1921. )
  1922. {
  1923. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1924. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1925. )
  1926. {
  1927. struct tm tmFrom, tmTo;
  1928. struct timeb tbFrom, tbTo;
  1929. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1930. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1931. {
  1932. tmFrom.tm_year -= 1900;
  1933. tmFrom.tm_mon -= 1;
  1934. tbFrom.time = mktime(&tmFrom);
  1935. tmTo.tm_year -= 1900;
  1936. tmTo.tm_mon -= 1;
  1937. tbTo.time = mktime(&tmTo);
  1938. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1939. {
  1940. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1941. {
  1942. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1943. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1944. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1945. }
  1946. if(txProfile.ChargingProfileId == -1)
  1947. DEBUG_INFO("TxProfile found.\n");
  1948. else
  1949. DEBUG_INFO("TxProfile updated.\n");
  1950. // Required item
  1951. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1952. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1953. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1954. if(isUnitA)
  1955. {
  1956. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1957. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1958. {
  1959. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1960. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1961. 3:
  1962. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1963. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1964. }
  1965. }
  1966. else
  1967. {
  1968. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1969. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1970. {
  1971. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1972. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1973. 3:
  1974. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1975. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1976. }
  1977. }
  1978. // Optional item
  1979. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1980. {
  1981. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1982. }
  1983. else
  1984. {
  1985. sprintf((char*)txProfile.ValidFrom, " ");
  1986. }
  1987. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1988. {
  1989. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1990. }
  1991. else
  1992. {
  1993. sprintf((char*)txProfile.ValidTo, " ");
  1994. }
  1995. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1996. {
  1997. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1998. }
  1999. else
  2000. {
  2001. sprintf((char*)txProfile.RecurrencyKind, " ");
  2002. }
  2003. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2004. {
  2005. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2006. }
  2007. else
  2008. {
  2009. txProfile.TransactionId = -1;
  2010. }
  2011. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2012. {
  2013. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2014. }
  2015. else
  2016. {
  2017. txProfile.ChargingSchedule.Duration = 86400;
  2018. }
  2019. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2020. {
  2021. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2022. }
  2023. else
  2024. {
  2025. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2026. }
  2027. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2028. {
  2029. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2030. }
  2031. else
  2032. {
  2033. txProfile.ChargingSchedule.MinChargingRate = -1;
  2034. }
  2035. }
  2036. }
  2037. }
  2038. else
  2039. {
  2040. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2041. {
  2042. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2043. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2044. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2045. }
  2046. if(txProfile.ChargingProfileId == -1)
  2047. DEBUG_INFO("TxProfile found.\n");
  2048. else
  2049. DEBUG_INFO("TxProfile updated.\n");
  2050. // Required item
  2051. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2052. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2053. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2054. if(isUnitA)
  2055. {
  2056. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2057. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2058. {
  2059. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2060. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2061. 3:
  2062. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2063. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2064. }
  2065. }
  2066. else
  2067. {
  2068. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2069. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2070. {
  2071. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2072. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2073. 3:
  2074. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2075. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2076. }
  2077. }
  2078. // Optional item
  2079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2080. {
  2081. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2082. }
  2083. else
  2084. {
  2085. sprintf((char*)txProfile.ValidFrom, " ");
  2086. }
  2087. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2088. {
  2089. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2090. }
  2091. else
  2092. {
  2093. sprintf((char*)txProfile.ValidTo, " ");
  2094. }
  2095. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2096. {
  2097. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2098. }
  2099. else
  2100. {
  2101. sprintf((char*)txProfile.RecurrencyKind, " ");
  2102. }
  2103. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2104. {
  2105. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2106. }
  2107. else
  2108. {
  2109. txProfile.TransactionId = -1;
  2110. }
  2111. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2112. {
  2113. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2114. }
  2115. else
  2116. {
  2117. txProfile.ChargingSchedule.Duration = 86400;
  2118. }
  2119. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2120. {
  2121. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2122. }
  2123. else
  2124. {
  2125. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2126. }
  2127. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2128. {
  2129. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2130. }
  2131. else
  2132. {
  2133. txProfile.ChargingSchedule.MinChargingRate = -1;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. json_object_put(obj);
  2139. }
  2140. fclose(fp);
  2141. /*
  2142. if(txProfile.ChargingProfileId != -1)
  2143. {
  2144. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2145. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2146. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2147. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2148. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2149. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2150. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2151. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2152. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2153. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2154. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2155. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2156. {
  2157. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2158. {
  2159. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2160. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2161. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2162. }
  2163. }
  2164. }
  2165. else
  2166. DEBUG_INFO("TxProfile not found.\n");*/
  2167. }
  2168. // Search default tx profile
  2169. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2170. if((access(profileFileName, F_OK))==-1)
  2171. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2172. if((access(profileFileName, F_OK))!=-1)
  2173. {
  2174. fp = fopen(profileFileName, "r");
  2175. while(getline(&line, &len, fp) != -1)
  2176. {
  2177. json_object *obj = NULL;
  2178. obj = json_tokener_parse(line);
  2179. if(is_error(obj))
  2180. {
  2181. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2182. }
  2183. else
  2184. {
  2185. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2186. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2187. )
  2188. {
  2189. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2190. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2191. )
  2192. {
  2193. struct tm tmFrom, tmTo;
  2194. struct timeb tbFrom, tbTo;
  2195. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2196. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2197. {
  2198. tmFrom.tm_year -= 1900;
  2199. tmFrom.tm_mon -= 1;
  2200. tbFrom.time = mktime(&tmFrom);
  2201. tmTo.tm_year -= 1900;
  2202. tmTo.tm_mon -= 1;
  2203. tbTo.time = mktime(&tmTo);
  2204. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2205. {
  2206. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2207. {
  2208. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2209. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2210. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2211. }
  2212. if(defaultTxProfile.ChargingProfileId == -1)
  2213. DEBUG_INFO("TxDefaultProfile found.\n");
  2214. else
  2215. DEBUG_INFO("TxDefaultProfile updated.\n");
  2216. // Required item
  2217. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2218. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2219. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2220. if(isUnitA)
  2221. {
  2222. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2223. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2224. {
  2225. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2226. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2227. 3:
  2228. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2229. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2230. }
  2231. }
  2232. else
  2233. {
  2234. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2235. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2236. {
  2237. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2238. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2239. 3:
  2240. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2241. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2242. }
  2243. }
  2244. // Optional item
  2245. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2246. {
  2247. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2248. }
  2249. else
  2250. {
  2251. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2252. }
  2253. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2254. {
  2255. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2256. }
  2257. else
  2258. {
  2259. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2260. }
  2261. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2262. {
  2263. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2264. }
  2265. else
  2266. {
  2267. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2268. }
  2269. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2270. {
  2271. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2272. }
  2273. else
  2274. {
  2275. defaultTxProfile.TransactionId = -1;
  2276. }
  2277. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2278. {
  2279. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2280. }
  2281. else
  2282. {
  2283. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2284. }
  2285. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2286. {
  2287. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2288. }
  2289. else
  2290. {
  2291. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2292. }
  2293. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2294. {
  2295. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2296. }
  2297. else
  2298. {
  2299. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2300. }
  2301. }
  2302. }
  2303. }
  2304. else
  2305. {
  2306. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2307. {
  2308. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2309. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2310. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2311. }
  2312. if(defaultTxProfile.ChargingProfileId == -1)
  2313. DEBUG_INFO("TxDefaultProfile found.\n");
  2314. else
  2315. DEBUG_INFO("TxDefaultProfile updated.\n");
  2316. // Required item
  2317. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2318. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2319. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2320. if(isUnitA)
  2321. {
  2322. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2323. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2324. {
  2325. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2326. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2327. 3:
  2328. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2329. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2330. }
  2331. }
  2332. else
  2333. {
  2334. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2335. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2336. {
  2337. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2338. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2339. 3:
  2340. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2341. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2342. }
  2343. }
  2344. // Optional item
  2345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2346. {
  2347. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2348. }
  2349. else
  2350. {
  2351. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2352. }
  2353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2354. {
  2355. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2356. }
  2357. else
  2358. {
  2359. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2360. }
  2361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2362. {
  2363. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2364. }
  2365. else
  2366. {
  2367. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2368. }
  2369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2370. {
  2371. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2372. }
  2373. else
  2374. {
  2375. defaultTxProfile.TransactionId = -1;
  2376. }
  2377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2378. {
  2379. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2380. }
  2381. else
  2382. {
  2383. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2384. }
  2385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2386. {
  2387. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2388. }
  2389. else
  2390. {
  2391. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2392. }
  2393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2394. {
  2395. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2396. }
  2397. else
  2398. {
  2399. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2400. }
  2401. }
  2402. }
  2403. }
  2404. json_object_put(obj);
  2405. }
  2406. fclose(fp);
  2407. /*
  2408. if(defaultTxProfile.ChargingProfileId != -1)
  2409. {
  2410. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2411. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2412. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2413. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2414. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2415. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2416. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2417. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2418. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2419. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2420. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2421. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2422. {
  2423. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2424. {
  2425. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2426. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2427. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2428. }
  2429. }
  2430. }
  2431. else
  2432. DEBUG_INFO("TxDefaultProfile not found.\n");
  2433. DEBUG_INFO("------------------------------------\n");*/
  2434. }
  2435. // Search max profile
  2436. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2437. if((access(profileFileName, F_OK))!=-1)
  2438. {
  2439. fp = fopen(profileFileName, "r");
  2440. while(getline(&line, &len, fp) != -1)
  2441. {
  2442. json_object *obj = NULL;
  2443. obj = json_tokener_parse(line);
  2444. if(is_error(obj))
  2445. {
  2446. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2447. }
  2448. else
  2449. {
  2450. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2451. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2452. )
  2453. {
  2454. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2455. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2456. )
  2457. {
  2458. struct tm tmFrom, tmTo;
  2459. struct timeb tbFrom, tbTo;
  2460. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2461. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2462. {
  2463. tmFrom.tm_year -= 1900;
  2464. tmFrom.tm_mon -= 1;
  2465. tbFrom.time = mktime(&tmFrom);
  2466. tmTo.tm_year -= 1900;
  2467. tmTo.tm_mon -= 1;
  2468. tbTo.time = mktime(&tmTo);
  2469. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2470. {
  2471. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2472. {
  2473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2474. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2475. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2476. }
  2477. if(maxProfile.ChargingProfileId == -1)
  2478. DEBUG_INFO("MaxProfile found.\n");
  2479. else
  2480. DEBUG_INFO("MaxProfile updated.\n");
  2481. // Required item
  2482. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2483. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2484. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2485. if(isUnitA)
  2486. {
  2487. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2488. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2489. {
  2490. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2491. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2492. 3:
  2493. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2494. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2495. }
  2496. }
  2497. else
  2498. {
  2499. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2500. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2501. {
  2502. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2503. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2504. 3:
  2505. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2506. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2507. }
  2508. }
  2509. // Optional item
  2510. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2511. {
  2512. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2513. }
  2514. else
  2515. {
  2516. sprintf((char*)maxProfile.ValidFrom, " ");
  2517. }
  2518. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2519. {
  2520. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2521. }
  2522. else
  2523. {
  2524. sprintf((char*)maxProfile.ValidTo, " ");
  2525. }
  2526. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2527. {
  2528. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2529. }
  2530. else
  2531. {
  2532. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2533. }
  2534. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2535. {
  2536. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2537. }
  2538. else
  2539. {
  2540. maxProfile.TransactionId = -1;
  2541. }
  2542. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2543. {
  2544. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2545. }
  2546. else
  2547. {
  2548. maxProfile.ChargingSchedule.Duration = 86400;
  2549. }
  2550. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2551. {
  2552. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2553. }
  2554. else
  2555. {
  2556. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2557. }
  2558. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2559. {
  2560. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2561. }
  2562. else
  2563. {
  2564. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. else
  2570. {
  2571. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2572. {
  2573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2574. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2576. }
  2577. if(maxProfile.ChargingProfileId == -1)
  2578. DEBUG_INFO("MaxProfile found.\n");
  2579. else
  2580. DEBUG_INFO("MaxProfile updated.\n");
  2581. // Required item
  2582. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2583. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2584. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2585. if(isUnitA)
  2586. {
  2587. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2588. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2589. {
  2590. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2591. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2592. 3:
  2593. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2594. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2595. }
  2596. }
  2597. else
  2598. {
  2599. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2600. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2601. {
  2602. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2604. 3:
  2605. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2606. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2607. }
  2608. }
  2609. // Optional item
  2610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2611. {
  2612. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2613. }
  2614. else
  2615. {
  2616. sprintf((char*)maxProfile.ValidFrom, " ");
  2617. }
  2618. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2619. {
  2620. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2621. }
  2622. else
  2623. {
  2624. sprintf((char*)maxProfile.ValidTo, " ");
  2625. }
  2626. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2627. {
  2628. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2629. }
  2630. else
  2631. {
  2632. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2633. }
  2634. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2635. {
  2636. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2637. }
  2638. else
  2639. {
  2640. maxProfile.TransactionId = -1;
  2641. }
  2642. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2643. {
  2644. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2645. }
  2646. else
  2647. {
  2648. maxProfile.ChargingSchedule.Duration = 86400;
  2649. }
  2650. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2651. {
  2652. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2653. }
  2654. else
  2655. {
  2656. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2657. }
  2658. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2659. {
  2660. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2661. }
  2662. else
  2663. {
  2664. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2665. }
  2666. }
  2667. }
  2668. }
  2669. json_object_put(obj);
  2670. }
  2671. fclose(fp);
  2672. /*
  2673. if(maxProfile.ChargingProfileId !=-1)
  2674. {
  2675. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2676. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2677. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2678. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2679. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2680. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2681. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2682. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2683. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2684. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2685. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2686. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2687. {
  2688. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2689. {
  2690. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2691. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2692. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2693. }
  2694. }
  2695. }
  2696. else
  2697. DEBUG_INFO("MaxProfile not found.\n");
  2698. DEBUG_INFO("------------------------------------\n");*/
  2699. }
  2700. /*
  2701. * Align found profile start schedule & periods
  2702. */
  2703. //DEBUG_INFO("====================================\n");
  2704. /*
  2705. // For local test usage, force modify found profile start schedule info
  2706. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  2707. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  2708. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  2709. */
  2710. if(txProfile.ChargingProfileId != -1)
  2711. {
  2712. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2713. {
  2714. if(txProfile.ChargingSchedule.Duration != -1)
  2715. {
  2716. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2717. 0:
  2718. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2719. }
  2720. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2721. {
  2722. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2723. {
  2724. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2725. 0:
  2726. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2727. if(idxPeriod > 0)
  2728. {
  2729. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2730. {
  2731. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2732. }
  2733. }
  2734. }
  2735. }
  2736. }
  2737. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2738. {
  2739. if(txProfile.ChargingSchedule.Duration != -1)
  2740. {
  2741. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2742. 0:
  2743. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2744. }
  2745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2746. {
  2747. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2748. {
  2749. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2750. 0:
  2751. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2752. if(idxPeriod > 0)
  2753. {
  2754. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2755. {
  2756. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2757. }
  2758. }
  2759. }
  2760. }
  2761. }
  2762. else
  2763. {
  2764. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2765. {
  2766. if(txProfile.ChargingSchedule.Duration != -1)
  2767. {
  2768. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2769. 0:
  2770. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2771. }
  2772. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2773. {
  2774. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2775. {
  2776. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2777. 0:
  2778. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2779. if(idxPeriod > 0)
  2780. {
  2781. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2782. {
  2783. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2784. }
  2785. }
  2786. }
  2787. }
  2788. }
  2789. else
  2790. {
  2791. if(txProfile.ChargingSchedule.Duration != -1)
  2792. {
  2793. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2794. 0:
  2795. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2796. }
  2797. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2798. {
  2799. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2800. {
  2801. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2802. 0:
  2803. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2804. if(idxPeriod > 0)
  2805. {
  2806. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2807. {
  2808. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. }
  2815. /*
  2816. DEBUG_INFO("txProfile after align.\n");
  2817. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2818. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2819. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2820. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2821. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2822. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2823. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2824. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2825. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2826. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2827. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2828. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2829. {
  2830. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2831. {
  2832. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2833. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2834. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2835. }
  2836. }*/
  2837. }
  2838. if(defaultTxProfile.ChargingProfileId != -1)
  2839. {
  2840. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2841. {
  2842. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2843. {
  2844. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2845. 0:
  2846. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2847. }
  2848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2849. {
  2850. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2851. {
  2852. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2853. 0:
  2854. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2855. if(idxPeriod > 0)
  2856. {
  2857. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2858. {
  2859. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. }
  2865. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2866. {
  2867. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2868. {
  2869. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2870. 0:
  2871. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2872. }
  2873. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2874. {
  2875. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2876. {
  2877. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2878. 0:
  2879. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2880. if(idxPeriod > 0)
  2881. {
  2882. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2883. {
  2884. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2885. }
  2886. }
  2887. }
  2888. }
  2889. }
  2890. else
  2891. {
  2892. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2893. {
  2894. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2895. {
  2896. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2897. 0:
  2898. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2899. }
  2900. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2901. {
  2902. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2903. {
  2904. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2905. 0:
  2906. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2907. if(idxPeriod > 0)
  2908. {
  2909. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2910. {
  2911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. else
  2918. {
  2919. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2920. {
  2921. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2922. 0:
  2923. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2924. }
  2925. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2926. {
  2927. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2928. {
  2929. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2930. 0:
  2931. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2932. if(idxPeriod > 0)
  2933. {
  2934. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2935. {
  2936. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2937. }
  2938. }
  2939. }
  2940. }
  2941. }
  2942. }
  2943. /*
  2944. DEBUG_INFO("defaultTxProfile after align.\n");
  2945. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2946. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2947. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2948. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2949. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2950. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2951. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2952. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2953. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2954. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2955. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2956. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2957. {
  2958. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2959. {
  2960. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2961. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2962. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2963. }
  2964. }
  2965. DEBUG_INFO("------------------------------------\n");*/
  2966. }
  2967. if(maxProfile.ChargingProfileId != -1)
  2968. {
  2969. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2970. {
  2971. if(maxProfile.ChargingSchedule.Duration != -1)
  2972. {
  2973. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2974. 0:
  2975. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2976. }
  2977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2978. {
  2979. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2980. {
  2981. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2982. 0:
  2983. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2984. if(idxPeriod > 0)
  2985. {
  2986. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2987. {
  2988. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2989. }
  2990. }
  2991. }
  2992. }
  2993. }
  2994. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2995. {
  2996. if(maxProfile.ChargingSchedule.Duration != -1)
  2997. {
  2998. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2999. 0:
  3000. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3001. }
  3002. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3003. {
  3004. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3005. {
  3006. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3007. 0:
  3008. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3009. if(idxPeriod > 0)
  3010. {
  3011. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3012. {
  3013. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3014. }
  3015. }
  3016. }
  3017. }
  3018. }
  3019. else
  3020. {
  3021. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3022. {
  3023. if(maxProfile.ChargingSchedule.Duration != -1)
  3024. {
  3025. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3026. 0:
  3027. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3028. }
  3029. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3030. {
  3031. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3032. {
  3033. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3034. 0:
  3035. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3036. if(idxPeriod > 0)
  3037. {
  3038. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3039. {
  3040. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3041. }
  3042. }
  3043. }
  3044. }
  3045. }
  3046. else
  3047. {
  3048. if(maxProfile.ChargingSchedule.Duration != -1)
  3049. {
  3050. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3051. 0:
  3052. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3053. }
  3054. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3055. {
  3056. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3057. {
  3058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3059. 0:
  3060. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3061. if(idxPeriod > 0)
  3062. {
  3063. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3064. {
  3065. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3066. }
  3067. }
  3068. }
  3069. }
  3070. }
  3071. }
  3072. /*
  3073. DEBUG_INFO("MaxProfile after align.\n");
  3074. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3075. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3076. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3077. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3078. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3079. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3080. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3081. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3082. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3083. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3084. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3085. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3086. {
  3087. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3088. {
  3089. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3090. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3091. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3092. }
  3093. }
  3094. DEBUG_INFO("------------------------------------\n");*/
  3095. }
  3096. /*
  3097. * Merge to conposite schedule
  3098. */
  3099. //DEBUG_INFO("====================================\n");
  3100. // Find each profile period quantity
  3101. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3102. {
  3103. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3104. limitMax = idx+1;
  3105. }
  3106. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3107. {
  3108. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3109. limitDef = idx+1;
  3110. }
  3111. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3112. {
  3113. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3114. limitTx = idx+1;
  3115. }
  3116. // TxProfile found, composite schedule based on it
  3117. if(txProfile.ChargingProfileId != -1)
  3118. {
  3119. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3120. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3121. {
  3122. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3123. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3124. (txProfile.ChargingSchedule.Duration > 0))
  3125. {
  3126. if(maxProfile.ChargingProfileId != -1)
  3127. {
  3128. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3129. {
  3130. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3131. {
  3132. if((maxProfile.ChargingSchedule.Duration > 0))
  3133. {
  3134. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3135. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3136. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3137. }
  3138. else
  3139. {
  3140. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3141. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3142. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3143. }
  3144. }
  3145. if(idxMaxPeriod == (limitMax-1))
  3146. {
  3147. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3148. {
  3149. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3150. {
  3151. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3152. compositePeriodIdx++;
  3153. }
  3154. else
  3155. {
  3156. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3157. }
  3158. }
  3159. }
  3160. }
  3161. }
  3162. else
  3163. {
  3164. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3165. {
  3166. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3167. compositePeriodIdx++;
  3168. }
  3169. else
  3170. {
  3171. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3172. }
  3173. }
  3174. }
  3175. if(idxTxPeriod == (limitTx-1))
  3176. {
  3177. if(defaultTxProfile.ChargingProfileId != -1)
  3178. {
  3179. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3180. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3181. {
  3182. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3183. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3184. (defaultTxProfile.ChargingSchedule.Duration>0))
  3185. {
  3186. if(maxProfile.ChargingProfileId != -1)
  3187. {
  3188. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3189. {
  3190. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3191. {
  3192. if((maxProfile.ChargingSchedule.Duration > 0))
  3193. {
  3194. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3195. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3196. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3197. }
  3198. else
  3199. {
  3200. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3201. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3202. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3203. }
  3204. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3205. {
  3206. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3207. {
  3208. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3209. compositePeriodIdx++;
  3210. }
  3211. else
  3212. {
  3213. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3214. }
  3215. }
  3216. // Delete duplicate period
  3217. if(compositePeriodIdx > 1)
  3218. {
  3219. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3220. {
  3221. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3222. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3223. compositePeriodIdx -= 1;
  3224. }
  3225. }
  3226. }
  3227. else
  3228. {
  3229. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3230. {
  3231. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3232. compositePeriodIdx++;
  3233. }
  3234. else
  3235. {
  3236. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3237. }
  3238. break;
  3239. }
  3240. }
  3241. }
  3242. else
  3243. {
  3244. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3245. {
  3246. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3247. compositePeriodIdx++;
  3248. }
  3249. else
  3250. {
  3251. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3252. }
  3253. }
  3254. }
  3255. }
  3256. }
  3257. }
  3258. }
  3259. }
  3260. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3261. else if(defaultTxProfile.ChargingProfileId != -1)
  3262. {
  3263. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3264. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3265. {
  3266. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3267. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3268. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3269. {
  3270. if(maxProfile.ChargingProfileId != -1)
  3271. {
  3272. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3273. {
  3274. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3275. {
  3276. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3277. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3278. if((maxProfile.ChargingSchedule.Duration > 0))
  3279. {
  3280. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3281. }
  3282. else
  3283. {
  3284. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3285. }
  3286. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3287. {
  3288. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3289. {
  3290. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3291. compositePeriodIdx++;
  3292. }
  3293. else
  3294. {
  3295. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3296. }
  3297. }
  3298. // Delete duplicate period
  3299. if(compositePeriodIdx > 1)
  3300. {
  3301. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3302. {
  3303. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3304. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3305. compositePeriodIdx -= 1;
  3306. }
  3307. }
  3308. }
  3309. else
  3310. {
  3311. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3312. {
  3313. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3314. compositePeriodIdx++;
  3315. }
  3316. else
  3317. {
  3318. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3319. }
  3320. break;
  3321. }
  3322. }
  3323. }
  3324. else
  3325. {
  3326. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3327. {
  3328. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3329. compositePeriodIdx++;
  3330. }
  3331. else
  3332. {
  3333. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3334. }
  3335. }
  3336. }
  3337. }
  3338. }
  3339. // Fill other period by MaxProfile
  3340. if(maxProfile.ChargingProfileId != -1)
  3341. {
  3342. if(compositePeriodIdx==0)
  3343. {
  3344. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3345. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3346. {
  3347. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3348. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3349. (maxProfile.ChargingSchedule.Duration > 0))
  3350. {
  3351. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3352. {
  3353. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3354. compositePeriodIdx++;
  3355. }
  3356. else
  3357. {
  3358. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3359. }
  3360. }
  3361. }
  3362. }
  3363. else
  3364. {
  3365. int lastCompositePeriodIdx = compositePeriodIdx;
  3366. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3367. {
  3368. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3369. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3370. (maxProfile.ChargingSchedule.Duration > 0))
  3371. {
  3372. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3373. {
  3374. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3375. {
  3376. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3377. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3378. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3379. }
  3380. else
  3381. {
  3382. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3383. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3384. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3385. }
  3386. }
  3387. if(tmpPeriod.Limit != -1)
  3388. {
  3389. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3390. {
  3391. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3392. {
  3393. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3394. compositePeriodIdx++;
  3395. }
  3396. else
  3397. {
  3398. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3399. }
  3400. }
  3401. // Delete duplicate period
  3402. if(compositePeriodIdx > 1)
  3403. {
  3404. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3405. {
  3406. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3407. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3408. compositePeriodIdx -= 1;
  3409. }
  3410. }
  3411. }
  3412. }
  3413. }
  3414. }
  3415. }
  3416. compositeProfile.ChargingSchedule.Duration = durationReq;
  3417. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3418. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3419. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3420. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3421. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3422. {
  3423. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3424. {
  3425. compositeProfile.ChargingProfileId = 1;
  3426. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3427. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3428. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3429. }
  3430. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3431. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3432. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3433. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3434. }
  3435. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3436. if(line)
  3437. free(line);
  3438. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3439. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3440. }
  3441. //==========================================
  3442. // Init all share memory
  3443. //==========================================
  3444. int InitShareMemory()
  3445. {
  3446. int result = PASS;
  3447. int MeterSMId;
  3448. //creat ShmSysConfigAndInfo
  3449. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3450. {
  3451. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3452. result = FAIL;
  3453. }
  3454. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3455. {
  3456. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3457. result = FAIL;
  3458. }
  3459. else
  3460. {}
  3461. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3462. {
  3463. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3464. result = FAIL;
  3465. }
  3466. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3467. {
  3468. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3469. result = FAIL;
  3470. }
  3471. else
  3472. {}
  3473. //creat ShmPsuData
  3474. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3475. {
  3476. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3477. result = FAIL;
  3478. }
  3479. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3480. {
  3481. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3482. result = FAIL;
  3483. }
  3484. else
  3485. {}
  3486. //link ShmOCPP16Data
  3487. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3488. {
  3489. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3490. result = FAIL;
  3491. }
  3492. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3493. {
  3494. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3495. result = FAIL;
  3496. }
  3497. else
  3498. {}
  3499. //creat ShmOCPP16DataPH
  3500. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3501. {
  3502. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3503. result = FAIL;
  3504. }
  3505. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3506. {
  3507. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3508. result = FAIL;
  3509. }
  3510. else
  3511. {}
  3512. /****************************** For Initial Settings************************************************/
  3513. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3514. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3515. // allocate Configuration memory address
  3516. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3517. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3518. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3519. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3520. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3521. //offline MeterValue Interval
  3522. TempMeterValueInterval = 0;
  3523. return result;
  3524. }
  3525. int ProcessShareMemory()
  3526. {
  3527. int result = PASS;
  3528. if(InitShareMemory() == FAIL)
  3529. {
  3530. DEBUG_ERROR("InitShareMemory NG\n");
  3531. if(ShmStatusCodeData!=NULL)
  3532. {
  3533. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3534. }
  3535. result = FAIL;
  3536. }
  3537. // Model name parsing
  3538. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3539. {
  3540. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3541. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3542. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3543. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3544. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  3545. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  3546. ) // 'D' means DC
  3547. {
  3548. // DO series
  3549. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3550. {
  3551. gunTotalNumber += 1;
  3552. gunType[gun_index] = GUN_TYPE_DO;
  3553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3554. {
  3555. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3556. {
  3557. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3558. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3559. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3560. }
  3561. }
  3562. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3563. {
  3564. case Gun_Type_Chademo:
  3565. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3566. break;
  3567. case Gun_Type_CCS_2:
  3568. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3569. break;
  3570. case Gun_Type_GB:
  3571. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3572. break;
  3573. case Gun_Type_AC:
  3574. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3575. break;
  3576. default:
  3577. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3578. break;
  3579. }
  3580. }
  3581. }
  3582. else
  3583. {
  3584. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3585. {
  3586. gunTotalNumber += 1;
  3587. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3588. {
  3589. case Gun_Type_Chademo:
  3590. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3591. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3592. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3593. {
  3594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3595. {
  3596. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3597. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3598. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  3599. }
  3600. }
  3601. break;
  3602. case Gun_Type_CCS_2:
  3603. gunType[gun_index] = GUN_TYPE_CCS;
  3604. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3605. for (int index = 0; index < CCS_QUANTITY; index++)
  3606. {
  3607. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3608. {
  3609. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3610. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3611. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  3612. }
  3613. }
  3614. break;
  3615. case Gun_Type_GB:
  3616. gunType[gun_index] = GUN_TYPE_GBT;
  3617. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3618. for (int index = 0; index < GB_QUANTITY; index++)
  3619. {
  3620. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3621. {
  3622. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3623. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3624. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  3625. }
  3626. }
  3627. break;
  3628. case Gun_Type_AC:
  3629. gunType[gun_index] = GUN_TYPE_AC;
  3630. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3631. for (int index = 0; index < AC_QUANTITY; index++)
  3632. {
  3633. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  3634. {
  3635. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3636. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3637. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  3638. }
  3639. }
  3640. break;
  3641. default:
  3642. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3643. break;
  3644. }
  3645. }
  3646. }
  3647. }
  3648. else
  3649. {
  3650. DEBUG_ERROR("Model name parsing fail.\n");
  3651. result = FAIL;
  3652. }
  3653. if(result != PASS)sleep(5);
  3654. return result;
  3655. }
  3656. void checkRemoteStart(uint8_t connectorIdInt)
  3657. {
  3658. uint8_t tempIndex;
  3659. int result = PASS;
  3660. char cmdBuf[512];
  3661. //check Transaction active
  3662. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3667. }
  3668. else
  3669. {
  3670. tempIndex = connectorIdInt -1;
  3671. }
  3672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3673. {
  3674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3675. {
  3676. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3677. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3678. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3679. {
  3680. //Reserved
  3681. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3682. }
  3683. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3684. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3685. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3686. {
  3687. //Reserved
  3688. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3689. result = FAIL;
  3690. goto end;
  3691. }
  3692. else
  3693. {
  3694. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3696. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3697. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3698. {
  3699. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3700. result = FAIL;
  3701. goto end;
  3702. }
  3703. }//END FOR ELSE
  3704. }
  3705. }// END FOR CHAdeMO_QUANTITY
  3706. }
  3707. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3708. {
  3709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3710. {
  3711. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3712. }
  3713. else
  3714. {
  3715. tempIndex = connectorIdInt -1;
  3716. }
  3717. for (int index = 0; index < CCS_QUANTITY; index++)
  3718. {
  3719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3720. {
  3721. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3722. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3723. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3724. {
  3725. //Reserved
  3726. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3727. }
  3728. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3729. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3730. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3731. {
  3732. //Reserved
  3733. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3734. result = FAIL;
  3735. goto end;
  3736. }
  3737. else
  3738. {
  3739. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3740. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3741. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3742. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3743. {
  3744. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3745. result = FAIL;
  3746. goto end;
  3747. }
  3748. }// END FOR ELSE
  3749. }
  3750. }// END FOR CCS_QUANTITY
  3751. }
  3752. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3753. {
  3754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3755. {
  3756. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3757. }
  3758. else
  3759. {
  3760. tempIndex = connectorIdInt -1;
  3761. }
  3762. for (int index = 0; index < GB_QUANTITY; index++)
  3763. {
  3764. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3765. {
  3766. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3767. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3768. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3769. {
  3770. //Reserved
  3771. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3772. }
  3773. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3774. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3775. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3776. {
  3777. //Reserved
  3778. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3779. result = FAIL;
  3780. goto end;
  3781. }
  3782. else
  3783. {
  3784. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3785. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3786. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3787. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3788. {
  3789. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3790. result = FAIL;
  3791. goto end;
  3792. }
  3793. }// END FOR ELSE
  3794. }
  3795. } // END FOR GB_QUANTITY
  3796. }
  3797. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3798. {
  3799. tempIndex = connectorIdInt -1;
  3800. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3801. {
  3802. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3803. {
  3804. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3805. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3806. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3807. {
  3808. //Reserved
  3809. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3810. }
  3811. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3812. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3813. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3814. {
  3815. //Reserved
  3816. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3817. result = FAIL;
  3818. goto end;
  3819. }
  3820. else
  3821. {
  3822. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3823. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3824. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3825. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3826. {
  3827. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3828. result = FAIL;
  3829. goto end;
  3830. }
  3831. }// END FOR ELSE
  3832. }
  3833. } // END FOR GB_QUANTITY
  3834. }
  3835. else
  3836. {
  3837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3838. {
  3839. tempIndex = 2;
  3840. }
  3841. else
  3842. {
  3843. tempIndex = connectorIdInt -1;
  3844. }
  3845. for (int index = 0; index < AC_QUANTITY; index++)
  3846. {
  3847. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3848. {
  3849. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3850. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3851. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3852. {
  3853. //Reserved
  3854. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3855. }
  3856. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3857. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3858. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3859. {
  3860. //Reserved
  3861. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3862. result = FAIL;
  3863. goto end;
  3864. }
  3865. else
  3866. {
  3867. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3868. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3869. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3870. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3871. {
  3872. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3873. result = FAIL;
  3874. goto end;
  3875. }
  3876. }//END FOR ELSE
  3877. }
  3878. }// END FOR AC_QUANTITY
  3879. }
  3880. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3881. {
  3882. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3883. {
  3884. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3885. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3886. {
  3887. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3888. system(cmdBuf);
  3889. }
  3890. }
  3891. else
  3892. {
  3893. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3894. result = FAIL;
  3895. }
  3896. }
  3897. end:
  3898. if(result == PASS)
  3899. {
  3900. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3901. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3902. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3903. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3905. }
  3906. }
  3907. void CheckSystemValue(void)
  3908. {
  3909. char filenmae[100]={0};
  3910. char str[100]={0};
  3911. int tempIndex = 0;
  3912. //===============================
  3913. // send Heartbeat
  3914. //===============================
  3915. if((server_sign == TRUE) && (HeartBeatWaitTime > 0) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3916. {
  3917. //parameter for test
  3918. sendHeartbeatRequest(0);
  3919. //==============================================
  3920. // Reset Waiting Time
  3921. //==============================================
  3922. HeartBeatWithNOResponse += 2;
  3923. }
  3924. //===============================
  3925. // Credit deduct report
  3926. //===============================
  3927. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3928. {
  3929. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3930. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3931. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3932. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3933. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3934. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3935. }
  3936. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3937. {
  3938. OCPP_query_deduct_info();
  3939. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3940. }
  3941. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3942. {
  3943. // ClockAlign MeterValue
  3944. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3945. {
  3946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3947. {
  3948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3949. {
  3950. tempIndex = ((gun_index==2) ? 1: 0);
  3951. }
  3952. else
  3953. {
  3954. tempIndex = gun_index;
  3955. }
  3956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3957. {
  3958. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3959. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3960. {
  3961. reqClockAlignMeter[gun_index] = 1;
  3962. }
  3963. }// End for CHAdeMO
  3964. }
  3965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3966. {
  3967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3968. {
  3969. tempIndex = ((gun_index==2) ? 1: 0);
  3970. }
  3971. else
  3972. {
  3973. tempIndex = gun_index;
  3974. }
  3975. for (int index = 0; index < CCS_QUANTITY; index++)
  3976. {
  3977. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3978. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3979. {
  3980. reqClockAlignMeter[gun_index] = 1;
  3981. }
  3982. } // End for CCS
  3983. }
  3984. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3985. {
  3986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3987. {
  3988. tempIndex = ((gun_index==2) ? 1: 0);
  3989. }
  3990. else
  3991. {
  3992. tempIndex = gun_index;
  3993. }
  3994. for (int index = 0; index < GB_QUANTITY; index++)
  3995. {
  3996. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3997. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3998. {
  3999. reqClockAlignMeter[gun_index] = 1;
  4000. }
  4001. }// End for GB
  4002. }
  4003. else if(gunType[gun_index] == GUN_TYPE_DO)
  4004. {
  4005. tempIndex = gun_index;
  4006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4007. {
  4008. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4009. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4010. {
  4011. reqClockAlignMeter[gun_index] = 1;
  4012. }
  4013. }
  4014. }
  4015. else
  4016. {
  4017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4018. {
  4019. tempIndex = 2;
  4020. }
  4021. else
  4022. {
  4023. tempIndex = gun_index;
  4024. }
  4025. for (int index = 0; index < AC_QUANTITY; index++)
  4026. {
  4027. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4028. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4029. {
  4030. reqClockAlignMeter[gun_index] = 1;
  4031. }
  4032. }//End for AC
  4033. }
  4034. }
  4035. }
  4036. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4037. {
  4038. //==========================================
  4039. // Check remote start without connector id
  4040. //==========================================
  4041. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  4042. {
  4043. int connectorIdInt = -1;
  4044. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4045. {
  4046. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4047. {
  4048. connectorIdInt = (gun_index+1);
  4049. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4050. checkRemoteStart(connectorIdInt);
  4051. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4052. break;
  4053. }
  4054. }
  4055. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4056. {
  4057. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4058. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4059. }
  4060. }
  4061. //==========================================
  4062. // csu trigger DataTransferReq
  4063. //==========================================
  4064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4065. {
  4066. sendDataTransferRequest(gun_index);
  4067. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4068. }
  4069. //===============================
  4070. // CSU Trigger Authorize Request
  4071. //===============================
  4072. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4073. {
  4074. sendAuthorizeRequest(0);
  4075. authorizeRetryTimes = authorizeRetryTimes + 1;
  4076. if(authorizeRetryTimes < 3)
  4077. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4078. }
  4079. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4080. {
  4081. authorizeRetryTimes = 0;
  4082. SetOcppConnStatus(FALSE);
  4083. server_sign = FALSE;
  4084. }
  4085. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0)&& (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1))
  4086. {
  4087. sendAuthorizeRequest(0);
  4088. }
  4089. //==============================================
  4090. // Charger start transaction
  4091. //==============================================
  4092. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4093. {
  4094. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4095. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4096. sendStartTransactionRequest(gun_index);
  4097. refreshStartTimer(&clientTime.StartTransaction);
  4098. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4099. //storeTempStopTransaction(gun_index);
  4100. }
  4101. //==============================================
  4102. // Charger stop transaction
  4103. //==============================================
  4104. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4105. {
  4106. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4107. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4108. sendStopTransactionRequest(gun_index);
  4109. refreshStartTimer(&clientTime.StopTransaction);
  4110. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4111. }
  4112. //==============================================
  4113. // Charger status report
  4114. //==============================================
  4115. //--- Check Mode Change ---//
  4116. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4117. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4118. {
  4119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4120. {
  4121. tempIndex = ((gun_index==2) ? 1: 0);
  4122. }
  4123. else
  4124. {
  4125. tempIndex = gun_index;
  4126. }
  4127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4128. {
  4129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4130. {
  4131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4132. {
  4133. // Sent unplug message for California pricing logic
  4134. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4135. {
  4136. uint8_t ts[36];
  4137. getNowDatetime(ts);
  4138. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4139. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4140. if(strcmp((char*)dmsVersion, "2.0")==0)
  4141. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4142. else
  4143. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4144. sendUnplugByDataTransferRequest(gun_index);
  4145. interLock.isSentUnplug[gun_index] = 1;
  4146. }
  4147. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4148. {
  4149. interLock.isSentUnplug[gun_index] = 0;
  4150. }
  4151. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4152. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4153. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4154. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4155. {
  4156. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4157. if((access(filenmae,F_OK))!=-1)
  4158. {
  4159. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4160. sprintf(str,"rm -f %s",filenmae);
  4161. system(str);
  4162. }
  4163. }
  4164. }
  4165. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4166. #if 1 // for TempStopTransaction
  4167. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4168. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4169. {
  4170. checkTempStopTransaction(gun_index);
  4171. }
  4172. #endif
  4173. }
  4174. }
  4175. }
  4176. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4177. {
  4178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4179. {
  4180. tempIndex = ((gun_index==2) ? 1: 0);
  4181. }
  4182. else
  4183. {
  4184. tempIndex = gun_index;
  4185. }
  4186. for (int index = 0; index < CCS_QUANTITY; index++)
  4187. {
  4188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4189. {
  4190. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4191. {
  4192. // Sent unplug message for California pricing logic
  4193. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4194. {
  4195. uint8_t ts[36];
  4196. getNowDatetime(ts);
  4197. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4198. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4199. if(strcmp((char*)dmsVersion, "2.0")==0)
  4200. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4201. else
  4202. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4203. sendUnplugByDataTransferRequest(gun_index);
  4204. interLock.isSentUnplug[gun_index] = 1;
  4205. }
  4206. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4207. {
  4208. interLock.isSentUnplug[gun_index] = 0;
  4209. }
  4210. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4211. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4212. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4213. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4214. {
  4215. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4216. if((access(filenmae,F_OK))!=-1)
  4217. {
  4218. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4219. sprintf(str,"rm -f %s",filenmae);
  4220. system(str);
  4221. }
  4222. }
  4223. }
  4224. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4225. #if 1 // for TempStopTransaction
  4226. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4227. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4228. {
  4229. checkTempStopTransaction(gun_index);
  4230. }
  4231. #endif
  4232. }
  4233. }
  4234. }
  4235. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4236. {
  4237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4238. {
  4239. tempIndex = ((gun_index==2) ? 1: 0);
  4240. }
  4241. else
  4242. {
  4243. tempIndex = gun_index;
  4244. }
  4245. for (int index = 0; index < GB_QUANTITY; index++)
  4246. {
  4247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4248. {
  4249. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4250. {
  4251. // Sent unplug message for California pricing logic
  4252. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4253. {
  4254. uint8_t ts[36];
  4255. getNowDatetime(ts);
  4256. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4257. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4258. if(strcmp((char*)dmsVersion, "2.0")==0)
  4259. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4260. else
  4261. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4262. sendUnplugByDataTransferRequest(gun_index);
  4263. interLock.isSentUnplug[gun_index] = 1;
  4264. }
  4265. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4266. {
  4267. interLock.isSentUnplug[gun_index] = 0;
  4268. }
  4269. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4270. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4271. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4272. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4273. {
  4274. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4275. if((access(filenmae,F_OK))!=-1)
  4276. {
  4277. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4278. sprintf(str,"rm -f %s",filenmae);
  4279. system(str);
  4280. }
  4281. }
  4282. }
  4283. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4284. #if 1 // for TempStopTransaction
  4285. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4286. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4287. {
  4288. checkTempStopTransaction(gun_index);
  4289. }
  4290. #endif
  4291. }
  4292. }
  4293. }
  4294. else if(gunType[gun_index] == GUN_TYPE_DO)
  4295. {
  4296. tempIndex = gun_index;
  4297. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4298. {
  4299. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4300. {
  4301. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4302. {
  4303. // Sent unplug message for California pricing logic
  4304. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4305. {
  4306. uint8_t ts[36];
  4307. getNowDatetime(ts);
  4308. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4309. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4310. if(strcmp((char*)dmsVersion, "2.0")==0)
  4311. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4312. else
  4313. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4314. sendUnplugByDataTransferRequest(gun_index);
  4315. interLock.isSentUnplug[gun_index] = 1;
  4316. }
  4317. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4318. {
  4319. interLock.isSentUnplug[gun_index] = 0;
  4320. }
  4321. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4322. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4323. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4324. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4325. {
  4326. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4327. if((access(filenmae,F_OK))!=-1)
  4328. {
  4329. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4330. sprintf(str,"rm -f %s",filenmae);
  4331. system(str);
  4332. }
  4333. }
  4334. }
  4335. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4336. #if 1 // for TempStopTransaction
  4337. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4338. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4339. {
  4340. checkTempStopTransaction(gun_index);
  4341. }
  4342. #endif
  4343. }
  4344. }
  4345. }
  4346. else
  4347. {
  4348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4349. {
  4350. tempIndex = 2;
  4351. }
  4352. else
  4353. {
  4354. tempIndex = gun_index;
  4355. }
  4356. for (int index = 0; index < AC_QUANTITY; index++)
  4357. {
  4358. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4359. {
  4360. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4361. {
  4362. // Sent unplug message for California pricing logic
  4363. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4364. {
  4365. uint8_t ts[36];
  4366. getNowDatetime(ts);
  4367. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4368. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4369. if(strcmp((char*)dmsVersion, "2.0")==0)
  4370. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4371. else
  4372. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4373. sendUnplugByDataTransferRequest(gun_index);
  4374. interLock.isSentUnplug[gun_index] = 1;
  4375. }
  4376. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4377. {
  4378. interLock.isSentUnplug[gun_index] = 0;
  4379. }
  4380. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4381. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4382. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4383. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4384. {
  4385. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4386. if((access(filenmae,F_OK))!=-1)
  4387. {
  4388. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4389. sprintf(str,"rm -f %s",filenmae);
  4390. system(str);
  4391. }
  4392. }
  4393. }
  4394. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4395. #if 1 // for TempStopTransaction
  4396. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4397. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4398. {
  4399. checkTempStopTransaction(gun_index);
  4400. }
  4401. #endif
  4402. }
  4403. }// END
  4404. }
  4405. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4406. (
  4407. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4408. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4409. )
  4410. )
  4411. {
  4412. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4413. sendStatusNotificationRequest(gun_index);
  4414. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4415. }
  4416. //==============================================
  4417. // TCCI reader status report
  4418. //==============================================
  4419. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4420. {
  4421. reportReaderStatus(gun_index);
  4422. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4423. }
  4424. //==============================================
  4425. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4426. //==============================================
  4427. if((ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  4428. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  4429. {
  4430. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4431. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4432. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  4433. }
  4434. //==============================================
  4435. // Meter report
  4436. //==============================================
  4437. // Trigger MeterValue
  4438. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4439. {
  4440. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4441. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4442. }
  4443. // Clock-aligned Meter value
  4444. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4445. {
  4446. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4447. reqClockAlignMeter[gun_index] = 0;
  4448. }
  4449. // Sample period MeterValue
  4450. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4451. {
  4452. //check Transaction active
  4453. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4454. {
  4455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4456. {
  4457. tempIndex = ((gun_index==2) ? 1: 0);
  4458. }
  4459. else
  4460. {
  4461. tempIndex = gun_index;
  4462. }
  4463. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4464. {
  4465. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4466. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4467. {
  4468. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4469. {
  4470. reqSampleMeter[gun_index] = 1;
  4471. }
  4472. }
  4473. }// End for CHAdeMO
  4474. }
  4475. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4476. {
  4477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4478. {
  4479. tempIndex = ((gun_index==2) ? 1: 0);
  4480. }
  4481. else
  4482. {
  4483. tempIndex = gun_index;
  4484. }
  4485. for (int index = 0; index < CCS_QUANTITY; index++)
  4486. {
  4487. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4488. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4489. {
  4490. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4491. {
  4492. reqSampleMeter[gun_index] = 1;
  4493. }
  4494. }
  4495. } // End for CCS
  4496. }
  4497. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4498. {
  4499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4500. {
  4501. tempIndex = ((gun_index==2) ? 1: 0);
  4502. }
  4503. else
  4504. {
  4505. tempIndex = gun_index;
  4506. }
  4507. for (int index = 0; index < GB_QUANTITY; index++)
  4508. {
  4509. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4510. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4511. {
  4512. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4513. {
  4514. reqSampleMeter[gun_index] = 1;
  4515. }
  4516. }
  4517. }// End for GB
  4518. }
  4519. else if(gunType[gun_index] == GUN_TYPE_DO)
  4520. {
  4521. tempIndex = gun_index;
  4522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4523. {
  4524. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4525. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4526. {
  4527. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4528. {
  4529. reqSampleMeter[gun_index] = 1;
  4530. }
  4531. }
  4532. }
  4533. }
  4534. else
  4535. {
  4536. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4537. {
  4538. tempIndex = 2;
  4539. }
  4540. else
  4541. {
  4542. tempIndex = gun_index;
  4543. }
  4544. for (int index = 0; index < AC_QUANTITY; index++)
  4545. {
  4546. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4547. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4548. {
  4549. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4550. {
  4551. reqSampleMeter[gun_index] = 1;
  4552. }
  4553. }
  4554. }//End for AC
  4555. }
  4556. if(reqSampleMeter[gun_index] == 1)
  4557. {
  4558. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4559. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4560. //storeTempStopTransaction(gun_index);
  4561. reqSampleMeter[gun_index] = 0;
  4562. }
  4563. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4564. }
  4565. //==============================================
  4566. // Check Connector reserved
  4567. //==============================================
  4568. //===============================
  4569. // Check if Reserve is expired
  4570. //===============================
  4571. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4572. {
  4573. double diff_t;
  4574. struct tm tp;
  4575. // current time
  4576. time_t t = time(NULL);
  4577. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4578. tp.tm_isdst = -1;
  4579. time_t utc = mktime(&tp);
  4580. diff_t = difftime(utc, t);
  4581. if(diff_t <= 0)
  4582. {
  4583. DEBUG_INFO("reserve expired.\n");
  4584. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4585. }
  4586. }//END OF Check if Reserve is expired
  4587. //==========================================
  4588. // csu trigger FirmwareStatusNotificationReq
  4589. //==========================================
  4590. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4591. {
  4592. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4593. }
  4594. //==========================================
  4595. // csu trigger DiagnosticsStatusNotificationReq
  4596. //==========================================
  4597. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4598. {
  4599. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4600. }
  4601. //==========================================
  4602. // csu trigger CancelReservationConf
  4603. //==========================================
  4604. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4605. {
  4606. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4607. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4608. }
  4609. //==========================================
  4610. // csu trigger ChangeAvailabilityConf
  4611. //==========================================
  4612. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4613. {
  4614. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4615. }
  4616. //==========================================
  4617. // csu trigger UnlockConnectorConf
  4618. //==========================================
  4619. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4620. {
  4621. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4622. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4623. }
  4624. //==========================================
  4625. // csu trigger ReserveNowConf
  4626. //==========================================
  4627. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4628. {
  4629. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4630. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4631. }
  4632. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4633. {
  4634. sendSignCertificateRequest();
  4635. }
  4636. }
  4637. }
  4638. //==========================================
  4639. // send request routine
  4640. //==========================================
  4641. int sendAuthorizeRequest(int gun_index)
  4642. {
  4643. mtrace();
  4644. int result = FAIL;
  4645. char message[100]={0};
  4646. char guid[37];
  4647. char tempdata[65]={0};
  4648. DEBUG_INFO("sendAuthorizeRequest...\n");
  4649. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4650. //Local Authorize
  4651. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4652. {
  4653. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4654. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4655. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4656. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4657. result = PASS;
  4658. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4659. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4660. authorizeRetryTimes = 0;
  4661. return result;
  4662. }
  4663. else if(((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0))||
  4664. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4665. {
  4666. // Query from cache
  4667. DEBUG_INFO("Authorize from cache.\n");
  4668. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4669. // Query from list
  4670. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4671. {
  4672. DEBUG_INFO("Authorize from list.\n");
  4673. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4674. }
  4675. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4676. {
  4677. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4678. {
  4679. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4680. }
  4681. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4682. {
  4683. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4684. }
  4685. if(!GetOcppConnStatus())
  4686. {
  4687. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4688. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4689. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4690. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4691. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4692. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4693. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4694. authorizeRetryTimes = 0;
  4695. return result;
  4696. }
  4697. }
  4698. else
  4699. {
  4700. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4701. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4702. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4703. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4704. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4705. else
  4706. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4707. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4708. result = PASS;
  4709. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4710. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4711. authorizeRetryTimes = 0;
  4712. return result;
  4713. }
  4714. }
  4715. //initialize struct Authorize
  4716. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4717. //get data from shared memory
  4718. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4719. random_uuid(guid);
  4720. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4721. LWS_Send(message);
  4722. sprintf(tempdata, "Authorize,%d", gun_index);
  4723. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4724. {
  4725. result = PASS;
  4726. DEBUG_INFO("Authorize mapItem pass\n");
  4727. }
  4728. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4729. return result;
  4730. }
  4731. int sendBootNotificationRequest(void)
  4732. {
  4733. mtrace();
  4734. int result = FAIL;
  4735. char message[500]={0}, payload[700]={0};
  4736. char guid[37]={0};
  4737. char tempdata[65]={0};
  4738. // Fill BootNotification fields
  4739. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4740. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4741. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4742. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4743. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4744. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4745. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4746. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4747. ShmOCPP16DataPH->ChargeBoxId
  4748. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4749. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4750. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4751. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4752. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4753. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4754. random_uuid(guid);
  4755. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4756. LWS_Send(message);
  4757. sprintf(tempdata, "BootNotification,0");
  4758. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4759. {
  4760. result = PASS;
  4761. }
  4762. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4763. strcpy(queuedata,message);
  4764. return result;
  4765. }
  4766. int sendDataTransferRequest(int gun_index)
  4767. {
  4768. mtrace();
  4769. char message[10240]={0};
  4770. char guid[37]={0};
  4771. char tempdata[65]={0};
  4772. int result = FAIL;
  4773. json_object *DataTransfer = json_object_new_object();
  4774. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId));
  4775. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId));
  4776. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data));
  4777. random_uuid(guid);
  4778. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  4779. guid,
  4780. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  4781. json_object_put(DataTransfer);
  4782. LWS_Send(message);
  4783. sprintf(tempdata, "DataTransfer,%d", gun_index);
  4784. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4785. {
  4786. result = PASS;
  4787. DEBUG_INFO("DataTransfer mapItem pass\n");
  4788. }
  4789. return result;
  4790. }
  4791. int sendUnplugByDataTransferRequest(int gun_index)
  4792. {
  4793. mtrace();
  4794. char message[10752]={0};
  4795. char guid[37]={0};
  4796. char tempdata[65]={0};
  4797. int result = FAIL;
  4798. random_uuid(guid);
  4799. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4800. (gun_index+1),
  4801. MESSAGE_TYPE_CALL,
  4802. guid,
  4803. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4804. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4805. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4806. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4807. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4808. {
  4809. result = PASS;
  4810. DEBUG_INFO("DataTransfer mapItem pass\n");
  4811. }
  4812. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4813. return result;
  4814. }
  4815. int sendDiagnosticsStatusNotificationRequest(char *status)
  4816. {
  4817. mtrace();
  4818. int result = FAIL;
  4819. char message[110]={0};
  4820. char guid[37]={0};
  4821. char tempdata[65]={0};
  4822. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4823. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4824. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4825. random_uuid(guid);
  4826. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4827. LWS_SendNow(message);
  4828. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4829. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4830. {
  4831. result = PASS;
  4832. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4833. }
  4834. //#ifdef SystemLogMessage
  4835. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4836. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4837. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4838. //#endif
  4839. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4840. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4841. //record status
  4842. if(strcmp(status,"Idle")==0)
  4843. {
  4844. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4845. }
  4846. else if(strcmp(status,"Uploaded")==0)
  4847. {
  4848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4849. }
  4850. else if(strcmp(status,"UploadFailed")==0)
  4851. {
  4852. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4853. }
  4854. else if(strcmp(status,"Uploading")==0)
  4855. {
  4856. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4857. }
  4858. return result;
  4859. }
  4860. int sendFirmwareStatusNotificationRequest(char *status)
  4861. {
  4862. mtrace();
  4863. int result = FAIL;
  4864. char message[110]={0};
  4865. char guid[37]={0};
  4866. char tempdata[65]={0};
  4867. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4868. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4869. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4870. random_uuid(guid);
  4871. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4872. LWS_SendNow(message);
  4873. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4874. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4875. {
  4876. result = PASS;
  4877. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4878. }
  4879. //#ifdef SystemLogMessage
  4880. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4881. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4882. //#endif
  4883. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4884. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4885. //record status
  4886. if(strcmp(status,"Downloaded")==0)
  4887. {
  4888. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4889. }
  4890. else if(strcmp(status,"DownloadFailed")==0)
  4891. {
  4892. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4893. }
  4894. else if(strcmp(status,"Downloading")==0)
  4895. {
  4896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4897. }
  4898. else if(strcmp(status,"Idle")==0)
  4899. {
  4900. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4901. }
  4902. else if(strcmp(status,"InstallationFailed")==0)
  4903. {
  4904. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4905. }
  4906. else if(strcmp(status,"Installing")==0)
  4907. {
  4908. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4909. }
  4910. else if(strcmp(status,"Installed")==0)
  4911. {
  4912. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4913. }
  4914. return result;
  4915. }
  4916. int sendHeartbeatRequest(int gun_index)
  4917. {
  4918. mtrace();
  4919. int result = FAIL;
  4920. char message[80]={0};
  4921. char guid[37]={0};
  4922. char tempdata[65]={0};
  4923. random_uuid(guid);
  4924. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4925. , MESSAGE_TYPE_CALL
  4926. , guid );
  4927. LWS_Send(message);
  4928. sprintf(tempdata, "Heartbeat,%d", 0);
  4929. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4930. {
  4931. result = PASS;
  4932. }
  4933. return result;
  4934. }
  4935. int sendStartTransactionRequest(int gun_index)
  4936. {
  4937. mtrace();
  4938. int result = FAIL;
  4939. char message[250]={0};
  4940. char guid[37]={0};
  4941. struct timeval tmnow;
  4942. struct tm *tm;
  4943. char buf[28];//, usec_buf[6];
  4944. char tempdata[65]={0};
  4945. int tempIndex = 0;
  4946. DEBUG_INFO("sendStartTransactionRequest...\n");
  4947. gettimeofday(&tmnow, NULL);
  4948. time_t t;
  4949. t = time(NULL);
  4950. /*UTC time and date*/
  4951. tm = gmtime(&t);
  4952. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4953. #if 0 // remove temporally
  4954. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4955. strcat(buf,".");
  4956. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4957. strcat(buf,usec_buf);
  4958. #endif
  4959. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4960. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4961. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4962. // clear StartTransaction Response
  4963. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4964. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4965. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4966. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4967. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4968. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4969. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4970. {
  4971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4972. {
  4973. tempIndex = ((gun_index==2) ? 1: 0);
  4974. }
  4975. else
  4976. {
  4977. tempIndex = gun_index;
  4978. }
  4979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4980. {
  4981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4982. {
  4983. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4984. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4985. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4986. }
  4987. }
  4988. }
  4989. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4990. {
  4991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4992. {
  4993. tempIndex = ((gun_index==2) ? 1: 0);
  4994. }
  4995. else
  4996. {
  4997. tempIndex = gun_index;
  4998. }
  4999. for (int index = 0; index < CCS_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5002. {
  5003. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5004. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5005. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5006. }
  5007. }
  5008. }
  5009. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5010. {
  5011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5012. {
  5013. tempIndex = ((gun_index==2) ? 1: 0);
  5014. }
  5015. else
  5016. {
  5017. tempIndex = gun_index;
  5018. }
  5019. for (int index = 0; index < GB_QUANTITY; index++)
  5020. {
  5021. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5022. {
  5023. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5024. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5025. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5026. }
  5027. }
  5028. }
  5029. else if(gunType[gun_index] == GUN_TYPE_DO)
  5030. {
  5031. tempIndex = gun_index;
  5032. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5033. {
  5034. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5035. {
  5036. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5037. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5038. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5039. }
  5040. }
  5041. }
  5042. else
  5043. {
  5044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5045. {
  5046. tempIndex = 2;
  5047. }
  5048. else
  5049. {
  5050. tempIndex = gun_index;
  5051. }
  5052. for (int index = 0; index < AC_QUANTITY; index++)
  5053. {
  5054. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5055. {
  5056. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5057. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5058. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5059. }
  5060. }
  5061. }
  5062. random_uuid(guid);
  5063. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5064. {
  5065. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5066. , gun_index +1
  5067. , MESSAGE_TYPE_CALL
  5068. , guid
  5069. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5070. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5071. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5072. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5073. }
  5074. else
  5075. {
  5076. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5077. , gun_index +1
  5078. , MESSAGE_TYPE_CALL
  5079. , guid
  5080. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5081. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5082. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5083. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5084. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5085. }
  5086. #if 1
  5087. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5088. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5089. {
  5090. result = PASS;
  5091. }
  5092. #endif
  5093. strcpy(queuedata, message);
  5094. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5095. OCPP_insert_transaction_msg(YES, queuedata);
  5096. return result;
  5097. }
  5098. int sendStatusNotificationRequest(int gun_index)
  5099. {
  5100. mtrace();
  5101. int result = FAIL;
  5102. char message[600]={0};
  5103. char guid[37];
  5104. int currentStatus = 0;
  5105. struct timeval tmnow;
  5106. struct tm *tm;
  5107. char buf[28];//, usec_buf[6];
  5108. char tempdata[65]={0};
  5109. int tempIndex = 0;
  5110. uint8_t isStateChanged = TRUE;
  5111. uint8_t isContentIllegal = TRUE;
  5112. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5113. gettimeofday(&tmnow, NULL);
  5114. time_t t;
  5115. t = time(NULL);
  5116. /*UTC time and date*/
  5117. tm = gmtime(&t);
  5118. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5119. #if 0 // remove temporally
  5120. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5121. strcat(buf,".");
  5122. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5123. strcat(buf,usec_buf);
  5124. #endif
  5125. //printf("%s",buf);
  5126. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5127. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5128. // it's option
  5129. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5130. /*
  5131. enum _SYSTEM_STATUS
  5132. {
  5133. S_BOOTING = 0,
  5134. S_IDLE, = 1
  5135. S_AUTHORIZING, =2
  5136. S_REASSIGN_CHECK, =3
  5137. S_REASSIGN, =4
  5138. S_PRECHARGE, =5
  5139. S_PREPARING_FOR_EV, =6
  5140. S_PREPARING_FOR_EVSE, =7
  5141. S_CHARGING, =8
  5142. S_TERMINATING, =9
  5143. S_COMPLETE, =10
  5144. S_ALARM, =11
  5145. S_FAULT =12
  5146. }
  5147. */
  5148. //check Transaction active
  5149. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5150. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5151. {
  5152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5153. {
  5154. tempIndex = ((gun_index==2) ? 1: 0);
  5155. }
  5156. else
  5157. {
  5158. tempIndex = gun_index;
  5159. }
  5160. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5161. {
  5162. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5163. {
  5164. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5165. {
  5166. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5167. {
  5168. currentStatus = Preparing; //OCPP Status: Preparing
  5169. }
  5170. else
  5171. {
  5172. currentStatus = Available; //OCPP Status: Available
  5173. }
  5174. }
  5175. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5176. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5177. ) //S_PRECHARGE
  5178. {
  5179. currentStatus = Preparing; //OCPP Status: Preparing
  5180. }
  5181. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5182. {
  5183. currentStatus = Charging; //OCPP Status: Charging
  5184. }
  5185. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5186. {
  5187. currentStatus = Finishing; //OCPP Status: Finishing
  5188. }
  5189. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5190. {
  5191. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5192. }
  5193. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5194. {
  5195. currentStatus = Unavailable; //OCPP Status: Unavailable
  5196. }
  5197. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5198. {
  5199. currentStatus = Faulted; //OCPP Status: Faulted
  5200. }
  5201. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5202. {
  5203. currentStatus = Reserved; //OCPP Status: Reserved
  5204. }
  5205. } //end of the same index
  5206. }//end of for CHAdeMO_QUANTITY
  5207. }
  5208. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5209. {
  5210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5211. {
  5212. tempIndex = ((gun_index==2) ? 1: 0);
  5213. }
  5214. else
  5215. {
  5216. tempIndex = gun_index;
  5217. }
  5218. for (int index = 0; index < CCS_QUANTITY; index++)
  5219. {
  5220. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5221. {
  5222. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5223. {
  5224. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5225. {
  5226. currentStatus = Preparing; //OCPP Status: Preparing
  5227. }
  5228. else
  5229. {
  5230. currentStatus = Available; //OCPP Status: Available
  5231. }
  5232. }
  5233. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5234. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5235. ) //S_PRECHARGE
  5236. {
  5237. currentStatus = Preparing; //OCPP Status: Preparing
  5238. }
  5239. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5240. {
  5241. currentStatus = Charging; //OCPP Status: Charging
  5242. }
  5243. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5244. {
  5245. currentStatus = Finishing; //OCPP Status: Finishing
  5246. }
  5247. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5248. {
  5249. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5250. }
  5251. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5252. {
  5253. currentStatus = Unavailable; //OCPP Status : Unavailable
  5254. }
  5255. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5256. {
  5257. currentStatus = Faulted; //OCPP Status: Faulted
  5258. }
  5259. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5260. {
  5261. currentStatus = Reserved; //OCPP Status: Reserved
  5262. }
  5263. } //end of the same index
  5264. } // end of for CCS_QUANTITY
  5265. }
  5266. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5267. {
  5268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5269. {
  5270. tempIndex = ((gun_index==2) ? 1: 0);
  5271. }
  5272. else
  5273. {
  5274. tempIndex = gun_index;
  5275. }
  5276. for (int index = 0; index < GB_QUANTITY; index++)
  5277. {
  5278. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5279. {
  5280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5281. {
  5282. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5283. {
  5284. currentStatus = Preparing; //OCPP Status: Preparing
  5285. }
  5286. else
  5287. {
  5288. currentStatus = Available; //OCPP Status: Available
  5289. }
  5290. }
  5291. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5292. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5293. ) //S_PRECHARGE
  5294. {
  5295. currentStatus = Preparing; //OCPP Status: Preparing
  5296. }
  5297. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5298. {
  5299. currentStatus = Charging; //OCPP Status: Charging
  5300. }
  5301. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5302. {
  5303. currentStatus = Finishing; //OCPP Status: Finishing
  5304. }
  5305. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5306. {
  5307. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5308. }
  5309. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5310. {
  5311. currentStatus = Unavailable; //OCPP Status: Unavailable
  5312. }
  5313. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5314. {
  5315. currentStatus = Faulted; //OCPP Status: Faulted
  5316. }
  5317. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5318. {
  5319. currentStatus = Reserved; //OCPP Status: Reserved
  5320. }
  5321. } //end of the same index
  5322. } // end of for GB_QUANTITY
  5323. }
  5324. else if(gunType[gun_index] == GUN_TYPE_DO)
  5325. {
  5326. tempIndex = gun_index;
  5327. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5328. {
  5329. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5330. {
  5331. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5332. {
  5333. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5334. {
  5335. currentStatus = Preparing; //OCPP Status: Preparing
  5336. }
  5337. else
  5338. {
  5339. currentStatus = Available; //OCPP Status: Available
  5340. }
  5341. }
  5342. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5343. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5344. ) //S_PRECHARGE
  5345. {
  5346. currentStatus = Preparing; //OCPP Status: Preparing
  5347. }
  5348. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5349. {
  5350. currentStatus = Charging; //OCPP Status: Charging
  5351. }
  5352. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5353. {
  5354. currentStatus = Finishing; //OCPP Status: Finishing
  5355. }
  5356. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5357. {
  5358. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5359. }
  5360. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5361. {
  5362. currentStatus = Unavailable; //OCPP Status: Unavailable
  5363. }
  5364. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5365. {
  5366. currentStatus = Faulted; //OCPP Status: Faulted
  5367. }
  5368. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5369. {
  5370. currentStatus = Reserved; //OCPP Status: Reserved
  5371. }
  5372. } //end of the same index
  5373. }
  5374. }
  5375. else
  5376. {
  5377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5378. {
  5379. tempIndex = 2;
  5380. }
  5381. else
  5382. {
  5383. tempIndex = gun_index;
  5384. }
  5385. for (int index = 0; index < AC_QUANTITY; index++)
  5386. {
  5387. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5388. {
  5389. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5390. {
  5391. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  5392. {
  5393. currentStatus = Preparing; //OCPP Status: Preparing
  5394. }
  5395. else
  5396. {
  5397. currentStatus = Available; //OCPP Status: Available
  5398. }
  5399. }
  5400. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5401. {
  5402. currentStatus = Preparing; //OCPP Status: Preparing
  5403. }
  5404. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5405. {
  5406. currentStatus = Charging; //OCPP Status: Charging
  5407. }
  5408. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5409. {
  5410. currentStatus = Finishing; //OCPP Status: Finishing
  5411. }
  5412. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5413. {
  5414. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5415. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5416. else
  5417. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5418. }
  5419. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  5420. {
  5421. currentStatus = Unavailable; //OCPP Status: Unavailable
  5422. }
  5423. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5424. {
  5425. currentStatus = Faulted; //OCPP Status: Faulted
  5426. }
  5427. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5428. {
  5429. currentStatus = Reserved; //OCPP Status: Reserved
  5430. }
  5431. }//end of the same index
  5432. }//end of for AC_QUANTITY
  5433. }
  5434. //it's option
  5435. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5436. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5437. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5438. {
  5439. isStateChanged = FALSE;
  5440. }
  5441. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5442. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5443. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5444. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5445. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5446. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5447. isContentIllegal = TRUE;
  5448. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5449. {
  5450. if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5451. {
  5452. isContentIllegal = FALSE;
  5453. break;
  5454. }
  5455. }
  5456. if(isContentIllegal)
  5457. {
  5458. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5459. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5460. }
  5461. random_uuid(guid);
  5462. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5463. , MESSAGE_TYPE_CALL
  5464. , guid
  5465. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5466. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5467. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5468. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5469. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5470. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5471. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5472. if((server_sign == TRUE) && isStateChanged)
  5473. {
  5474. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5475. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5476. LWS_Send(message);
  5477. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5478. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5479. {
  5480. //DEBUG_ERROR("statusNotification mapitem pass");
  5481. result = PASS;
  5482. }
  5483. }
  5484. else
  5485. {
  5486. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5487. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5488. result = PASS;
  5489. }
  5490. return result;
  5491. }
  5492. int sendStopTransactionRequest(int gun_index)
  5493. {
  5494. mtrace();
  5495. int result = FAIL;
  5496. //char message[1500]={0};
  5497. char guid[37]={0};
  5498. char tempdata[65]={0};
  5499. int tempIndex = 0;
  5500. char TempStopTransaction[256];
  5501. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5502. //int idx_sample=0;
  5503. DEBUG_INFO("sendStopTransactionRequest \n");
  5504. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5505. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5506. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5507. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5508. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5509. {
  5510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5511. {
  5512. tempIndex = ((gun_index==2) ? 1: 0);
  5513. }
  5514. else
  5515. {
  5516. tempIndex = gun_index;
  5517. }
  5518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5519. {
  5520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5521. {
  5522. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5523. }
  5524. }// END OF CHAdeMO_QUANTITY
  5525. }
  5526. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5527. {
  5528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5529. {
  5530. tempIndex = ((gun_index==2) ? 1: 0);
  5531. }
  5532. else
  5533. {
  5534. tempIndex = gun_index;
  5535. }
  5536. for (int index = 0; index < CCS_QUANTITY; index++)
  5537. {
  5538. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5539. {
  5540. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5541. }
  5542. }// END OF CCS_QUANTITY
  5543. }
  5544. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5545. {
  5546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5547. {
  5548. tempIndex = ((gun_index==2) ? 1: 0);
  5549. }
  5550. else
  5551. {
  5552. tempIndex = gun_index;
  5553. }
  5554. for (int index = 0; index < GB_QUANTITY; index++)
  5555. {
  5556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5557. {
  5558. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5559. }
  5560. }// END OF GB_QUANTITY
  5561. }
  5562. else if(gunType[gun_index] == GUN_TYPE_DO)
  5563. {
  5564. tempIndex = gun_index;
  5565. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5566. {
  5567. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5568. {
  5569. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5570. }
  5571. }// END OF GB_QUANTITY
  5572. }
  5573. else
  5574. {
  5575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5576. {
  5577. tempIndex = 2;
  5578. }
  5579. else
  5580. {
  5581. tempIndex = gun_index;
  5582. }
  5583. for (int index = 0; index < AC_QUANTITY; index++)
  5584. {
  5585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5586. {
  5587. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5588. }
  5589. }// END OF AC_QUANTITY
  5590. }
  5591. //====================================== Stop Transaction Time =====================================================
  5592. struct timeval tmnow;
  5593. struct tm *tm;
  5594. char buf[28];//, usec_buf[6];
  5595. gettimeofday(&tmnow, NULL);
  5596. time_t t;
  5597. t = time(NULL);
  5598. /*UTC time and date*/
  5599. tm = gmtime(&t);
  5600. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5601. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5602. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5603. random_uuid(guid);
  5604. /***********************************transactionData******************************************************/
  5605. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5607. //=================================
  5608. // Transaction_Begin
  5609. //=================================
  5610. //=================================
  5611. // Transaction_End
  5612. //=================================
  5613. // ================================= Current.Import L1 ===============================================
  5614. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5615. {
  5616. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5617. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5618. {
  5619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5620. {
  5621. tempIndex = ((gun_index==2) ? 1: 0);
  5622. }
  5623. else
  5624. {
  5625. tempIndex = gun_index;
  5626. }
  5627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5628. {
  5629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5630. {
  5631. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5632. }
  5633. }// End of for CHAdeMO_QUANTITY
  5634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5635. }
  5636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5637. {
  5638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5639. {
  5640. tempIndex = ((gun_index==2) ? 1: 0);
  5641. }
  5642. else
  5643. {
  5644. tempIndex = gun_index;
  5645. }
  5646. for (int index = 0; index < CCS_QUANTITY; index++)
  5647. {
  5648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5649. {
  5650. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5651. }
  5652. }// End of for CCS_QUANTITY
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5654. }
  5655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5656. {
  5657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5658. {
  5659. tempIndex = ((gun_index==2) ? 1: 0);
  5660. }
  5661. else
  5662. {
  5663. tempIndex = gun_index;
  5664. }
  5665. for (int index = 0; index < GB_QUANTITY; index++)
  5666. {
  5667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5668. {
  5669. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5670. }
  5671. }// End of for GB_QUANTITY
  5672. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5673. }
  5674. else if(gunType[gun_index] == GUN_TYPE_DO)
  5675. {
  5676. tempIndex = gun_index;
  5677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5678. {
  5679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5680. {
  5681. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5682. }
  5683. }
  5684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5685. }
  5686. else
  5687. {
  5688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5689. {
  5690. tempIndex = 2;
  5691. }
  5692. else
  5693. {
  5694. tempIndex = gun_index;
  5695. }
  5696. for (int index = 0; index < AC_QUANTITY; index++)
  5697. {
  5698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5699. {
  5700. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5701. }
  5702. }// End of for AC_QUANTITY
  5703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5704. }
  5705. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5710. }
  5711. // ================================= Energy.Active.Import.Interval ==============================================
  5712. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5713. {
  5714. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5715. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5716. {
  5717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5718. {
  5719. tempIndex = ((gun_index==2) ? 1: 0);
  5720. }
  5721. else
  5722. {
  5723. tempIndex = gun_index;
  5724. }
  5725. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5726. {
  5727. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5728. {
  5729. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5730. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5731. }
  5732. }// END OF CHAdeMO_QUANTITY
  5733. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5734. }
  5735. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5736. {
  5737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5738. {
  5739. tempIndex = ((gun_index==2) ? 1: 0);
  5740. }
  5741. else
  5742. {
  5743. tempIndex = gun_index;
  5744. }
  5745. for (int index = 0; index < CCS_QUANTITY; index++)
  5746. {
  5747. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5748. {
  5749. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5750. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5751. }
  5752. }// END OF CCS_QUANTITY
  5753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5754. }
  5755. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5756. {
  5757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5758. {
  5759. tempIndex = ((gun_index==2) ? 1: 0);
  5760. }
  5761. else
  5762. {
  5763. tempIndex = gun_index;
  5764. }
  5765. for (int index = 0; index < GB_QUANTITY; index++)
  5766. {
  5767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5768. {
  5769. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5770. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5771. }
  5772. }// END OF GB_QUANTITY
  5773. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5774. }
  5775. else if(gunType[gun_index] == GUN_TYPE_DO)
  5776. {
  5777. tempIndex = gun_index;
  5778. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5779. {
  5780. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5781. {
  5782. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5783. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5784. }
  5785. }
  5786. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5787. }
  5788. else
  5789. {
  5790. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5791. {
  5792. tempIndex = 2;
  5793. }
  5794. else
  5795. {
  5796. tempIndex = gun_index;
  5797. }
  5798. for (int index = 0; index < AC_QUANTITY; index++)
  5799. {
  5800. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5801. {
  5802. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5803. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5804. }
  5805. }// END OF AC_QUANTITY
  5806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5807. }
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5810. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5811. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5812. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5813. }
  5814. //=================================== Power.Active.Import ==================================================
  5815. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5816. {
  5817. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5818. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5819. {
  5820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5821. {
  5822. tempIndex = ((gun_index==2) ? 1: 0);
  5823. }
  5824. else
  5825. {
  5826. tempIndex = gun_index;
  5827. }
  5828. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5829. {
  5830. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5831. {
  5832. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5833. }
  5834. } // End for CHAdeMO_QUANTITY
  5835. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5836. }
  5837. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5838. {
  5839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5840. {
  5841. tempIndex = ((gun_index==2) ? 1: 0);
  5842. }
  5843. else
  5844. {
  5845. tempIndex = gun_index;
  5846. }
  5847. for (int index = 0; index < CCS_QUANTITY; index++)
  5848. {
  5849. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5850. {
  5851. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5852. }
  5853. } // END for CCS_QUANTITY
  5854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5855. }
  5856. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5857. {
  5858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5859. {
  5860. tempIndex = ((gun_index==2) ? 1: 0);
  5861. }
  5862. else
  5863. {
  5864. tempIndex = gun_index;
  5865. }
  5866. for (int index = 0; index < GB_QUANTITY; index++)
  5867. {
  5868. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5869. {
  5870. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5871. }
  5872. }// END for GB_QUANTITY
  5873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5874. }
  5875. else if(gunType[gun_index] == GUN_TYPE_DO)
  5876. {
  5877. tempIndex = gun_index;
  5878. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5879. {
  5880. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5881. {
  5882. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5883. }
  5884. }
  5885. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5886. }
  5887. else
  5888. {
  5889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5890. {
  5891. tempIndex = 2;
  5892. }
  5893. else
  5894. {
  5895. tempIndex = gun_index;
  5896. }
  5897. for (int index = 0; index < AC_QUANTITY; index++)
  5898. {
  5899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5900. {
  5901. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5902. }
  5903. } // END for AC_QUANTITY
  5904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5905. }
  5906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5908. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5909. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5910. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5911. }
  5912. //============================ Voltage L1 ====================================
  5913. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5914. {
  5915. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5916. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5917. {
  5918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5919. {
  5920. tempIndex = ((gun_index==2) ? 1: 0);
  5921. }
  5922. else
  5923. {
  5924. tempIndex = gun_index;
  5925. }
  5926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5927. {
  5928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5929. {
  5930. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5931. }
  5932. } // END OF FOR CHAdeMO_QUANTITY
  5933. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5934. }
  5935. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5936. {
  5937. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5938. {
  5939. tempIndex = ((gun_index==2) ? 1: 0);
  5940. }
  5941. else
  5942. {
  5943. tempIndex = gun_index;
  5944. }
  5945. for (int index = 0; index < CCS_QUANTITY; index++)
  5946. {
  5947. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5948. {
  5949. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5950. }
  5951. } // END OF FOR CCS_QUANTITY
  5952. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5953. }
  5954. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5955. {
  5956. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5957. {
  5958. tempIndex = ((gun_index==2) ? 1: 0);
  5959. }
  5960. else
  5961. {
  5962. tempIndex = gun_index;
  5963. }
  5964. for (int index = 0; index < GB_QUANTITY; index++)
  5965. {
  5966. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5967. {
  5968. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5969. }
  5970. } // END OF FOR GB_QUANTITY
  5971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5972. }
  5973. else if(gunType[gun_index] == GUN_TYPE_DO)
  5974. {
  5975. tempIndex = gun_index;
  5976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5977. {
  5978. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5979. {
  5980. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5981. }
  5982. }
  5983. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5984. }
  5985. else
  5986. {
  5987. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5988. {
  5989. tempIndex = 2;
  5990. }
  5991. else
  5992. {
  5993. tempIndex = gun_index;
  5994. }
  5995. for (int index = 0; index < AC_QUANTITY; index++)
  5996. {
  5997. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5998. {
  5999. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6000. }
  6001. } // END OF FOR AC_QUANTITY
  6002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6003. }
  6004. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6005. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6007. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6008. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6009. }
  6010. //====================== End SoC ================================
  6011. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6012. {
  6013. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6014. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6015. {
  6016. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6017. {
  6018. tempIndex = ((gun_index==2) ? 1: 0);
  6019. }
  6020. else
  6021. {
  6022. tempIndex = gun_index;
  6023. }
  6024. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6025. {
  6026. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6027. {
  6028. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6029. {
  6030. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6031. }
  6032. }
  6033. }
  6034. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6035. {
  6036. for (int index = 0; index < CCS_QUANTITY; index++)
  6037. {
  6038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6039. {
  6040. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6041. }
  6042. }
  6043. }
  6044. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6045. {
  6046. for (int index = 0; index < GB_QUANTITY; index++)
  6047. {
  6048. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6049. {
  6050. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6051. }
  6052. }
  6053. }
  6054. else if(gunType[gun_index] == GUN_TYPE_DO)
  6055. {
  6056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6057. {
  6058. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6059. {
  6060. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6061. }
  6062. }
  6063. }
  6064. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6066. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6067. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6068. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6069. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6070. } // END FOR DC CASE
  6071. }
  6072. // ================================= Current.Import L2 ===============================================
  6073. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6074. {
  6075. // AC 3 phse L2 current
  6076. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6077. {
  6078. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6079. {
  6080. tempIndex = 2;
  6081. }
  6082. else
  6083. {
  6084. tempIndex = gun_index;
  6085. }
  6086. for (int index = 0; index < AC_QUANTITY; index++)
  6087. {
  6088. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6089. {
  6090. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6091. }
  6092. }// End of for AC_QUANTITY
  6093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6094. }
  6095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6096. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6097. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6098. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6099. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6100. }
  6101. // ================================= Current.Import L3 ===============================================
  6102. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6103. {
  6104. // AC 3 phse L3 current
  6105. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6106. {
  6107. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6108. {
  6109. tempIndex = 2;
  6110. }
  6111. else
  6112. {
  6113. tempIndex = gun_index;
  6114. }
  6115. for (int index = 0; index < AC_QUANTITY; index++)
  6116. {
  6117. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6118. {
  6119. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6120. }
  6121. }// End of for AC_QUANTITY
  6122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6123. }
  6124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6125. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6126. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6127. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6128. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6129. }
  6130. //============================ Voltage L2 ====================================
  6131. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6132. {
  6133. // AC 3 phse L2 voltage
  6134. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6135. {
  6136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6137. {
  6138. tempIndex = 2;
  6139. }
  6140. else
  6141. {
  6142. tempIndex = gun_index;
  6143. }
  6144. for (int index = 0; index < AC_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6147. {
  6148. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6149. }
  6150. } // END OF FOR AC_QUANTITY
  6151. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6152. }
  6153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6154. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6158. }
  6159. //============================ Voltage L3 ====================================
  6160. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6161. {
  6162. // AC 3 phse L3 voltage
  6163. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6164. {
  6165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6166. {
  6167. tempIndex = 2;
  6168. }
  6169. else
  6170. {
  6171. tempIndex = gun_index;
  6172. }
  6173. for (int index = 0; index < AC_QUANTITY; index++)
  6174. {
  6175. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6176. {
  6177. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6178. }
  6179. } // END OF FOR AC_QUANTITY
  6180. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6181. }
  6182. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6186. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6187. }
  6188. //====================== Start SoC ================================
  6189. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6190. {
  6191. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6192. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6193. {
  6194. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6195. {
  6196. tempIndex = ((gun_index==2) ? 1: 0);
  6197. }
  6198. else
  6199. {
  6200. tempIndex = gun_index;
  6201. }
  6202. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6203. {
  6204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6205. {
  6206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6207. {
  6208. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6209. }
  6210. }
  6211. }
  6212. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6213. {
  6214. for (int index = 0; index < CCS_QUANTITY; index++)
  6215. {
  6216. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6217. {
  6218. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6219. }
  6220. }
  6221. }
  6222. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6223. {
  6224. for (int index = 0; index < GB_QUANTITY; index++)
  6225. {
  6226. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6227. {
  6228. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6229. }
  6230. }
  6231. }
  6232. else if(gunType[gun_index] == GUN_TYPE_DO)
  6233. {
  6234. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6235. {
  6236. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6237. {
  6238. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6239. }
  6240. }
  6241. }
  6242. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6243. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6244. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6245. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6246. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6247. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6248. } // END FOR DC CASE
  6249. }
  6250. //================================================ Message create ====================================================
  6251. json_object *StopTransaction = json_object_new_object();
  6252. json_object *transactionDatas = json_object_new_array();
  6253. json_object *sampledValues = json_object_new_array();
  6254. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6255. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6256. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6257. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6258. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6259. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6260. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6261. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6262. {
  6263. json_object *transactionData = json_object_new_object();
  6264. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6265. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6266. {
  6267. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6268. {
  6269. json_object *sampledValue = json_object_new_object();
  6270. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6271. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6272. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6273. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6274. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6275. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6276. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6277. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6278. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6279. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6280. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6281. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6282. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6283. json_object_array_add(sampledValues, sampledValue);
  6284. }
  6285. }
  6286. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6287. json_object_array_add(transactionDatas, transactionData);
  6288. }
  6289. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6290. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6291. ,MESSAGE_TYPE_CALL
  6292. ,guid
  6293. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6294. json_object_put(StopTransaction);
  6295. #if 1 // for TempStopTransaction
  6296. //Delete TempStopTransaction
  6297. if((access(TempStopTransaction,F_OK))!=-1)
  6298. {
  6299. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6300. }
  6301. #endif
  6302. #if 1
  6303. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6304. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6305. {
  6306. result = PASS;
  6307. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6308. }
  6309. #endif
  6310. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6311. OCPP_insert_transaction_msg(NO, queuedata);
  6312. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6313. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6314. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6315. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6316. {
  6317. //SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6318. }
  6319. //for test
  6320. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6321. return result;
  6322. }
  6323. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6324. {
  6325. mtrace();
  6326. int result = FAIL;
  6327. char guid[37]={0};
  6328. char tempdata[65]={0};
  6329. int tempIndex = 0;
  6330. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6331. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6332. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6333. //set value
  6334. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6335. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6336. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6337. -1);
  6338. random_uuid(guid);
  6339. //UTC Date time
  6340. struct timeval tmnow;
  6341. struct tm *tm;
  6342. char buf[28];//, usec_buf[6];
  6343. gettimeofday(&tmnow, NULL);
  6344. time_t t;
  6345. t = time(NULL);
  6346. /*UTC time and date*/
  6347. tm = gmtime(&t);
  6348. if(dataType == ReadingContext_Sample_Clock)
  6349. {
  6350. struct tm *tmTarget;
  6351. struct timeb tbTarget;
  6352. tbTarget.time = mktime(tm);
  6353. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6354. tmTarget = gmtime(&tbTarget.time);
  6355. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6356. }
  6357. else
  6358. {
  6359. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6360. }
  6361. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6362. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6363. //********************************(1)Current.Import L1************************************************/
  6364. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6365. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6366. (dataType == ReadingContext_Trigger))
  6367. {
  6368. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6369. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6370. {
  6371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6372. {
  6373. tempIndex = ((gun_index==2) ? 1: 0);
  6374. }
  6375. else
  6376. {
  6377. tempIndex = gun_index;
  6378. }
  6379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6380. {
  6381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6382. {
  6383. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6384. }
  6385. }
  6386. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6387. }
  6388. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6389. {
  6390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6391. {
  6392. tempIndex = ((gun_index==2) ? 1: 0);
  6393. }
  6394. else
  6395. {
  6396. tempIndex = gun_index;
  6397. }
  6398. for (int index = 0; index < CCS_QUANTITY; index++)
  6399. {
  6400. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6401. {
  6402. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6403. }
  6404. }
  6405. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6406. }
  6407. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6408. {
  6409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6410. {
  6411. tempIndex = ((gun_index==2) ? 1: 0);
  6412. }
  6413. else
  6414. {
  6415. tempIndex = gun_index;
  6416. }
  6417. for (int index = 0; index < GB_QUANTITY; index++)
  6418. {
  6419. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6420. {
  6421. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6422. }
  6423. }
  6424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6425. }
  6426. else if(gunType[gun_index] == GUN_TYPE_DO)
  6427. {
  6428. tempIndex = gun_index;
  6429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6430. {
  6431. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6432. {
  6433. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6434. }
  6435. }
  6436. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6437. }
  6438. else
  6439. {
  6440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6441. {
  6442. tempIndex = 2;
  6443. }
  6444. else
  6445. {
  6446. tempIndex = gun_index;
  6447. }
  6448. for (int index = 0; index < AC_QUANTITY; index++)
  6449. {
  6450. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6451. {
  6452. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6453. }
  6454. }
  6455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6456. }
  6457. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6458. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6459. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6460. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6461. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6462. }
  6463. //********************************(2)Energy.Active.Import.Register ************************************************/
  6464. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6465. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6466. (dataType == ReadingContext_Trigger))
  6467. {
  6468. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6469. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6470. {
  6471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6472. {
  6473. tempIndex = ((gun_index==2) ? 1: 0);
  6474. }
  6475. else
  6476. {
  6477. tempIndex = gun_index;
  6478. }
  6479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6480. {
  6481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6482. {
  6483. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6484. }
  6485. }
  6486. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6487. }
  6488. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6489. {
  6490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6491. {
  6492. tempIndex = ((gun_index==2) ? 1: 0);
  6493. }
  6494. else
  6495. {
  6496. tempIndex = gun_index;
  6497. }
  6498. for (int index = 0; index < CCS_QUANTITY; index++)
  6499. {
  6500. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6501. {
  6502. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6503. }
  6504. }
  6505. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6506. }
  6507. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6508. {
  6509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6510. {
  6511. tempIndex = ((gun_index==2) ? 1: 0);
  6512. }
  6513. else
  6514. {
  6515. tempIndex = gun_index;
  6516. }
  6517. for (int index = 0; index < GB_QUANTITY; index++)
  6518. {
  6519. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6520. {
  6521. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6522. }
  6523. }
  6524. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6525. }
  6526. else if(gunType[gun_index] == GUN_TYPE_DO)
  6527. {
  6528. tempIndex = gun_index;
  6529. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6530. {
  6531. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6532. {
  6533. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6534. }
  6535. }
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6537. }
  6538. else
  6539. {
  6540. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6541. {
  6542. tempIndex = 2;
  6543. }
  6544. else
  6545. {
  6546. tempIndex = gun_index;
  6547. }
  6548. for (int index = 0; index < AC_QUANTITY; index++)
  6549. {
  6550. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6551. {
  6552. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6553. }
  6554. }
  6555. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6556. }
  6557. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6558. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6559. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6560. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6561. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6562. }
  6563. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6564. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6565. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6566. (dataType == ReadingContext_Trigger))
  6567. {
  6568. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6569. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6570. {
  6571. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6572. {
  6573. tempIndex = ((gun_index==2) ? 1: 0);
  6574. }
  6575. else
  6576. {
  6577. tempIndex = gun_index;
  6578. }
  6579. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6580. {
  6581. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6582. {
  6583. if(dataType == ReadingContext_Sample_Clock)
  6584. {
  6585. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6586. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6587. }
  6588. else if(dataType == ReadingContext_Sample_Periodic)
  6589. {
  6590. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6591. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6592. }
  6593. else
  6594. {
  6595. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6596. }
  6597. }
  6598. } // END OF FOR CHAdeMO_QUANTITY
  6599. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6600. }
  6601. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6602. {
  6603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6604. {
  6605. tempIndex = ((gun_index==2) ? 1: 0);
  6606. }
  6607. else
  6608. {
  6609. tempIndex = gun_index;
  6610. }
  6611. for (int index = 0; index < CCS_QUANTITY; index++)
  6612. {
  6613. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6614. {
  6615. if(dataType == ReadingContext_Sample_Clock)
  6616. {
  6617. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6618. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6619. }
  6620. else if(dataType == ReadingContext_Sample_Periodic)
  6621. {
  6622. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6623. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6624. }
  6625. else
  6626. {
  6627. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6628. }
  6629. }
  6630. } // END OF CCS_QUANTITY
  6631. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6632. }
  6633. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6634. {
  6635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6636. {
  6637. tempIndex = ((gun_index==2) ? 1: 0);
  6638. }
  6639. else
  6640. {
  6641. tempIndex = gun_index;
  6642. }
  6643. for (int index = 0; index < GB_QUANTITY; index++)
  6644. {
  6645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6646. {
  6647. if(dataType == ReadingContext_Sample_Clock)
  6648. {
  6649. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6650. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6651. }
  6652. else if(dataType == ReadingContext_Sample_Periodic)
  6653. {
  6654. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6655. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6656. }
  6657. else
  6658. {
  6659. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6660. }
  6661. }
  6662. } // END OF GB_QUANTITY
  6663. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6664. }
  6665. else if(gunType[gun_index] == GUN_TYPE_DO)
  6666. {
  6667. tempIndex = gun_index;
  6668. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6669. {
  6670. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6671. {
  6672. if(dataType == ReadingContext_Sample_Clock)
  6673. {
  6674. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6675. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6676. }
  6677. else if(dataType == ReadingContext_Sample_Periodic)
  6678. {
  6679. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6680. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6681. }
  6682. else
  6683. {
  6684. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6685. }
  6686. }
  6687. }
  6688. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6689. }
  6690. else
  6691. {
  6692. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6693. {
  6694. tempIndex = 2;
  6695. }
  6696. else
  6697. {
  6698. tempIndex = gun_index;
  6699. }
  6700. for (int index = 0; index < AC_QUANTITY; index++)
  6701. {
  6702. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6703. {
  6704. if(dataType == ReadingContext_Sample_Clock)
  6705. {
  6706. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6707. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6708. }
  6709. else if(dataType == ReadingContext_Sample_Periodic)
  6710. {
  6711. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6712. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6713. }
  6714. else
  6715. {
  6716. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6717. }
  6718. }
  6719. }
  6720. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6721. }
  6722. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6723. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6724. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6725. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6726. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6727. }
  6728. //********************************(4)Power.Active.Import************************************************/
  6729. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6730. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6731. (dataType == ReadingContext_Trigger))
  6732. {
  6733. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6734. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6735. {
  6736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6737. {
  6738. tempIndex = ((gun_index==2) ? 1: 0);
  6739. }
  6740. else
  6741. {
  6742. tempIndex = gun_index;
  6743. }
  6744. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6745. {
  6746. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6747. {
  6748. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6749. }
  6750. } // END OF FOR
  6751. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6752. }
  6753. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6754. {
  6755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6756. {
  6757. tempIndex = ((gun_index==2) ? 1: 0);
  6758. }
  6759. else
  6760. {
  6761. tempIndex = gun_index;
  6762. }
  6763. for (int index = 0; index < CCS_QUANTITY; index++)
  6764. {
  6765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6766. {
  6767. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6768. }
  6769. }
  6770. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6771. }
  6772. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6773. {
  6774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6775. {
  6776. tempIndex = ((gun_index==2) ? 1: 0);
  6777. }
  6778. else
  6779. {
  6780. tempIndex = gun_index;
  6781. }
  6782. for (int index = 0; index < GB_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6785. {
  6786. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6787. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6788. }
  6789. }
  6790. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6791. }
  6792. else if(gunType[gun_index] == GUN_TYPE_DO)
  6793. {
  6794. tempIndex = gun_index;
  6795. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6796. {
  6797. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6798. {
  6799. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6800. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6801. }
  6802. }
  6803. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6804. }
  6805. else
  6806. {
  6807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6808. {
  6809. tempIndex = 2;
  6810. }
  6811. else
  6812. {
  6813. tempIndex = gun_index;
  6814. }
  6815. for (int index = 0; index < AC_QUANTITY; index++)
  6816. {
  6817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6818. {
  6819. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6820. }
  6821. }
  6822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6823. }
  6824. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6825. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6826. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6827. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6828. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6829. }
  6830. //***********************************************(5)VOLTAGE L1******************************************************/
  6831. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6832. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6833. (dataType == ReadingContext_Trigger))
  6834. {
  6835. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6836. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6837. {
  6838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6839. {
  6840. tempIndex = ((gun_index==2) ? 1: 0);
  6841. }
  6842. else
  6843. {
  6844. tempIndex = gun_index;
  6845. }
  6846. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6847. {
  6848. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6849. {
  6850. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6851. }
  6852. }
  6853. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6854. }
  6855. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6856. {
  6857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6858. {
  6859. tempIndex = ((gun_index==2) ? 1: 0);
  6860. }
  6861. else
  6862. {
  6863. tempIndex = gun_index;
  6864. }
  6865. for (int index = 0; index < CCS_QUANTITY; index++)
  6866. {
  6867. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6868. {
  6869. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6870. }
  6871. }
  6872. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6873. }
  6874. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6875. {
  6876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6877. {
  6878. tempIndex = ((gun_index==2) ? 1: 0);
  6879. }
  6880. else
  6881. {
  6882. tempIndex = gun_index;
  6883. }
  6884. for (int index = 0; index < GB_QUANTITY; index++)
  6885. {
  6886. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6887. {
  6888. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6889. }
  6890. }
  6891. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6892. }
  6893. else if(gunType[gun_index] == GUN_TYPE_DO)
  6894. {
  6895. tempIndex = gun_index;
  6896. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6897. {
  6898. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6899. {
  6900. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6901. }
  6902. }
  6903. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6904. }
  6905. else
  6906. {
  6907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6908. {
  6909. tempIndex = 2;
  6910. }
  6911. else
  6912. {
  6913. tempIndex = gun_index;
  6914. }
  6915. for (int index = 0; index < AC_QUANTITY; index++)
  6916. {
  6917. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6918. {
  6919. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6920. }
  6921. }
  6922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6923. }
  6924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6926. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6927. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6928. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6929. }
  6930. //***********************************************(6)SOC******************************************************/
  6931. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6932. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6933. (dataType == ReadingContext_Trigger))
  6934. {
  6935. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6936. {
  6937. //idx_sample=5;
  6938. //sampledValue = NULL;
  6939. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6940. {
  6941. tempIndex = ((gun_index==2) ? 1: 0);
  6942. }
  6943. else
  6944. {
  6945. tempIndex = gun_index;
  6946. }
  6947. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6948. {
  6949. //tempIndex = ((gun_index==2) ? 1: 0);
  6950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6951. {
  6952. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6953. {
  6954. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6955. }
  6956. }
  6957. }
  6958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6959. {
  6960. //tempIndex = ((gun_index==2) ? 1: 0);
  6961. for (int index = 0; index < CCS_QUANTITY; index++)
  6962. {
  6963. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6964. {
  6965. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6966. }
  6967. }
  6968. }
  6969. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6970. {
  6971. //tempIndex = ((gun_index==2) ? 1: 0);
  6972. for (int index = 0; index < GB_QUANTITY; index++)
  6973. {
  6974. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6975. {
  6976. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6977. }
  6978. }
  6979. }
  6980. else if(gunType[gun_index] == GUN_TYPE_DO)
  6981. {
  6982. //tempIndex = ((gun_index==2) ? 1: 0);
  6983. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6984. {
  6985. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6986. {
  6987. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6988. }
  6989. }
  6990. }
  6991. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6992. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6993. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6994. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6995. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6996. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6997. }
  6998. }
  6999. //********************************(7)Current.Import L2************************************************/
  7000. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7001. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7002. (dataType == ReadingContext_Trigger))
  7003. {
  7004. // Only for AC 3 phase
  7005. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7006. {
  7007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7008. {
  7009. tempIndex = 2;
  7010. }
  7011. else
  7012. {
  7013. tempIndex = gun_index;
  7014. }
  7015. for (int index = 0; index < AC_QUANTITY; index++)
  7016. {
  7017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7018. {
  7019. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7020. }
  7021. }
  7022. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7023. }
  7024. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7025. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7026. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7027. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7028. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7029. }
  7030. //********************************(8)Current.Import L3************************************************/
  7031. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7032. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7033. (dataType == ReadingContext_Trigger))
  7034. {
  7035. // Only for AC 3 phase
  7036. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7037. {
  7038. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7039. {
  7040. tempIndex = 2;
  7041. }
  7042. else
  7043. {
  7044. tempIndex = gun_index;
  7045. }
  7046. for (int index = 0; index < AC_QUANTITY; index++)
  7047. {
  7048. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7049. {
  7050. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7051. }
  7052. }
  7053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7054. }
  7055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7056. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7057. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7058. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7059. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7060. }
  7061. //***********************************************(9)VOLTAGE L2******************************************************/
  7062. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7063. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7064. (dataType == ReadingContext_Trigger))
  7065. {
  7066. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7067. {
  7068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7069. {
  7070. tempIndex = 2;
  7071. }
  7072. else
  7073. {
  7074. tempIndex = gun_index;
  7075. }
  7076. for (int index = 0; index < AC_QUANTITY; index++)
  7077. {
  7078. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7079. {
  7080. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7081. }
  7082. }
  7083. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7084. }
  7085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7086. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7087. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7088. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7089. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7090. }
  7091. //***********************************************(10)VOLTAGE L3******************************************************/
  7092. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7093. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7094. (dataType == ReadingContext_Trigger))
  7095. {
  7096. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7097. {
  7098. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7099. {
  7100. tempIndex = 2;
  7101. }
  7102. else
  7103. {
  7104. tempIndex = gun_index;
  7105. }
  7106. for (int index = 0; index < AC_QUANTITY; index++)
  7107. {
  7108. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7109. {
  7110. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7111. }
  7112. }
  7113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7114. }
  7115. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7116. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7117. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7119. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7120. }
  7121. //***********************************************(11)Current.Offered******************************************************/
  7122. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7123. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7124. (dataType == ReadingContext_Trigger))
  7125. {
  7126. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7127. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7128. {
  7129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7130. {
  7131. tempIndex = ((gun_index==2) ? 1: 0);
  7132. }
  7133. else
  7134. {
  7135. tempIndex = gun_index;
  7136. }
  7137. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7138. {
  7139. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7140. {
  7141. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7142. }
  7143. } // END OF FOR CHAdeMO_QUANTITY
  7144. }
  7145. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7146. {
  7147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7148. {
  7149. tempIndex = ((gun_index==2) ? 1: 0);
  7150. }
  7151. else
  7152. {
  7153. tempIndex = gun_index;
  7154. }
  7155. for (int index = 0; index < CCS_QUANTITY; index++)
  7156. {
  7157. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7158. {
  7159. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7160. }
  7161. } // END OF CCS_QUANTITY
  7162. }
  7163. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7164. {
  7165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7166. {
  7167. tempIndex = ((gun_index==2) ? 1: 0);
  7168. }
  7169. else
  7170. {
  7171. tempIndex = gun_index;
  7172. }
  7173. for (int index = 0; index < GB_QUANTITY; index++)
  7174. {
  7175. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7176. {
  7177. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7178. }
  7179. } // END OF GB_QUANTITY
  7180. }
  7181. else if(gunType[gun_index] == GUN_TYPE_DO)
  7182. {
  7183. tempIndex = gun_index;
  7184. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7185. {
  7186. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7187. {
  7188. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7189. }
  7190. }
  7191. }
  7192. else
  7193. {
  7194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7195. {
  7196. tempIndex = 2;
  7197. }
  7198. else
  7199. {
  7200. tempIndex = gun_index;
  7201. }
  7202. for (int index = 0; index < AC_QUANTITY; index++)
  7203. {
  7204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7205. {
  7206. uint16_t currentOffer;
  7207. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7208. {
  7209. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7210. }
  7211. else
  7212. {
  7213. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7214. }
  7215. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7216. }
  7217. }
  7218. }
  7219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7221. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7222. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7223. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7224. }
  7225. //***********************************************(12)Power.Offered******************************************************/
  7226. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7227. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7228. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7229. {
  7230. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7231. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7232. {
  7233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7234. {
  7235. tempIndex = ((gun_index==2) ? 1: 0);
  7236. }
  7237. else
  7238. {
  7239. tempIndex = gun_index;
  7240. }
  7241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7242. {
  7243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7244. {
  7245. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7246. }
  7247. } // END OF FOR CHAdeMO_QUANTITY
  7248. }
  7249. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7250. {
  7251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7252. {
  7253. tempIndex = ((gun_index==2) ? 1: 0);
  7254. }
  7255. else
  7256. {
  7257. tempIndex = gun_index;
  7258. }
  7259. for (int index = 0; index < CCS_QUANTITY; index++)
  7260. {
  7261. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7262. {
  7263. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7264. }
  7265. } // END OF CCS_QUANTITY
  7266. }
  7267. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7268. {
  7269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7270. {
  7271. tempIndex = ((gun_index==2) ? 1: 0);
  7272. }
  7273. else
  7274. {
  7275. tempIndex = gun_index;
  7276. }
  7277. for (int index = 0; index < GB_QUANTITY; index++)
  7278. {
  7279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7280. {
  7281. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7282. }
  7283. } // END OF GB_QUANTITY
  7284. }
  7285. else if(gunType[gun_index] == GUN_TYPE_DO)
  7286. {
  7287. tempIndex = gun_index;
  7288. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7289. {
  7290. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7291. {
  7292. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7293. }
  7294. }
  7295. }
  7296. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7297. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7298. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7300. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7301. }
  7302. // Message create ====================================================================================================
  7303. if(TRUE)
  7304. {
  7305. json_object *MeterValueReq = json_object_new_object();
  7306. json_object *MeterValues = json_object_new_array();
  7307. json_object *sampledValues = json_object_new_array();
  7308. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7309. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7310. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7311. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7312. {
  7313. json_object *MeterValue = json_object_new_object();
  7314. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7315. {
  7316. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7317. {
  7318. json_object *sampledValue = json_object_new_object();
  7319. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7320. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7321. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7322. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7323. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7324. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7325. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7326. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7327. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7328. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7329. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7330. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7331. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7332. json_object_array_add(sampledValues, sampledValue);
  7333. }
  7334. }
  7335. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7336. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7337. json_object_array_add(MeterValues, MeterValue);
  7338. }
  7339. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7340. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7341. ,gun_index + 1
  7342. ,MESSAGE_TYPE_CALL
  7343. ,guid
  7344. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7345. json_object_put(MeterValueReq);
  7346. }
  7347. // Put request guid to hash map
  7348. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7349. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  7350. {
  7351. result = PASS;
  7352. //DEBUG_INFO("MeterValues mapitem pass\n");
  7353. }
  7354. if((dataType != ReadingContext_Trigger) &&
  7355. (dataType != ReadingContext_Sample_Clock) &&
  7356. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7357. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7358. else
  7359. {
  7360. if(FirstHeartBeat)
  7361. LWS_Send(queuedata +2);
  7362. }
  7363. return result;
  7364. }
  7365. int sendLogStatusNotificationRequest(char *status)
  7366. {
  7367. mtrace();
  7368. int result = PASS;
  7369. char message[4096]={0};
  7370. char guid[37]={0};
  7371. char tempdata[128]={0};
  7372. json_object *LogStatusNotification = json_object_new_object();
  7373. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7374. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7375. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7376. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7377. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7378. random_uuid(guid);
  7379. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7380. json_object_put(LogStatusNotification);
  7381. LWS_Send(message);
  7382. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7383. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7384. {
  7385. result = PASS;
  7386. }
  7387. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7388. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7389. return result;
  7390. }
  7391. int sendSecurityEventNotificationRequest()
  7392. {
  7393. mtrace();
  7394. int result = PASS;
  7395. char message[4096]={0};
  7396. char guid[37]={0};
  7397. char tempdata[128]={0};
  7398. json_object *SecurityEventNotification = json_object_new_object();
  7399. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7400. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7401. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7402. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7403. random_uuid(guid);
  7404. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7405. json_object_put(SecurityEventNotification);
  7406. LWS_Send(message);
  7407. sprintf(tempdata, "SecurityEventNotification,0");
  7408. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7409. {
  7410. result = PASS;
  7411. }
  7412. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7413. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7414. return result;
  7415. }
  7416. int sendSignCertificateRequest()
  7417. {
  7418. mtrace();
  7419. int result = PASS;
  7420. char message[4096]={0};
  7421. char guid[37]={0};
  7422. char tempdata[128]={0};
  7423. json_object *SignCertificate = json_object_new_object();
  7424. DEBUG_INFO("sendSignCertificateRequest...\n");
  7425. // Read csr file content
  7426. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7427. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7428. char *line = NULL;
  7429. size_t len = 0;
  7430. while(getline(&line, &len, fp) != -1)
  7431. {
  7432. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7433. {
  7434. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7435. }
  7436. }
  7437. fclose(fp);
  7438. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7439. random_uuid(guid);
  7440. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7441. json_object_put(SignCertificate);
  7442. LWS_Send(message);
  7443. sprintf(tempdata, "SignCertificate,0");
  7444. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7445. {
  7446. result = PASS;
  7447. }
  7448. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7449. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7450. return result;
  7451. }
  7452. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7453. {
  7454. mtrace();
  7455. int result = PASS;
  7456. char message[110]={0};
  7457. char guid[37]={0};
  7458. char tempdata[65]={0};
  7459. json_object *FirmwareStatusNotification = json_object_new_object();
  7460. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7461. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7462. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7463. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7464. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7465. random_uuid(guid);
  7466. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7467. json_object_put(FirmwareStatusNotification);
  7468. LWS_Send(message);
  7469. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7470. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7471. {
  7472. result = PASS;
  7473. }
  7474. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7475. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7476. return result;
  7477. }
  7478. //==========================================
  7479. // send confirm routine
  7480. //==========================================
  7481. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7482. {
  7483. mtrace();
  7484. int result = FAIL;
  7485. char message[100]={0};
  7486. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7487. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7488. LWS_Send(message);
  7489. result = TRUE;
  7490. return result;
  7491. }
  7492. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7493. {
  7494. mtrace();
  7495. int result = FAIL;
  7496. char message[100]={0};
  7497. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7498. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7499. LWS_Send(message);
  7500. result = TRUE;
  7501. return result;
  7502. }
  7503. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7504. {
  7505. mtrace();
  7506. int result = FAIL;
  7507. char message[100]={0};
  7508. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7509. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7510. LWS_Send(message);
  7511. result = TRUE;
  7512. return result;
  7513. }
  7514. int sendClearCacheConfirmation(char *uuid,char *payload)
  7515. {
  7516. mtrace();
  7517. int result = FAIL;
  7518. char message[500]={0};
  7519. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7520. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7521. LWS_Send(message);
  7522. return result;
  7523. }
  7524. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7525. {
  7526. mtrace();
  7527. int result = FAIL;
  7528. char message[500]={0};
  7529. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7530. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7531. LWS_Send(message);
  7532. return result;
  7533. }
  7534. int sendDataTransferConfirmation(char *uuid,char *payload)
  7535. {
  7536. mtrace();
  7537. char statusStr[20]={0};
  7538. char dataStr[10]={0};
  7539. char sstr[20]={0};
  7540. int c = 0;
  7541. char *loc;
  7542. int result = FAIL;
  7543. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7544. /**********************status**************************/
  7545. loc = strstr(payload, "status");
  7546. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7547. c = 0;
  7548. while (loc[3+strlen("status")+c] != '\"')
  7549. {
  7550. sstr[c] = loc[3+strlen("status")+c];
  7551. c++;
  7552. }
  7553. sstr[c] = '\0';
  7554. strcpy(statusStr, sstr);
  7555. /**********************data**************************/
  7556. loc = strstr(payload, "data");
  7557. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7558. c = 0;
  7559. while (loc[3+strlen("data")+c] != '\"')
  7560. {
  7561. sstr[c] = loc[3+strlen("data")+c];
  7562. c++;
  7563. }
  7564. sstr[c] = '\0';
  7565. strcpy(dataStr, sstr);
  7566. return result;
  7567. }
  7568. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7569. {
  7570. mtrace();
  7571. int result = FAIL;
  7572. char message[1000]={0};
  7573. int CompositeScheduleIndex = 0;
  7574. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7575. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7576. if(nPeriod == 0)
  7577. {
  7578. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7579. {
  7580. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7581. ,MESSAGE_TYPE_CALLRESULT
  7582. ,uuid
  7583. ,payload
  7584. ,connectorIdInt);
  7585. }
  7586. else
  7587. {
  7588. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7589. ,MESSAGE_TYPE_CALLRESULT
  7590. ,uuid
  7591. ,payload
  7592. ,connectorIdInt
  7593. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7594. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7595. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7596. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7597. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7598. }
  7599. }
  7600. else
  7601. {
  7602. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7603. ,MESSAGE_TYPE_CALLRESULT
  7604. ,uuid
  7605. ,payload
  7606. ,connectorIdInt
  7607. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7608. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7609. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7610. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7611. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7612. {
  7613. if (idx_sample == 0)
  7614. {
  7615. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7616. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7617. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7618. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7619. }
  7620. else
  7621. {
  7622. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7623. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7624. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7625. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7626. }
  7627. }
  7628. sprintf(message + strlen(message), "]}}]");
  7629. }
  7630. LWS_Send(message);
  7631. result = TRUE;
  7632. return result;
  7633. }
  7634. int sendGetConfigurationConfirmation(char *uuid)
  7635. {
  7636. mtrace();
  7637. int result = FAIL;
  7638. int MaxKeySupported = 0;
  7639. int sentConfigurationNumber= 0;
  7640. int sentunConfigurationNumber= 0;
  7641. char message[1024*10]={0};
  7642. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7643. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7644. //configuration key
  7645. json_object *GetConfiguration = json_object_new_object();
  7646. json_object *configurationKey = json_object_new_array();
  7647. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7648. {
  7649. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7650. {
  7651. json_object *keyValue = json_object_new_object();
  7652. json_object_object_add(keyValue, "key", json_object_new_string((char*)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key));
  7653. json_object_object_add(keyValue, "readonly", atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1?json_object_new_boolean(1):json_object_new_boolean(0));
  7654. json_object_object_add(keyValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value));
  7655. json_object_array_add(configurationKey, keyValue);
  7656. sentConfigurationNumber = sentConfigurationNumber + 1;
  7657. }
  7658. }
  7659. json_object *unknownKey = json_object_new_array();
  7660. if(UnknownKeynum != 0)
  7661. {
  7662. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7663. {
  7664. DEBUG_INFO("unknown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7665. json_object_array_add(unknownKey, json_object_new_string((char*)ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  7666. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7667. }
  7668. }
  7669. if((sentConfigurationNumber>0) && (sentunConfigurationNumber>0))
  7670. {
  7671. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  7672. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  7673. }
  7674. else if(sentConfigurationNumber>0)
  7675. {
  7676. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  7677. json_object_put(unknownKey);
  7678. }
  7679. else
  7680. {
  7681. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  7682. json_object_put(configurationKey);
  7683. }
  7684. sprintf(message,"[%d,\"%s\",%s]"
  7685. ,MESSAGE_TYPE_CALLRESULT
  7686. ,uuid
  7687. ,json_object_to_json_string_ext(GetConfiguration, JSON_C_TO_STRING_PLAIN));
  7688. json_object_put(GetConfiguration);
  7689. LWS_Send(message);
  7690. return result;
  7691. }
  7692. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7693. {
  7694. mtrace();
  7695. int result = FAIL;
  7696. char message[400]={0};
  7697. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7698. if(strcmp(payload,"")==0)
  7699. {
  7700. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7701. }
  7702. else
  7703. {
  7704. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7705. }
  7706. LWS_Send(message);
  7707. result = TRUE;
  7708. return result;
  7709. }
  7710. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7711. {
  7712. mtrace();
  7713. int result = FAIL;
  7714. char message[80]={0};
  7715. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7716. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7717. LWS_Send(message);
  7718. result = TRUE;
  7719. return result;
  7720. }
  7721. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7722. {
  7723. mtrace();
  7724. int result = FAIL;
  7725. char message[80]={0};
  7726. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7727. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7728. LWS_Send(message);
  7729. result = TRUE;
  7730. return result;
  7731. }
  7732. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7733. {
  7734. mtrace();
  7735. int result = FAIL;
  7736. char message[80]={0};
  7737. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7738. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7739. LWS_Send(message);
  7740. result = TRUE;
  7741. return result;
  7742. }
  7743. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7744. {
  7745. mtrace();
  7746. int result = FAIL;
  7747. char message[80]={0};
  7748. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7749. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7750. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7751. LWS_Send(message);
  7752. result = TRUE;
  7753. return result;
  7754. }
  7755. int sendResetConfirmation(char *uuid,char *payload)
  7756. {
  7757. mtrace();
  7758. int result = FAIL;
  7759. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7760. char message[80]={0};
  7761. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7762. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7763. LWS_Send(message);
  7764. result = TRUE;
  7765. return result;
  7766. }
  7767. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7768. {
  7769. mtrace();
  7770. int result = FAIL;
  7771. char message[500]={0};
  7772. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7773. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7774. LWS_Send(message);
  7775. result = TRUE;
  7776. return result;
  7777. }
  7778. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7779. {
  7780. mtrace();
  7781. int result = FAIL;
  7782. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7783. char message[80]={0};
  7784. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7785. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7786. LWS_Send(message);
  7787. result = TRUE;
  7788. return result;
  7789. }
  7790. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7791. {
  7792. mtrace();
  7793. int result = FAIL;
  7794. char message[80]={0};
  7795. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7796. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7797. LWS_Send(message);
  7798. result = TRUE;
  7799. return result;
  7800. }
  7801. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7802. {
  7803. mtrace();
  7804. int result = FAIL;
  7805. char message[80]={0};
  7806. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7807. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7808. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7809. LWS_Send(message);
  7810. result = TRUE;
  7811. return result;
  7812. }
  7813. int sendUpdateFirmwareConfirmation(char *uuid)
  7814. {
  7815. mtrace();
  7816. int result = FAIL;
  7817. char message[60]={0};
  7818. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7819. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7820. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7821. LWS_Send(message);
  7822. result = TRUE;
  7823. return result;
  7824. }
  7825. int sendCertificateSignedConfirmation(char *uuid)
  7826. {
  7827. mtrace();
  7828. int result = PASS;
  7829. char message[4096]={0};
  7830. json_object *CertificateSigned = json_object_new_object();
  7831. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7832. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7833. sprintf(message,"[%d,\"%s\",%s]"
  7834. ,MESSAGE_TYPE_CALLRESULT
  7835. ,uuid
  7836. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7837. json_object_put(CertificateSigned);
  7838. LWS_Send(message);
  7839. return result;
  7840. }
  7841. int sendDeleteCertificateConfirmation(char *uuid)
  7842. {
  7843. mtrace();
  7844. int result = PASS;
  7845. char message[4096]={0};
  7846. json_object *DeleteCertificate = json_object_new_object();
  7847. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7848. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7849. sprintf(message,"[%d,\"%s\",%s]"
  7850. ,MESSAGE_TYPE_CALLRESULT
  7851. ,uuid
  7852. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7853. json_object_put(DeleteCertificate);
  7854. LWS_Send(message);
  7855. return result;
  7856. }
  7857. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7858. {
  7859. mtrace();
  7860. int result = PASS;
  7861. char message[4096]={0};
  7862. json_object *ExtendedTriggerMessage = json_object_new_object();
  7863. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7864. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7865. sprintf(message,"[%d,\"%s\",%s]"
  7866. ,MESSAGE_TYPE_CALLRESULT
  7867. ,uuid
  7868. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7869. json_object_put(ExtendedTriggerMessage);
  7870. LWS_Send(message);
  7871. return result;
  7872. }
  7873. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7874. {
  7875. mtrace();
  7876. int result = PASS;
  7877. char message[4096]={0};
  7878. json_object *GetInstalledCertificateIds = json_object_new_object();
  7879. json_object *certificateHashDataDatas = json_object_new_array();
  7880. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7881. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7882. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7883. {
  7884. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7885. {
  7886. json_object *certificateHashData = json_object_new_object();
  7887. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7888. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7889. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7890. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7891. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7892. }
  7893. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7894. }
  7895. else
  7896. {
  7897. json_object_put(certificateHashDataDatas);
  7898. }
  7899. sprintf(message,"[%d,\"%s\",%s]"
  7900. ,MESSAGE_TYPE_CALLRESULT
  7901. ,uuid
  7902. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7903. json_object_put(GetInstalledCertificateIds);
  7904. LWS_Send(message);
  7905. return result;
  7906. }
  7907. int sendGetLogConfirmation(char *uuid)
  7908. {
  7909. mtrace();
  7910. int result = PASS;
  7911. char message[4096]={0};
  7912. json_object *GetLog = json_object_new_object();
  7913. DEBUG_INFO("sendGetLogConfirmation...\n");
  7914. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7915. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7916. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7917. sprintf(message,"[%d,\"%s\",%s]"
  7918. ,MESSAGE_TYPE_CALLRESULT
  7919. ,uuid
  7920. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7921. json_object_put(GetLog);
  7922. LWS_Send(message);
  7923. return result;
  7924. }
  7925. int sendInstallCertificateConfirmation(char *uuid)
  7926. {
  7927. mtrace();
  7928. int result = PASS;
  7929. char message[4096]={0};
  7930. json_object *InstallCertificate = json_object_new_object();
  7931. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7932. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7933. sprintf(message,"[%d,\"%s\",%s]"
  7934. ,MESSAGE_TYPE_CALLRESULT
  7935. ,uuid
  7936. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7937. json_object_put(InstallCertificate);
  7938. LWS_Send(message);
  7939. return result;
  7940. }
  7941. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7942. {
  7943. mtrace();
  7944. int result = PASS;
  7945. char message[4096]={0};
  7946. json_object *SignedUpdateFirmware = json_object_new_object();
  7947. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7948. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7949. sprintf(message,"[%d,\"%s\",%s]"
  7950. ,MESSAGE_TYPE_CALLRESULT
  7951. ,uuid
  7952. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7953. json_object_put(SignedUpdateFirmware);
  7954. LWS_Send(message);
  7955. return result;
  7956. }
  7957. int sendUnknownConfirmation(char *uuid)
  7958. {
  7959. mtrace();
  7960. int result = PASS;
  7961. char message[256]={0};
  7962. DEBUG_INFO("sendUnknownConfirmation...\n");
  7963. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7964. LWS_Send(message);
  7965. return result;
  7966. }
  7967. //==========================================
  7968. // Handle server request routine Start
  7969. //==========================================
  7970. int handleCancelReservationRequest(char *uuid, char *payload)
  7971. {
  7972. mtrace();
  7973. int result = FAIL;
  7974. int gunNO = 0;
  7975. int reservationIdInt = -1;
  7976. char comfirmstr[20];
  7977. DEBUG_INFO("handleCancelReservationRequest...\n");
  7978. json_object *CancelReservation;
  7979. CancelReservation = json_tokener_parse(payload);
  7980. if(!is_error(CancelReservation))
  7981. {
  7982. // Required data
  7983. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7984. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7985. }
  7986. json_object_put(CancelReservation);
  7987. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7988. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7989. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7990. if(reservationIdInt != -1)
  7991. {
  7992. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7993. //check Transaction active
  7994. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7995. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7996. {
  7997. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7998. {
  7999. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8000. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8001. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8002. {
  8003. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8004. }
  8005. else
  8006. {
  8007. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8008. }
  8009. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8010. goto end;
  8011. }
  8012. }
  8013. for (int index = 0; index < CCS_QUANTITY; index++)
  8014. {
  8015. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8016. {
  8017. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8018. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8019. if(gunType[2] == GUN_TYPE_CCS)
  8020. {
  8021. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8022. }
  8023. else
  8024. {
  8025. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8026. }
  8027. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8028. goto end;
  8029. }
  8030. }
  8031. for (int index = 0; index < GB_QUANTITY; index++)
  8032. {
  8033. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8034. {
  8035. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8036. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8037. if(gunType[2] == GUN_TYPE_GBT)
  8038. {
  8039. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8040. }
  8041. else
  8042. {
  8043. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8044. }
  8045. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8046. goto end;
  8047. }
  8048. }
  8049. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8050. {
  8051. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8052. {
  8053. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8054. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8055. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8056. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8057. goto end;
  8058. }
  8059. }
  8060. for (int index = 0; index < AC_QUANTITY; index++)
  8061. {
  8062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8063. {
  8064. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8065. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8067. {
  8068. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8069. }
  8070. else
  8071. {
  8072. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8073. }
  8074. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8075. goto end;
  8076. }
  8077. }
  8078. }
  8079. //The reservationId does NOT match the reservationId
  8080. sendCancelReservationConfirmation(uuid, comfirmstr);
  8081. end:
  8082. // Fill in ocpp packet uuid
  8083. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8084. return result;
  8085. }
  8086. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8087. {
  8088. mtrace();
  8089. int result = FAIL;
  8090. int gunIndex = -1;
  8091. char typeStr[16]={0};
  8092. char comfirmstr[20];
  8093. int specificId = FALSE;
  8094. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8095. json_object *ChangeAvailability;
  8096. ChangeAvailability = json_tokener_parse(payload);
  8097. if(!is_error(ChangeAvailability))
  8098. {
  8099. // Required data
  8100. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8101. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8102. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8103. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8104. }
  8105. json_object_put(ChangeAvailability);
  8106. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8107. {
  8108. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8109. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8110. }
  8111. else if(gunIndex == 0)
  8112. {
  8113. for(int i=0; i < gunTotalNumber; i++)
  8114. {
  8115. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8116. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8117. }
  8118. }
  8119. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8120. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8121. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8122. {
  8123. specificId = TRUE;
  8124. }
  8125. if(specificId == FALSE)
  8126. goto end;
  8127. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8128. {
  8129. //----------------------gunIndex is 0 ------------------------------------------------//
  8130. if(gunIndex == 0)
  8131. {
  8132. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8133. {
  8134. for(int i=0; i < gunTotalNumber; i++)
  8135. {
  8136. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8137. {
  8138. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8139. {
  8140. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8141. {
  8142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8143. goto end;
  8144. }
  8145. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8146. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8147. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8148. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8149. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8150. {
  8151. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8152. goto end;
  8153. }
  8154. }
  8155. }//END FOR CHAdeMO_QUANTITY
  8156. for (int index = 0; index < CCS_QUANTITY; index++)
  8157. {
  8158. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8159. {
  8160. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8161. {
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8163. goto end;
  8164. }
  8165. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8168. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8169. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8170. {
  8171. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8172. goto end;
  8173. }
  8174. }
  8175. }//END FOR CCS_QUANTITY
  8176. for (int index = 0; index < GB_QUANTITY; index++)
  8177. {
  8178. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8179. {
  8180. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8181. {
  8182. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8183. goto end;
  8184. }
  8185. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8188. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8189. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8190. {
  8191. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8192. goto end;
  8193. }
  8194. }
  8195. }// END FOR GB_QUANTITY
  8196. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8197. {
  8198. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8199. {
  8200. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8201. {
  8202. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8203. goto end;
  8204. }
  8205. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8206. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8207. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8208. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8209. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8210. {
  8211. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8212. goto end;
  8213. }
  8214. }
  8215. }// END FOR GENERAL_GUN_QUANTITY
  8216. for (int index = 0; index < AC_QUANTITY; index++)
  8217. {
  8218. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8219. {
  8220. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8221. {
  8222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8223. goto end;
  8224. }
  8225. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8226. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8227. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8228. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8229. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8230. {
  8231. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8232. goto end;
  8233. }
  8234. }
  8235. }//END FOR AC_QUANTITY
  8236. }// END FOR gunTotalNumber
  8237. }
  8238. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8239. {
  8240. for(int i=0; i < gunTotalNumber; i++)
  8241. {
  8242. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8243. {
  8244. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8245. goto end;
  8246. }
  8247. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8248. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8249. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8250. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8251. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8252. {
  8253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8254. goto end;
  8255. }
  8256. }
  8257. }
  8258. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8259. goto end;
  8260. }
  8261. //----------------------gunIndex is not 0 ------------------------------------------------//
  8262. //check Transaction active
  8263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8264. {
  8265. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8266. {
  8267. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8268. {
  8269. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8270. goto end;
  8271. }
  8272. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8273. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8274. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8275. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8276. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8277. {
  8278. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8279. goto end;
  8280. }
  8281. else
  8282. {
  8283. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8285. goto end;
  8286. }
  8287. }
  8288. }//END FOR CHAdeMO_QUANTITY
  8289. for (int index = 0; index < CCS_QUANTITY; index++)
  8290. {
  8291. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8292. {
  8293. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8294. {
  8295. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8296. goto end;
  8297. }
  8298. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8301. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8302. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8303. {
  8304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8305. goto end;
  8306. }
  8307. else
  8308. {
  8309. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8311. goto end;
  8312. }
  8313. }
  8314. }//END FOR CCS_QUANTITY
  8315. for (int index = 0; index < GB_QUANTITY; index++)
  8316. {
  8317. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8318. {
  8319. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8320. {
  8321. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8322. goto end;
  8323. }
  8324. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8325. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8326. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8327. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8328. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8329. {
  8330. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8331. goto end;
  8332. }
  8333. else
  8334. {
  8335. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8337. goto end;
  8338. }
  8339. }
  8340. }// END FOR GB_QUANTITY
  8341. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8342. {
  8343. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8344. {
  8345. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8346. {
  8347. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8348. goto end;
  8349. }
  8350. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8351. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8352. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8353. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8354. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8355. {
  8356. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8357. goto end;
  8358. }
  8359. else
  8360. {
  8361. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8362. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8363. goto end;
  8364. }
  8365. }
  8366. }// END FOR GENERAL_GUN_QUANTITY
  8367. for (int index = 0; index < AC_QUANTITY; index++)
  8368. {
  8369. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8370. {
  8371. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8372. {
  8373. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8374. goto end;
  8375. }
  8376. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8377. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8378. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8379. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8380. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8381. {
  8382. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8383. goto end;
  8384. }
  8385. else
  8386. {
  8387. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8389. goto end;
  8390. }
  8391. }
  8392. }//END FOR AC_QUANTITY
  8393. }//END FOR AvailabilityTypeStr[Inoperative]
  8394. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8395. {
  8396. //----------------------gunIndex is 0 ------------------------------------------------//
  8397. if(gunIndex == 0)
  8398. {
  8399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8400. {
  8401. for(int i=0; i < gunTotalNumber; i++)
  8402. {
  8403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8404. {
  8405. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8406. {
  8407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8408. goto end;
  8409. }
  8410. }//END FOR CHAdeMO_QUANTITY
  8411. for (int index = 0; index < CCS_QUANTITY; index++)
  8412. {
  8413. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8414. {
  8415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8416. goto end;
  8417. }
  8418. }//END FOR CCS_QUANTITY
  8419. for (int index = 0; index < GB_QUANTITY; index++)
  8420. {
  8421. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8422. {
  8423. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8425. goto end;
  8426. }
  8427. }// END FOR GB_QUANTITY
  8428. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8429. {
  8430. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8431. {
  8432. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8434. goto end;
  8435. }
  8436. }// END FOR GENERAL_GUN_QUANTITY
  8437. for (int index = 0; index < AC_QUANTITY; index++)
  8438. {
  8439. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8440. {
  8441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8442. goto end;
  8443. }
  8444. }//END FOR CHAdeMO_QUANTITY
  8445. }// END FOR gunTotalNumber
  8446. }
  8447. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8448. {
  8449. for(int i=0; i < gunTotalNumber; i++)
  8450. {
  8451. for (int index = 0; index < AC_QUANTITY; index++)
  8452. {
  8453. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8454. {
  8455. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8456. goto end;
  8457. }
  8458. }//END FOR CHAdeMO_QUANTITY
  8459. } // END FOR gunTotalNumber
  8460. }
  8461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8462. goto end;
  8463. }
  8464. //----------------------gunIndex is not 0 ------------------------------------------------//
  8465. //check Transaction active
  8466. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8467. {
  8468. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8469. {
  8470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8471. goto end;
  8472. }
  8473. }//END FOR CHAdeMO_QUANTITY
  8474. for (int index = 0; index < CCS_QUANTITY; index++)
  8475. {
  8476. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8477. {
  8478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8479. goto end;
  8480. }
  8481. }//END FOR CCS_QUANTITY
  8482. for (int index = 0; index < GB_QUANTITY; index++)
  8483. {
  8484. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8485. {
  8486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8487. goto end;
  8488. }
  8489. }// END FOR GB_QUANTITY
  8490. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8491. {
  8492. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8493. {
  8494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8495. goto end;
  8496. }
  8497. }// END FOR GENERAL_GUN_QUANTITY
  8498. for (int index = 0; index < AC_QUANTITY; index++)
  8499. {
  8500. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8501. {
  8502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8503. goto end;
  8504. }
  8505. }//END FOR AC_QUANTITY
  8506. }//END FOR AvailabilityTypeStr[Operative]
  8507. end:
  8508. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8509. {
  8510. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8511. }
  8512. else
  8513. {
  8514. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8515. }
  8516. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8517. {
  8518. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8519. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8520. }
  8521. else if(gunIndex == 0)
  8522. {
  8523. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8524. {
  8525. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8526. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8527. }
  8528. }
  8529. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8530. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8531. return result;
  8532. }
  8533. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8534. {
  8535. mtrace();
  8536. int valueInvalid = NO;
  8537. int result = FAIL;
  8538. char keystr[40]={0};
  8539. char valuestr[501]={0}; //value should be limited in 500 bytes
  8540. char comfirmstr[20]={0};
  8541. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8542. json_object *ChangeConfiguration;
  8543. ChangeConfiguration = json_tokener_parse(payload);
  8544. if(!is_error(ChangeConfiguration))
  8545. {
  8546. // Required data
  8547. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8548. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8549. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8550. {
  8551. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8552. }
  8553. else
  8554. {
  8555. valueInvalid = YES;
  8556. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8557. }
  8558. }
  8559. json_object_put(ChangeConfiguration);
  8560. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8561. {
  8562. DEBUG_ERROR("Payload is null or not accepted.\n");
  8563. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8564. }
  8565. else
  8566. {
  8567. int status = setKeyValue(keystr, valuestr);
  8568. switch(status)
  8569. {
  8570. case ConfigurationStatus_Accepted:
  8571. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8572. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8573. StoreConfigurationTable();
  8574. break;
  8575. case RebootRequired:
  8576. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8577. StoreConfigurationTable();
  8578. break;
  8579. case NotSupported:
  8580. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8581. break;
  8582. case ConfigurationStatus_Rejected:
  8583. default:
  8584. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8585. break;
  8586. }
  8587. }
  8588. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8589. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8590. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8591. {
  8592. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8593. SetOcppConnStatus(FALSE);
  8594. }
  8595. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0) || (strcmp(keystr,"RfidEndianType")==0) ||
  8596. (strcmp(keystr,"Enable15118")==0) || (strcmp(keystr,"WifiSsid")==0) || (strcmp(keystr,"WifiPassword")==0) || (strcmp(keystr,"StopChargingByButton")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8597. {
  8598. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8599. }
  8600. return result;
  8601. }
  8602. int handleClearCacheRequest(char *uuid, char *payload)
  8603. {
  8604. mtrace();
  8605. int result = FAIL;
  8606. char comfirmstr[20];
  8607. char rmFileCmd[100]={0};
  8608. struct stat stats;
  8609. DEBUG_INFO("handleClearCacheRequest...\n");
  8610. stat("/Storage/OCPP_PH", &stats);
  8611. // Check for directory existence
  8612. if (S_ISDIR(stats.st_mode) == 1)
  8613. {}
  8614. else
  8615. {
  8616. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8617. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8618. system(rmFileCmd);
  8619. }
  8620. if(OCPP_cleanLocalCache())
  8621. {
  8622. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8623. }
  8624. else
  8625. {
  8626. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8627. }
  8628. sendClearCacheConfirmation(uuid, comfirmstr);
  8629. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8630. return result;
  8631. }
  8632. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8633. {
  8634. mtrace();
  8635. int result = FAIL;
  8636. int resultRename;
  8637. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8638. char chargingProfilePurposeStr[26]={0};
  8639. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8640. char tempchargingProfilePurposeStr[26]={0};
  8641. char str[100]={0};
  8642. char fname[200]={0};
  8643. char comfirmstr[20]={0};
  8644. char word[1600]={0};
  8645. int clearflag = FALSE;
  8646. int chargingProfileIdIsNULL = FALSE;
  8647. int connectorIsNULL = FALSE;
  8648. int chargingProfilePurposeIsNULL = FALSE;
  8649. int stackLevelIsNULL = FALSE;
  8650. //int GotoEnd = FALSE;
  8651. FILE *fptr1, *fptr2;
  8652. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8653. int n_chargingProfile=0;
  8654. int isEmptyFile = FALSE;
  8655. char sLineWord[1600]={0};
  8656. char chargingProfiles[10][100]={0};
  8657. int ChargeProfileCount = 0;
  8658. int ch;
  8659. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8660. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8661. json_object *ClearChargingProfile;
  8662. ClearChargingProfile = json_tokener_parse(payload);
  8663. if(!is_error(ClearChargingProfile))
  8664. {
  8665. // Optional data
  8666. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8667. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8668. else
  8669. chargingProfileIdIsNULL = TRUE;
  8670. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8671. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8672. else
  8673. connectorIsNULL = TRUE;
  8674. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8675. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8676. else
  8677. chargingProfilePurposeIsNULL = TRUE;
  8678. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8679. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8680. else
  8681. stackLevelIsNULL = TRUE;
  8682. }
  8683. json_object_put(ClearChargingProfile);
  8684. if(connectorIdInt > 0)
  8685. {
  8686. if(chargingProfilePurposeIsNULL == TRUE)
  8687. {
  8688. int m = 0;
  8689. memset(fname, 0, ARRAY_SIZE(fname));
  8690. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8691. if((access(fname,F_OK))!=-1)
  8692. {
  8693. strcpy(chargingProfiles[m], fname);
  8694. m = m + 1;
  8695. }
  8696. memset(fname, 0, ARRAY_SIZE(fname));
  8697. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8698. if((access(fname,F_OK))!=-1)
  8699. {
  8700. strcpy(chargingProfiles[m], fname);
  8701. m = m + 1;
  8702. }
  8703. ChargeProfileCount = m;
  8704. }
  8705. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8706. {
  8707. //strcpy(fname, TxDefaultProfile_1_JSON);
  8708. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8709. if((access(fname,F_OK))!=-1)
  8710. {
  8711. strcpy(chargingProfiles[0], fname);
  8712. ChargeProfileCount = 1;
  8713. }
  8714. }
  8715. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8716. {
  8717. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8718. if((access(fname,F_OK))!=-1)
  8719. {
  8720. strcpy(chargingProfiles[0], fname);
  8721. ChargeProfileCount = 1;
  8722. }
  8723. //strcpy(fname, TxProfile_1_JSON);
  8724. }
  8725. }
  8726. else // Check all Charging Profiles
  8727. {
  8728. int i = 0;
  8729. char fnametemp[200]={0};
  8730. ChargeProfileCount = 0;
  8731. //Check ChargePointMaxProfile.json exit
  8732. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8733. {
  8734. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8735. i = i + 1;
  8736. }
  8737. //Check TxDefaultProfile_0.json exit
  8738. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8739. {
  8740. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8741. i = i + 1;
  8742. }
  8743. //Check TxDefaultProfile_%d.json
  8744. for(int j=1; j <= gunTotalNumber; j++)
  8745. {
  8746. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8747. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8748. if((access(fnametemp,F_OK))!=-1)
  8749. {
  8750. strcpy(chargingProfiles[i], fnametemp);
  8751. i = i + 1;
  8752. }
  8753. }
  8754. //Check TxProfile_%d.json
  8755. for(int j=1; j <= gunTotalNumber; j++)
  8756. {
  8757. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8758. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8759. if((access(fnametemp,F_OK))!=-1)
  8760. {
  8761. strcpy(chargingProfiles[i], fnametemp);
  8762. i = i + 1;
  8763. }
  8764. }
  8765. ChargeProfileCount = i;
  8766. }// End connectorIsNULL is TRUE
  8767. if(ChargeProfileCount == 0)
  8768. {
  8769. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8770. goto end;
  8771. }
  8772. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8773. {
  8774. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8775. goto end;
  8776. }
  8777. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8778. {
  8779. memset(str, 0, ARRAY_SIZE(str));
  8780. // clear temp file
  8781. sprintf(str,"rm -f %s",temp);
  8782. system(str);
  8783. for(int k=0; k < ChargeProfileCount; k++)
  8784. {
  8785. memset(str, 0, ARRAY_SIZE(str));
  8786. //clear file in C
  8787. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8788. system(str);
  8789. }
  8790. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8791. goto end;
  8792. }
  8793. else if(connectorIsNULL == TRUE)
  8794. {
  8795. for(int k=0; k < ChargeProfileCount; k++)
  8796. {
  8797. fptr1 = fopen(chargingProfiles[k], "r");
  8798. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8799. //Check Charging Profile Count
  8800. while(fscanf(fptr1, "%s", word) != EOF)
  8801. {
  8802. //DEBUG_INFO("word=%s\n",word);
  8803. if(strstr(word, "chargingProfileId")!= NULL)
  8804. {
  8805. //DEBUG_INFO("test chargingProfileId \n");
  8806. n_chargingProfile = n_chargingProfile + 1;
  8807. //DEBUG_INFO("chargingProfileId Found\n");
  8808. }
  8809. }
  8810. rewind(fptr1);
  8811. //search Charging Profile Element
  8812. //int i= 0;
  8813. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8814. {
  8815. json_object *tmpProfilee;
  8816. tmpProfilee = json_tokener_parse(sLineWord);
  8817. if(!is_error(tmpProfilee))
  8818. {
  8819. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8820. {
  8821. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8822. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8823. }
  8824. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8825. {
  8826. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8827. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8828. }
  8829. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8830. {
  8831. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8832. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8833. }
  8834. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8835. {
  8836. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8837. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8838. }
  8839. }
  8840. json_object_put(tmpProfilee);
  8841. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8842. {
  8843. //------- not write to fptr2-------//
  8844. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8845. //clearflag = TRUE;
  8846. }
  8847. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8848. {
  8849. //------- not write to fptr2-------//
  8850. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8851. }
  8852. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8853. {
  8854. //------- not write to fptr2-------//
  8855. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8856. }
  8857. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8858. {
  8859. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8860. }
  8861. else
  8862. {
  8863. fprintf(fptr2, sLineWord);//writing data into file
  8864. }
  8865. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8866. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8867. if(clearflag == TRUE)
  8868. {
  8869. fclose(fptr1);
  8870. fclose(fptr2);
  8871. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8872. system(str);
  8873. // clear temp file
  8874. sprintf(str,"rm -f %s",temp);
  8875. system(str);
  8876. }
  8877. else
  8878. {
  8879. fclose(fptr1);
  8880. fclose(fptr2);
  8881. memset(str, 0, ARRAY_SIZE(str));
  8882. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8883. system(str);
  8884. resultRename = rename(temp, chargingProfiles[k]);
  8885. if(resultRename == 0)
  8886. {
  8887. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8888. }
  8889. else
  8890. {
  8891. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8892. }
  8893. if(comfirmstr[0]== 0)
  8894. {
  8895. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8896. }
  8897. //Check chargingProfile is empty file
  8898. /*------ Read the file ----------------*/
  8899. fptr1=fopen(chargingProfiles[k],"r");
  8900. ch=fgetc(fptr1);
  8901. rewind(fptr1);
  8902. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8903. if(ch!=EOF)
  8904. {
  8905. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8906. {
  8907. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8908. if(sLineWord[0]=='\0')
  8909. {
  8910. isEmptyFile = TRUE;
  8911. break;
  8912. }
  8913. else
  8914. {
  8915. isEmptyFile = FALSE;
  8916. break;
  8917. }
  8918. }
  8919. }
  8920. else
  8921. isEmptyFile = TRUE;
  8922. fclose(fptr1);
  8923. if(isEmptyFile == TRUE)
  8924. {
  8925. memset(str, 0, ARRAY_SIZE(str));
  8926. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8927. system(str);
  8928. }
  8929. }
  8930. }// End of while(int k=0; k < ChargePointCount; k++)
  8931. }
  8932. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8933. {
  8934. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8935. for(int k=0; k < ChargeProfileCount; k++)
  8936. {
  8937. fptr1 = fopen(chargingProfiles[k], "r");
  8938. fptr2 = fopen(temp, "w+");
  8939. //Check Charging Profile Count
  8940. while(fscanf(fptr1, "%s", word) != EOF)
  8941. {
  8942. //DEBUG_INFO("word=%s\n",word);
  8943. if(strstr(word, "chargingProfileId")!= NULL)
  8944. {
  8945. n_chargingProfile = n_chargingProfile + 1;
  8946. }
  8947. }
  8948. rewind(fptr1);
  8949. //search Charging Profile Element
  8950. //int i= 0;
  8951. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8952. {
  8953. json_object *tmpProfilee;
  8954. tmpProfilee = json_tokener_parse(sLineWord);
  8955. if(!is_error(tmpProfilee))
  8956. {
  8957. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8958. {
  8959. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8960. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8961. }
  8962. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8963. {
  8964. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8965. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8966. }
  8967. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8968. {
  8969. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8970. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8971. }
  8972. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8973. {
  8974. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8975. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8976. }
  8977. }
  8978. json_object_put(tmpProfilee);
  8979. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8980. {
  8981. //------- not write to fptr2-------//
  8982. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8983. //clearflag = TRUE;
  8984. }
  8985. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8986. {
  8987. //------- not write to fptr2-------//
  8988. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8989. }
  8990. else if(stackLevelIsNULL == TRUE)
  8991. {
  8992. //Clear Whole File
  8993. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8994. clearflag = TRUE;
  8995. break;
  8996. }
  8997. else
  8998. {
  8999. fprintf(fptr2, sLineWord);//writing data into file
  9000. }
  9001. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9002. }
  9003. if(clearflag == TRUE)
  9004. {
  9005. fclose(fptr1);
  9006. fclose(fptr2);
  9007. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9008. system(str);
  9009. // clear temp file
  9010. sprintf(str,"rm -f %s",temp);
  9011. system(str);
  9012. }
  9013. else
  9014. {
  9015. fclose(fptr1);
  9016. fclose(fptr2);
  9017. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9018. system(str);
  9019. resultRename = rename(temp, chargingProfiles[k]);
  9020. if(resultRename == 0)
  9021. {
  9022. DEBUG_INFO("File ChargingProfile renamed successfully");
  9023. }
  9024. else
  9025. {
  9026. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9027. }
  9028. if(comfirmstr[0]== 0)
  9029. {
  9030. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9031. }
  9032. //Check chargingProfile is empty file
  9033. /*------ Read the file ----------------*/
  9034. fptr1=fopen(chargingProfiles[k],"r");
  9035. ch=fgetc(fptr1);
  9036. rewind(fptr1);
  9037. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9038. if(ch!=EOF)
  9039. {
  9040. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9041. {
  9042. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9043. if(sLineWord[0]=='\0')
  9044. {
  9045. isEmptyFile = TRUE;
  9046. break;
  9047. }
  9048. else
  9049. {
  9050. isEmptyFile = FALSE;
  9051. break;
  9052. }
  9053. }
  9054. }
  9055. else
  9056. isEmptyFile = TRUE;
  9057. fclose(fptr1);
  9058. if(isEmptyFile == TRUE)
  9059. {
  9060. memset(str, 0, ARRAY_SIZE(str));
  9061. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9062. system(str);
  9063. }
  9064. /*------- End of reading ---------------*/
  9065. }
  9066. } // while(int k=0; k < ChargeProfileCount; k++)
  9067. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9068. end:
  9069. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9070. {
  9071. if(connectorIdInt == 0)
  9072. {
  9073. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9074. {
  9075. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9076. }
  9077. }
  9078. else
  9079. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9080. }
  9081. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9082. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9083. return result;
  9084. }
  9085. void createFirmwareVersionByDataTransfer(void)
  9086. {
  9087. json_object *FirmwareDataTransfer = json_object_new_object();
  9088. // AC & DC model
  9089. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9090. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9091. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9092. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9093. // DC model
  9094. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9095. {
  9096. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9097. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9098. (gunType[3] != GUN_TYPE_UNKNOWN))
  9099. {
  9100. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9101. }
  9102. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9103. {
  9104. // DS DM DW
  9105. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9106. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9107. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9108. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9109. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9110. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9111. }
  9112. else
  9113. {
  9114. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9115. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9116. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9117. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9118. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9119. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9120. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9121. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9122. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9123. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9124. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9125. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9126. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9127. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9128. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9129. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9130. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9131. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9132. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9133. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9134. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9135. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9136. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9137. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9138. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9139. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9140. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9141. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9142. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9143. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9144. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9145. }
  9146. }
  9147. // 4G model
  9148. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9149. {
  9150. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9151. }
  9152. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9153. json_object_put(FirmwareDataTransfer);
  9154. }
  9155. int handleDataTransferRequest(char *uuid, char *payload)
  9156. {
  9157. mtrace();
  9158. json_object *response = json_object_new_object();
  9159. int result = FAIL;
  9160. char tempvendorId[255]={0};
  9161. char tempmessageId[50]={0};
  9162. char tempdata[1024]={0};
  9163. char message[2048]={0};
  9164. DEBUG_INFO("handleDataTransferRequest...\n");
  9165. if((uuid != NULL) && (payload != NULL))
  9166. {
  9167. json_object *DataTransfer;
  9168. DataTransfer = json_tokener_parse(payload);
  9169. if(!is_error(DataTransfer))
  9170. {
  9171. // Required data
  9172. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9173. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9174. // Optional data
  9175. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9176. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9177. if(json_object_object_get(DataTransfer, "data") != NULL)
  9178. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9179. result = PASS;
  9180. }
  9181. json_object_put(DataTransfer);
  9182. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9183. {
  9184. // Send all moudle firmware version on EVSE
  9185. createFirmwareVersionByDataTransfer();
  9186. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9187. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9188. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9189. json_object_put(response);
  9190. }
  9191. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9192. {
  9193. system("/usr/bin/run_tmate_restart.sh &");
  9194. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9195. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9196. json_object_put(response);
  9197. }
  9198. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9199. {
  9200. json_object *data;
  9201. data = json_tokener_parse(tempdata);
  9202. if(!is_error(data))
  9203. {
  9204. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9205. {
  9206. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9207. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9208. if(json_object_object_get(data, "SOC") != NULL)
  9209. {
  9210. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9211. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9212. }
  9213. if(json_object_object_get(data, "Energy") != NULL)
  9214. {
  9215. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9216. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9217. }
  9218. if(json_object_object_get(data, "Duration") != NULL)
  9219. {
  9220. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9221. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9222. }
  9223. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9224. }
  9225. else
  9226. {
  9227. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9228. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9229. }
  9230. }
  9231. else
  9232. {
  9233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9235. }
  9236. json_object_put(data);
  9237. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9238. json_object_put(response);
  9239. }
  9240. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9241. {
  9242. json_object *data;
  9243. data = json_tokener_parse(tempdata);
  9244. if(!is_error(data))
  9245. {
  9246. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9247. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9248. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9249. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9250. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9251. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9252. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9253. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9254. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9255. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9256. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9257. }
  9258. else
  9259. {
  9260. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9261. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9262. }
  9263. json_object_put(data);
  9264. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9265. json_object_put(response);
  9266. }
  9267. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9268. {
  9269. json_object *data;
  9270. data = json_tokener_parse(tempdata);
  9271. if(!is_error(data))
  9272. {
  9273. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9274. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9275. if(json_object_object_get(data, "idToken") != NULL)
  9276. {
  9277. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9278. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9279. }
  9280. else
  9281. {
  9282. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9283. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9284. }
  9285. if(json_object_object_get(data, "price") != NULL) //v1.0
  9286. {
  9287. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9288. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9289. }
  9290. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9291. {
  9292. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9293. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9294. }
  9295. else
  9296. {
  9297. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9298. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9299. }
  9300. }
  9301. else
  9302. {
  9303. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9304. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9305. }
  9306. json_object_put(data);
  9307. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9308. json_object_put(response);
  9309. }
  9310. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9311. {
  9312. json_object *data;
  9313. data = json_tokener_parse(tempdata);
  9314. if(!is_error(data))
  9315. {
  9316. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9317. if(json_object_object_get(data, "txId") != NULL)
  9318. {
  9319. // California pricing V1.0
  9320. DEBUG_INFO("California pricing V1.0\n");
  9321. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9322. sprintf((char*)dmsVersion, "1.0");
  9323. for(int idx = 0;idx<gunTotalNumber;idx++)
  9324. {
  9325. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9326. {
  9327. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9328. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9329. if(json_object_object_get(data, "description") != NULL)
  9330. {
  9331. // California pricing V1.0
  9332. DEBUG_INFO("California pricing V1.0\n");
  9333. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9334. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9335. }
  9336. }
  9337. }
  9338. }
  9339. else if(json_object_object_get(data, "transactionId") != NULL)
  9340. {
  9341. // California pricing V2.0
  9342. DEBUG_INFO("California pricing V2.0\n");
  9343. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9344. sprintf((char*)dmsVersion, "2.0");
  9345. for(int idx=0;idx<gunTotalNumber;idx++)
  9346. {
  9347. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9348. {
  9349. if(json_object_object_get(data, "timestamp") != NULL)
  9350. {
  9351. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9352. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9353. }
  9354. else
  9355. {
  9356. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9357. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9358. }
  9359. if(json_object_object_get(data, "meterValue") != NULL)
  9360. {
  9361. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9362. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9363. }
  9364. else
  9365. {
  9366. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9367. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9368. }
  9369. if(json_object_object_get(data, "cost") != NULL)
  9370. {
  9371. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9372. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9373. }
  9374. else
  9375. {
  9376. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9377. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9378. }
  9379. if(json_object_object_get(data, "state") != NULL)
  9380. {
  9381. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9382. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9383. }
  9384. else
  9385. {
  9386. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9387. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9388. }
  9389. if(json_object_object_get(data, "chargingPrice") != NULL)
  9390. {
  9391. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9392. {
  9393. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9394. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9395. }
  9396. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9397. {
  9398. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9399. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9400. }
  9401. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9402. {
  9403. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9404. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9405. }
  9406. }
  9407. else
  9408. {
  9409. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9410. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9411. }
  9412. if(json_object_object_get(data, "idlePrice") != NULL)
  9413. {
  9414. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9415. {
  9416. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9417. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9418. }
  9419. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9420. {
  9421. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9422. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9423. }
  9424. }
  9425. if(json_object_object_get(data, "nextPeriod") != NULL)
  9426. {
  9427. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9428. {
  9429. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9430. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9431. }
  9432. else
  9433. {
  9434. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9435. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9436. }
  9437. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9438. {
  9439. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9440. {
  9441. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  9442. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  9443. }
  9444. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9445. {
  9446. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  9447. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  9448. }
  9449. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9450. {
  9451. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  9452. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  9453. }
  9454. }
  9455. else
  9456. {
  9457. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9458. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9459. }
  9460. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9461. {
  9462. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9463. {
  9464. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  9465. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  9466. }
  9467. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9468. {
  9469. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  9470. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  9471. }
  9472. }
  9473. }
  9474. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9475. {
  9476. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9477. {
  9478. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9479. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9480. }
  9481. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9482. {
  9483. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9484. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9485. }
  9486. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9487. {
  9488. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9489. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9490. }
  9491. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9492. {
  9493. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9494. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9495. }
  9496. }
  9497. }
  9498. }
  9499. }
  9500. else
  9501. {
  9502. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9503. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9504. }
  9505. }
  9506. else
  9507. {
  9508. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9509. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9510. }
  9511. json_object_put(data);
  9512. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9513. json_object_put(response);
  9514. }
  9515. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9516. {
  9517. json_object *data;
  9518. data = json_tokener_parse(tempdata);
  9519. if(!is_error(data))
  9520. {
  9521. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9522. if(json_object_object_get(data, "txId") != NULL)
  9523. {
  9524. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9525. for(int idx = 0;idx<gunTotalNumber;idx++)
  9526. {
  9527. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9528. {
  9529. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9530. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9531. if(json_object_object_get(data, "description") != NULL)
  9532. {
  9533. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9534. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9535. }
  9536. else
  9537. {
  9538. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9539. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9540. }
  9541. }
  9542. }
  9543. }
  9544. else if(json_object_object_get(data, "transactionId") != NULL)
  9545. {
  9546. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9547. for(int idx = 0;idx<gunTotalNumber;idx++)
  9548. {
  9549. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9550. {
  9551. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9552. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9553. if(json_object_object_get(data, "cost") != NULL)
  9554. {
  9555. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  9556. ShmOCPP16DataPH->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9557. }
  9558. else
  9559. {
  9560. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9561. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9562. }
  9563. if(json_object_object_get(data, "priceText") != NULL)
  9564. {
  9565. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9566. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9567. }
  9568. else
  9569. {
  9570. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9571. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  9572. }
  9573. if(json_object_object_get(data, "qrCodeText") != NULL)
  9574. {
  9575. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9576. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9577. }
  9578. }
  9579. }
  9580. }
  9581. else
  9582. {
  9583. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9584. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9585. }
  9586. }
  9587. else
  9588. {
  9589. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9590. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9591. }
  9592. json_object_put(data);
  9593. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9594. json_object_put(response);
  9595. }
  9596. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9597. {
  9598. json_object *data;
  9599. data = json_tokener_parse(tempdata);
  9600. if(!is_error(data))
  9601. {
  9602. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9603. if(json_object_object_get(data, "Content_Type") != NULL)
  9604. {
  9605. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  9606. {
  9607. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9608. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9609. {
  9610. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9611. }
  9612. }
  9613. else
  9614. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9615. }
  9616. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9617. }
  9618. else
  9619. {
  9620. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9621. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9622. }
  9623. json_object_put(data);
  9624. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9625. json_object_put(response);
  9626. }
  9627. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9628. {
  9629. json_object *data;
  9630. data = json_tokener_parse(tempdata);
  9631. if(!is_error(data))
  9632. {
  9633. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9634. if(json_object_object_get(data, "ConnectorId") != NULL)
  9635. {
  9636. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9637. }
  9638. if(json_object_object_get(data, "SerialNo") != NULL)
  9639. {
  9640. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9641. }
  9642. if(json_object_object_get(data, "Page_Index") != NULL)
  9643. {
  9644. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9645. }
  9646. if(json_object_object_get(data, "Duration") != NULL)
  9647. {
  9648. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9649. }
  9650. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9651. }
  9652. else
  9653. {
  9654. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9655. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9656. }
  9657. json_object_put(data);
  9658. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9659. json_object_put(response);
  9660. }
  9661. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9662. {
  9663. json_object *data;
  9664. data = json_tokener_parse(tempdata);
  9665. if(!is_error(data))
  9666. {
  9667. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9668. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9669. {
  9670. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9671. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9672. else
  9673. {
  9674. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9675. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9676. }
  9677. }
  9678. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9679. {
  9680. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9681. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9682. else
  9683. {
  9684. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9685. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9686. }
  9687. }
  9688. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9689. {
  9690. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9691. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9692. else
  9693. {
  9694. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9695. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9696. }
  9697. }
  9698. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9699. {
  9700. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9701. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9702. else
  9703. {
  9704. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9705. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9706. }
  9707. }
  9708. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9709. {
  9710. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9711. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9712. else
  9713. {
  9714. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9715. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9716. }
  9717. }
  9718. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9719. {
  9720. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9721. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9722. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9723. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9724. else
  9725. {
  9726. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9727. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9728. }
  9729. }
  9730. if(json_object_object_get(data, "isAuthentication") != NULL)
  9731. {
  9732. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9733. {
  9734. case 0:
  9735. case 1:
  9736. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9737. break;
  9738. default:
  9739. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9740. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9741. break;
  9742. }
  9743. }
  9744. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9745. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9746. }
  9747. else
  9748. {
  9749. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9750. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9751. }
  9752. json_object_put(data);
  9753. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9754. json_object_put(response);
  9755. }
  9756. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9757. {
  9758. json_object *data;
  9759. data = json_tokener_parse(tempdata);
  9760. if(!is_error(data))
  9761. {
  9762. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9763. if(json_object_object_get(data, "stationName") != NULL)
  9764. {
  9765. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9766. }
  9767. else
  9768. {
  9769. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9770. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9771. }
  9772. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9773. {
  9774. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9775. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9776. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9777. }
  9778. }
  9779. else
  9780. {
  9781. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9782. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9783. }
  9784. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9785. json_object_put(response);
  9786. }
  9787. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9788. {
  9789. json_object *data;
  9790. data = json_tokener_parse(tempdata);
  9791. if(!is_error(data))
  9792. {
  9793. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9794. if(json_object_object_get(data, "weatherId") != NULL)
  9795. {
  9796. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9797. }
  9798. else
  9799. {
  9800. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9801. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9802. }
  9803. if(json_object_object_get(data, "Temperature") != NULL)
  9804. {
  9805. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9806. }
  9807. else
  9808. {
  9809. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9810. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9811. }
  9812. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9813. {
  9814. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9815. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9816. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9817. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9818. }
  9819. }
  9820. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9821. {
  9822. json_object *data;
  9823. data = json_tokener_parse(tempdata);
  9824. if(!is_error(data))
  9825. {
  9826. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9827. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9828. {
  9829. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9830. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9831. }
  9832. else
  9833. {
  9834. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9835. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9836. }
  9837. }
  9838. else
  9839. {
  9840. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9841. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9842. }
  9843. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9844. json_object_put(response);
  9845. }
  9846. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9847. {
  9848. json_object *data;
  9849. data = json_tokener_parse(tempdata);
  9850. if(!is_error(data))
  9851. {
  9852. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9853. {
  9854. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9855. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9856. if(gun_index < gunTotalNumber)
  9857. {
  9858. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9859. {
  9860. json_object *responsedata = json_object_new_object();
  9861. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9862. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9863. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9864. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9865. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.VEMData[gun_index]));
  9866. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9867. }
  9868. else
  9869. {
  9870. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9871. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9872. }
  9873. }
  9874. else
  9875. {
  9876. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9877. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9878. }
  9879. }
  9880. else
  9881. {
  9882. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9883. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9884. }
  9885. }
  9886. else
  9887. {
  9888. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9889. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9890. }
  9891. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9892. json_object_put(response);
  9893. }
  9894. else
  9895. {
  9896. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9897. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9898. }
  9899. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9900. json_object_put(response);
  9901. }
  9902. else
  9903. {
  9904. // Can not find valid message id
  9905. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9906. }
  9907. }
  9908. else
  9909. {
  9910. // Payload is null
  9911. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9912. }
  9913. LWS_Send(message);
  9914. return result;
  9915. }
  9916. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9917. {
  9918. mtrace();
  9919. int result = FAIL;
  9920. int connectorIdInt, durationInt;
  9921. char chargingRateUnitStr[4]={0};
  9922. char comfirmstr[20];
  9923. int confirmPeriods = 0;
  9924. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9925. json_object *GetCompositeSchedule;
  9926. GetCompositeSchedule = json_tokener_parse(payload);
  9927. if(!is_error(GetCompositeSchedule))
  9928. {
  9929. // Required data
  9930. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9931. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9932. else
  9933. connectorIdInt = -1;
  9934. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9935. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9936. else
  9937. durationInt = 86400;
  9938. // Optional data
  9939. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9940. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9941. }
  9942. json_object_put(GetCompositeSchedule);
  9943. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9944. if((connectorIdInt == 0) ||
  9945. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9946. {
  9947. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9948. struct StructChargingProfile tmpProfile[1];
  9949. if(strstr(chargingRateUnitStr, "W") != NULL)
  9950. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9951. else
  9952. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9953. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9954. {
  9955. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9956. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9957. }
  9958. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9959. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9960. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9961. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9962. {
  9963. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9964. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9965. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9966. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9967. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9968. {
  9969. confirmPeriods = idx;
  9970. break;
  9971. }
  9972. }
  9973. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9974. {
  9975. confirmPeriods += 1;
  9976. }
  9977. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9978. }
  9979. else
  9980. {
  9981. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9982. }
  9983. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9984. return result;
  9985. }
  9986. int handleGetConfigurationRequest(char *uuid, char *payload)
  9987. {
  9988. mtrace();
  9989. int result = FAIL;
  9990. int MaxKeySupported = 0;
  9991. int n_keys = 0;
  9992. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9993. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9994. json_object *GetConfiguration;
  9995. GetConfiguration = json_tokener_parse(payload);
  9996. if(!is_error(GetConfiguration))
  9997. {
  9998. // Optional data
  9999. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10000. {
  10001. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10002. {
  10003. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10004. n_keys = idx + 1;
  10005. }
  10006. }
  10007. }
  10008. json_object_put(GetConfiguration);
  10009. UnknownKeynum = 0;
  10010. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10011. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10012. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10013. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10014. if(n_keys != 0)
  10015. {
  10016. for(int i=0;i<n_keys;i++)
  10017. {
  10018. getKeyValue(requestKey[i]);
  10019. }
  10020. }
  10021. else
  10022. {
  10023. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10024. getKeyValue("");
  10025. }
  10026. processUnkownKey();
  10027. sendGetConfigurationConfirmation(uuid);
  10028. return result;
  10029. }
  10030. static char fnamePlusPath[100]={0};
  10031. static char fnamePWithNoPath[60]={0};
  10032. void checkUploadLog(void)
  10033. {
  10034. FILE *fp;
  10035. /* Open the command for reading. */
  10036. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10037. if (fp == NULL) {
  10038. DEBUG_WARN("Failed to run command\n" );
  10039. exit(1);
  10040. }
  10041. int ftppathlen = 0;
  10042. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10043. int i = 0;
  10044. /* Read the output a line at a time - output it. */
  10045. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10046. if(i==0)
  10047. {
  10048. ftppathlen = strlen(fnamePlusPath);
  10049. DEBUG_INFO("%s\n", fnamePlusPath);
  10050. fnamePlusPath[ftppathlen]='\0';
  10051. break;
  10052. }
  10053. i= i+1;
  10054. }
  10055. /* close */
  10056. pclose(fp);
  10057. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10058. {
  10059. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10060. {
  10061. fnamePlusPath[k]='\0';
  10062. }
  10063. }
  10064. i=1;
  10065. //char fname[60]={0};
  10066. while(i < ftppathlen)
  10067. {
  10068. int len=ftppathlen-i;
  10069. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10070. {
  10071. DEBUG_INFO("compare '/' all right\n");
  10072. break;
  10073. }
  10074. i=i+1;
  10075. }
  10076. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10077. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10078. fnamePWithNoPath[i+1] = '\0';
  10079. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10080. {
  10081. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10082. {
  10083. fnamePWithNoPath[j]='\0';
  10084. }
  10085. }
  10086. FILE* fp1 = fopen(fnamePlusPath, "r");
  10087. if (fp1)
  10088. {
  10089. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10090. // file exists
  10091. fclose(fp1);
  10092. }
  10093. else
  10094. {
  10095. // file doesn't exist
  10096. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10097. }
  10098. }
  10099. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10100. {
  10101. mtrace();
  10102. int result = FAIL;
  10103. time_t CurrentTime;
  10104. struct tm *tm;
  10105. pthread_t th_Status;
  10106. CurrentTime = time(NULL);
  10107. tm = localtime(&CurrentTime);
  10108. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  10109. sprintf((char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  10110. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10111. if(!interLock.isGetDiagnosticGoing)
  10112. {
  10113. interLock.isGetDiagnosticGoing = 1;
  10114. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10115. sleep(1);
  10116. }
  10117. else
  10118. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10119. return result;
  10120. }
  10121. void* GetDiagnosticsProcess(void* data)
  10122. {
  10123. pthread_detach(pthread_self());
  10124. mtrace();
  10125. int retriesInt=0, retryIntervalInt=0;
  10126. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10127. char protocol[10]={0}, user[64]={0},password[128]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  10128. int port=0;
  10129. int isSuccess = FALSE;
  10130. char ftpbuf[200]={0};
  10131. char cmdBuf[2048];
  10132. struct tm *tmNow;
  10133. time_t CurrentTime;
  10134. struct tm tmStart;
  10135. struct tm tmStop;
  10136. CurrentTime = time(NULL);
  10137. tmNow=localtime(&CurrentTime);
  10138. uint16_t targetYear, targetMonth;
  10139. json_object *GetDiagnostics;
  10140. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10141. GetDiagnostics = json_tokener_parse(data);
  10142. if(!is_error(GetDiagnostics))
  10143. {
  10144. // Required data
  10145. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10146. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10147. // Optional data
  10148. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10149. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10150. else
  10151. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10152. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10153. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10154. else
  10155. retryIntervalInt = 30;
  10156. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10157. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10158. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10159. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10160. }
  10161. json_object_put(GetDiagnostics);
  10162. // Notify CSU to get log of dispensers.
  10163. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  10164. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  10165. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  10166. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  10167. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  10168. )
  10169. {
  10170. sprintf((char *)ShmOCPP16DataPH->GetDiagnostics.StartTime,"%s",startTimestr);
  10171. sprintf((char *)ShmOCPP16DataPH->GetDiagnostics.StopTime,"%s",stopTimestr);
  10172. ShmOCPP16DataPH->MsMsg.bits.GetDiagnosticsReq = TRUE;
  10173. struct timespec timerGetDiagnostics;
  10174. refreshStartTimer(&timerGetDiagnostics);
  10175. while(ShmOCPP16DataPH->MsMsg.bits.GetDiagnosticsReq != FALSE)
  10176. {
  10177. if(getDiffSecNow(timerGetDiagnostics)>=180)
  10178. {
  10179. ShmOCPP16DataPH->MsMsg.bits.GetDiagnosticsReq = FALSE;
  10180. DEBUG_INFO("Waiting log of dispenser timeout.");
  10181. }
  10182. }
  10183. }
  10184. // Pack log to compress file
  10185. if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  10186. (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  10187. {
  10188. // Pack system log
  10189. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10190. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10191. targetYear = tmStart.tm_year;
  10192. targetMonth = tmStart.tm_mon;
  10193. do
  10194. {
  10195. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10196. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10197. if(targetMonth+1>=13)
  10198. {
  10199. targetYear += 1;
  10200. targetMonth = 1;
  10201. }
  10202. else
  10203. {
  10204. targetMonth += 1;
  10205. }
  10206. }while((targetYear < (tmNow->tm_year+1900)) ||
  10207. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10208. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10209. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10210. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  10211. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  10212. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  10213. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  10214. system(cmdBuf);
  10215. // Pack charging & event log
  10216. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10217. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10218. targetYear = tmStart.tm_year;
  10219. targetMonth = tmStart.tm_mon;
  10220. do
  10221. {
  10222. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10223. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  10224. if(targetMonth+1>=13)
  10225. {
  10226. targetYear += 1;
  10227. targetMonth = 1;
  10228. }
  10229. else
  10230. {
  10231. targetMonth += 1;
  10232. }
  10233. }while((targetYear < (tmNow->tm_year+1900)) ||
  10234. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10235. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10236. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10237. system(cmdBuf);
  10238. // Combine log file
  10239. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10240. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10241. }
  10242. else
  10243. {
  10244. system("exec /root/logPackTools 'log' 6");
  10245. }
  10246. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10247. system(cmdBuf);
  10248. checkUploadLog();
  10249. //****************location*******************/
  10250. if(strcmp(locationstr,"")==0)
  10251. {
  10252. DEBUG_INFO("location is <Empty>!\n");
  10253. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10254. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10255. goto end;
  10256. }
  10257. memset(protocol, 0, ARRAY_SIZE(protocol));
  10258. memset(user, 0, ARRAY_SIZE(user) );
  10259. memset(password, 0, ARRAY_SIZE(password));
  10260. memset(host, 0, ARRAY_SIZE(host));
  10261. memset(path, 0, ARRAY_SIZE(path));
  10262. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10263. memset(host1, 0, ARRAY_SIZE(host1));
  10264. memset(path1, 0, ARRAY_SIZE(path1));
  10265. /*location: ftp://user:password@host:port/path*/
  10266. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10267. if((access(fnamePlusPath,F_OK))!=-1)
  10268. {
  10269. DEBUG_INFO("fnamePlusPath exist.\n");
  10270. }
  10271. else
  10272. {
  10273. DEBUG_INFO("fnamePlusPath not exist!\n");
  10274. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10275. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10276. goto end;
  10277. }
  10278. if(strchr(locationstr,'@')==NULL)
  10279. {
  10280. sscanf(locationstr,
  10281. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10282. protocol, host, &port, path);
  10283. strcpy(user,"anonymous");
  10284. strcpy(password,"");
  10285. }
  10286. else
  10287. {
  10288. //DEBUG_INFO("pch=%s\n", pch);
  10289. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10290. protocol, user, password, host, &port, path);
  10291. }
  10292. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"sftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10293. {
  10294. DEBUG_INFO("protocol is not ftp/http ! \n");
  10295. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10296. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10297. goto end;
  10298. }
  10299. if(strncmp(locationstr,"http", 4) == 0)
  10300. {
  10301. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10302. sprintf(ftppath,"/%s", path);
  10303. do
  10304. {
  10305. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10306. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10307. sleep(3);
  10308. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10309. if(!isSuccess)
  10310. {
  10311. DEBUG_INFO("Diagnostics fail.\n");
  10312. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10313. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10314. sleep(retryIntervalInt);
  10315. }
  10316. else
  10317. {
  10318. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10319. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10320. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10321. }
  10322. retriesInt--;
  10323. }while((isSuccess == 0)&&(retriesInt >= 0));
  10324. }
  10325. else
  10326. {
  10327. sscanf(host,"%[^/]%s",host1, path1);
  10328. if(strlen(path) > 0)
  10329. sprintf(ftppath,"/%s", path);
  10330. else
  10331. sprintf(ftppath,"/%s", path1);
  10332. int ftppathlen=strlen(ftppath);
  10333. int i=1;
  10334. char filenametemp[50];
  10335. while(i < ftppathlen)
  10336. {
  10337. int len=ftppathlen-i;
  10338. if(ftppath[len]== 47) // '/' ascll code: 47
  10339. {
  10340. DEBUG_INFO("find '/' all right\n");
  10341. break;
  10342. }
  10343. i=i+1;
  10344. }
  10345. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10346. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10347. filenametemp[i+1] = 0;
  10348. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10349. if(port == 0)
  10350. port = 21;
  10351. do
  10352. {
  10353. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10354. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10355. sleep(3);
  10356. if(strncmp(locationstr,"sftp", 4) == 0)
  10357. isSuccess = sftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10358. else
  10359. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10360. if(!isSuccess)
  10361. {
  10362. DEBUG_INFO("Diagnostics fail.\n");
  10363. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10364. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10365. sleep(retryIntervalInt);
  10366. }
  10367. else
  10368. {
  10369. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10370. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10371. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10372. }
  10373. retriesInt--;
  10374. }while((!isSuccess)&&(retriesInt >= 0));
  10375. }
  10376. end:
  10377. system("rm -f /mnt/*");
  10378. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  10379. sleep(5);
  10380. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10381. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10382. interLock.isGetDiagnosticGoing = 0;
  10383. pthread_exit(NULL);
  10384. }
  10385. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10386. {
  10387. mtrace();
  10388. int result = FAIL;
  10389. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10390. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10391. {
  10392. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10393. locallistVersion = -1;
  10394. }
  10395. else
  10396. {
  10397. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10398. locallistVersion = 0;
  10399. OCPP_getListVerion();
  10400. }
  10401. //from db.OCPP_getListVerion
  10402. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10403. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10404. sendGetLocalListVersionConfirmation(uuid,"");
  10405. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10406. return result;
  10407. }
  10408. int handleRemoteStartRequest(char *uuid, char *payload)
  10409. {
  10410. mtrace();
  10411. int result = PASS;
  10412. int connectorIdInt=-1;
  10413. int tempIndex = 0;
  10414. char comfirmstr[20]={0};
  10415. char cmdBuf[512];
  10416. json_object *RemoteStartTransaction;
  10417. FILE *fp;
  10418. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10419. if(server_pending == TRUE)
  10420. {
  10421. result = FAIL;
  10422. }
  10423. RemoteStartTransaction = json_tokener_parse(payload);
  10424. if(!is_error(RemoteStartTransaction))
  10425. {
  10426. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10427. {
  10428. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10429. }
  10430. else
  10431. {
  10432. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10433. {
  10434. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10435. {
  10436. connectorIdInt = (gun_index+1);
  10437. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10438. break;
  10439. }
  10440. }
  10441. }
  10442. if(connectorIdInt == 0)
  10443. {
  10444. DEBUG_WARN("Connector id shall not equal 0.\n");
  10445. result = FAIL;
  10446. }
  10447. else if(connectorIdInt == -1)
  10448. {
  10449. DEBUG_INFO("Connector id does not specific.\n");
  10450. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10451. {
  10452. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10453. // Required data
  10454. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10455. // Optional data
  10456. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10457. {
  10458. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10459. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10460. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10461. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10462. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10463. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10464. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10465. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10466. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10467. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10468. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10469. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10470. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10471. {
  10472. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10473. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10474. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10475. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10476. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10477. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10478. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10479. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10480. {
  10481. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10482. {
  10483. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10484. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10485. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10486. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10487. }
  10488. }
  10489. }
  10490. }
  10491. else
  10492. {
  10493. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10494. }
  10495. }
  10496. }
  10497. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10498. {
  10499. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10500. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10501. // Required data
  10502. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10503. // Optional data
  10504. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10505. {
  10506. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10507. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10508. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10509. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10510. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10511. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10512. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10513. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10514. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10515. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10516. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10517. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10518. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10519. {
  10520. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10521. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10522. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10523. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10524. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10525. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10526. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10527. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10528. {
  10529. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10530. {
  10531. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10532. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10533. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10534. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10535. }
  10536. }
  10537. }
  10538. }
  10539. else
  10540. {
  10541. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10542. }
  10543. }
  10544. else
  10545. {
  10546. DEBUG_WARN("Connector id is over maximun value.\n");
  10547. result = FAIL;
  10548. }
  10549. }
  10550. if(result == PASS)
  10551. {
  10552. if(connectorIdInt > 0)
  10553. {
  10554. //check Transaction active
  10555. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10556. {
  10557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10558. {
  10559. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10560. }
  10561. else
  10562. {
  10563. tempIndex = connectorIdInt -1;
  10564. }
  10565. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10566. {
  10567. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10568. {
  10569. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10570. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10571. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10572. {
  10573. //Reserved
  10574. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10575. }
  10576. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10577. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10578. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10579. {
  10580. //Reserved
  10581. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10582. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10583. goto end;
  10584. }
  10585. else
  10586. {
  10587. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10588. {
  10589. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10590. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10591. goto end;
  10592. }
  10593. }//END FOR ELSE
  10594. }
  10595. }// END FOR CHAdeMO_QUANTITY
  10596. }
  10597. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10598. {
  10599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10600. {
  10601. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10602. }
  10603. else
  10604. {
  10605. tempIndex = connectorIdInt -1;
  10606. }
  10607. for (int index = 0; index < CCS_QUANTITY; index++)
  10608. {
  10609. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10610. {
  10611. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10612. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10613. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10614. {
  10615. //Reserved
  10616. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10617. }
  10618. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10619. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10620. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10621. {
  10622. //Reserved
  10623. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10624. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10625. goto end;
  10626. }
  10627. else
  10628. {
  10629. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10630. {
  10631. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10632. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10633. goto end;
  10634. }
  10635. }// END FOR ELSE
  10636. }
  10637. }// END FOR CCS_QUANTITY
  10638. }
  10639. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10640. {
  10641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10642. {
  10643. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10644. }
  10645. else
  10646. {
  10647. tempIndex = connectorIdInt -1;
  10648. }
  10649. for (int index = 0; index < GB_QUANTITY; index++)
  10650. {
  10651. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10652. {
  10653. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10654. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10655. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10656. {
  10657. //Reserved
  10658. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10659. }
  10660. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10661. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10662. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10663. {
  10664. //Reserved
  10665. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10666. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10667. goto end;
  10668. }
  10669. else
  10670. {
  10671. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10672. {
  10673. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10674. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10675. goto end;
  10676. }
  10677. }// END FOR ELSE
  10678. }
  10679. } // END FOR GB_QUANTITY
  10680. }
  10681. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10682. {
  10683. tempIndex = connectorIdInt -1;
  10684. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10685. {
  10686. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10687. {
  10688. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10689. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10690. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10691. {
  10692. //Reserved
  10693. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10694. }
  10695. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10696. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10697. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10698. {
  10699. //Reserved
  10700. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10702. goto end;
  10703. }
  10704. else
  10705. {
  10706. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10707. {
  10708. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10709. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10710. goto end;
  10711. }
  10712. }// END FOR ELSE
  10713. }
  10714. } // END FOR GB_QUANTITY
  10715. }
  10716. else
  10717. {
  10718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10719. {
  10720. tempIndex = 2;
  10721. }
  10722. else
  10723. {
  10724. tempIndex = connectorIdInt -1;
  10725. }
  10726. for (int index = 0; index < AC_QUANTITY; index++)
  10727. {
  10728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10729. {
  10730. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10731. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10732. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10733. {
  10734. //Reserved
  10735. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10736. }
  10737. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10738. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10739. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10740. {
  10741. //Reserved
  10742. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10743. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10744. goto end;
  10745. }
  10746. else
  10747. {
  10748. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10749. {
  10750. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10751. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10752. goto end;
  10753. }
  10754. }//END FOR ELSE
  10755. }
  10756. }// END FOR AC_QUANTITY
  10757. }
  10758. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10759. {
  10760. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10761. {
  10762. // Save profile to file
  10763. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10764. system(cmdBuf);
  10765. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10766. fp = fopen(cmdBuf, "w");
  10767. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10768. fclose(fp);
  10769. }
  10770. else
  10771. {
  10772. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10773. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10774. goto end;
  10775. }
  10776. }
  10777. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10778. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10779. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10780. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10781. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10783. }
  10784. else
  10785. {
  10786. uint8_t isHasIdleConnector = FALSE;
  10787. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10788. {
  10789. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10790. {
  10791. isHasIdleConnector = TRUE;
  10792. break;
  10793. }
  10794. }
  10795. if((isHasIdleConnector == TRUE) && !ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  10796. {
  10797. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10798. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10799. {
  10800. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10801. {
  10802. // Save profile to file
  10803. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10804. system(cmdBuf);
  10805. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10806. fp = fopen(cmdBuf, "w");
  10807. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10808. fclose(fp);
  10809. refreshStartTimer(&clientTime.RemoteStartWait);
  10810. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10811. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10812. }
  10813. else
  10814. {
  10815. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10816. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10817. }
  10818. }
  10819. else
  10820. {
  10821. refreshStartTimer(&clientTime.RemoteStartWait);
  10822. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10823. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10824. }
  10825. }
  10826. else
  10827. {
  10828. DEBUG_INFO("There is not any connector is idle.\n");
  10829. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10830. }
  10831. }
  10832. }
  10833. else
  10834. {
  10835. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10836. }
  10837. end:
  10838. json_object_put(RemoteStartTransaction);
  10839. sendRemoteStartConfirmation(uuid, comfirmstr);
  10840. return result;
  10841. }
  10842. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10843. {
  10844. mtrace();
  10845. int result = FAIL;
  10846. int match = FALSE;
  10847. int GunNO = 0;
  10848. int tempIndex = 0;
  10849. int transactionIdInt=0;
  10850. int transactionIdIsNULL= TRUE;
  10851. char comfirmstr[20];
  10852. json_object *RemoteStopTransaction;
  10853. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10854. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10855. if(server_pending == TRUE)
  10856. {
  10857. return 0;
  10858. }
  10859. RemoteStopTransaction = json_tokener_parse(payload);
  10860. if(!is_error(RemoteStopTransaction))
  10861. {
  10862. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10863. {
  10864. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10865. transactionIdIsNULL = FALSE;
  10866. }
  10867. }
  10868. json_object_put(RemoteStopTransaction);
  10869. if(transactionIdIsNULL == FALSE)
  10870. {
  10871. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10872. {
  10873. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10874. {
  10875. //check Transaction active
  10876. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10877. {
  10878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10879. {
  10880. tempIndex = ((gun_index==2) ? 1: 0);
  10881. }
  10882. else
  10883. {
  10884. tempIndex = gun_index;
  10885. }
  10886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10887. {
  10888. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10889. {
  10890. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10891. {
  10892. match = TRUE;
  10893. GunNO = gun_index;
  10894. }
  10895. }
  10896. }// END FOR CHAdeMO_QUANTITY
  10897. }
  10898. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10899. {
  10900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10901. {
  10902. tempIndex = ((gun_index==2) ? 1: 0);
  10903. }
  10904. else
  10905. {
  10906. tempIndex = gun_index;
  10907. }
  10908. for (int index = 0; index < CCS_QUANTITY; index++)
  10909. {
  10910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10911. {
  10912. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10913. {
  10914. match = TRUE;
  10915. GunNO = gun_index;
  10916. }
  10917. }
  10918. }// END FOR CCS_QUANTITY
  10919. }
  10920. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10921. {
  10922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10923. {
  10924. tempIndex = ((gun_index==2) ? 1: 0);
  10925. }
  10926. else
  10927. {
  10928. tempIndex = gun_index;
  10929. }
  10930. for (int index = 0; index < GB_QUANTITY; index++)
  10931. {
  10932. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10933. {
  10934. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10935. {
  10936. match = TRUE;
  10937. GunNO = gun_index;
  10938. }
  10939. }
  10940. }// END FOR GB_QUANTITY
  10941. }
  10942. else if(gunType[gun_index] == GUN_TYPE_DO)
  10943. {
  10944. tempIndex = gun_index;
  10945. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10946. {
  10947. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10948. {
  10949. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10950. {
  10951. match = TRUE;
  10952. GunNO = gun_index;
  10953. }
  10954. }
  10955. }// END FOR GB_QUANTITY
  10956. }
  10957. else
  10958. {
  10959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10960. {
  10961. tempIndex = 2;
  10962. }
  10963. else
  10964. {
  10965. tempIndex = gun_index;
  10966. }
  10967. for (int index = 0; index < AC_QUANTITY; index++)
  10968. {
  10969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10970. {
  10971. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10972. {
  10973. match = TRUE;
  10974. GunNO = gun_index;
  10975. }
  10976. }
  10977. }// END FOR CHAdeMO_QUANTITY
  10978. } // END FOR AC ELSE
  10979. }// CHECK IF ResponseTransactionId == transactionIdInt
  10980. }//END FOR
  10981. if( match == TRUE)
  10982. {
  10983. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10984. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10985. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10986. }
  10987. else
  10988. {
  10989. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10990. }
  10991. }
  10992. else
  10993. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10994. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10995. return result;
  10996. }
  10997. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10998. {
  10999. mtrace();
  11000. int result = FAIL;
  11001. int connectorIdInt=0, reservationIdInt=0;
  11002. int tempIndex = 0;
  11003. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11004. char comfirmstr[20]={0};
  11005. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11006. int c = 0;
  11007. char *loc;
  11008. //char *ptr;
  11009. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11010. strcpy(sstrtemp, stringtrimspace(payload));
  11011. //***(1)connectorId ****/
  11012. c=0;
  11013. loc = strstr(sstrtemp, "connectorId");
  11014. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11015. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11016. {
  11017. sstr[c] = loc[strlen("connectorId")+2+c];
  11018. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11019. c++;
  11020. }
  11021. sstr[c] = '\0';
  11022. connectorIdInt = atoi(sstr);
  11023. //***(2)expiryDate ****/
  11024. loc = strstr(sstrtemp, "expiryDate");
  11025. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11026. c = 0;
  11027. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11028. {
  11029. sstr[c] = loc[3+strlen("expiryDate")+c];
  11030. c++;
  11031. }
  11032. sstr[c] = '\0';
  11033. strcpy(expiryDatestr, sstr);
  11034. //***(3)idTag ****/
  11035. loc = strstr(sstrtemp, "idTag");
  11036. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11037. c = 0;
  11038. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11039. {
  11040. sstr[c] = loc[3+strlen("idTag")+c];
  11041. c++;
  11042. }
  11043. sstr[c] = '\0';
  11044. strcpy(idTagstr, sstr);
  11045. //***(4)parentIdTag ****/
  11046. loc = strstr(sstrtemp, "parentIdTag");
  11047. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11048. c = 0;
  11049. if(loc == NULL)
  11050. {
  11051. strcpy(parentIdTagstr, "");
  11052. }
  11053. else
  11054. {
  11055. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11056. {
  11057. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11058. c++;
  11059. }
  11060. sstr[c] = '\0';
  11061. strcpy(parentIdTagstr, sstr);
  11062. }
  11063. //***(5)reservationId ****/
  11064. c=0;
  11065. loc = strstr(sstrtemp, "reservationId");
  11066. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11067. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11068. {
  11069. sstr[c] = loc[strlen("reservationId")+2+c];
  11070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11071. c++;
  11072. }
  11073. sstr[c] = '\0';
  11074. reservationIdInt = atoi(sstr);
  11075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11076. /*
  11077. enum SYSTEM_STATUS
  11078. {
  11079. SYS_MODE_BOOTING = 0,
  11080. SYS_MODE_IDLE = 1,
  11081. SYS_MODE_AUTHORIZING = 2,
  11082. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11083. SYS_MODE_REASSIGN = 4,
  11084. SYS_MODE_PREPARING = 5,
  11085. SYS_MODE_PREPARE_FOR_EV = 6,
  11086. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11087. SYS_MODE_CHARGING = 8,
  11088. SYS_MODE_TERMINATING = 9,
  11089. SYS_MODE_COMPLETE = 10,
  11090. SYS_MODE_ALARM = 11,
  11091. SYS_MODE_FAULT = 12,
  11092. SYS_MODE_RESERVATION = 13,
  11093. SYS_MODE_BOOKING = 14,
  11094. SYS_MODE_MAINTAIN = 15,
  11095. SYS_MODE_DEBUG = 16,
  11096. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11097. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11098. SYS_MODE_UPDATE = 19
  11099. };
  11100. */
  11101. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11102. {
  11103. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11104. goto end;
  11105. }
  11106. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11107. {
  11108. //check Transaction active
  11109. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11110. {
  11111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11112. {
  11113. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11114. }
  11115. else
  11116. {
  11117. tempIndex = connectorIdInt -1;
  11118. }
  11119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11120. {
  11121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11122. {
  11123. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11124. {
  11125. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11126. {
  11127. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11128. {
  11129. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11130. {
  11131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11132. }
  11133. else
  11134. {
  11135. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11137. }
  11138. }
  11139. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11140. {
  11141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11142. }
  11143. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11144. {
  11145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11146. }
  11147. else
  11148. {
  11149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11150. }
  11151. }
  11152. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  11153. {
  11154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11155. }
  11156. }
  11157. else
  11158. {
  11159. //replace reservation
  11160. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11161. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11162. }
  11163. }
  11164. } // END FOR CHAdeMO_QUANTITY
  11165. }
  11166. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11167. {
  11168. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11169. {
  11170. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11171. }
  11172. else
  11173. {
  11174. tempIndex = connectorIdInt -1;
  11175. }
  11176. for (int index = 0; index < CCS_QUANTITY; index++)
  11177. {
  11178. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11179. {
  11180. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11181. {
  11182. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11183. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11184. {
  11185. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11186. {
  11187. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11188. {
  11189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11190. }
  11191. else
  11192. {
  11193. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11195. }
  11196. }
  11197. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  11198. {
  11199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11200. }
  11201. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11202. {
  11203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11204. }
  11205. else
  11206. {
  11207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11208. }
  11209. }
  11210. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  11211. {
  11212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11213. }
  11214. }
  11215. else
  11216. {
  11217. //replace reservation
  11218. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11220. }
  11221. }
  11222. } // END FOR CCS_QUANTITY
  11223. }
  11224. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11225. {
  11226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11227. {
  11228. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11229. }
  11230. else
  11231. {
  11232. tempIndex = connectorIdInt -1;
  11233. }
  11234. for (int index = 0; index < GB_QUANTITY; index++)
  11235. {
  11236. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11237. {
  11238. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11239. {
  11240. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11241. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11242. {
  11243. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11244. {
  11245. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11246. {
  11247. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11248. }
  11249. else
  11250. {
  11251. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11252. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11253. }
  11254. }
  11255. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11256. {
  11257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11258. }
  11259. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11260. {
  11261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11262. }
  11263. else
  11264. {
  11265. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11266. }
  11267. }
  11268. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  11269. {
  11270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11271. }
  11272. }
  11273. else
  11274. {
  11275. //replace reservation
  11276. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11277. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11278. }
  11279. }
  11280. }// END FOR GB_QUANTITY
  11281. }
  11282. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11283. {
  11284. tempIndex = connectorIdInt -1;
  11285. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11286. {
  11287. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11288. {
  11289. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11290. {
  11291. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11292. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11293. {
  11294. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11295. {
  11296. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11297. {
  11298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11299. }
  11300. else
  11301. {
  11302. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11303. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11304. }
  11305. }
  11306. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11307. {
  11308. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11309. }
  11310. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11311. {
  11312. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11313. }
  11314. else
  11315. {
  11316. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11317. }
  11318. }
  11319. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  11320. {
  11321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11322. }
  11323. }
  11324. else
  11325. {
  11326. //replace reservation
  11327. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11329. }
  11330. }
  11331. }// END FOR GB_QUANTITY
  11332. }
  11333. else
  11334. {
  11335. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11336. {
  11337. tempIndex = 2;
  11338. }
  11339. else
  11340. {
  11341. tempIndex = (connectorIdInt -1);
  11342. }
  11343. for (int index = 0; index < AC_QUANTITY; index++)
  11344. {
  11345. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11346. {
  11347. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11348. {
  11349. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11350. {
  11351. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11352. {
  11353. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  11354. {
  11355. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11356. }
  11357. else
  11358. {
  11359. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11360. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11361. }
  11362. }
  11363. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11364. {
  11365. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11366. }
  11367. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11368. {
  11369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11370. }
  11371. else
  11372. {
  11373. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11374. }
  11375. }
  11376. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  11377. {
  11378. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11379. }
  11380. }
  11381. else
  11382. {
  11383. //replace reservation
  11384. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11386. }
  11387. }
  11388. } // END FOR AC_QUANTITY
  11389. }
  11390. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11391. }
  11392. else if(connectorIdInt == 0)
  11393. {
  11394. //check Transaction active
  11395. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11396. {
  11397. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11398. {
  11399. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11400. {
  11401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11402. goto end;
  11403. }
  11404. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11405. {
  11406. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11407. goto end;
  11408. }
  11409. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11410. {
  11411. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11412. goto end;
  11413. }
  11414. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11415. {
  11416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11417. goto end;
  11418. }
  11419. }
  11420. }// END FOR CHAdeMO_QUANTITY
  11421. for (int index = 0; index < CCS_QUANTITY; index++)
  11422. {
  11423. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11424. {
  11425. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  11426. {
  11427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11428. goto end;
  11429. }
  11430. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11431. {
  11432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11433. goto end;
  11434. }
  11435. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11436. {
  11437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11438. goto end;
  11439. }
  11440. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11441. {
  11442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11443. goto end;
  11444. }
  11445. }
  11446. } // END FOR CCS_QUANTITY
  11447. for (int index = 0; index < GB_QUANTITY; index++)
  11448. {
  11449. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11450. {
  11451. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11452. {
  11453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11454. goto end;
  11455. }
  11456. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11457. {
  11458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11459. goto end;
  11460. }
  11461. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING) ) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11462. {
  11463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11464. goto end;
  11465. }
  11466. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11467. {
  11468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11469. goto end;
  11470. }
  11471. }
  11472. } // END FOR GB_QUANTITY
  11473. for (int index = 0; index < AC_QUANTITY; index++)
  11474. {
  11475. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11476. {
  11477. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11478. {
  11479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11480. goto end;
  11481. }
  11482. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11483. {
  11484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11485. goto end;
  11486. }
  11487. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11488. {
  11489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11490. goto end;
  11491. }
  11492. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11493. {
  11494. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  11495. {
  11496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11497. goto end;
  11498. }
  11499. }
  11500. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11501. {
  11502. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11503. goto end;
  11504. }
  11505. }
  11506. }// END FOR AC_QUANTITY
  11507. //The connectorId is 0
  11508. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11509. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11510. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11511. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11512. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11513. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11514. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11515. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11516. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11517. result = TRUE;
  11518. return result;
  11519. }
  11520. else
  11521. {
  11522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11523. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11524. }
  11525. if(strcmp(comfirmstr,"Accepted") == 0)
  11526. {
  11527. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11528. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11529. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11530. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11531. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11532. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11533. result = TRUE;
  11534. return result;
  11535. }
  11536. end:
  11537. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11538. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11539. return result;
  11540. }
  11541. int handleResetRequest(char *uuid, char *payload)
  11542. {
  11543. mtrace();
  11544. int result = FAIL;
  11545. char sstr[10]={0},sstrtemp[30]={ 0 };
  11546. char typestr[10]={0};
  11547. char comfirmstr[20]={0};
  11548. int c = 0;
  11549. char *loc;
  11550. DEBUG_INFO("handleResetRequest...\n");
  11551. strcpy(sstrtemp, stringtrimspace(payload));
  11552. loc = strstr(sstrtemp, "type");
  11553. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11554. c = 0;
  11555. while (loc[3+strlen("type")+c] != '\"')
  11556. {
  11557. sstr[c] = loc[3+strlen("type")+c];
  11558. c++;
  11559. }
  11560. sstr[c] = '\0';
  11561. strcpy(typestr,sstr);
  11562. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11563. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11564. {
  11565. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11566. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11567. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11568. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11569. }
  11570. else
  11571. {
  11572. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11573. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11574. result = PASS;
  11575. }
  11576. sendResetConfirmation(uuid, comfirmstr);
  11577. return result;
  11578. }
  11579. int handleSendLocalListRequest(char *uuid, char *payload)
  11580. {
  11581. mtrace();
  11582. int result = FAIL;
  11583. char comfirmstr[20];
  11584. int checkState_Faulted = FALSE;
  11585. json_object *SendLocalList;
  11586. DEBUG_INFO("handleSendLocalListRequest...\n");
  11587. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11588. {
  11589. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11590. goto end;
  11591. }
  11592. //check Charge Point state
  11593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11594. {
  11595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11596. {
  11597. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11598. }
  11599. }
  11600. for (int index = 0; index < CCS_QUANTITY; index++)
  11601. {
  11602. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11603. {
  11604. checkState_Faulted = TRUE; //OCPP Status
  11605. }
  11606. }
  11607. for (int index = 0; index < GB_QUANTITY; index++)
  11608. {
  11609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11610. {
  11611. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11612. }
  11613. }
  11614. //check Charge Point state
  11615. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11616. {
  11617. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11618. {
  11619. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11620. }
  11621. }
  11622. //check Charge Point state
  11623. for (int index = 0; index < AC_QUANTITY; index++)
  11624. {
  11625. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11626. {
  11627. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11628. }
  11629. }
  11630. if(checkState_Faulted == TRUE)
  11631. {
  11632. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11633. goto end;
  11634. }
  11635. // Parsing payload
  11636. SendLocalList = json_tokener_parse(payload);
  11637. if(!is_error(SendLocalList))
  11638. {
  11639. // Required data
  11640. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11641. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11642. // Optional data
  11643. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11644. {
  11645. //Check UpdateType
  11646. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11647. {
  11648. //Local list full update
  11649. DEBUG_INFO("Local list full update.\n");
  11650. locallistVersion = 0;
  11651. OCPP_getListVerion();
  11652. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11653. {
  11654. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11655. goto end;
  11656. }*/
  11657. OCPP_cleanLocalList();
  11658. }
  11659. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11660. {
  11661. //Local list different update
  11662. DEBUG_INFO("Local list different update.\n");
  11663. locallistVersion = 0;
  11664. OCPP_getListVerion();
  11665. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11666. {
  11667. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11668. goto end;
  11669. }
  11670. }
  11671. else
  11672. {
  11673. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11674. goto end;
  11675. }
  11676. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  11677. {
  11678. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  11679. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11680. goto end;
  11681. }
  11682. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11683. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11684. {
  11685. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  11686. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11687. {
  11688. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  11689. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11690. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  11691. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11692. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  11693. }
  11694. // Add to db
  11695. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11696. {
  11697. //Local list full update
  11698. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11699. idx,
  11700. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11701. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11702. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11703. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11704. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11705. // update list
  11706. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11707. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11708. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11709. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11710. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11711. }
  11712. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11713. {
  11714. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11715. idx,
  11716. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11717. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11718. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11719. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11720. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11721. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11722. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11723. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11724. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11725. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11726. }
  11727. }
  11728. }
  11729. else
  11730. {
  11731. //Check UpdateType
  11732. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11733. {
  11734. //Local list full update
  11735. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11736. OCPP_cleanLocalList();
  11737. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11738. goto end;
  11739. }
  11740. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11741. {
  11742. //Local list different update
  11743. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11744. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11745. goto end;
  11746. }
  11747. }
  11748. result = PASS;
  11749. }
  11750. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11751. end:
  11752. json_object_put(SendLocalList);
  11753. sendSendLocalListConfirmation(uuid, comfirmstr);
  11754. return result;
  11755. }
  11756. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11757. {
  11758. mtrace();
  11759. int result = FAIL;
  11760. struct StructSetChargingProfile SetProfileReq = {0};
  11761. int tempchargingProfileIdInt;
  11762. int tempstackLevelInt;
  11763. int chargingSchedulePeriodCount = 0;
  11764. char comfirmstr[20]={0};
  11765. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11766. char rmFileCmd[128]={0};
  11767. int profileQuantity = 0;
  11768. int replaceableProfileCnt = 0;
  11769. json_object *SetChargingProfile;
  11770. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11771. SetChargingProfile = json_tokener_parse(payload);
  11772. if(!is_error(SetChargingProfile))
  11773. {
  11774. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11775. {
  11776. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11777. }
  11778. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11779. {
  11780. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11781. {
  11782. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11783. }
  11784. else
  11785. {
  11786. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11787. DEBUG_WARN("Cannot find chargingProfileId field.");
  11788. goto end;
  11789. }
  11790. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11791. {
  11792. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11793. }
  11794. else
  11795. {
  11796. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11797. DEBUG_WARN("Cannot find stackLevel field.");
  11798. goto end;
  11799. }
  11800. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11801. {
  11802. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11803. }
  11804. else
  11805. {
  11806. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11807. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  11808. goto end;
  11809. }
  11810. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11811. {
  11812. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11813. }
  11814. else
  11815. {
  11816. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11817. DEBUG_WARN("Cannot find chargingProfileKind field.");
  11818. goto end;
  11819. }
  11820. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11821. {
  11822. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11823. }
  11824. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11825. {
  11826. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11827. }
  11828. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11829. {
  11830. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11831. }
  11832. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11833. {
  11834. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11835. }
  11836. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11837. {
  11838. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11839. {
  11840. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  11841. }
  11842. else
  11843. {
  11844. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11845. DEBUG_WARN("Cannot find chargingRateUnit field.");
  11846. goto end;
  11847. }
  11848. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11849. {
  11850. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11851. }
  11852. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11853. {
  11854. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11855. }
  11856. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11857. {
  11858. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  11859. }
  11860. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11861. {
  11862. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11863. if(chargingSchedulePeriodCount <= 10)
  11864. {
  11865. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  11866. {
  11867. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  11868. {
  11869. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11870. }
  11871. else
  11872. {
  11873. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11874. DEBUG_WARN("Cannot find startPeriod field.");
  11875. goto end;
  11876. }
  11877. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  11878. {
  11879. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11880. }
  11881. else
  11882. {
  11883. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11884. DEBUG_WARN("Cannot find limit field.");
  11885. goto end;
  11886. }
  11887. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  11888. {
  11889. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11890. }
  11891. }
  11892. }
  11893. }
  11894. else
  11895. {
  11896. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11897. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  11898. goto end;
  11899. }
  11900. }
  11901. else
  11902. {
  11903. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11904. DEBUG_WARN("Cannot find chargingSchedule field.");
  11905. goto end;
  11906. }
  11907. }
  11908. }
  11909. // Profile periods quantity check
  11910. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11911. {
  11912. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11913. goto end;
  11914. }
  11915. // Check invalid limit
  11916. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  11917. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  11918. {
  11919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11920. {
  11921. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11922. {
  11923. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  11924. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11925. {
  11926. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11927. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11928. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11929. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11930. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11931. goto end;
  11932. }
  11933. }
  11934. }
  11935. else
  11936. {
  11937. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11938. {
  11939. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  11940. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  11941. {
  11942. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11943. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11944. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11945. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11946. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11947. goto end;
  11948. }
  11949. }
  11950. }
  11951. }
  11952. // Profile purpose info check
  11953. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11954. {
  11955. FILE *fp;
  11956. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11957. if(SetProfileReq.ConnectorId != 0)
  11958. {
  11959. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11960. goto end;
  11961. }
  11962. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11963. if (!fp)
  11964. {
  11965. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11966. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11967. }
  11968. else
  11969. {
  11970. char *line = NULL;
  11971. size_t len = 0;
  11972. while(getline(&line, &len, fp) != -1)
  11973. {
  11974. json_object *obj = NULL;
  11975. obj = json_tokener_parse(line);
  11976. if(is_error(obj))
  11977. {
  11978. DEBUG_ERROR("Parse txProfile from file error.\n");
  11979. }
  11980. else
  11981. {
  11982. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11983. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11984. {
  11985. profileQuantity += 1;
  11986. }
  11987. else
  11988. replaceableProfileCnt += 1;
  11989. }
  11990. }
  11991. }
  11992. fclose(fp);
  11993. }
  11994. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11995. {
  11996. FILE *fp;
  11997. char filename[128]={0};
  11998. int tmpProfileQuantity;
  11999. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12000. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12001. {
  12002. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12003. goto end;
  12004. }
  12005. if(SetProfileReq.ConnectorId == 0)
  12006. {
  12007. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12008. {
  12009. tmpProfileQuantity = 0;
  12010. memset(filename, 0, ARRAY_SIZE(filename));
  12011. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12012. fp = fopen(filename, "r");
  12013. if (!fp)
  12014. {
  12015. DEBUG_INFO("%s does not create.\n", filename);
  12016. fp = fopen(filename, "w+");
  12017. }
  12018. else
  12019. {
  12020. char *line = NULL;
  12021. size_t len = 0;
  12022. while(getline(&line, &len, fp) != -1)
  12023. {
  12024. json_object *obj = NULL;
  12025. obj = json_tokener_parse(line);
  12026. if(is_error(obj))
  12027. {
  12028. DEBUG_ERROR("Parse txProfile from file error.\n");
  12029. }
  12030. else
  12031. {
  12032. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12033. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12034. {
  12035. tmpProfileQuantity += 1;
  12036. }
  12037. else
  12038. replaceableProfileCnt += 1;
  12039. }
  12040. }
  12041. }
  12042. fclose(fp);
  12043. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12044. }
  12045. }
  12046. else
  12047. {
  12048. memset(filename, 0, ARRAY_SIZE(filename));
  12049. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12050. fp = fopen(filename, "r");
  12051. if (!fp)
  12052. {
  12053. DEBUG_INFO("%s does not create.\n", filename);
  12054. fp = fopen(filename, "w+");
  12055. }
  12056. else
  12057. {
  12058. char *line = NULL;
  12059. size_t len = 0;
  12060. while(getline(&line, &len, fp) != -1)
  12061. {
  12062. json_object *obj = NULL;
  12063. obj = json_tokener_parse(line);
  12064. if(is_error(obj))
  12065. {
  12066. DEBUG_ERROR("Parse txProfile from file error.\n");
  12067. }
  12068. else
  12069. {
  12070. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12071. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12072. {
  12073. profileQuantity += 1;
  12074. }
  12075. else
  12076. replaceableProfileCnt += 1;
  12077. }
  12078. }
  12079. }
  12080. fclose(fp);
  12081. }
  12082. }
  12083. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12084. {
  12085. int isMatchTransactiodId= FALSE;
  12086. FILE *fp;
  12087. char filename[128]={0};
  12088. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12089. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12090. if(SetProfileReq.ConnectorId == 0)
  12091. {
  12092. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12093. goto end;
  12094. }
  12095. int tempIndex = 0;
  12096. //check Transaction active
  12097. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12098. {
  12099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12100. {
  12101. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12102. }
  12103. else
  12104. {
  12105. tempIndex = SetProfileReq.ConnectorId -1;
  12106. }
  12107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12108. {
  12109. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12110. {
  12111. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12112. {
  12113. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12114. {
  12115. isMatchTransactiodId = TRUE;
  12116. break;
  12117. }
  12118. }
  12119. }
  12120. }
  12121. }
  12122. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12123. {
  12124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12125. {
  12126. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12127. }
  12128. else
  12129. {
  12130. tempIndex = SetProfileReq.ConnectorId -1;
  12131. }
  12132. for (int index = 0; index < CCS_QUANTITY; index++)
  12133. {
  12134. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12135. {
  12136. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12137. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12138. {
  12139. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12140. {
  12141. isMatchTransactiodId = TRUE;
  12142. break;
  12143. }
  12144. }
  12145. }
  12146. }
  12147. }
  12148. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12149. {
  12150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12151. {
  12152. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12153. }
  12154. else
  12155. {
  12156. tempIndex = SetProfileReq.ConnectorId -1;
  12157. }
  12158. for (int index = 0; index < GB_QUANTITY; index++)
  12159. {
  12160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12161. {
  12162. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12163. {
  12164. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12165. {
  12166. isMatchTransactiodId = TRUE;
  12167. break;
  12168. }
  12169. }
  12170. }
  12171. }
  12172. }
  12173. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12174. {
  12175. tempIndex = SetProfileReq.ConnectorId -1;
  12176. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12177. {
  12178. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12179. {
  12180. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12181. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12182. {
  12183. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12184. {
  12185. isMatchTransactiodId = TRUE;
  12186. break;
  12187. }
  12188. }
  12189. }
  12190. }
  12191. }
  12192. else
  12193. {
  12194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12195. {
  12196. tempIndex = 2;
  12197. }
  12198. else
  12199. {
  12200. tempIndex = (SetProfileReq.ConnectorId -1);
  12201. }
  12202. for (int index = 0; index < AC_QUANTITY; index++)
  12203. {
  12204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12205. {
  12206. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12207. {
  12208. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12209. {
  12210. isMatchTransactiodId = TRUE;
  12211. break;
  12212. }
  12213. }
  12214. }
  12215. }
  12216. }
  12217. //check Transaction active
  12218. if(isMatchTransactiodId == FALSE)
  12219. {
  12220. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12221. goto end;
  12222. }
  12223. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12224. {
  12225. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12226. goto end;
  12227. }
  12228. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12229. fp = fopen(filename, "r");
  12230. if (!fp)
  12231. {
  12232. DEBUG_INFO("%s does not create.\n", filename);
  12233. fp = fopen(filename, "w+");
  12234. }
  12235. else
  12236. {
  12237. char *line = NULL;
  12238. size_t len = 0;
  12239. while(getline(&line, &len, fp) != -1)
  12240. {
  12241. json_object *obj = NULL;
  12242. obj = json_tokener_parse(line);
  12243. if(is_error(obj))
  12244. {
  12245. DEBUG_ERROR("Parse txProfile from file error.\n");
  12246. }
  12247. else
  12248. {
  12249. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12250. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12251. {
  12252. profileQuantity += 1;
  12253. }
  12254. else
  12255. replaceableProfileCnt += 1;
  12256. }
  12257. }
  12258. }
  12259. fclose(fp);
  12260. }
  12261. // Check ChargeProfileMaxStackLevel
  12262. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12263. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12264. {
  12265. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12266. goto end;
  12267. }
  12268. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12269. {
  12270. FILE *fp;
  12271. char dataLine[4096]={0};
  12272. char fnametemp[128]={0};
  12273. int tmpProfileQuantity;
  12274. //Check ChargePointMaxProfile.json exit
  12275. profileQuantity = 0;
  12276. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12277. {
  12278. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12279. //Check Charging Profile Count
  12280. tmpProfileQuantity = 0;
  12281. while(fscanf(fp, "%s", dataLine) != EOF)
  12282. {
  12283. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12284. {
  12285. profileQuantity += 1;
  12286. tmpProfileQuantity += 1;
  12287. }
  12288. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12289. }
  12290. fclose(fp);
  12291. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12292. }
  12293. //Check TxDefaultProfile_%d.json
  12294. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12295. {
  12296. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12297. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12298. if((access(fnametemp,F_OK))!=-1)
  12299. {
  12300. fp = fopen(fnametemp, "r");
  12301. //Check Charging Profile Count
  12302. tmpProfileQuantity = 0;
  12303. while(fscanf(fp, "%s", dataLine) != EOF)
  12304. {
  12305. //DEBUG_INFO("word=%s\n",word);
  12306. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12307. {
  12308. profileQuantity += 1;
  12309. tmpProfileQuantity += 1;
  12310. }
  12311. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12312. }
  12313. fclose(fp);
  12314. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12315. }
  12316. }
  12317. //Check TxProfile_%d.json
  12318. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12319. {
  12320. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12321. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12322. if((access(fnametemp,F_OK))!=-1)
  12323. {
  12324. fp = fopen(fnametemp, "r");
  12325. //Check Charging Profile Count
  12326. tmpProfileQuantity = 0;
  12327. while(fscanf(fp, "%s", dataLine) != EOF)
  12328. {
  12329. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12330. {
  12331. profileQuantity += 1;
  12332. tmpProfileQuantity += 1;
  12333. }
  12334. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12335. }
  12336. fclose(fp);
  12337. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12338. }
  12339. }
  12340. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12341. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12342. // To check total Profile quantity
  12343. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12344. {
  12345. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12346. {
  12347. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12348. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12349. goto end;
  12350. }
  12351. }
  12352. else
  12353. {
  12354. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12355. {
  12356. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12357. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12358. goto end;
  12359. }
  12360. }
  12361. }
  12362. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12363. //**********************************Write to File********************************************************/
  12364. {
  12365. FILE *infile;
  12366. FILE *outfile;
  12367. char dataLine[4096]={0};
  12368. char filename[128]={0};
  12369. int chkChar=0;
  12370. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12371. {
  12372. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12373. {
  12374. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12375. }
  12376. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12377. {
  12378. if(SetProfileReq.ConnectorId==0)
  12379. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12380. else
  12381. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12382. }
  12383. else
  12384. {
  12385. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12386. }
  12387. infile = fopen (filename, "r");
  12388. outfile = fopen (tempfile, "w");
  12389. chkChar = fgetc(infile);
  12390. rewind(infile);
  12391. if(chkChar == EOF)
  12392. {
  12393. // Profile is empty
  12394. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12395. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12396. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12397. fclose(infile);
  12398. fclose(outfile);
  12399. sprintf(rmFileCmd,"rm -f %s",filename);
  12400. system(rmFileCmd);
  12401. rename(tempfile, filename);
  12402. }
  12403. else
  12404. {
  12405. // Profile is not empty
  12406. int ChargingProfileAdded = FALSE;
  12407. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12408. {
  12409. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12410. json_object *tmpChargingProfile;
  12411. tmpChargingProfile = json_tokener_parse(dataLine);
  12412. if(!is_error(SetChargingProfile))
  12413. {
  12414. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12415. {
  12416. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12417. {
  12418. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12419. }
  12420. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12421. {
  12422. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12423. }
  12424. }
  12425. }
  12426. json_object_put(tmpChargingProfile);
  12427. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12428. {
  12429. if(ChargingProfileAdded == FALSE)
  12430. {
  12431. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12432. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12433. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12434. ChargingProfileAdded = TRUE;
  12435. }
  12436. }
  12437. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12438. {
  12439. if(ChargingProfileAdded == FALSE)
  12440. {
  12441. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12442. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12443. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12444. ChargingProfileAdded = TRUE;
  12445. }
  12446. }
  12447. else
  12448. {
  12449. fprintf(outfile,"%s\n",dataLine);
  12450. if(ChargingProfileAdded == FALSE)
  12451. {
  12452. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12453. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12454. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12455. ChargingProfileAdded = TRUE;
  12456. }
  12457. }
  12458. } // end of while loop
  12459. fclose(infile);
  12460. fclose(outfile);
  12461. sprintf(rmFileCmd,"rm -f %s",filename);
  12462. system(rmFileCmd);
  12463. rename(tempfile, filename);
  12464. }
  12465. }
  12466. sleep(1);
  12467. result = TRUE;
  12468. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12469. }
  12470. end:
  12471. json_object_put(SetChargingProfile);
  12472. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12473. {
  12474. if(SetProfileReq.ConnectorId == 0)
  12475. {
  12476. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12477. {
  12478. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12479. }
  12480. }
  12481. else
  12482. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12483. }
  12484. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12485. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12486. return result;
  12487. }
  12488. int handleTriggerMessageRequest(char *uuid, char *payload)
  12489. {
  12490. mtrace();
  12491. int result = FAIL;
  12492. int connectorIdIsNULL = FALSE;
  12493. int connectorIdInt =0;
  12494. char sstr[40]={0},sstrtemp[100]={ 0 };
  12495. char requestedMessagestr[40]={0};
  12496. char comfirmstr[20]={0};
  12497. int c = 0;
  12498. char *loc;
  12499. DEBUG_INFO("handleTriggerMessageRequest\n");
  12500. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12501. strcpy(sstrtemp, stringtrimspace(payload));
  12502. c = 0;
  12503. loc = strstr(sstrtemp, "requestedMessage");
  12504. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12505. {
  12506. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12507. c++;
  12508. }
  12509. sstr[c] = '\0';
  12510. strcpy(requestedMessagestr, sstr);
  12511. c = 0;
  12512. loc = strstr(sstrtemp, "connectorId");
  12513. if(loc == NULL)
  12514. {
  12515. connectorIdIsNULL = TRUE;
  12516. }
  12517. else
  12518. {
  12519. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12520. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12521. {
  12522. sstr[c] = loc[strlen("connectorId")+2+c];
  12523. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12524. c++;
  12525. }
  12526. sstr[c] = '\0';
  12527. connectorIdInt = atoi(sstr);
  12528. }
  12529. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12530. {
  12531. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12532. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12533. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12534. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12535. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12536. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12537. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12538. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12539. {
  12540. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12541. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12542. return TRUE;
  12543. }
  12544. else
  12545. {
  12546. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12547. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12548. }
  12549. }
  12550. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12551. {
  12552. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12553. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12554. return TRUE;
  12555. }
  12556. //==========================
  12557. // Trigger message
  12558. //==========================
  12559. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12560. {
  12561. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12562. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12563. {
  12564. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12565. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12566. }
  12567. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12568. }
  12569. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12570. {
  12571. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12572. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12573. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12574. }
  12575. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12576. {
  12577. //sendBootNotificationRequest();
  12578. server_sign = FALSE;
  12579. }
  12580. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12581. {
  12582. refreshStartTimer(&clientTime.Heartbeat);
  12583. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12584. }
  12585. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12586. {
  12587. if(connectorIdIsNULL == FALSE)
  12588. {
  12589. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12590. {
  12591. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12592. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12593. }
  12594. }
  12595. else
  12596. {
  12597. for(int idx=0;idx< gunTotalNumber;idx++)
  12598. {
  12599. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12600. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12601. }
  12602. }
  12603. }
  12604. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12605. {
  12606. if(connectorIdIsNULL == FALSE)
  12607. {
  12608. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12609. {
  12610. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12611. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12612. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12613. }
  12614. }
  12615. else
  12616. {
  12617. for(int idx=0;idx< gunTotalNumber;idx++)
  12618. {
  12619. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12620. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12621. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12622. }
  12623. }
  12624. }
  12625. return result;
  12626. }
  12627. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12628. {
  12629. mtrace();
  12630. int result = FAIL;
  12631. int connectorIdInt =0;
  12632. char comfirmstr[20]={0};
  12633. int tempIndex = 0;
  12634. json_object *UnlockConnector;
  12635. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12636. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12637. UnlockConnector = json_tokener_parse(payload);
  12638. if(!is_error(UnlockConnector))
  12639. {
  12640. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12641. {
  12642. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12643. }
  12644. }
  12645. json_object_put(UnlockConnector);
  12646. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12647. if(gunTotalNumber == 0)
  12648. {
  12649. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12650. goto end;
  12651. }
  12652. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12653. {
  12654. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12655. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12656. goto end;
  12657. }
  12658. else
  12659. {
  12660. //check Transaction active
  12661. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12662. {
  12663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12664. {
  12665. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12666. }
  12667. else
  12668. {
  12669. tempIndex = connectorIdInt -1;
  12670. }
  12671. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12672. {
  12673. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12674. {
  12675. //stop Transaction
  12676. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12677. }
  12678. }
  12679. }
  12680. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12681. {
  12682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12683. {
  12684. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12685. }
  12686. else
  12687. {
  12688. tempIndex = connectorIdInt -1;
  12689. }
  12690. for (int index = 0; index < CCS_QUANTITY; index++)
  12691. {
  12692. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12693. {
  12694. //stop Transaction
  12695. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12696. }
  12697. }
  12698. }
  12699. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12700. {
  12701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12702. {
  12703. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12704. }
  12705. else
  12706. {
  12707. tempIndex = connectorIdInt -1;
  12708. }
  12709. for (int index = 0; index < GB_QUANTITY; index++)
  12710. {
  12711. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12712. {
  12713. //stop Transaction
  12714. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12715. }
  12716. }
  12717. }
  12718. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12719. {
  12720. tempIndex = connectorIdInt -1;
  12721. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12722. {
  12723. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12724. {
  12725. //stop Transaction
  12726. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12727. }
  12728. }
  12729. }
  12730. else
  12731. {
  12732. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12733. {
  12734. tempIndex = 2;
  12735. }
  12736. else
  12737. {
  12738. tempIndex = connectorIdInt-1;
  12739. }
  12740. for (int index = 0; index < AC_QUANTITY; index++)
  12741. {
  12742. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12743. {
  12744. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12745. }
  12746. }
  12747. }
  12748. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12749. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12750. result = TRUE;
  12751. return result;
  12752. }
  12753. end:
  12754. //json_object_put(obj); --- remove temporally
  12755. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12756. return result;
  12757. }
  12758. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12759. {
  12760. mtrace();
  12761. int result = FAIL;
  12762. pthread_t t;
  12763. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12764. sendUpdateFirmwareConfirmation(uuid);
  12765. if(!interLock.isUpdateFirmwareGoing)
  12766. {
  12767. interLock.isUpdateFirmwareGoing = 1;
  12768. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  12769. sleep(1);
  12770. }
  12771. else
  12772. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12773. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12774. return result;
  12775. }
  12776. void *UpdateFirmwareProcess(void *data)
  12777. {
  12778. pthread_detach(pthread_self());
  12779. mtrace();
  12780. int retriesInt =0, retryIntervalInt=0;
  12781. char protocol[10], user[64],password[64],host[1280], path[1024], ftppath[1024],host1[256],path1[1024];
  12782. int port=0;
  12783. char locationstr[2048]={0}, retrieveDatestr[36]={0};
  12784. int isSuccess = 0;
  12785. char ftpbuf[2048];
  12786. char temp[2048];
  12787. char filenametemp[256];
  12788. char * pch;
  12789. json_object *UpdateFirmware;
  12790. UpdateFirmware = json_tokener_parse(data);
  12791. if(!is_error(UpdateFirmware))
  12792. {
  12793. // Required data
  12794. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12795. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12796. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12797. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12798. // Optional data
  12799. if(json_object_object_get(UpdateFirmware, "retries"))
  12800. {
  12801. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12802. }
  12803. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12804. {
  12805. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12806. }
  12807. }
  12808. json_object_put(UpdateFirmware);
  12809. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12810. memset(path, 0, ARRAY_SIZE(path));
  12811. // Wait retrieveData
  12812. if(strlen(retrieveDatestr) > 10)
  12813. {
  12814. do
  12815. {
  12816. sleep(1);
  12817. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12818. }
  12819. // Ready to download
  12820. system("rm -f /mnt/*");
  12821. if(strncmp(locationstr,"http", 4) == 0)
  12822. {
  12823. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12824. sprintf(ftppath,"/%s", path);
  12825. DEBUG_INFO("locationstr: %s\n", locationstr);
  12826. DEBUG_INFO("protocol: %s\n",protocol);
  12827. DEBUG_INFO("host: %s\n",host);
  12828. DEBUG_INFO("path: %s\n",path);
  12829. DEBUG_INFO("ftppath: %s\n",ftppath);
  12830. int ftppathlen=strlen(ftppath);
  12831. int i=1;
  12832. while(i < ftppathlen)
  12833. {
  12834. int len=ftppathlen-i;
  12835. if(ftppath[len]== 47) // '/' ascll code: 47
  12836. {
  12837. DEBUG_INFO("compare '/' all right\n");
  12838. break;
  12839. }
  12840. i=i+1;
  12841. }
  12842. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12843. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12844. filenametemp[i+1] = 0;
  12845. do
  12846. {
  12847. sleep(1);
  12848. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12849. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12850. sleep(1);
  12851. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12852. if(!isSuccess)
  12853. {
  12854. sleep(1);
  12855. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12856. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12857. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  12858. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12859. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12860. }
  12861. else
  12862. {
  12863. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12864. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12865. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12866. }
  12867. retriesInt--;
  12868. }while((isSuccess == 0)&&(retriesInt >= 0));
  12869. }
  12870. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  12871. {
  12872. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12873. memset(temp, 0, ARRAY_SIZE(temp));
  12874. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12875. strcpy(ftpbuf, locationstr);
  12876. int ftppathlen=strlen(ftpbuf);
  12877. int i=1;
  12878. while(i < ftppathlen)
  12879. {
  12880. int len=ftppathlen-i;
  12881. if(ftpbuf[len]== 47) // '/' ascii code: 47
  12882. {
  12883. DEBUG_INFO(" compare '/' all right\n");
  12884. break;
  12885. }
  12886. i=i+1;
  12887. }
  12888. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12889. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12890. filenametemp[i+1] = 0;
  12891. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12892. pch=strchr(temp,'@');
  12893. if(pch==NULL)
  12894. {
  12895. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12896. protocol, host, &port, path);
  12897. strcpy(user,"anonymous");
  12898. strcpy(password,"");
  12899. }
  12900. else
  12901. {
  12902. char loginInfo[128];
  12903. sscanf(temp,"%[^:]:%*2[/]%[^@]@", protocol, loginInfo);
  12904. // Check if it contains 'password'
  12905. if(strstr(loginInfo, ":") != NULL)
  12906. {
  12907. sscanf(loginInfo,"%[^:]:%s", user, password);
  12908. }
  12909. else
  12910. {
  12911. strcpy(user,loginInfo);
  12912. strcpy(password,"");
  12913. }
  12914. if(strstr(pch,":") != NULL)
  12915. {
  12916. sscanf(pch,"@%[^:]:%i/%512[^\n]", host, &port, path);
  12917. sprintf(host,"%s/%s", host,path);
  12918. }
  12919. else
  12920. {
  12921. sscanf(pch,"@%s[^\n]", host);
  12922. }
  12923. //sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]", protocol, user, host, &port, path);
  12924. }
  12925. sscanf(host,"%[^/]%s",host1, path1);
  12926. sprintf(ftppath,"%s:/%s", host,path);
  12927. if(port == 0)
  12928. {
  12929. port = 22;
  12930. }
  12931. do
  12932. {
  12933. sleep(1);
  12934. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12935. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12936. sleep(1);
  12937. isSuccess = sftpDownLoadFile(host1, user, password, port, path1, filenametemp, locationstr);
  12938. if(!isSuccess)
  12939. {
  12940. //BulldogUtil.sleepMs(interval*1000);
  12941. DEBUG_INFO("Update firmware request and download file fail.\n");
  12942. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12943. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12944. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  12945. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12946. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12947. }
  12948. else
  12949. {
  12950. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12951. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12952. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12953. }
  12954. retriesInt--;
  12955. }while((!isSuccess)&&(retriesInt >= 0));
  12956. }
  12957. else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
  12958. {
  12959. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12960. memset(temp, 0, ARRAY_SIZE(temp));
  12961. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12962. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12963. int ftppathlen=strlen(ftpbuf);
  12964. int i=1;
  12965. while(i < ftppathlen)
  12966. {
  12967. int len=ftppathlen-i;
  12968. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12969. {
  12970. DEBUG_INFO(" compare '/' all right\n");
  12971. break;
  12972. }
  12973. i=i+1;
  12974. }
  12975. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12976. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12977. filenametemp[i+1] = 0;
  12978. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12979. pch=strchr(temp,'@');
  12980. if(pch==NULL)
  12981. {
  12982. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12983. protocol, host, &port, path);
  12984. strcpy(user,"anonymous");
  12985. strcpy(password,"");
  12986. }
  12987. else
  12988. {
  12989. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12990. protocol, user, password, host, &port, path);
  12991. }
  12992. sscanf(host,"%[^/]%s",host1, path1);
  12993. sprintf(ftppath,"%s", path1);
  12994. //DEBUG_INFO("protocol =%s\n",protocol);
  12995. //DEBUG_INFO("user =%s\n",user);
  12996. //DEBUG_INFO("password =%s\n",password);
  12997. //DEBUG_INFO("host1 =%s\n",host1);
  12998. //DEBUG_INFO("port =%d\n",port);
  12999. //DEBUG_INFO("path1 =%s\n",path1);
  13000. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13001. //ftpFile(host, user, password, port, ftppath, fname);
  13002. //download firmware pthred
  13003. if(port == 0)
  13004. {
  13005. port = 21;
  13006. }
  13007. do
  13008. {
  13009. sleep(1);
  13010. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13011. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13012. sleep(1);
  13013. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13014. if(!isSuccess)
  13015. {
  13016. //BulldogUtil.sleepMs(interval*1000);
  13017. DEBUG_INFO("Update firmware request and download file fail.\n");
  13018. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13019. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13020. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13021. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13022. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13023. }
  13024. else
  13025. {
  13026. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13027. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13028. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13029. }
  13030. retriesInt--;
  13031. }while((!isSuccess)&&(retriesInt >= 0));
  13032. }
  13033. else
  13034. {
  13035. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13036. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13037. sleep(1);
  13038. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13039. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13040. }
  13041. // OCPPPH only, must announce CSU upgrade firmware
  13042. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13043. {
  13044. sleep(3);
  13045. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13046. }
  13047. interLock.isUpdateFirmwareGoing = 0;
  13048. pthread_exit(NULL);
  13049. }
  13050. int handleCertificateSignedRequest(char *uuid, char *payload)
  13051. {
  13052. mtrace();
  13053. int result = PASS;
  13054. json_object *CertificateSigned;
  13055. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13056. CertificateSigned = json_tokener_parse(payload);
  13057. if(!is_error(CertificateSigned))
  13058. {
  13059. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13060. }
  13061. json_object_put(CertificateSigned);
  13062. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13063. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13064. fclose(fp);
  13065. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13066. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13067. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13068. sendCertificateSignedConfirmation(uuid);
  13069. return result;
  13070. }
  13071. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13072. {
  13073. mtrace();
  13074. int result = PASS;
  13075. json_object *DeleteCertificate;
  13076. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13077. DeleteCertificate = json_tokener_parse(payload);
  13078. if(!is_error(DeleteCertificate))
  13079. {
  13080. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13081. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13082. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13083. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13084. }
  13085. json_object_put(DeleteCertificate);
  13086. /*
  13087. * TODO: Delete certificateSigned process
  13088. */
  13089. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13090. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13091. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13092. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13093. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13094. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13095. sendDeleteCertificateConfirmation(uuid);
  13096. return result;
  13097. }
  13098. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13099. {
  13100. mtrace();
  13101. int result = PASS;
  13102. json_object *ExtendedTriggerMessage;
  13103. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13104. ExtendedTriggerMessage = json_tokener_parse(payload);
  13105. if(!is_error(ExtendedTriggerMessage))
  13106. {
  13107. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13108. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13109. {
  13110. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13111. }
  13112. else
  13113. {
  13114. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13115. }
  13116. }
  13117. json_object_put(ExtendedTriggerMessage);
  13118. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13119. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13120. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13121. {
  13122. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13123. }
  13124. else
  13125. {
  13126. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13127. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13128. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13129. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13130. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13131. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13132. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13133. {
  13134. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13135. }
  13136. else
  13137. {
  13138. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13139. }
  13140. }
  13141. sendExtendedTriggerMessageConfirmation(uuid);
  13142. //==========================
  13143. // Trigger message
  13144. //==========================
  13145. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13146. {
  13147. //sendBootNotificationRequest();
  13148. server_sign = FALSE;
  13149. }
  13150. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13151. {
  13152. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13153. }
  13154. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13155. {
  13156. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13157. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13158. {
  13159. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13160. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13161. }
  13162. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13163. }
  13164. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13165. {
  13166. refreshStartTimer(&clientTime.Heartbeat);
  13167. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13168. }
  13169. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13170. {
  13171. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13172. {
  13173. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13174. }
  13175. else
  13176. {
  13177. for(int idx=0;idx< gunTotalNumber;idx++)
  13178. {
  13179. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13180. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13181. }
  13182. }
  13183. }
  13184. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13185. {
  13186. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13187. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13188. {
  13189. system("openssl req -newkey rsa:2048 -out /Storage/OCPP_PH/certCP.csr -nodes -keyout /Storage/OCPP_PH/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  13190. }
  13191. }
  13192. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13193. {
  13194. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13195. {
  13196. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13197. }
  13198. else
  13199. {
  13200. for(int idx=0;idx< gunTotalNumber;idx++)
  13201. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13202. }
  13203. }
  13204. return result;
  13205. }
  13206. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13207. {
  13208. mtrace();
  13209. int result = PASS;
  13210. json_object *GetInstalledCertificateIds;
  13211. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13212. GetInstalledCertificateIds = json_tokener_parse(payload);
  13213. if(!is_error(GetInstalledCertificateIds))
  13214. {
  13215. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13216. }
  13217. json_object_put(GetInstalledCertificateIds);
  13218. /*
  13219. * TODO: Return installed certificate process
  13220. */
  13221. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13222. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13223. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13224. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13225. sendGetInstalledCertificateIdsConfirmation(uuid);
  13226. return result;
  13227. }
  13228. int handleGetLogRequest(char *uuid, char *payload)
  13229. {
  13230. mtrace();
  13231. int result = PASS;
  13232. json_object *GetLog;
  13233. DEBUG_INFO("handleGetLogRequest...\n");
  13234. GetLog = json_tokener_parse(payload);
  13235. if(!is_error(GetLog))
  13236. {
  13237. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13238. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13239. if(json_object_object_get(GetLog, "retries") != NULL)
  13240. {
  13241. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13242. }
  13243. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13244. {
  13245. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13246. }
  13247. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13248. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13249. {
  13250. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13251. }
  13252. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13253. {
  13254. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13255. }
  13256. }
  13257. json_object_put(GetLog);
  13258. /*
  13259. * TODO: Upload log process
  13260. */
  13261. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13262. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13263. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13264. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13265. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13266. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13267. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13268. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13269. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13270. sendGetLogConfirmation(uuid);
  13271. return result;
  13272. }
  13273. int handleInstallCertificateRequest(char *uuid, char *payload)
  13274. {
  13275. mtrace();
  13276. int result = PASS;
  13277. json_object *InstallCertificate;
  13278. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13279. InstallCertificate = json_tokener_parse(payload);
  13280. if(!is_error(InstallCertificate))
  13281. {
  13282. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13283. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13284. /*
  13285. * TODO: Install certificate process
  13286. */
  13287. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13288. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13289. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13290. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13291. sendInstallCertificateConfirmation(uuid);
  13292. }
  13293. json_object_put(InstallCertificate);
  13294. return result;
  13295. }
  13296. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13297. {
  13298. mtrace();
  13299. int result = PASS;
  13300. json_object *SignedUpdateFirmware;
  13301. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13302. SignedUpdateFirmware = json_tokener_parse(payload);
  13303. if(!is_error(SignedUpdateFirmware))
  13304. {
  13305. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13306. {
  13307. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13308. }
  13309. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13310. {
  13311. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13312. }
  13313. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13314. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13315. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13316. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13317. {
  13318. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13319. }
  13320. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13321. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13322. }
  13323. json_object_put(SignedUpdateFirmware);
  13324. /*
  13325. * TODO: Upgrade firmware process
  13326. */
  13327. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13328. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13329. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13330. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13331. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13332. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13333. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13334. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13335. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13336. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13337. sendInstallCertificateConfirmation(uuid);
  13338. return result;
  13339. }
  13340. int handleUnknownRequest(char *uuid, char *payload)
  13341. {
  13342. mtrace();
  13343. int result = PASS;
  13344. DEBUG_INFO("handleUnknownRequest...\n");
  13345. sendUnknownConfirmation(uuid);
  13346. result = PASS;
  13347. return result;
  13348. }
  13349. //==========================================
  13350. // Handle server response routine
  13351. //==========================================
  13352. void handleAuthorizeResponse(char *payload, int gun_index)
  13353. {
  13354. mtrace();
  13355. char expiryDatestr[36]={0};
  13356. char parentIdTagstr[21]={0};
  13357. char statusstr[20]={0};
  13358. int expiryDateISNULL=FALSE;
  13359. int parentIdTagISNULL=FALSE;
  13360. DEBUG_INFO("handleAuthorizeResponse...\n");
  13361. json_object *Authorize;
  13362. Authorize = json_tokener_parse(payload);
  13363. if(!is_error(Authorize))
  13364. {
  13365. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13366. {
  13367. // Required data
  13368. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13369. // Optional data
  13370. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13371. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13372. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13373. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13374. }
  13375. }
  13376. json_object_put(Authorize);
  13377. if(expiryDateISNULL == FALSE)
  13378. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13379. if(parentIdTagISNULL == FALSE)
  13380. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13381. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13382. //Update idTag information to authorization cache if supproted
  13383. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13384. {
  13385. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13386. }
  13387. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13388. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13389. authorizeRetryTimes = 0;
  13390. }
  13391. void handleBootNotificationResponse(char *payload, int gun_index)
  13392. {
  13393. mtrace();
  13394. char statusStr[12]={0};
  13395. char currentTimeStr[30]={0};
  13396. int intervalInt = 0;
  13397. DEBUG_INFO("handleBootNotificationResponse...\n");
  13398. json_object *BootNotification;
  13399. BootNotification = json_tokener_parse(payload);
  13400. if(!is_error(BootNotification))
  13401. {
  13402. // Required data
  13403. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13404. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13405. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13406. }
  13407. json_object_put(BootNotification);
  13408. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13409. BootNotificationInterval = intervalInt;
  13410. //write back to ShmOCPP16DataPH->BootNotification
  13411. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13412. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13413. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13414. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13415. {
  13416. BootNotificationInterval = 0;
  13417. if((intervalInt == 0) || (intervalInt >= 10))
  13418. {
  13419. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13420. HeartBeatWaitTime = intervalInt;
  13421. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13422. }
  13423. server_sign = TRUE;
  13424. server_pending =FALSE;
  13425. }
  13426. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13427. {
  13428. server_pending = TRUE;
  13429. }
  13430. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13431. srand(time(NULL));
  13432. refreshStartTimer(&clientTime.Heartbeat);
  13433. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13434. SetOcppConnStatus(TRUE);
  13435. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13436. }
  13437. void handleDataTransferResponse(char *payload, int gun_index)
  13438. {
  13439. json_object *DataTransfer = json_tokener_parse(payload);
  13440. if(!is_error(DataTransfer))
  13441. {
  13442. // Required data
  13443. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13444. // Optional data
  13445. if(json_object_object_get(DataTransfer, "data") != NULL)
  13446. {
  13447. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13448. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13449. if(!is_error(Data))
  13450. {
  13451. if(json_object_object_get(Data, "msgId") != NULL)
  13452. {
  13453. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13454. {
  13455. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  13456. }
  13457. }
  13458. }
  13459. json_object_put(Data);
  13460. }
  13461. }
  13462. json_object_put(DataTransfer);
  13463. }
  13464. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13465. {
  13466. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13467. //struct json_object *obj;
  13468. // obj = json_tokener_parse(payload);
  13469. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13470. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13471. //No fields are defined.
  13472. }
  13473. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13474. {
  13475. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13476. //struct json_object *obj;
  13477. // obj = json_tokener_parse(payload);
  13478. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13479. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13480. //No fields are defined.
  13481. }
  13482. void handleHeartbeatResponse(char *payload, int gun_index)
  13483. {
  13484. mtrace();
  13485. DEBUG_INFO("handleHeartbeatResponse...\n");
  13486. json_object *Heartbeat;
  13487. Heartbeat = json_tokener_parse(payload);
  13488. if(!is_error(Heartbeat))
  13489. {
  13490. // Required data
  13491. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13492. }
  13493. json_object_put(Heartbeat);
  13494. if(FirstHeartBeat == 0)
  13495. {
  13496. FirstHeartBeat = 1;
  13497. DEBUG_INFO("FirstHeartBeat \n");
  13498. }
  13499. HeartBeatWithNOResponse = 0;
  13500. refreshStartTimer(&clientTime.Heartbeat);
  13501. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13502. }
  13503. void handleMeterValuesResponse(char *payload, int gun_index)
  13504. {
  13505. mtrace();
  13506. DEBUG_INFO("handleMeterValuesResponse...\n");
  13507. isQueueSendable = 1;
  13508. }
  13509. void handleStartTransactionResponse(char *payload, int gun_index)
  13510. {
  13511. mtrace();
  13512. //int transactionIdInt = 0;
  13513. FILE *outfile;
  13514. char data[100]={0};
  13515. DEBUG_INFO("handleStartTransactionResponse...\n");
  13516. json_object *StartTransaction;
  13517. StartTransaction = json_tokener_parse(payload);
  13518. if(!is_error(StartTransaction))
  13519. {
  13520. // Required data
  13521. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13522. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13523. // Optional data
  13524. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13525. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13526. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13527. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13528. }
  13529. json_object_put(StartTransaction);
  13530. isQueueSendable = 1;
  13531. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13532. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13533. //-----------Start : write to the Queue TransactionId file -----------------//
  13534. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13535. {}
  13536. else
  13537. {
  13538. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13539. if(log == NULL)
  13540. {
  13541. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13542. return ;
  13543. }
  13544. else
  13545. {
  13546. fclose(log);
  13547. }
  13548. }
  13549. // open file for writing
  13550. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13551. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13552. {
  13553. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13554. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13555. fputs(data, outfile);
  13556. fclose (outfile);
  13557. }
  13558. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13559. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13560. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13561. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13562. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13563. }
  13564. void handleStatusNotificationResponse(char *payload, int gun_index)
  13565. {
  13566. mtrace();
  13567. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13568. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13569. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13570. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13571. }
  13572. void handleStopTransactionnResponse(char *payload, int gun_index)
  13573. {
  13574. mtrace();
  13575. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13576. json_object *StopTransaction;
  13577. StopTransaction = json_tokener_parse(payload);
  13578. if(!is_error(StopTransaction))
  13579. {
  13580. // Optional data
  13581. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13582. {
  13583. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13584. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13585. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13586. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13587. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13588. }
  13589. }
  13590. json_object_put(StopTransaction);
  13591. isQueueSendable = 1;
  13592. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13593. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13594. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13595. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13596. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13597. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13598. }
  13599. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13600. {
  13601. mtrace();
  13602. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13603. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13604. }
  13605. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13606. {
  13607. mtrace();
  13608. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13609. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13610. }
  13611. void handleSignCertificateResponse(char *payload, int gun_index)
  13612. {
  13613. mtrace();
  13614. DEBUG_INFO("handleSignCertificateResponse...\n");
  13615. json_object *SignCertificate;
  13616. SignCertificate = json_tokener_parse(payload);
  13617. if(!is_error(SignCertificate))
  13618. {
  13619. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13620. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13621. }
  13622. json_object_put(SignCertificate);
  13623. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13624. }
  13625. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13626. {
  13627. mtrace();
  13628. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13629. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13630. }
  13631. //==========================================
  13632. // Handle Error routine
  13633. //==========================================
  13634. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13635. {
  13636. mtrace();
  13637. #ifdef SystemLogMessage
  13638. DEBUG_INFO("errorCode: %s\n", errorCode);
  13639. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13640. DEBUG_INFO("errorDetails: %s\n", payload);
  13641. #endif
  13642. }
  13643. //===============================================
  13644. // Common routine
  13645. //===============================================
  13646. int initialConfigurationTable(void)
  13647. {
  13648. //clock_t start_t, end_t, total_t;
  13649. FILE *fp;
  13650. FILE *outfile;
  13651. char str[512]={0};
  13652. int confVersion = 20;
  13653. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13654. //start_t = clock();
  13655. //printf("Starting of the program, start_t = %ld\n", start_t);
  13656. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13657. // Check configuration file size is correct
  13658. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13659. {
  13660. struct stat st;
  13661. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13662. if(st.st_size < 3100)
  13663. {
  13664. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13665. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13666. }
  13667. }
  13668. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13669. {
  13670. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13671. if(outfile == NULL)
  13672. {
  13673. DEBUG_INFO("Error opening file\n");
  13674. return FALSE;
  13675. }
  13676. /*Core Profile*/
  13677. //AllowOfflineTxForUnknownId
  13678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13682. //AuthorizationCacheEnabled
  13683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13687. //AuthorizeRemoteTxRequests
  13688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13692. //BlinkRepeat
  13693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13697. //ClockAlignedDataInterval
  13698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13699. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13702. //ConnectionTimeOut
  13703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13707. //GetConfigurationMaxKeys
  13708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13712. // HeartbeatInterval
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13717. // LightIntensity
  13718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13720. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13722. // LocalAuthorizeOffline
  13723. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13725. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13727. // LocalPreAuthorize
  13728. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13729. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13730. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13732. // MaxEnergyOnInvalidId
  13733. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13734. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13735. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13737. // MeterValuesAlignedData
  13738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13739. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13740. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13741. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13742. else
  13743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13745. // MeterValuesAlignedDataMaxLength
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13748. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13749. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13750. else
  13751. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13753. // MeterValuesSampledData
  13754. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13755. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13758. else
  13759. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13761. // MeterValuesSampledDataMaxLength
  13762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13765. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13766. else
  13767. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13769. // MeterValueSampleInterval
  13770. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13771. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13772. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13774. // MinimumStatusDuration
  13775. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13776. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13778. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13780. // NumberOfConnectors
  13781. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13782. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13784. {
  13785. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13786. }
  13787. else
  13788. {
  13789. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13790. }
  13791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13792. // ResetRetries
  13793. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13797. // ConnectorPhaseRotation
  13798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13802. // ConnectorPhaseRotationMaxLength
  13803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13807. // StopTransactionOnEVSideDisconnect
  13808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13812. // StopTransactionOnInvalidId
  13813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13817. // StopTxnAlignedData
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13822. // StopTxnAlignedDataMaxLength
  13823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13827. // StopTxnSampledData
  13828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13830. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13832. else
  13833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13835. // StopTxnSampledDataMaxLength
  13836. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13838. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13839. {
  13840. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13841. }
  13842. else
  13843. {
  13844. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13845. }
  13846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13847. // SupportedFeatureProfiles
  13848. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13849. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13852. // SupportedFeatureProfilesMaxLength
  13853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13857. // TransactionMessageAttempts
  13858. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13861. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13863. // TransactionMessageRetryInterval
  13864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13867. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13869. // UnlockConnectorOnEVSideDisconnect
  13870. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13874. // WebSocketPingInterval
  13875. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13879. // QueueOffLineMeterValues
  13880. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13884. // AuthorizationKey
  13885. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13889. // SecurityProfile
  13890. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13892. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13894. // DefaultPrice
  13895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13899. // CustomDisplayCostAndPrice
  13900. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13904. // CustomIdleFeeAfterStop
  13905. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13909. // SystemUptimeSec
  13910. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13914. // FreeVend
  13915. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13919. // FreeVendIdtag
  13920. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13924. // OcppServer
  13925. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13927. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13929. // MaintainServer
  13930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13932. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13934. // StatusNotificationPeriodically
  13935. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13939. // StatusNotificationInterval
  13940. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13944. // isEnableLocalPowerSharing
  13945. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  13946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  13947. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  13948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  13949. // PowerSharingServerIP
  13950. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  13951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  13952. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  13953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  13954. // EVCCID_PREFIX
  13955. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  13956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  13957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  13958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  13959. // OffLineMaxChargingPower
  13960. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  13961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  13962. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  13963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  13964. // Configuration Version
  13965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13967. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13969. // Charging profile refresh interval
  13970. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  13971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  13972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  13973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  13974. // Ocpp Software certificated version
  13975. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  13976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  13977. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  13978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  13979. // Check certificate of download link
  13980. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  13981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  13982. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", "FALSE");
  13983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  13984. // RFID endian type
  13985. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  13986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  13987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE"));
  13988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  13989. // Authorization timeout
  13990. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  13991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  13992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "15");
  13993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  13994. // Enable AC charger CCS function
  13995. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility = 1;
  13996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemName, "Enable15118");
  13997. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemData, (ShmSysConfigAndInfo->SysConfig.isEnable15118==1?"TRUE":"FALSE"));
  13998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","Enable15118", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemData);
  13999. // Wifi SSID
  14000. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility = 1;
  14001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemName, "WifiSsid");
  14002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  14003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WifiSsid", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemData);
  14004. // Wifi password
  14005. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility = 1;
  14006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemName, "WifiPassword");
  14007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  14008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WifiPassword", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemData);
  14009. // Stop Charging By Button
  14010. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility = 1;
  14011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemName, "StopChargingByButton");
  14012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData, (ShmSysConfigAndInfo->SysConfig.StopChargingByButton==1?"TRUE":"FALSE"));
  14013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopChargingByButton", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData);
  14014. //* Local Auth List Management Profile*/
  14015. #if 0
  14016. //For OCTT Test Case
  14017. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14018. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14019. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14020. #endif
  14021. #if 1
  14022. //LocalAuthListEnabled
  14023. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14024. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14025. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14027. #endif
  14028. //LocalAuthListMaxLength
  14029. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14033. //SendLocalListMaxLength
  14034. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  14037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14038. //ReserveConnectorZeroSupported
  14039. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14043. //* Smart Charging Profile */
  14044. //ChargeProfileMaxStackLevel
  14045. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14046. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14049. // ChargingScheduleAllowedChargingRateUnit
  14050. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14054. // ChargingScheduleMaxPeriods
  14055. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14059. // ConnectorSwitch3to1PhaseSupported
  14060. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14064. // MaxChargingProfilesInstalled
  14065. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14069. fclose(outfile);
  14070. }
  14071. else
  14072. {
  14073. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14074. char keystr[60]={0};
  14075. char readonlystr[10]={0};
  14076. char valuestr[256]={0};
  14077. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14078. if(fp == NULL) {
  14079. DEBUG_INFO("Error opening file");
  14080. return FALSE;
  14081. }
  14082. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14083. {
  14084. //DEBUG_INFO("Get Configuration \n");
  14085. if(strlen(str) > 0)
  14086. {
  14087. json_object *OCPPConfiguration;
  14088. OCPPConfiguration = json_tokener_parse(str);
  14089. if(json_object_object_get(OCPPConfiguration, "key") != NULL)
  14090. strcpy(keystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"key")));
  14091. if(json_object_object_get(OCPPConfiguration, "readonly") != NULL)
  14092. strcpy(readonlystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"readonly")));
  14093. if(json_object_object_get(OCPPConfiguration, "value") != NULL)
  14094. strcpy(valuestr, json_object_get_string(json_object_object_get(OCPPConfiguration,"value")));
  14095. json_object_put(OCPPConfiguration);
  14096. // DEBUG_INFO("keystr=%s\n",keystr);
  14097. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14098. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14099. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14100. {
  14101. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14102. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14103. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14104. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14105. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14106. }
  14107. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14108. {
  14109. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14112. }
  14113. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14114. {
  14115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14117. }
  14118. if(strcmp(keystr, "BlinkRepeat") == 0)
  14119. {
  14120. //Charger.BlinkRepeat = Integer.parseInt(value);
  14121. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14122. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14123. }
  14124. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14125. {
  14126. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14127. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14128. }
  14129. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14130. {
  14131. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14132. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14133. }
  14134. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14135. {
  14136. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14137. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14138. }
  14139. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14140. {
  14141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14142. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14143. HeartBeatWaitTime = atoi(valuestr);
  14144. }
  14145. if(strcmp(keystr, "LightIntensity") == 0)
  14146. {
  14147. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14148. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14149. }
  14150. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14151. {
  14152. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14154. }
  14155. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14156. {
  14157. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14158. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14159. }
  14160. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14161. {
  14162. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14163. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14164. }
  14165. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14166. {
  14167. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14168. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14169. }
  14170. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14171. {
  14172. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14173. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14174. }
  14175. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14176. {
  14177. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14178. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14179. }
  14180. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14181. {
  14182. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14183. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14184. }
  14185. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14186. {
  14187. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14188. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14189. }
  14190. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14191. {
  14192. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14193. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14194. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14195. }
  14196. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14197. {
  14198. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14199. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14200. }
  14201. if(strcmp(keystr, "ResetRetries") == 0)
  14202. {
  14203. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14204. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14205. }
  14206. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14207. {
  14208. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14209. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14210. }
  14211. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14212. {
  14213. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14214. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14215. }
  14216. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14217. {
  14218. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14219. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14220. }
  14221. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14222. {
  14223. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14224. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14225. }
  14226. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14227. {
  14228. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14229. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14230. }
  14231. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14232. {
  14233. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14234. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14235. }
  14236. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14237. {
  14238. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14239. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14240. }
  14241. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14242. {
  14243. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14244. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14245. }
  14246. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14247. {
  14248. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14249. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14250. }
  14251. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14252. {
  14253. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14254. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14255. }
  14256. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14257. {
  14258. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14259. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14260. TransactionMessageAttemptsValue = atoi(valuestr);
  14261. }
  14262. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14263. {
  14264. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14265. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14266. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14267. }
  14268. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14269. {
  14270. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14271. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14272. }
  14273. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14274. {
  14275. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14277. }
  14278. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14279. {
  14280. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14282. }
  14283. if(strcmp(keystr, "AuthorizationKey") == 0)
  14284. {
  14285. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14286. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14287. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14288. }
  14289. if(strcmp(keystr, "SecurityProfile") == 0)
  14290. {
  14291. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14292. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14294. }
  14295. if(strcmp(keystr, "DefaultPrice") == 0)
  14296. {
  14297. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14298. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14299. }
  14300. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14301. {
  14302. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14303. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14304. }
  14305. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14306. {
  14307. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14308. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14309. }
  14310. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14311. {
  14312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14314. }
  14315. if(strcmp(keystr, "FreeVend") == 0)
  14316. {
  14317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14318. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14319. }
  14320. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14321. {
  14322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14324. }
  14325. if(strcmp(keystr, "OcppServer") == 0)
  14326. {
  14327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14328. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14329. }
  14330. if(strcmp(keystr, "MaintainServer") == 0)
  14331. {
  14332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14333. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14334. }
  14335. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14336. {
  14337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14338. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14339. }
  14340. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14341. {
  14342. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14343. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14344. }
  14345. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14346. {
  14347. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14348. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14349. }
  14350. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14351. {
  14352. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14353. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14354. }
  14355. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14356. {
  14357. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14358. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14359. }
  14360. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  14361. {
  14362. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14363. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  14364. }
  14365. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14366. {
  14367. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14368. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14369. }
  14370. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  14371. {
  14372. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14373. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  14374. }
  14375. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  14376. {
  14377. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14378. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  14379. }
  14380. if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
  14381. {
  14382. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14383. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
  14384. }
  14385. if(strcmp(keystr, "RfidEndianType") == 0)
  14386. {
  14387. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14388. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE"));
  14389. }
  14390. if(strcmp(keystr, "AuthorizeTimeout") == 0)
  14391. {
  14392. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14393. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", valuestr);
  14394. }
  14395. if(strcmp(keystr, "Enable15118") == 0)
  14396. {
  14397. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14398. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.isEnable15118==1?"TRUE":"FALSE"));
  14399. }
  14400. if(strcmp(keystr, "WifiSsid") == 0)
  14401. {
  14402. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14403. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  14404. }
  14405. if(strcmp(keystr, "WifiPassword") == 0)
  14406. {
  14407. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14408. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  14409. }
  14410. if(strcmp(keystr, "StopChargingByButton") == 0)
  14411. {
  14412. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14413. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.StopChargingByButton==1?"TRUE":"FALSE"));
  14414. }
  14415. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14416. {
  14417. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14418. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14419. }
  14420. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14421. {
  14422. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14423. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14424. }
  14425. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14426. {
  14427. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14428. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14429. }
  14430. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14431. {
  14432. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14433. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14434. }
  14435. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14436. {
  14437. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14438. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14439. }
  14440. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14441. {
  14442. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14443. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14444. }
  14445. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14446. {
  14447. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14449. }
  14450. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14451. {
  14452. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14453. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14454. }
  14455. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14456. {
  14457. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14458. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14459. }
  14460. }
  14461. }
  14462. fclose(fp);
  14463. }
  14464. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14465. {
  14466. return PASS;
  14467. }
  14468. else
  14469. {
  14470. return FAIL;
  14471. }
  14472. }
  14473. void StoreConfigurationTable(void)
  14474. {
  14475. FILE *outfile;
  14476. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14477. if(outfile == NULL)
  14478. {
  14479. DEBUG_INFO("Error opening file");
  14480. return ;
  14481. }
  14482. /*Core Profile*/
  14483. //AllowOfflineTxForUnknownId
  14484. /*
  14485. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14486. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14487. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14488. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14489. */
  14490. //DEBUG_INFO("data=%s\n",data);
  14491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14492. //AuthorizationCacheEnabled
  14493. /*
  14494. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14495. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14496. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14497. */
  14498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14499. //AuthorizeRemoteTxRequests
  14500. /*
  14501. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14502. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14503. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14504. */
  14505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14506. //BlinkRepeat
  14507. /*
  14508. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14509. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14510. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14511. */
  14512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14513. //ClockAlignedDataInterval
  14514. /*
  14515. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14516. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14517. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14518. */
  14519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14520. //ConnectionTimeOut
  14521. /*
  14522. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14523. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14524. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14525. */
  14526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14527. //GetConfigurationMaxKeys
  14528. /*
  14529. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14530. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14531. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14532. */
  14533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14534. // HeartbeatInterval
  14535. /*
  14536. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14537. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14538. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14539. */
  14540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14541. // LightIntensity
  14542. /*
  14543. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14544. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14545. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14546. */
  14547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14548. // LocalAuthorizeOffline
  14549. /*
  14550. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14551. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14552. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14553. */
  14554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14555. // LocalPreAuthorize
  14556. /*
  14557. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14558. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14560. */
  14561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14562. // MaxEnergyOnInvalidId
  14563. /*
  14564. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14565. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14566. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14567. */
  14568. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14570. // MeterValuesAlignedData
  14571. /*
  14572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14574. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14575. */
  14576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14577. // MeterValuesAlignedDataMaxLength
  14578. /*
  14579. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14582. */
  14583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14584. // MeterValuesSampledData
  14585. /*
  14586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14589. */
  14590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14591. // MeterValuesSampledDataMaxLength
  14592. /*
  14593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14594. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14595. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14596. */
  14597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14598. // MeterValueSampleInterval
  14599. /*
  14600. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14603. */
  14604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14605. // MinimumStatusDuration
  14606. /*
  14607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14610. */
  14611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14612. // NumberOfConnectors
  14613. /*
  14614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14617. {
  14618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14619. }
  14620. else
  14621. {
  14622. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14623. }
  14624. */
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14626. // ResetRetries
  14627. /*
  14628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14631. */
  14632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14633. // ConnectorPhaseRotation
  14634. /*
  14635. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14638. */
  14639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14640. // ConnectorPhaseRotationMaxLength
  14641. /*
  14642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14645. */
  14646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14647. // StopTransactionOnEVSideDisconnect
  14648. /*
  14649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14650. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14652. */
  14653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14654. // StopTransactionOnInvalidId
  14655. /*
  14656. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14659. */
  14660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14661. // StopTxnAlignedData
  14662. /*
  14663. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14666. */
  14667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14668. // StopTxnAlignedDataMaxLength
  14669. /*
  14670. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14671. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14673. */
  14674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14675. // StopTxnSampledData
  14676. /*
  14677. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14678. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14680. */
  14681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14682. // StopTxnSampledDataMaxLength
  14683. /*
  14684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14687. */
  14688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14689. // SupportedFeatureProfiles
  14690. /*
  14691. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14692. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14694. */
  14695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14696. // SupportedFeatureProfilesMaxLength
  14697. /*
  14698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14699. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14701. */
  14702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14703. // TransactionMessageAttempts
  14704. /*
  14705. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14706. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14707. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14708. */
  14709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14710. // TransactionMessageRetryInterval
  14711. /*
  14712. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14713. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14715. */
  14716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14717. // UnlockConnectorOnEVSideDisconnect
  14718. /*
  14719. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14720. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14721. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14722. */
  14723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14724. // WebSocketPingInterval
  14725. /*
  14726. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14727. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14729. */
  14730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14731. // QueueOffLineMeterValues
  14732. /*
  14733. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14734. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14735. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14736. */
  14737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14738. // AuthorizationKey
  14739. /*
  14740. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14741. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14743. */
  14744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14745. // SecurityProfile
  14746. /*
  14747. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14748. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14749. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14750. */
  14751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14752. // DefaultPrice
  14753. /*
  14754. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14755. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14756. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14757. */
  14758. json_object *tmp;
  14759. tmp = json_tokener_parse((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14760. if(!is_error(tmp))
  14761. {
  14762. DEBUG_INFO("JSON string type\n");
  14763. json_object *target = json_object_new_object();
  14764. json_object_object_add(target, "key", json_object_new_string("DefaultPrice"));
  14765. json_object_object_add(target, "readonly", (ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility?json_object_new_boolean(0):json_object_new_boolean(1)));
  14766. json_object_object_add(target, "value", json_object_new_string((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData));
  14767. fprintf(outfile, "%s\n", json_object_to_json_string_ext(target, JSON_C_TO_STRING_PLAIN));
  14768. json_object_put(target);
  14769. }
  14770. else
  14771. {
  14772. DEBUG_INFO("Normal string type\n");
  14773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14774. }
  14775. json_object_put(tmp);
  14776. // CustomDisplayCostAndPrice
  14777. /*
  14778. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14779. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14780. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14781. */
  14782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14783. // CustomIdleFeeAfterStop
  14784. /*
  14785. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14786. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14787. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14788. */
  14789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14790. // SystemUptimeSec
  14791. /*
  14792. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14793. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14795. */
  14796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14797. // FreeVend
  14798. /*
  14799. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14801. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14802. */
  14803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14804. // FreeVendIdtag
  14805. /*
  14806. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14807. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14808. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14809. */
  14810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14811. // OcppServer
  14812. /*
  14813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14816. */
  14817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14818. // MaintainServer
  14819. /*
  14820. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14823. */
  14824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14825. // StatusNotificationPeriodically
  14826. /*
  14827. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14828. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14830. */
  14831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14832. // StatusNotificationInterval
  14833. /*
  14834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14837. */
  14838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14839. // isEnableLocalPowerSharing
  14840. /*
  14841. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  14844. */
  14845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14846. // PowerSharingServerIP
  14847. /*
  14848. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  14851. */
  14852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14853. // EVCCID_PREFIX
  14854. /*
  14855. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14858. */
  14859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14860. // OffLineMaxChargingPower
  14861. /*
  14862. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  14865. */
  14866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14867. // ConfigurationVersion
  14868. /*
  14869. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14872. */
  14873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14874. // CharingProfileRefreshInterval
  14875. /*
  14876. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  14877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  14878. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  14879. */
  14880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  14881. // OcppSoftwareVersion
  14882. /*
  14883. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  14884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  14885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  14886. */
  14887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  14888. // AuthDownloadlinkCertificate
  14889. /*
  14890. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  14891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  14892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "" );
  14893. */
  14894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  14895. // RfidEndianType
  14896. /*
  14897. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  14898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  14899. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "BIG" );
  14900. */
  14901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  14902. // AuthorizeTimeout
  14903. /*
  14904. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  14905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  14906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "60" );
  14907. */
  14908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  14909. // Enable15118
  14910. /*
  14911. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility = 1;
  14912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemName, "Enable15118");
  14913. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemData, "TRUE" );
  14914. */
  14915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","Enable15118", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemData);
  14916. // WifiSsid
  14917. /*
  14918. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility = 1;
  14919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemName, "WifiSsid");
  14920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemData, "TRUE" );
  14921. */
  14922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WifiSsid", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemData);
  14923. // WifiPassword
  14924. /*
  14925. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility = 1;
  14926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemName, "WifiPassword");
  14927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemData, "TRUE" );
  14928. */
  14929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WifiPassword", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemData);
  14930. // StopChargingByButton
  14931. /*
  14932. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility = 1;
  14933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemName, "StopChargingByButton");
  14934. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData, "TRUE" );
  14935. */
  14936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopChargingByButton", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData);
  14937. //* Local Auth List Management Profile*/
  14938. //LocalAuthListEnabled
  14939. /*
  14940. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14943. */
  14944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14945. //LocalAuthListMaxLength
  14946. /*
  14947. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14948. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14950. */
  14951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14952. //SendLocalListMaxLength
  14953. /*
  14954. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14955. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14957. */
  14958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14959. //ReserveConnectorZeroSupported
  14960. /*
  14961. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14962. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14964. */
  14965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14966. //* Smart Charging Profile */
  14967. //ChargeProfileMaxStackLevel
  14968. /*
  14969. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14972. */
  14973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14974. // ChargingScheduleAllowedChargingRateUnit
  14975. /*
  14976. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14979. */
  14980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14981. // ChargingScheduleMaxPeriods
  14982. /*
  14983. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14986. */
  14987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14988. // ConnectorSwitch3to1PhaseSupported
  14989. /*
  14990. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14993. */
  14994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14995. // MaxChargingProfilesInstalled
  14996. /*
  14997. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15000. */
  15001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15002. fclose(outfile);
  15003. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15004. }
  15005. void getKeyValue(char *keyReq)
  15006. {
  15007. int isEmpty = FALSE;
  15008. int isKnowKey = FALSE;
  15009. DEBUG_INFO("keyReq = %s\n", keyReq);
  15010. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15011. isEmpty = TRUE;
  15012. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15013. {
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15016. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15017. {
  15018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15019. }
  15020. else
  15021. {
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15023. }
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15025. isKnowKey = TRUE;
  15026. }
  15027. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15028. {
  15029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15031. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15032. {
  15033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15034. }
  15035. else
  15036. {
  15037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15038. }
  15039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15040. isKnowKey = TRUE;
  15041. }
  15042. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15043. {
  15044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15046. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15047. {
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15049. }
  15050. else
  15051. {
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15053. }
  15054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15055. isKnowKey = TRUE;
  15056. }
  15057. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15058. {
  15059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15061. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15062. {
  15063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15064. }
  15065. else
  15066. {
  15067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15068. }
  15069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15070. isKnowKey = TRUE;
  15071. }
  15072. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15073. {
  15074. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15076. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15077. {
  15078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15079. }
  15080. else
  15081. {
  15082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15083. }
  15084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15085. isKnowKey = TRUE;
  15086. }
  15087. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15088. {
  15089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15091. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15092. {
  15093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15094. }
  15095. else
  15096. {
  15097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15098. }
  15099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15100. isKnowKey = TRUE;
  15101. }
  15102. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15103. {
  15104. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15106. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15107. {
  15108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15109. }
  15110. else
  15111. {
  15112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15113. }
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15115. isKnowKey = TRUE;
  15116. }
  15117. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15118. {
  15119. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15121. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15122. {
  15123. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15124. }
  15125. else
  15126. {
  15127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15128. }
  15129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15130. isKnowKey = TRUE;
  15131. }
  15132. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15133. {
  15134. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15136. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15137. {
  15138. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15139. }
  15140. else
  15141. {
  15142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15143. }
  15144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15145. isKnowKey = TRUE;
  15146. }
  15147. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15148. {
  15149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15151. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15152. {
  15153. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15154. }
  15155. else
  15156. {
  15157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15158. }
  15159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15160. isKnowKey = TRUE;
  15161. }
  15162. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15163. {
  15164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15166. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15167. {
  15168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15169. }
  15170. else
  15171. {
  15172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15173. }
  15174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15175. isKnowKey = TRUE;
  15176. }
  15177. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15178. {
  15179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15181. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15182. {
  15183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15184. }
  15185. else
  15186. {
  15187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15188. }
  15189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15190. isKnowKey = TRUE;
  15191. }
  15192. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15193. {
  15194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15195. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15196. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15197. {
  15198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15199. }
  15200. else
  15201. {
  15202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15203. }
  15204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15205. isKnowKey = TRUE;
  15206. }
  15207. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15208. {
  15209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15210. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15211. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15212. {
  15213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15214. }
  15215. else
  15216. {
  15217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15218. }
  15219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15220. isKnowKey = TRUE;
  15221. }
  15222. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15223. {
  15224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15225. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15226. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15227. {
  15228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15229. }
  15230. else
  15231. {
  15232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15233. }
  15234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15235. isKnowKey = TRUE;
  15236. }
  15237. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15238. {
  15239. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15241. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15242. {
  15243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15244. }
  15245. else
  15246. {
  15247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15248. }
  15249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15250. isKnowKey = TRUE;
  15251. }
  15252. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15253. {
  15254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15256. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15257. {
  15258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15259. }
  15260. else
  15261. {
  15262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15263. }
  15264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15265. isKnowKey = TRUE;
  15266. }
  15267. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15268. {
  15269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15271. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15272. {
  15273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15274. }
  15275. else
  15276. {
  15277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15278. }
  15279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15280. isKnowKey = TRUE;
  15281. }
  15282. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15283. {
  15284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15286. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15287. {
  15288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15289. }
  15290. else
  15291. {
  15292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15293. }
  15294. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15296. isKnowKey = TRUE;
  15297. }
  15298. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15299. {
  15300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15302. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15303. {
  15304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15305. }
  15306. else
  15307. {
  15308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15309. }
  15310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15311. isKnowKey = TRUE;
  15312. }
  15313. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15314. {
  15315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15317. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15318. {
  15319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15320. }
  15321. else
  15322. {
  15323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15324. }
  15325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15326. isKnowKey = TRUE;
  15327. }
  15328. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15329. {
  15330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15332. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15333. {
  15334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15335. }
  15336. else
  15337. {
  15338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15339. }
  15340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15341. isKnowKey = TRUE;
  15342. }
  15343. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15344. {
  15345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15347. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15348. {
  15349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15350. }
  15351. else
  15352. {
  15353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15354. }
  15355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15356. isKnowKey = TRUE;
  15357. }
  15358. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15359. {
  15360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15362. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15363. {
  15364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15365. }
  15366. else
  15367. {
  15368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15369. }
  15370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15371. isKnowKey = TRUE;
  15372. }
  15373. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15374. {
  15375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15377. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15378. {
  15379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15380. }
  15381. else
  15382. {
  15383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15384. }
  15385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15386. isKnowKey = TRUE;
  15387. }
  15388. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15389. {
  15390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15392. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15393. {
  15394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15395. }
  15396. else
  15397. {
  15398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15399. }
  15400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15401. isKnowKey = TRUE;
  15402. }
  15403. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15404. {
  15405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15407. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15408. {
  15409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15410. }
  15411. else
  15412. {
  15413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15414. }
  15415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15416. isKnowKey = TRUE;
  15417. }
  15418. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15419. {
  15420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15422. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15423. {
  15424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15425. }
  15426. else
  15427. {
  15428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15429. }
  15430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15431. isKnowKey = TRUE;
  15432. }
  15433. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15434. {
  15435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15437. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15438. {
  15439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15440. }
  15441. else
  15442. {
  15443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15444. }
  15445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15446. isKnowKey = TRUE;
  15447. }
  15448. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15449. {
  15450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15452. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15453. {
  15454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15455. }
  15456. else
  15457. {
  15458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15459. }
  15460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15461. isKnowKey = TRUE;
  15462. }
  15463. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15464. {
  15465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15467. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15468. {
  15469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15470. }
  15471. else
  15472. {
  15473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15474. }
  15475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15476. isKnowKey = TRUE;
  15477. }
  15478. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15479. {
  15480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15482. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15483. {
  15484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15485. }
  15486. else
  15487. {
  15488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15489. }
  15490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15491. isKnowKey = TRUE;
  15492. }
  15493. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15494. {
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15497. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15498. {
  15499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15500. }
  15501. else
  15502. {
  15503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15504. }
  15505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15506. isKnowKey = TRUE;
  15507. }
  15508. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15509. {
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15512. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15513. {
  15514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15515. }
  15516. else
  15517. {
  15518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15519. }
  15520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15521. isKnowKey = TRUE;
  15522. }
  15523. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15524. {
  15525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15527. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15528. {
  15529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15530. }
  15531. else
  15532. {
  15533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15534. }
  15535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15536. isKnowKey = TRUE;
  15537. }
  15538. /*
  15539. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15540. {
  15541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15543. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15544. {
  15545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15546. }
  15547. else
  15548. {
  15549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15550. }
  15551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15552. isKnowKey = TRUE;
  15553. }*/
  15554. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15555. {
  15556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15558. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15559. {
  15560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15561. }
  15562. else
  15563. {
  15564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15565. }
  15566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15567. isKnowKey = TRUE;
  15568. }
  15569. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15570. {
  15571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15573. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15574. {
  15575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15576. }
  15577. else
  15578. {
  15579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15580. }
  15581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15582. isKnowKey = TRUE;
  15583. }
  15584. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15585. {
  15586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15588. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15589. {
  15590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15591. }
  15592. else
  15593. {
  15594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15595. }
  15596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15597. isKnowKey = TRUE;
  15598. }
  15599. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15600. {
  15601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15603. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15604. {
  15605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15606. }
  15607. else
  15608. {
  15609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15610. }
  15611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15612. isKnowKey = TRUE;
  15613. }
  15614. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15615. {
  15616. struct sysinfo s_info;
  15617. int error = sysinfo(&s_info);
  15618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15620. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15621. {
  15622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15623. }
  15624. else
  15625. {
  15626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15627. }
  15628. if(error != 0)
  15629. {
  15630. DEBUG_WARN("System uptime get error: %d\n", error);
  15631. }
  15632. else
  15633. {
  15634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15635. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15636. }
  15637. isKnowKey = TRUE;
  15638. }
  15639. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15640. {
  15641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15643. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15644. {
  15645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15646. }
  15647. else
  15648. {
  15649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15650. }
  15651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15652. isKnowKey = TRUE;
  15653. }
  15654. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15655. {
  15656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15658. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15659. {
  15660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15661. }
  15662. else
  15663. {
  15664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15665. }
  15666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15667. isKnowKey = TRUE;
  15668. }
  15669. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15670. {
  15671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15673. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15674. {
  15675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15676. }
  15677. else
  15678. {
  15679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15680. }
  15681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15682. isKnowKey = TRUE;
  15683. }
  15684. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15685. {
  15686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15688. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15689. {
  15690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15691. }
  15692. else
  15693. {
  15694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15695. }
  15696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15697. isKnowKey = TRUE;
  15698. }
  15699. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15700. {
  15701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15703. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15704. {
  15705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15706. }
  15707. else
  15708. {
  15709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15710. }
  15711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15712. isKnowKey = TRUE;
  15713. }
  15714. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15715. {
  15716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15718. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15719. {
  15720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15721. }
  15722. else
  15723. {
  15724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15725. }
  15726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15727. isKnowKey = TRUE;
  15728. }
  15729. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15730. {
  15731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15733. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15734. {
  15735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15736. }
  15737. else
  15738. {
  15739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15740. }
  15741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15742. isKnowKey = TRUE;
  15743. }
  15744. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15745. {
  15746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15748. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15749. {
  15750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15751. }
  15752. else
  15753. {
  15754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15755. }
  15756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15757. isKnowKey = TRUE;
  15758. }
  15759. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15760. {
  15761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15763. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15764. {
  15765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15766. }
  15767. else
  15768. {
  15769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15770. }
  15771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15772. isKnowKey = TRUE;
  15773. }
  15774. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  15775. {
  15776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  15777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  15778. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  15779. {
  15780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  15781. }
  15782. else
  15783. {
  15784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  15785. }
  15786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  15787. isKnowKey = TRUE;
  15788. }
  15789. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15790. {
  15791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15793. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15794. {
  15795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15796. }
  15797. else
  15798. {
  15799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15800. }
  15801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15802. isKnowKey = TRUE;
  15803. }
  15804. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  15805. {
  15806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  15807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  15808. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  15809. {
  15810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  15811. }
  15812. else
  15813. {
  15814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  15815. }
  15816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  15817. isKnowKey = TRUE;
  15818. }
  15819. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  15820. {
  15821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  15822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  15823. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  15824. {
  15825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  15826. }
  15827. else
  15828. {
  15829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  15830. }
  15831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  15832. isKnowKey = TRUE;
  15833. }
  15834. if(isEmpty || strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
  15835. {
  15836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
  15837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
  15838. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  15839. {
  15840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
  15841. }
  15842. else
  15843. {
  15844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
  15845. }
  15846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
  15847. isKnowKey = TRUE;
  15848. }
  15849. if(isEmpty || strcmp(keyReq, "RfidEndianType") == 0 )
  15850. {
  15851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_RfidEndianType].Item, "RfidEndianType");
  15852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Key, "RfidEndianType");
  15853. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  15854. {
  15855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "0"/*"FALSE"*/);
  15856. }
  15857. else
  15858. {
  15859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "1"/*"TRUE"*/);
  15860. }
  15861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Value, (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE"));
  15862. isKnowKey = TRUE;
  15863. }
  15864. if(isEmpty || strcmp(keyReq, "AuthorizeTimeout") == 0 )
  15865. {
  15866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeTimeout].Item, "AuthorizeTimeout");
  15867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Key, "AuthorizeTimeout");
  15868. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  15869. {
  15870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "0"/*"FALSE"*/);
  15871. }
  15872. else
  15873. {
  15874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "1"/*"TRUE"*/);
  15875. }
  15876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  15877. isKnowKey = TRUE;
  15878. }
  15879. if(isEmpty || strcmp(keyReq, "Enable15118") == 0 )
  15880. {
  15881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_Enable15118].Item, "Enable15118");
  15882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].Key, "Enable15118");
  15883. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility == 1)
  15884. {
  15885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].ReadOnly, "0"/*"FALSE"*/);
  15886. }
  15887. else
  15888. {
  15889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].ReadOnly, "1"/*"TRUE"*/);
  15890. }
  15891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_Enable15118].Value, (ShmSysConfigAndInfo->SysConfig.isEnable15118==1?"TRUE":"FALSE"));
  15892. isKnowKey = TRUE;
  15893. }
  15894. if(isEmpty || strcmp(keyReq, "WifiSsid") == 0 )
  15895. {
  15896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WifiSsid].Item, "WifiSsid");
  15897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiSsid].Key, "WifiSsid");
  15898. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility == 1)
  15899. {
  15900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiSsid].ReadOnly, "0"/*"FALSE"*/);
  15901. }
  15902. else
  15903. {
  15904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiSsid].ReadOnly, "1"/*"TRUE"*/);
  15905. }
  15906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiSsid].Value, (const char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
  15907. isKnowKey = TRUE;
  15908. }
  15909. if(isEmpty || strcmp(keyReq, "WifiPassword") == 0 )
  15910. {
  15911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WifiPassword].Item, "WifiPassword");
  15912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiPassword].Key, "WifiPassword");
  15913. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility == 1)
  15914. {
  15915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiPassword].ReadOnly, "0"/*"FALSE"*/);
  15916. }
  15917. else
  15918. {
  15919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiPassword].ReadOnly, "1"/*"TRUE"*/);
  15920. }
  15921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WifiPassword].Value, (const char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
  15922. isKnowKey = TRUE;
  15923. }
  15924. if(isEmpty || strcmp(keyReq, "StopChargingByButton") == 0 )
  15925. {
  15926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopChargingByButton].Item, "StopChargingByButton");
  15927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopChargingByButton].Key, "StopChargingByButton");
  15928. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility == 1)
  15929. {
  15930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopChargingByButton].ReadOnly, "0"/*"FALSE"*/);
  15931. }
  15932. else
  15933. {
  15934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopChargingByButton].ReadOnly, "1"/*"TRUE"*/);
  15935. }
  15936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopChargingByButton].Value, (ShmSysConfigAndInfo->SysConfig.StopChargingByButton==1?"TRUE":"FALSE"));
  15937. isKnowKey = TRUE;
  15938. }
  15939. #if 1
  15940. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15941. {
  15942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15944. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15945. {
  15946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15947. }
  15948. else
  15949. {
  15950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15951. }
  15952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15953. isKnowKey = TRUE;
  15954. }
  15955. #endif
  15956. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15957. {
  15958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15960. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15961. {
  15962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15963. }
  15964. else
  15965. {
  15966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15967. }
  15968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15969. isKnowKey = TRUE;
  15970. }
  15971. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15972. {
  15973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15975. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15976. {
  15977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15978. }
  15979. else
  15980. {
  15981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15982. }
  15983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15984. isKnowKey = TRUE;
  15985. }
  15986. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15987. {
  15988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15990. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15991. {
  15992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15993. }
  15994. else
  15995. {
  15996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15997. }
  15998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15999. isKnowKey = TRUE;
  16000. }
  16001. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16002. {
  16003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16005. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16006. {
  16007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16008. }
  16009. else
  16010. {
  16011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16012. }
  16013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16014. isKnowKey = TRUE;
  16015. }
  16016. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16017. {
  16018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16020. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16021. {
  16022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16023. }
  16024. else
  16025. {
  16026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16027. }
  16028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16029. isKnowKey = TRUE;
  16030. }
  16031. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16032. {
  16033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16035. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16036. {
  16037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16038. }
  16039. else
  16040. {
  16041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16042. }
  16043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16044. isKnowKey = TRUE;
  16045. }
  16046. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16047. {
  16048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16050. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16051. {
  16052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16053. }
  16054. else
  16055. {
  16056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16057. }
  16058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16059. isKnowKey = TRUE;
  16060. }
  16061. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16062. {
  16063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16065. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16066. {
  16067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16068. }
  16069. else
  16070. {
  16071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16072. }
  16073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16074. isKnowKey = TRUE;
  16075. }
  16076. //=========================================================
  16077. if(!isEmpty && !isKnowKey)
  16078. {
  16079. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16080. strcpy(unknownkey[UnknownKeynum], keyReq);
  16081. UnknownKeynum = UnknownKeynum + 1;
  16082. }
  16083. }
  16084. void processUnkownKey(void)
  16085. {
  16086. DEBUG_INFO("processUnkownKey...\n");
  16087. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16088. for(int index=0; index < UnknownKeynum; index++)
  16089. {
  16090. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16091. {
  16092. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16093. }
  16094. }
  16095. }
  16096. int setKeyValue(char *key, char *value)
  16097. {
  16098. int isSuccess = NotSupported;
  16099. int check_ascii=0;
  16100. char str[501]={0};
  16101. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16102. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16103. {
  16104. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16105. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16106. {
  16107. strcpy(str, (const char*)value);
  16108. for(int i = 0; str[i]; i++){
  16109. str[i] = tolower(str[i]);
  16110. }
  16111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16112. isSuccess = ConfigurationStatus_Accepted;
  16113. }
  16114. else
  16115. {
  16116. isSuccess = ConfigurationStatus_Rejected;
  16117. }
  16118. }
  16119. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16120. {
  16121. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16122. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16123. {
  16124. strcpy(str, (const char*)value);
  16125. for(int i = 0; str[i]; i++){
  16126. str[i] = tolower(str[i]);
  16127. }
  16128. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16129. isSuccess = ConfigurationStatus_Accepted;
  16130. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  16131. }
  16132. else
  16133. {
  16134. isSuccess = ConfigurationStatus_Rejected;
  16135. }
  16136. }
  16137. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16138. {
  16139. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16140. {
  16141. strcpy(str, (const char*)value);
  16142. for(int i = 0; str[i]; i++)
  16143. {
  16144. str[i] = tolower(str[i]);
  16145. }
  16146. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16148. isSuccess = ConfigurationStatus_Accepted;
  16149. }
  16150. else
  16151. {
  16152. isSuccess = ConfigurationStatus_Rejected;
  16153. }
  16154. }
  16155. if(strcmp(key, "BlinkRepeat") == 0)
  16156. {
  16157. //Charger.BlinkRepeat = Integer.parseInt(value);
  16158. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16159. {
  16160. check_ascii = value[0];
  16161. if( (check_ascii < 48) || (check_ascii > 57) )
  16162. {
  16163. isSuccess = ConfigurationStatus_Rejected;
  16164. }
  16165. else
  16166. {
  16167. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16168. isSuccess = ConfigurationStatus_Accepted;
  16169. }
  16170. }
  16171. else
  16172. {
  16173. isSuccess = ConfigurationStatus_Rejected;
  16174. }
  16175. }
  16176. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16177. {
  16178. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16179. {
  16180. check_ascii = value[0];
  16181. if( (check_ascii < 48) || (check_ascii > 57) )
  16182. {
  16183. isSuccess = ConfigurationStatus_Rejected;
  16184. }
  16185. else
  16186. {
  16187. if((atoi(value) == 0) || (atoi(value) >= 5))
  16188. {
  16189. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16190. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16191. isSuccess = ConfigurationStatus_Accepted;
  16192. }
  16193. else
  16194. isSuccess = ConfigurationStatus_Rejected;
  16195. }
  16196. }
  16197. else
  16198. {
  16199. isSuccess = ConfigurationStatus_Rejected;
  16200. }
  16201. }
  16202. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16203. {
  16204. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16205. {
  16206. check_ascii = value[0];
  16207. if( (check_ascii < 48) || (check_ascii > 57) )
  16208. {
  16209. isSuccess = ConfigurationStatus_Rejected;
  16210. }
  16211. else
  16212. {
  16213. if((atoi(value) >= 30) && (atoi(value) <= 3600))
  16214. {
  16215. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16216. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16217. isSuccess = ConfigurationStatus_Accepted;
  16218. }
  16219. else
  16220. isSuccess = ConfigurationStatus_Rejected;
  16221. }
  16222. }
  16223. else
  16224. {
  16225. isSuccess = ConfigurationStatus_Rejected;
  16226. }
  16227. }
  16228. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16229. {
  16230. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16231. {
  16232. check_ascii = value[0];
  16233. if( (check_ascii < 48) || (check_ascii > 57) )
  16234. {
  16235. isSuccess = ConfigurationStatus_Rejected;
  16236. }
  16237. else
  16238. {
  16239. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16240. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16241. isSuccess = ConfigurationStatus_Accepted;
  16242. }
  16243. }
  16244. else
  16245. {
  16246. isSuccess = ConfigurationStatus_Rejected;
  16247. }
  16248. }
  16249. if(strcmp(key, "HeartbeatInterval") == 0)
  16250. {
  16251. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16252. {
  16253. check_ascii = value[0];
  16254. if( (check_ascii < 48) || (check_ascii > 57) )
  16255. {
  16256. isSuccess = ConfigurationStatus_Rejected;
  16257. }
  16258. else
  16259. {
  16260. if((atoi(value) == 0) || (atoi(value) >= 10))
  16261. {
  16262. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16263. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16264. HeartBeatWaitTime = atoi(value);
  16265. isSuccess = ConfigurationStatus_Accepted;
  16266. }
  16267. else
  16268. {
  16269. isSuccess = ConfigurationStatus_Rejected;
  16270. }
  16271. }
  16272. }
  16273. else
  16274. {
  16275. isSuccess = ConfigurationStatus_Rejected;
  16276. }
  16277. }
  16278. if(strcmp(key, "LightIntensity") == 0)
  16279. {
  16280. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16281. {
  16282. check_ascii = value[0];
  16283. if( (check_ascii < 48) || (check_ascii > 57) )
  16284. {
  16285. isSuccess = ConfigurationStatus_Rejected;
  16286. }
  16287. else
  16288. {
  16289. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16290. isSuccess = ConfigurationStatus_Accepted;
  16291. }
  16292. }
  16293. else
  16294. {
  16295. isSuccess = ConfigurationStatus_Rejected;
  16296. }
  16297. }
  16298. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16299. {
  16300. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16301. {
  16302. strcpy(str, (const char*)value);
  16303. for(int i = 0; str[i]; i++)
  16304. {
  16305. str[i] = tolower(str[i]);
  16306. }
  16307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16308. isSuccess = ConfigurationStatus_Accepted;
  16309. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16310. }
  16311. else
  16312. {
  16313. isSuccess = ConfigurationStatus_Rejected;
  16314. }
  16315. }
  16316. if(strcmp(key, "LocalPreAuthorize") == 0)
  16317. {
  16318. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16319. {
  16320. strcpy(str, (const char*)value);
  16321. for(int i = 0; str[i]; i++)
  16322. {
  16323. str[i] = tolower(str[i]);
  16324. }
  16325. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16326. isSuccess = ConfigurationStatus_Accepted;
  16327. }
  16328. else
  16329. {
  16330. isSuccess = ConfigurationStatus_Rejected;
  16331. }
  16332. }
  16333. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16334. {
  16335. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16336. {
  16337. check_ascii = value[0];
  16338. if( (check_ascii < 48) || (check_ascii > 57) )
  16339. {
  16340. isSuccess = ConfigurationStatus_Rejected;
  16341. }
  16342. else
  16343. {
  16344. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16345. isSuccess = ConfigurationStatus_Accepted;
  16346. }
  16347. }
  16348. else
  16349. {
  16350. isSuccess = ConfigurationStatus_Rejected;
  16351. }
  16352. }
  16353. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16354. {
  16355. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16356. {
  16357. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16358. isSuccess = ConfigurationStatus_Accepted;
  16359. }
  16360. else
  16361. {
  16362. isSuccess = ConfigurationStatus_Rejected;
  16363. }
  16364. }
  16365. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16366. {
  16367. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16368. {
  16369. check_ascii = value[0];
  16370. if( (check_ascii < 48) || (check_ascii > 57) )
  16371. {
  16372. isSuccess = ConfigurationStatus_Rejected;
  16373. }
  16374. else
  16375. {
  16376. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16377. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16378. isSuccess = ConfigurationStatus_Accepted;
  16379. }
  16380. }
  16381. else
  16382. {
  16383. isSuccess = ConfigurationStatus_Rejected;
  16384. }
  16385. }
  16386. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16387. {
  16388. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16389. {
  16390. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16391. isSuccess = ConfigurationStatus_Accepted;
  16392. }
  16393. else
  16394. {
  16395. isSuccess = ConfigurationStatus_Rejected;
  16396. }
  16397. }
  16398. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16399. {
  16400. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16401. {
  16402. check_ascii = value[0];
  16403. if( (check_ascii < 48) || (check_ascii > 57) )
  16404. {
  16405. isSuccess = ConfigurationStatus_Rejected;
  16406. }
  16407. else
  16408. {
  16409. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16410. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16411. isSuccess = ConfigurationStatus_Accepted;
  16412. }
  16413. }
  16414. else
  16415. {
  16416. isSuccess = ConfigurationStatus_Rejected;
  16417. }
  16418. }
  16419. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16420. {
  16421. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16422. {
  16423. check_ascii = value[0];
  16424. if( (check_ascii < 48) || (check_ascii > 57) )
  16425. {
  16426. isSuccess = ConfigurationStatus_Rejected;
  16427. }
  16428. else
  16429. {
  16430. if((atoi(value) == 0) || (atoi(value) >= 3))
  16431. {
  16432. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16433. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16434. isSuccess = ConfigurationStatus_Accepted;
  16435. }
  16436. else
  16437. {
  16438. isSuccess = ConfigurationStatus_Rejected;
  16439. }
  16440. }
  16441. }
  16442. else
  16443. {
  16444. isSuccess = ConfigurationStatus_Rejected;
  16445. }
  16446. }
  16447. if(strcmp(key, "MinimumStatusDuration") == 0)
  16448. {
  16449. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16450. {
  16451. check_ascii = value[0];
  16452. if( (check_ascii < 48) || (check_ascii > 57) )
  16453. {
  16454. isSuccess = ConfigurationStatus_Rejected;
  16455. }
  16456. else
  16457. {
  16458. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16459. {
  16460. isSuccess = ConfigurationStatus_Rejected;
  16461. }
  16462. else
  16463. {
  16464. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16465. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16466. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16467. isSuccess = ConfigurationStatus_Accepted;
  16468. }
  16469. }
  16470. }
  16471. else
  16472. {
  16473. isSuccess = ConfigurationStatus_Rejected;
  16474. }
  16475. }
  16476. if(strcmp(key, "NumberOfConnectors") == 0)
  16477. {
  16478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16479. {
  16480. check_ascii = value[0];
  16481. if( (check_ascii < 48) || (check_ascii > 57) )
  16482. {
  16483. isSuccess = ConfigurationStatus_Rejected;
  16484. }
  16485. else
  16486. {
  16487. //Charger.ResetRetries = Integer.parseInt(value);
  16488. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16489. isSuccess = ConfigurationStatus_Accepted;
  16490. }
  16491. }
  16492. else
  16493. {
  16494. isSuccess = ConfigurationStatus_Rejected;
  16495. }
  16496. }
  16497. if(strcmp(key, "ResetRetries") == 0)
  16498. {
  16499. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16500. {
  16501. check_ascii = value[0];
  16502. if( (check_ascii < 48) || (check_ascii > 57) )
  16503. {
  16504. isSuccess = ConfigurationStatus_Rejected;
  16505. }
  16506. else
  16507. {
  16508. //Charger.ResetRetries = Integer.parseInt(value);
  16509. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16510. isSuccess = ConfigurationStatus_Accepted;
  16511. }
  16512. }
  16513. else
  16514. {
  16515. isSuccess = ConfigurationStatus_Rejected;
  16516. }
  16517. }
  16518. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16519. {
  16520. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16521. {
  16522. strcpy(str, (const char*)value);
  16523. for(int i = 0; str[i]; i++)
  16524. {
  16525. str[i] = tolower(str[i]);
  16526. }
  16527. if(strcmp(str, "notapplicable")== 0)
  16528. {
  16529. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16530. isSuccess = ConfigurationStatus_Accepted;
  16531. }
  16532. else if(strcmp(str, "unknown")== 0)
  16533. {
  16534. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16535. isSuccess = ConfigurationStatus_Accepted;
  16536. }
  16537. else if(strcmp(str, "rst")== 0)
  16538. {
  16539. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16540. isSuccess = ConfigurationStatus_Accepted;
  16541. }
  16542. else if(strcmp(str, "rts")== 0)
  16543. {
  16544. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16545. isSuccess = ConfigurationStatus_Accepted;
  16546. }
  16547. else if(strcmp(str, "srt")== 0)
  16548. {
  16549. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16550. isSuccess = ConfigurationStatus_Accepted;
  16551. }
  16552. else if(strcmp(str, "str")== 0)
  16553. {
  16554. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16555. isSuccess = ConfigurationStatus_Accepted;
  16556. }
  16557. else if(strcmp(str, "trs")== 0)
  16558. {
  16559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16560. isSuccess = ConfigurationStatus_Accepted;
  16561. }
  16562. else if(strcmp(str, "tsr")== 0)
  16563. {
  16564. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16565. isSuccess = ConfigurationStatus_Accepted;
  16566. }
  16567. else
  16568. {
  16569. isSuccess = ConfigurationStatus_Rejected;
  16570. }
  16571. }
  16572. else
  16573. {
  16574. isSuccess = ConfigurationStatus_Rejected;
  16575. }
  16576. }
  16577. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16578. {
  16579. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16580. {
  16581. check_ascii = value[0];
  16582. if( (check_ascii < 48) || (check_ascii > 57) )
  16583. {
  16584. isSuccess = ConfigurationStatus_Rejected;
  16585. }
  16586. else
  16587. {
  16588. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16589. isSuccess = ConfigurationStatus_Accepted;
  16590. }
  16591. }
  16592. else
  16593. {
  16594. isSuccess = ConfigurationStatus_Rejected;
  16595. }
  16596. }
  16597. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16598. {
  16599. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16600. {
  16601. strcpy(str, (const char*)value);
  16602. for(int i = 0; str[i]; i++)
  16603. {
  16604. str[i] = tolower(str[i]);
  16605. }
  16606. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16607. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16608. isSuccess = ConfigurationStatus_Accepted;
  16609. }
  16610. else
  16611. {
  16612. isSuccess = ConfigurationStatus_Rejected;
  16613. }
  16614. }
  16615. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16616. {
  16617. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16618. {
  16619. strcpy(str, (const char*)value);
  16620. for(int i = 0; str[i]; i++)
  16621. {
  16622. str[i] = tolower(str[i]);
  16623. }
  16624. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16625. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16626. isSuccess = ConfigurationStatus_Accepted;
  16627. }
  16628. else
  16629. {
  16630. isSuccess = ConfigurationStatus_Rejected;
  16631. }
  16632. }
  16633. if(strcmp(key, "StopTxnAlignedData") == 0)
  16634. {
  16635. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16636. {
  16637. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16638. isSuccess = ConfigurationStatus_Accepted;
  16639. }
  16640. else
  16641. {
  16642. isSuccess = ConfigurationStatus_Rejected;
  16643. }
  16644. }
  16645. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16646. {
  16647. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16648. {
  16649. check_ascii = value[0];
  16650. if( (check_ascii < 48) || (check_ascii > 57) )
  16651. {
  16652. isSuccess = ConfigurationStatus_Rejected;
  16653. }
  16654. else
  16655. {
  16656. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16657. isSuccess = ConfigurationStatus_Accepted;
  16658. }
  16659. }
  16660. else
  16661. {
  16662. isSuccess = ConfigurationStatus_Rejected;
  16663. }
  16664. }
  16665. if(strcmp(key, "StopTxnSampledData") == 0)
  16666. {
  16667. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16668. {
  16669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16670. isSuccess = ConfigurationStatus_Accepted;
  16671. }
  16672. else
  16673. {
  16674. isSuccess = ConfigurationStatus_Rejected;
  16675. }
  16676. }
  16677. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16678. {
  16679. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16680. {
  16681. check_ascii = value[0];
  16682. if( (check_ascii < 48) || (check_ascii > 57) )
  16683. {
  16684. isSuccess = ConfigurationStatus_Rejected;
  16685. }
  16686. else
  16687. {
  16688. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16689. isSuccess = ConfigurationStatus_Accepted;
  16690. }
  16691. }
  16692. else
  16693. {
  16694. isSuccess = ConfigurationStatus_Rejected;
  16695. }
  16696. }
  16697. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16698. {
  16699. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16700. {
  16701. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16702. isSuccess = ConfigurationStatus_Accepted;
  16703. }
  16704. else
  16705. {
  16706. isSuccess = ConfigurationStatus_Rejected;
  16707. }
  16708. }
  16709. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16710. {
  16711. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16712. {
  16713. check_ascii = value[0];
  16714. if( (check_ascii < 48) || (check_ascii > 57) )
  16715. {
  16716. isSuccess = ConfigurationStatus_Rejected;
  16717. }
  16718. else
  16719. {
  16720. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16721. isSuccess = ConfigurationStatus_Accepted;
  16722. }
  16723. }
  16724. else
  16725. {
  16726. isSuccess = ConfigurationStatus_Rejected;
  16727. }
  16728. }
  16729. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16730. {
  16731. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16732. {
  16733. check_ascii = value[0];
  16734. if( (check_ascii < 48) || (check_ascii > 57) )
  16735. {
  16736. isSuccess = ConfigurationStatus_Rejected;
  16737. }
  16738. else
  16739. {
  16740. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16741. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16742. TransactionMessageAttemptsValue = atoi(value);
  16743. isSuccess = ConfigurationStatus_Accepted;
  16744. }
  16745. }
  16746. else
  16747. {
  16748. isSuccess = ConfigurationStatus_Rejected;
  16749. }
  16750. }
  16751. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16752. {
  16753. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16754. {
  16755. check_ascii = value[0];
  16756. if( (check_ascii < 48) || (check_ascii > 57) )
  16757. {
  16758. isSuccess = ConfigurationStatus_Rejected;
  16759. }
  16760. else
  16761. {
  16762. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16763. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16764. TransactionMessageRetryIntervalValue = atoi(value);
  16765. isSuccess = ConfigurationStatus_Accepted;
  16766. }
  16767. }
  16768. else
  16769. {
  16770. isSuccess = ConfigurationStatus_Rejected;
  16771. }
  16772. }
  16773. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16774. {
  16775. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16776. {
  16777. strcpy(str, (const char*)value);
  16778. for(int i = 0; str[i]; i++)
  16779. {
  16780. str[i] = tolower(str[i]);
  16781. }
  16782. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16784. isSuccess = ConfigurationStatus_Accepted;
  16785. }
  16786. else
  16787. {
  16788. isSuccess = ConfigurationStatus_Rejected;
  16789. }
  16790. }
  16791. if(strcmp(key, "WebSocketPingInterval") == 0)
  16792. {
  16793. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16794. {
  16795. check_ascii = value[0];
  16796. if( (check_ascii < 48) || (check_ascii > 57) )
  16797. {
  16798. isSuccess = ConfigurationStatus_Rejected;
  16799. }
  16800. else
  16801. {
  16802. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16803. isSuccess = ConfigurationStatus_Accepted;
  16804. if((atoi(value) == 0) || (atoi(value) >= 10))
  16805. {
  16806. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16807. isSuccess = ConfigurationStatus_Accepted;
  16808. }
  16809. else
  16810. isSuccess = ConfigurationStatus_Rejected;
  16811. }
  16812. }
  16813. else
  16814. {
  16815. isSuccess = ConfigurationStatus_Rejected;
  16816. }
  16817. }
  16818. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16819. {
  16820. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16821. {
  16822. strcpy(str, (const char*)value);
  16823. for(int i = 0; str[i]; i++)
  16824. {
  16825. str[i] = tolower(str[i]);
  16826. }
  16827. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16828. isSuccess = ConfigurationStatus_Accepted;
  16829. }
  16830. else
  16831. {
  16832. isSuccess = ConfigurationStatus_Rejected;
  16833. }
  16834. }
  16835. if(strcmp(key, "AuthorizationKey") == 0)
  16836. {
  16837. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16838. {
  16839. strcpy(str, (const char*)value);
  16840. int strlength = strlen(str);
  16841. char capture[3];
  16842. char stackItem = 0;
  16843. char password[21] = {0};
  16844. printf("String length: %d\n", strlength);
  16845. for(int idx=0; idx<(strlength/2); idx++)
  16846. {
  16847. capture[0] = str[(idx*2)];
  16848. capture[1] = str[(idx*2)+1];
  16849. capture[2] = 0;
  16850. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  16851. sprintf(password,"%s%c", password, stackItem);
  16852. }
  16853. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  16854. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16855. isSuccess = ConfigurationStatus_Accepted;
  16856. }
  16857. else
  16858. {
  16859. isSuccess = ConfigurationStatus_Rejected;
  16860. }
  16861. }
  16862. if(strcmp(key, "SecurityProfile") == 0)
  16863. {
  16864. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16865. {
  16866. check_ascii = value[0];
  16867. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16868. {
  16869. isSuccess = ConfigurationStatus_Rejected;
  16870. }
  16871. else if(check_ascii == 0x33)
  16872. {
  16873. isSuccess = NotSupported;
  16874. }
  16875. else
  16876. {
  16877. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16878. {
  16879. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16880. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16881. isSuccess = ConfigurationStatus_Accepted;
  16882. }
  16883. else
  16884. isSuccess = ConfigurationStatus_Rejected;
  16885. }
  16886. }
  16887. else
  16888. {
  16889. isSuccess = ConfigurationStatus_Rejected;
  16890. }
  16891. }
  16892. if(strcmp(key, "DefaultPrice") == 0)
  16893. {
  16894. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16895. {
  16896. strcpy(str, (const char*)value);
  16897. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16898. isSuccess = ConfigurationStatus_Accepted;
  16899. }
  16900. else
  16901. {
  16902. isSuccess = ConfigurationStatus_Rejected;
  16903. }
  16904. }
  16905. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16906. {
  16907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16908. {
  16909. strcpy(str, (const char*)value);
  16910. for(int i = 0; str[i]; i++)
  16911. {
  16912. str[i] = tolower(str[i]);
  16913. }
  16914. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16915. isSuccess = ConfigurationStatus_Accepted;
  16916. }
  16917. else
  16918. {
  16919. isSuccess = ConfigurationStatus_Rejected;
  16920. }
  16921. }
  16922. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16923. {
  16924. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16925. {
  16926. strcpy(str, (const char*)value);
  16927. for(int i = 0; str[i]; i++)
  16928. {
  16929. str[i] = tolower(str[i]);
  16930. }
  16931. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16932. isSuccess = ConfigurationStatus_Accepted;
  16933. }
  16934. else
  16935. {
  16936. isSuccess = ConfigurationStatus_Rejected;
  16937. }
  16938. }
  16939. if(strcmp(key, "SystemUptimeSec") == 0)
  16940. {
  16941. isSuccess = NotSupported;
  16942. }
  16943. if(strcmp(key, "FreeVend") == 0)
  16944. {
  16945. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16946. {
  16947. strcpy(str, (const char*)value);
  16948. for(int i = 0; str[i]; i++)
  16949. {
  16950. str[i] = tolower(str[i]);
  16951. }
  16952. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16953. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16954. isSuccess = ConfigurationStatus_Accepted;
  16955. }
  16956. else
  16957. {
  16958. isSuccess = ConfigurationStatus_Rejected;
  16959. }
  16960. }
  16961. if(strcmp(key, "FreeVendIdtag") == 0)
  16962. {
  16963. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16964. {
  16965. strcpy(str, (const char*)value);
  16966. if(strlen(str) <= 20)
  16967. {
  16968. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16969. isSuccess = ConfigurationStatus_Accepted;
  16970. }
  16971. else
  16972. {
  16973. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16974. isSuccess = ConfigurationStatus_Rejected;
  16975. }
  16976. }
  16977. else
  16978. {
  16979. isSuccess = ConfigurationStatus_Rejected;
  16980. }
  16981. }
  16982. if(strcmp(key, "OcppServer") == 0)
  16983. {
  16984. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16985. {
  16986. strcpy(str, (const char*)value);
  16987. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16988. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16989. isSuccess = ConfigurationStatus_Accepted;
  16990. }
  16991. else
  16992. {
  16993. isSuccess = ConfigurationStatus_Rejected;
  16994. }
  16995. }
  16996. if(strcmp(key, "MaintainServer") == 0)
  16997. {
  16998. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16999. {
  17000. strcpy(str, (const char*)value);
  17001. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17002. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17003. isSuccess = ConfigurationStatus_Accepted;
  17004. }
  17005. else
  17006. {
  17007. isSuccess = ConfigurationStatus_Rejected;
  17008. }
  17009. }
  17010. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17011. {
  17012. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17013. {
  17014. strcpy(str, (const char*)value);
  17015. for(int i = 0; str[i]; i++)
  17016. {
  17017. str[i] = tolower(str[i]);
  17018. }
  17019. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17020. isSuccess = ConfigurationStatus_Accepted;
  17021. }
  17022. else
  17023. {
  17024. isSuccess = ConfigurationStatus_Rejected;
  17025. }
  17026. }
  17027. if(strcmp(key, "StatusNotificationInterval") == 0)
  17028. {
  17029. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17030. {
  17031. check_ascii = value[0];
  17032. if( (check_ascii < 48) || (check_ascii > 57) )
  17033. {
  17034. isSuccess = ConfigurationStatus_Rejected;
  17035. }
  17036. else
  17037. {
  17038. if((atoi(value) == 0) || (atoi(value) >= 10))
  17039. {
  17040. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17041. isSuccess = ConfigurationStatus_Accepted;
  17042. }
  17043. else
  17044. isSuccess = ConfigurationStatus_Rejected;
  17045. }
  17046. }
  17047. else
  17048. {
  17049. isSuccess = ConfigurationStatus_Rejected;
  17050. }
  17051. }
  17052. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17053. {
  17054. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17055. {
  17056. check_ascii = value[0];
  17057. if( (check_ascii < 48) || (check_ascii > 57) )
  17058. {
  17059. isSuccess = ConfigurationStatus_Rejected;
  17060. }
  17061. else
  17062. {
  17063. if(atoi(value) >= 0)
  17064. {
  17065. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  17066. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17067. isSuccess = ConfigurationStatus_Accepted;
  17068. }
  17069. else
  17070. isSuccess = ConfigurationStatus_Rejected;
  17071. }
  17072. }
  17073. else
  17074. {
  17075. isSuccess = ConfigurationStatus_Rejected;
  17076. }
  17077. }
  17078. if(strcmp(key, "PowerSharingServerIP") == 0)
  17079. {
  17080. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17081. {
  17082. strcpy(str, (const char*)value);
  17083. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17084. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17085. isSuccess = ConfigurationStatus_Accepted;
  17086. }
  17087. else
  17088. {
  17089. isSuccess = ConfigurationStatus_Rejected;
  17090. }
  17091. }
  17092. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17093. {
  17094. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17095. {
  17096. strcpy(str, (const char*)value);
  17097. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17098. isSuccess = ConfigurationStatus_Accepted;
  17099. }
  17100. else
  17101. {
  17102. isSuccess = ConfigurationStatus_Rejected;
  17103. }
  17104. }
  17105. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17106. {
  17107. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17108. {
  17109. if(atoi(value) > modelnameInfo.ratedPower)
  17110. {
  17111. isSuccess = ConfigurationStatus_Rejected;
  17112. }
  17113. else{
  17114. strcpy(str, (const char*)value);
  17115. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17116. isSuccess = ConfigurationStatus_Accepted;
  17117. }
  17118. }
  17119. else
  17120. {
  17121. isSuccess = ConfigurationStatus_Rejected;
  17122. }
  17123. }
  17124. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  17125. {
  17126. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17127. {
  17128. if((atoi(value) != 0) && (atoi(value) < 5))
  17129. {
  17130. isSuccess = ConfigurationStatus_Rejected;
  17131. }
  17132. else{
  17133. strcpy(str, (const char*)value);
  17134. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  17135. isSuccess = ConfigurationStatus_Accepted;
  17136. }
  17137. }
  17138. else
  17139. {
  17140. isSuccess = ConfigurationStatus_Rejected;
  17141. }
  17142. }
  17143. if(strcmp(key, "OcppSoftwareVersion") == 0)
  17144. {
  17145. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17146. {
  17147. strcpy(str, (const char*)value);
  17148. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str );
  17149. isSuccess = ConfigurationStatus_Accepted;
  17150. }
  17151. else
  17152. {
  17153. isSuccess = ConfigurationStatus_Rejected;
  17154. }
  17155. }
  17156. if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
  17157. {
  17158. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  17159. {
  17160. strcpy(str, (const char*)value);
  17161. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", str );
  17162. isSuccess = ConfigurationStatus_Accepted;
  17163. }
  17164. else
  17165. {
  17166. isSuccess = ConfigurationStatus_Rejected;
  17167. }
  17168. }
  17169. if(strcmp(key, "RfidEndianType") == 0)
  17170. {
  17171. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  17172. {
  17173. strcpy(str, (const char*)value);
  17174. for(int i = 0; str[i]; i++)
  17175. {
  17176. str[i] = tolower(str[i]);
  17177. }
  17178. if((strcmp(str, "big")==0) || (strcmp(str, "little")==0))
  17179. {
  17180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "%s", str);
  17181. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strcmp(str, "big")==0)?1:0;
  17182. isSuccess = ConfigurationStatus_Accepted;
  17183. }
  17184. else
  17185. isSuccess = ConfigurationStatus_Rejected;
  17186. }
  17187. else
  17188. {
  17189. isSuccess = ConfigurationStatus_Rejected;
  17190. }
  17191. }
  17192. if(strcmp(key, "AuthorizeTimeout") == 0)
  17193. {
  17194. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  17195. {
  17196. check_ascii = value[0];
  17197. if((check_ascii < 48) || (check_ascii > 57))
  17198. {
  17199. isSuccess = ConfigurationStatus_Rejected;
  17200. }
  17201. else
  17202. {
  17203. if((atoi(value) >= 10) && (atoi(value) <= 300))
  17204. {
  17205. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%d", atoi(value));
  17206. isSuccess = ConfigurationStatus_Accepted;
  17207. }
  17208. else
  17209. {
  17210. isSuccess = ConfigurationStatus_Rejected;
  17211. }
  17212. }
  17213. }
  17214. else
  17215. {
  17216. isSuccess = ConfigurationStatus_Rejected;
  17217. }
  17218. }
  17219. if(strcmp(key, "Enable15118") == 0)
  17220. {
  17221. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemAccessibility == 1)
  17222. {
  17223. strcpy(str, (const char*)value);
  17224. for(int i = 0; str[i]; i++)
  17225. {
  17226. str[i] = tolower(str[i]);
  17227. }
  17228. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  17229. {
  17230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[Enable15118].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  17231. ShmSysConfigAndInfo->SysConfig.isEnable15118 = (strcmp(str, "true")==0)?1:0;
  17232. isSuccess = ConfigurationStatus_Accepted;
  17233. }
  17234. else
  17235. isSuccess = ConfigurationStatus_Rejected;
  17236. }
  17237. else
  17238. {
  17239. isSuccess = ConfigurationStatus_Rejected;
  17240. }
  17241. }
  17242. if(strcmp(key, "WifiSsid") == 0)
  17243. {
  17244. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemAccessibility == 1)
  17245. {
  17246. strcpy(str, (const char*)value);
  17247. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemData, str);
  17248. sprintf((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiSsid].ItemData);
  17249. isSuccess = ConfigurationStatus_Accepted;
  17250. }
  17251. else
  17252. {
  17253. isSuccess = ConfigurationStatus_Rejected;
  17254. }
  17255. }
  17256. if(strcmp(key, "WifiPassword") == 0)
  17257. {
  17258. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemAccessibility == 1)
  17259. {
  17260. strcpy(str, (const char*)value);
  17261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemData, str);
  17262. sprintf((char *)ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WifiPassword].ItemData);
  17263. isSuccess = ConfigurationStatus_Accepted;
  17264. }
  17265. else
  17266. {
  17267. isSuccess = ConfigurationStatus_Rejected;
  17268. }
  17269. }
  17270. if(strcmp(key, "StopChargingByButton") == 0)
  17271. {
  17272. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemAccessibility == 1)
  17273. {
  17274. strcpy(str, (const char*)value);
  17275. for(int i = 0; str[i]; i++)
  17276. {
  17277. str[i] = tolower(str[i]);
  17278. }
  17279. if((strcmp(str, "true")==0) || (strcmp(str, "false")==0))
  17280. {
  17281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopChargingByButton].ItemData, "%s", (strcmp(str, "true")==0)?"TRUE":"FALSE");
  17282. ShmSysConfigAndInfo->SysConfig.StopChargingByButton = (strcmp(str, "true")==0)?1:0;
  17283. isSuccess = ConfigurationStatus_Accepted;
  17284. }
  17285. else
  17286. isSuccess = ConfigurationStatus_Rejected;
  17287. }
  17288. else
  17289. {
  17290. isSuccess = ConfigurationStatus_Rejected;
  17291. }
  17292. }
  17293. #if 0
  17294. //For OCPP Test Case
  17295. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17296. {
  17297. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17298. {
  17299. strcpy(str, (const char*)value);
  17300. for(int i = 0; str[i]; i++)
  17301. {
  17302. str[i] = tolower(str[i]);
  17303. }
  17304. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17305. isSuccess = ConfigurationStatus_Accepted;
  17306. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17307. }
  17308. else
  17309. {
  17310. isSuccess = ConfigurationStatus_Rejected;
  17311. }
  17312. }
  17313. #endif
  17314. #if 1
  17315. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17316. {
  17317. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17318. {
  17319. strcpy(str, (const char*)value);
  17320. for(int i = 0; str[i]; i++)
  17321. {
  17322. str[i] = tolower(str[i]);
  17323. }
  17324. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17325. isSuccess = ConfigurationStatus_Accepted;
  17326. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17327. }
  17328. else
  17329. {
  17330. isSuccess = ConfigurationStatus_Rejected;
  17331. }
  17332. }
  17333. #endif
  17334. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17335. {
  17336. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17337. {
  17338. check_ascii = value[0];
  17339. if( (check_ascii < 48) || (check_ascii > 57) )
  17340. {
  17341. isSuccess = ConfigurationStatus_Rejected;
  17342. }
  17343. else
  17344. {
  17345. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17346. isSuccess = ConfigurationStatus_Accepted;
  17347. }
  17348. }
  17349. else
  17350. {
  17351. isSuccess = ConfigurationStatus_Rejected;
  17352. }
  17353. }
  17354. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17355. {
  17356. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17357. {
  17358. check_ascii = value[0];
  17359. if( (check_ascii < 48) || (check_ascii > 57) )
  17360. {
  17361. isSuccess = ConfigurationStatus_Rejected;
  17362. }
  17363. else
  17364. {
  17365. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17366. isSuccess = ConfigurationStatus_Accepted;
  17367. }
  17368. }
  17369. else
  17370. {
  17371. isSuccess = ConfigurationStatus_Rejected;
  17372. }
  17373. }
  17374. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17375. {
  17376. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17377. {
  17378. strcpy(str, (const char*)value);
  17379. for(int i = 0; str[i]; i++)
  17380. {
  17381. str[i] = tolower(str[i]);
  17382. }
  17383. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17384. isSuccess = ConfigurationStatus_Accepted;
  17385. }
  17386. else
  17387. {
  17388. isSuccess = ConfigurationStatus_Rejected;
  17389. }
  17390. }
  17391. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17392. {
  17393. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17394. {
  17395. check_ascii = value[0];
  17396. if( (check_ascii < 48) || (check_ascii > 57) )
  17397. {
  17398. isSuccess = ConfigurationStatus_Rejected;
  17399. }
  17400. else
  17401. {
  17402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17403. isSuccess = ConfigurationStatus_Accepted;
  17404. }
  17405. }
  17406. else
  17407. {
  17408. isSuccess = ConfigurationStatus_Rejected;
  17409. }
  17410. }
  17411. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17412. {
  17413. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17414. {
  17415. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17416. isSuccess = ConfigurationStatus_Accepted;
  17417. }
  17418. else
  17419. {
  17420. isSuccess = ConfigurationStatus_Rejected;
  17421. }
  17422. }
  17423. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17424. {
  17425. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17426. {
  17427. check_ascii = value[0];
  17428. if( (check_ascii < 48) || (check_ascii > 57) )
  17429. {
  17430. isSuccess = ConfigurationStatus_Rejected;
  17431. }
  17432. else
  17433. {
  17434. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17435. isSuccess = ConfigurationStatus_Accepted;
  17436. }
  17437. }
  17438. else
  17439. {
  17440. isSuccess = ConfigurationStatus_Rejected;
  17441. }
  17442. }
  17443. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17444. {
  17445. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17446. {
  17447. strcpy(str, (const char*)value);
  17448. for(int i = 0; str[i]; i++)
  17449. {
  17450. str[i] = tolower(str[i]);
  17451. }
  17452. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17453. isSuccess = ConfigurationStatus_Accepted;
  17454. }
  17455. else
  17456. {
  17457. isSuccess = ConfigurationStatus_Rejected;
  17458. }
  17459. }
  17460. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17461. {
  17462. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17463. {
  17464. check_ascii = value[0];
  17465. if( (check_ascii < 48) || (check_ascii > 57) )
  17466. {
  17467. isSuccess = ConfigurationStatus_Rejected;
  17468. }
  17469. else
  17470. {
  17471. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17472. isSuccess = ConfigurationStatus_Accepted;
  17473. }
  17474. }
  17475. else
  17476. {
  17477. isSuccess = ConfigurationStatus_Rejected;
  17478. }
  17479. }
  17480. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17481. return isSuccess;
  17482. }
  17483. int TransactionMessageAttemptsGet(void)
  17484. {
  17485. return TransactionMessageAttemptsValue;
  17486. }
  17487. int FirstHeartBeatResponse(void)
  17488. {
  17489. return FirstHeartBeat;
  17490. }
  17491. int TransactionMessageRetryIntervalGet(void)
  17492. {
  17493. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17494. }
  17495. int ReadHttpStatus(int sock)
  17496. {
  17497. //char c;
  17498. char buff[1024]="",*ptr=buff+1;
  17499. int bytes_received, status;
  17500. DEBUG_INFO("Begin Response ..\n");
  17501. while((bytes_received = recv(sock, ptr, 1, 0))){
  17502. if(bytes_received==-1){
  17503. perror("ReadHttpStatus");
  17504. exit(1);
  17505. }
  17506. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17507. ptr++;
  17508. }
  17509. *ptr=0;
  17510. ptr=buff+1;
  17511. sscanf(ptr,"%*s %d ", &status);
  17512. DEBUG_INFO("%s\n",ptr);
  17513. DEBUG_INFO("status=%d\n",status);
  17514. DEBUG_INFO("End Response ..\n");
  17515. return (bytes_received>0)?status:0;
  17516. }
  17517. //the only filed that it parsed is 'Content-Length'
  17518. int ParseHeader(int sock)
  17519. {
  17520. //char c;
  17521. char buff[1024]="",*ptr=buff+4;
  17522. int bytes_received;
  17523. DEBUG_INFO("Begin HEADER ..\n");
  17524. while((bytes_received = recv(sock, ptr, 1, 0))){
  17525. if(bytes_received==-1){
  17526. perror("Parse Header");
  17527. exit(1);
  17528. }
  17529. if(
  17530. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17531. (ptr[-1]=='\r') && (*ptr=='\n' )
  17532. ) break;
  17533. ptr++;
  17534. }
  17535. *ptr=0;
  17536. ptr=buff+4;
  17537. //printf("%s",ptr);
  17538. if(bytes_received){
  17539. ptr=strstr(ptr,"Content-Length:");
  17540. if(ptr){
  17541. sscanf(ptr,"%*s %d",&bytes_received);
  17542. }else
  17543. bytes_received=-1; //unknown size
  17544. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17545. }
  17546. DEBUG_INFO("End HEADER ..\n");
  17547. return bytes_received ;
  17548. }
  17549. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17550. {
  17551. int result = TRUE;
  17552. char rmFileCmd[300]={0};
  17553. char FilePath[256]={0};
  17554. char ftpbuf[2048];
  17555. int systemresult;
  17556. sprintf(FilePath,"/mnt/%s",filename);
  17557. system("ping 8.8.8.8 &");
  17558. if((access(FilePath,F_OK))!=-1)
  17559. {
  17560. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17561. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17562. system(rmFileCmd);
  17563. }
  17564. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17565. if(strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  17566. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  17567. else
  17568. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17569. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17570. systemresult = system(ftpbuf);
  17571. if(systemresult != 0)
  17572. {
  17573. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17574. result = FALSE;
  17575. }
  17576. system("pkill ping");
  17577. return result;
  17578. }
  17579. int sftpDownLoadFile(char *host, char *user, char *password, int port, char *path, char *filename,char *url)
  17580. {
  17581. int result = TRUE;
  17582. char rmFileCmd[300]={0};
  17583. char FilePath[256]={0};
  17584. char ftpbuf[2048];
  17585. int systemresult;
  17586. sprintf(FilePath,"/mnt/%s",filename);
  17587. system("ping 8.8.8.8 &");
  17588. if((access(FilePath,F_OK))!=-1)
  17589. {
  17590. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17591. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17592. system(rmFileCmd);
  17593. }
  17594. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17595. if(strlen(password)>0)
  17596. sprintf(ftpbuf,"timeout -t 360 sshpass -p '%s' scp -P %d %s@%s:%s%s %s", password, port, user, host, path, filename, FilePath);
  17597. else
  17598. sprintf(ftpbuf,"timeout -t 360 sshpass scp -P %d %s@%s:%s%s %s", port, user, host, path, filename, FilePath);
  17599. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17600. systemresult = system(ftpbuf);
  17601. if(systemresult != 0)
  17602. {
  17603. DEBUG_WARN("sshpass scp error!\n");
  17604. result = FALSE;
  17605. }
  17606. system("pkill ping");
  17607. return result;
  17608. }
  17609. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17610. {
  17611. int result = TRUE;
  17612. char rmFileCmd[300]={0};
  17613. char FilePath[256]={0};
  17614. char ftpbuf[2048];
  17615. int systemresult;
  17616. sprintf(FilePath,"/mnt/%s",filename);
  17617. system("ping 8.8.8.8 &");
  17618. if((access(FilePath,F_OK))!=-1)
  17619. {
  17620. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17621. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17622. system(rmFileCmd);
  17623. }
  17624. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17625. if(strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  17626. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  17627. else
  17628. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17629. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17630. systemresult = system(ftpbuf);
  17631. if(systemresult != 0)
  17632. {
  17633. if(strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  17634. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
  17635. else
  17636. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
  17637. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17638. systemresult = system(ftpbuf);
  17639. if(systemresult != 0)
  17640. {
  17641. DEBUG_WARN("FTP download fail!\n");
  17642. result = FALSE;
  17643. }
  17644. }
  17645. system("pkill ping");
  17646. return result;
  17647. }
  17648. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17649. {
  17650. char rmFileCmd[100]={0};
  17651. char FilePath[100]={0};
  17652. char buf[512];
  17653. int systemresult = 0;
  17654. //DEBUG_INFO("filename=%s\n",filename);
  17655. //DEBUG_INFO("url=%s\n",url);
  17656. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17657. if((access(FilePath,F_OK))!=-1)
  17658. {
  17659. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17660. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17661. system(rmFileCmd);
  17662. }
  17663. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17664. if(fp == NULL)
  17665. {
  17666. DEBUG_INFO("log is NULL\n");
  17667. return FALSE;
  17668. }
  17669. else
  17670. {
  17671. fprintf(fp, "%s\n", url);
  17672. fprintf(fp, "%s\n", filename);
  17673. fclose(fp);
  17674. }
  17675. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17676. if(phpFP == NULL)
  17677. {
  17678. DEBUG_INFO("PHP upload fail.\n");
  17679. return FALSE;
  17680. }
  17681. else
  17682. {
  17683. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17684. {
  17685. if(strstr(buf, "result") != NULL)
  17686. {
  17687. sscanf(buf, "result: %d", &systemresult);
  17688. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17689. }
  17690. }
  17691. pclose(phpFP);
  17692. }
  17693. if(systemresult != 1)
  17694. {
  17695. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17696. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17697. if(phpFP == NULL)
  17698. {
  17699. DEBUG_WARN("PHP PUT upload fail.\n");
  17700. return FALSE;
  17701. }
  17702. else
  17703. {
  17704. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17705. {
  17706. if(strstr(buf, "result") != NULL)
  17707. {
  17708. sscanf(buf, "result: %d", &systemresult);
  17709. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17710. }
  17711. }
  17712. pclose(phpFP);
  17713. }
  17714. }
  17715. if(systemresult != 1)
  17716. {
  17717. DEBUG_WARN("PHP PUT upload fail.\n");
  17718. return FALSE;
  17719. }
  17720. return TRUE;
  17721. }
  17722. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17723. {
  17724. int result = FALSE;
  17725. char ftpbuf[200];
  17726. int systemresult;
  17727. /*
  17728. // Domaind name transfer to IP address
  17729. struct hostent* server;
  17730. char *IPbuffer;
  17731. server = gethostbyname(location);
  17732. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17733. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17734. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17735. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17736. systemresult = system(ftpbuf);
  17737. if(systemresult != 0)
  17738. {
  17739. DEBUG_INFO("ftpput error!\n");
  17740. }
  17741. else
  17742. {
  17743. result = TRUE;
  17744. DEBUG_INFO("ftpput OK!\n");
  17745. }
  17746. return result;
  17747. }
  17748. int sftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17749. {
  17750. int result = FALSE;
  17751. char ftpbuf[200];
  17752. int systemresult;
  17753. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17754. sprintf(ftpbuf, "sshpass -p %s scp %s -P %d %s@%s:%s%s", password, fnamePlusPath, port, user, location, path, filename);
  17755. DEBUG_INFO("sftp command: %s\n",ftpbuf);
  17756. systemresult = system(ftpbuf);
  17757. if(systemresult != 0)
  17758. {
  17759. DEBUG_INFO("sshpass error!\n");
  17760. }
  17761. else
  17762. {
  17763. result = TRUE;
  17764. DEBUG_INFO("sshpass OK!\n");
  17765. }
  17766. return result;
  17767. }
  17768. int GetOcppServerURL()
  17769. {
  17770. int result = FALSE;
  17771. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17772. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17773. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17774. struct yuarel url;
  17775. char urlStr[512];
  17776. // OCPPPH only
  17777. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17778. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17779. {
  17780. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17781. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17782. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17783. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17784. if(yuarel_parse(&url, urlStr) != -1)
  17785. {
  17786. sprintf(OcppProtocol, "%s", url.scheme);
  17787. sprintf(OcppHost, "%s", url.host);
  17788. if(url.path == NULL)
  17789. OcppTempPath[0] = '\0';
  17790. else
  17791. sprintf(OcppTempPath, "%s", url.path);
  17792. if(url.port == 0)
  17793. {
  17794. if(strcmp(OcppProtocol, "wss") == 0)
  17795. OcppPort = 443;
  17796. else
  17797. OcppPort = 80;
  17798. }
  17799. else
  17800. OcppPort = url.port;
  17801. result = TRUE;
  17802. }
  17803. }
  17804. else
  17805. {
  17806. strcpy(OcppHost,"");
  17807. }
  17808. return result;
  17809. }
  17810. int GetOcppPath()
  17811. {
  17812. int result = FALSE;
  17813. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17814. {
  17815. if(OcppTempPath == NULL)
  17816. {
  17817. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17818. }
  17819. else
  17820. {
  17821. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17822. }
  17823. result = TRUE;
  17824. goto End;
  17825. }
  17826. else
  17827. {
  17828. strcpy(OcppPath,"");
  17829. }
  17830. End:
  17831. return result;
  17832. }
  17833. int GetOcppPort()
  17834. {
  17835. return OcppPort;
  17836. }
  17837. int GetOcppConnStatus(void)
  17838. {
  17839. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17840. }
  17841. void SetOcppConnStatus(uint8_t status)
  17842. {
  17843. ShmOCPP16DataPH->OcppConnStatus = status;
  17844. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17845. }
  17846. int GetHeartBeatWithNOResponse(void)
  17847. {
  17848. return HeartBeatWithNOResponse;
  17849. }
  17850. void SetHeartBeatWithNOResponse(void)
  17851. {
  17852. HeartBeatWithNOResponse = 0;
  17853. }
  17854. void GetStartTransactionIdTag(int gun_index)
  17855. {
  17856. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17857. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17858. }
  17859. int GetStartTransactionId(int gun_index)
  17860. {
  17861. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17862. }
  17863. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17864. {
  17865. char ch;
  17866. FILE *fptr1;
  17867. int temptransactionId;
  17868. char str[100]={0};
  17869. temptransactionId = 0;
  17870. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17871. {
  17872. DEBUG_INFO("IdTag is empty.\n");
  17873. return temptransactionId;
  17874. }
  17875. /*------ Read the file ----------------*/
  17876. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17877. if (!fptr1)
  17878. {
  17879. DEBUG_INFO("QueueTransactionId file open error.\n");
  17880. //printf(" File not found or unable to open the input file!!\n");
  17881. return temptransactionId;
  17882. }
  17883. ch=fgetc(fptr1);
  17884. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17885. rewind(fptr1);
  17886. if(ch!=EOF)
  17887. {
  17888. // printf("%c",ch);
  17889. while (fgets(str, 100, fptr1) != NULL)
  17890. {
  17891. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17892. if(str[0]=='\0')
  17893. {
  17894. break;
  17895. }
  17896. char *revbuf[8] = {0}; // Variable store string split
  17897. int num = 0;// Quantity after string split
  17898. DEBUG_INFO("Transaction queue data= %s\n", str);
  17899. splitstring(str,",",revbuf,&num); // String split
  17900. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17901. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17902. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17903. DEBUG_INFO("------------------------------\n");
  17904. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17905. {
  17906. if(isStopTransaction)
  17907. {
  17908. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17909. {
  17910. temptransactionId = atoi(revbuf[2]);
  17911. //break;
  17912. }
  17913. }
  17914. else
  17915. {
  17916. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17917. {
  17918. temptransactionId = atoi(revbuf[2]);
  17919. //break;
  17920. }
  17921. }
  17922. }
  17923. }
  17924. }
  17925. else
  17926. DEBUG_INFO("EOF\n");
  17927. fclose(fptr1);
  17928. /*------- End of reading ---------------*/
  17929. return temptransactionId;
  17930. }
  17931. void SetTransactionIdZero(int transactionId)
  17932. {
  17933. char ch;
  17934. FILE *fptr1, *fptr2;
  17935. int temptransactionId = 0;
  17936. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17937. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17938. if (!fptr1)
  17939. {
  17940. //printf(" File not found or unable to open the input file!!\n");
  17941. return ;
  17942. }
  17943. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17944. if (!fptr2)
  17945. {
  17946. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17947. fclose(fptr1);
  17948. return ;
  17949. }
  17950. ch=fgetc(fptr1);
  17951. rewind(fptr1);
  17952. if(ch!=EOF)
  17953. {
  17954. // copy all contents to the temporary file except the specific line
  17955. while (fgets(str, 100, fptr1) != NULL)
  17956. {
  17957. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17958. if(str[0]=='\0')
  17959. {
  17960. break;
  17961. }
  17962. char *revbuf[8] = {0};
  17963. int num = 0;
  17964. strcpy(strtemp, str);
  17965. splitstring(str,",",revbuf,&num);
  17966. if(revbuf[2][0] != '\0')
  17967. {
  17968. temptransactionId = atoi(revbuf[2]);
  17969. if(transactionId != temptransactionId)
  17970. {
  17971. fprintf(fptr2, "%s\n", strtemp);
  17972. }
  17973. }
  17974. }
  17975. }
  17976. fclose(fptr1);
  17977. fclose(fptr2);
  17978. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17979. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17980. /*------ Read the file ----------------*/
  17981. }
  17982. int InternetDisconnect(void)
  17983. {
  17984. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17985. }
  17986. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17987. void storeTempStopTransaction(int gun_index)
  17988. {
  17989. char guid[37]={0};
  17990. int tempIndex = 0;
  17991. char TempStopTransaction[256];
  17992. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17993. DEBUG_INFO("storeTempStopTransaction...\n");
  17994. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17995. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17996. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17997. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17998. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17999. {
  18000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18001. {
  18002. tempIndex = ((gun_index==2) ? 1: 0);
  18003. }
  18004. else
  18005. {
  18006. tempIndex = gun_index;
  18007. }
  18008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18009. {
  18010. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18011. {
  18012. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  18013. }
  18014. }// END OF CHAdeMO_QUANTITY
  18015. }
  18016. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18017. {
  18018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18019. {
  18020. tempIndex = ((gun_index==2) ? 1: 0);
  18021. }
  18022. else
  18023. {
  18024. tempIndex = gun_index;
  18025. }
  18026. for (int index = 0; index < CCS_QUANTITY; index++)
  18027. {
  18028. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18029. {
  18030. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  18031. }
  18032. }// END OF CCS_QUANTITY
  18033. }
  18034. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18035. {
  18036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18037. {
  18038. tempIndex = ((gun_index==2) ? 1: 0);
  18039. }
  18040. else
  18041. {
  18042. tempIndex = gun_index;
  18043. }
  18044. for (int index = 0; index < GB_QUANTITY; index++)
  18045. {
  18046. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18047. {
  18048. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  18049. }
  18050. }// END OF GB_QUANTITY
  18051. }
  18052. else if(gunType[gun_index] == GUN_TYPE_DO)
  18053. {
  18054. tempIndex = gun_index;
  18055. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18056. {
  18057. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18058. {
  18059. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  18060. }
  18061. }
  18062. }
  18063. else
  18064. {
  18065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18066. {
  18067. tempIndex = 2;
  18068. }
  18069. else
  18070. {
  18071. tempIndex = gun_index;
  18072. }
  18073. for (int index = 0; index < AC_QUANTITY; index++)
  18074. {
  18075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18076. {
  18077. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  18078. }
  18079. }// END OF AC_QUANTITY
  18080. }
  18081. //Stop Transaction Time
  18082. struct timeval tmnow;
  18083. struct tm *tm;
  18084. char buf[28];//, usec_buf[6];
  18085. gettimeofday(&tmnow, NULL);
  18086. time_t t;
  18087. t = time(NULL);
  18088. /*UTC time and date*/
  18089. tm = gmtime(&t);
  18090. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  18091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  18092. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  18093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  18094. random_uuid(guid);
  18095. /***********************************transactionData******************************************************/
  18096. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  18097. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  18098. //=================================
  18099. //1. Transaction_Begin
  18100. //=================================
  18101. //============================== Energy.Active.Import.Interval ===========================================
  18102. //=================================
  18103. //2. Transaction_End
  18104. //=================================
  18105. //2.1====================================== Current.Import L1 ==============================================
  18106. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18107. {
  18108. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  18109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18110. {
  18111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18112. {
  18113. tempIndex = ((gun_index==2) ? 1: 0);
  18114. }
  18115. else
  18116. {
  18117. tempIndex = gun_index;
  18118. }
  18119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18120. {
  18121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18122. {
  18123. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18124. }
  18125. }// End of for CHAdeMO_QUANTITY
  18126. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18127. }
  18128. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18129. {
  18130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18131. {
  18132. tempIndex = ((gun_index==2) ? 1: 0);
  18133. }
  18134. else
  18135. {
  18136. tempIndex = gun_index;
  18137. }
  18138. for (int index = 0; index < CCS_QUANTITY; index++)
  18139. {
  18140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18141. {
  18142. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18143. }
  18144. }// End of for CCS_QUANTITY
  18145. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18146. }
  18147. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18148. {
  18149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18150. {
  18151. tempIndex = ((gun_index==2) ? 1: 0);
  18152. }
  18153. else
  18154. {
  18155. tempIndex = gun_index;
  18156. }
  18157. for (int index = 0; index < GB_QUANTITY; index++)
  18158. {
  18159. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18160. {
  18161. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18162. }
  18163. }// End of for GB_QUANTITY
  18164. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18165. }
  18166. else if(gunType[gun_index] == GUN_TYPE_DO)
  18167. {
  18168. tempIndex = gun_index;
  18169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18170. {
  18171. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18172. {
  18173. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18174. }
  18175. }
  18176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18177. }
  18178. else
  18179. {
  18180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18181. {
  18182. tempIndex = 2;
  18183. }
  18184. else
  18185. {
  18186. tempIndex = gun_index;
  18187. }
  18188. for (int index = 0; index < AC_QUANTITY; index++)
  18189. {
  18190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18191. {
  18192. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18193. }
  18194. }// End of for AC_QUANTITY
  18195. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18196. }
  18197. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18198. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18200. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18201. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18202. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18203. }
  18204. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18205. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18206. {
  18207. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18208. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18209. {
  18210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18211. {
  18212. tempIndex = ((gun_index==2) ? 1: 0);
  18213. }
  18214. else
  18215. {
  18216. tempIndex = gun_index;
  18217. }
  18218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18219. {
  18220. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18221. {
  18222. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18223. }
  18224. }// END OF CHAdeMO_QUANTITY
  18225. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18226. }
  18227. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18228. {
  18229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18230. {
  18231. tempIndex = ((gun_index==2) ? 1: 0);
  18232. }
  18233. else
  18234. {
  18235. tempIndex = gun_index;
  18236. }
  18237. for (int index = 0; index < CCS_QUANTITY; index++)
  18238. {
  18239. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18240. {
  18241. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18242. }
  18243. }// END OF CCS_QUANTITY
  18244. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18245. }
  18246. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18247. {
  18248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18249. {
  18250. tempIndex = ((gun_index==2) ? 1: 0);
  18251. }
  18252. else
  18253. {
  18254. tempIndex = gun_index;
  18255. }
  18256. for (int index = 0; index < GB_QUANTITY; index++)
  18257. {
  18258. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18259. {
  18260. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18261. }
  18262. }// END OF GB_QUANTITY
  18263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18264. }
  18265. else if(gunType[gun_index] == GUN_TYPE_DO)
  18266. {
  18267. tempIndex = gun_index;
  18268. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18269. {
  18270. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18271. {
  18272. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18273. }
  18274. }
  18275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18276. }
  18277. else
  18278. {
  18279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18280. {
  18281. tempIndex = 2;
  18282. }
  18283. else
  18284. {
  18285. tempIndex = gun_index;
  18286. }
  18287. for (int index = 0; index < AC_QUANTITY; index++)
  18288. {
  18289. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18290. {
  18291. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18292. }
  18293. }// END OF AC_QUANTITY
  18294. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18295. }
  18296. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18297. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18298. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18299. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18300. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18301. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18302. }
  18303. //2.3====================================== Power.Active.Import =========================================
  18304. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18305. {
  18306. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18307. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18308. {
  18309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18310. {
  18311. tempIndex = ((gun_index==2) ? 1: 0);
  18312. }
  18313. else
  18314. {
  18315. tempIndex = gun_index;
  18316. }
  18317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18318. {
  18319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18320. {
  18321. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18322. }
  18323. } // End for CHAdeMO_QUANTITY
  18324. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18325. }
  18326. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18327. {
  18328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18329. {
  18330. tempIndex = ((gun_index==2) ? 1: 0);
  18331. }
  18332. else
  18333. {
  18334. tempIndex = gun_index;
  18335. }
  18336. for (int index = 0; index < CCS_QUANTITY; index++)
  18337. {
  18338. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18339. {
  18340. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18341. }
  18342. } // END for CCS_QUANTITY
  18343. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18344. }
  18345. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18346. {
  18347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18348. {
  18349. tempIndex = ((gun_index==2) ? 1: 0);
  18350. }
  18351. else
  18352. {
  18353. tempIndex = gun_index;
  18354. }
  18355. for (int index = 0; index < GB_QUANTITY; index++)
  18356. {
  18357. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18358. {
  18359. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18360. }
  18361. }// END for GB_QUANTITY
  18362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18363. }
  18364. else if(gunType[gun_index] == GUN_TYPE_DO)
  18365. {
  18366. tempIndex = gun_index;
  18367. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18368. {
  18369. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18370. {
  18371. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18372. }
  18373. }
  18374. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18375. }
  18376. else
  18377. {
  18378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18379. {
  18380. tempIndex = 2;
  18381. }
  18382. else
  18383. {
  18384. tempIndex = gun_index;
  18385. }
  18386. for (int index = 0; index < AC_QUANTITY; index++)
  18387. {
  18388. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18389. {
  18390. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18391. }
  18392. } // END for AC_QUANTITY
  18393. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18394. }
  18395. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18396. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18397. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18398. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18399. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18400. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18401. }
  18402. //2.4====================================== Voltage L1 ====================================================
  18403. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18404. {
  18405. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18406. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18407. {
  18408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18409. {
  18410. tempIndex = ((gun_index==2) ? 1: 0);
  18411. }
  18412. else
  18413. {
  18414. tempIndex = gun_index;
  18415. }
  18416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18417. {
  18418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18419. {
  18420. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18421. }
  18422. } // END OF FOR CHAdeMO_QUANTITY
  18423. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18424. }
  18425. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18426. {
  18427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18428. {
  18429. tempIndex = ((gun_index==2) ? 1: 0);
  18430. }
  18431. else
  18432. {
  18433. tempIndex = gun_index;
  18434. }
  18435. for (int index = 0; index < CCS_QUANTITY; index++)
  18436. {
  18437. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18438. {
  18439. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18440. }
  18441. } // END OF FOR CCS_QUANTITY
  18442. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18443. }
  18444. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18445. {
  18446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18447. {
  18448. tempIndex = ((gun_index==2) ? 1: 0);
  18449. }
  18450. else
  18451. {
  18452. tempIndex = gun_index;
  18453. }
  18454. for (int index = 0; index < GB_QUANTITY; index++)
  18455. {
  18456. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18457. {
  18458. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18459. }
  18460. } // END OF FOR GB_QUANTITY
  18461. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18462. }
  18463. else if(gunType[gun_index] == GUN_TYPE_DO)
  18464. {
  18465. tempIndex = gun_index;
  18466. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18467. {
  18468. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18469. {
  18470. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18471. }
  18472. }
  18473. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18474. }
  18475. else
  18476. {
  18477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18478. {
  18479. tempIndex = 2;
  18480. }
  18481. else
  18482. {
  18483. tempIndex = gun_index;
  18484. }
  18485. for (int index = 0; index < AC_QUANTITY; index++)
  18486. {
  18487. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18488. {
  18489. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  18490. }
  18491. } // END OF FOR AC_QUANTITY
  18492. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18493. }
  18494. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18495. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18496. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18497. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18498. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18499. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18500. }
  18501. //2.5============================================== End SoC =========================================================
  18502. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18503. {
  18504. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18505. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  18506. {
  18507. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18508. {
  18509. tempIndex = ((gun_index==2) ? 1: 0);
  18510. }
  18511. else
  18512. {
  18513. tempIndex = gun_index;
  18514. }
  18515. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18516. {
  18517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18518. {
  18519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18520. {
  18521. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18522. }
  18523. }
  18524. }
  18525. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18526. {
  18527. for (int index = 0; index < CCS_QUANTITY; index++)
  18528. {
  18529. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18530. {
  18531. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18532. }
  18533. }
  18534. }
  18535. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18536. {
  18537. for (int index = 0; index < GB_QUANTITY; index++)
  18538. {
  18539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18540. {
  18541. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18542. }
  18543. }
  18544. }
  18545. else if(gunType[gun_index] == GUN_TYPE_DO)
  18546. {
  18547. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18548. {
  18549. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18550. {
  18551. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18552. }
  18553. }
  18554. }
  18555. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18557. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18558. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18561. } // END FOR DC CASE
  18562. }
  18563. //2.6====================================== Current.Import L2 ==============================================
  18564. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18565. {
  18566. // AC 3 phase L2 current
  18567. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18568. {
  18569. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18570. {
  18571. tempIndex = 2;
  18572. }
  18573. else
  18574. {
  18575. tempIndex = gun_index;
  18576. }
  18577. for (int index = 0; index < AC_QUANTITY; index++)
  18578. {
  18579. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18580. {
  18581. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18582. }
  18583. }// End of for AC_QUANTITY
  18584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18585. }
  18586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18587. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18588. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18589. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18590. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18591. }
  18592. //2.7====================================== Current.Import L3 ==============================================
  18593. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18594. {
  18595. // AC 3 phase L3 current
  18596. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18597. {
  18598. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18599. {
  18600. tempIndex = 2;
  18601. }
  18602. else
  18603. {
  18604. tempIndex = gun_index;
  18605. }
  18606. for (int index = 0; index < AC_QUANTITY; index++)
  18607. {
  18608. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18609. {
  18610. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18611. }
  18612. }// End of for AC_QUANTITY
  18613. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18614. }
  18615. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18616. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18617. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18618. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18619. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18620. }
  18621. //2.9====================================== Voltage L2 ====================================================
  18622. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18623. {
  18624. // AC 3 phase L2 volatge
  18625. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18626. {
  18627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18628. {
  18629. tempIndex = 2;
  18630. }
  18631. else
  18632. {
  18633. tempIndex = gun_index;
  18634. }
  18635. for (int index = 0; index < AC_QUANTITY; index++)
  18636. {
  18637. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18638. {
  18639. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  18640. }
  18641. } // END OF FOR AC_QUANTITY
  18642. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18643. }
  18644. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18645. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18646. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18647. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18648. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18649. }
  18650. //2.10====================================== Voltage L3 ====================================================
  18651. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18652. {
  18653. // AC 3 phase L3 volatge
  18654. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18655. {
  18656. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18657. {
  18658. tempIndex = 2;
  18659. }
  18660. else
  18661. {
  18662. tempIndex = gun_index;
  18663. }
  18664. for (int index = 0; index < AC_QUANTITY; index++)
  18665. {
  18666. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18667. {
  18668. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  18669. }
  18670. } // END OF FOR AC_QUANTITY
  18671. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18672. }
  18673. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18674. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18675. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18678. }
  18679. //====================== Start SoC ================================
  18680. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18681. {
  18682. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18683. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  18684. {
  18685. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18686. {
  18687. tempIndex = ((gun_index==2) ? 1: 0);
  18688. }
  18689. else
  18690. {
  18691. tempIndex = gun_index;
  18692. }
  18693. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18694. {
  18695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18696. {
  18697. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18698. {
  18699. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18700. }
  18701. }
  18702. }
  18703. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18704. {
  18705. for (int index = 0; index < CCS_QUANTITY; index++)
  18706. {
  18707. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18708. {
  18709. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18710. }
  18711. }
  18712. }
  18713. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18714. {
  18715. for (int index = 0; index < GB_QUANTITY; index++)
  18716. {
  18717. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18718. {
  18719. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18720. }
  18721. }
  18722. }
  18723. else if(gunType[gun_index] == GUN_TYPE_DO)
  18724. {
  18725. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18726. {
  18727. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18728. {
  18729. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18730. }
  18731. }
  18732. }
  18733. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18734. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18735. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18736. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18739. } // END FOR DC CASE
  18740. }
  18741. //======================================== Message create ==============================================
  18742. json_object *StopTransaction = json_object_new_object();
  18743. json_object *transactionDatas = json_object_new_array();
  18744. json_object *sampledValues = json_object_new_array();
  18745. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18746. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18747. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18748. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18749. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18750. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18751. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18752. {
  18753. json_object *transactionData = json_object_new_object();
  18754. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18755. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18756. {
  18757. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18758. {
  18759. json_object *sampledValue = json_object_new_object();
  18760. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18761. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18762. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18763. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18764. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18765. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18766. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18767. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18768. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18769. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18770. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18771. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18772. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18773. json_object_array_add(sampledValues, sampledValue);
  18774. }
  18775. }
  18776. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18777. json_object_array_add(transactionDatas, transactionData);
  18778. }
  18779. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18780. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18781. ,MESSAGE_TYPE_CALL
  18782. ,guid
  18783. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18784. json_object_put(StopTransaction);
  18785. // Check File "TempStopTransaction" Exist
  18786. if((access(TempStopTransaction,F_OK))!=-1)
  18787. {
  18788. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18789. fclose(fopen(TempStopTransaction, "w"));
  18790. }
  18791. else
  18792. {
  18793. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18794. FILE *log = fopen(TempStopTransaction, "w+");
  18795. if(log == NULL)
  18796. {
  18797. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18798. return ;
  18799. }
  18800. else
  18801. {
  18802. fclose(log);
  18803. }
  18804. }
  18805. //Add TempStopTransaction | Update TempStopTransaction
  18806. // open file for writing
  18807. FILE *outfile;
  18808. outfile = fopen (TempStopTransaction, "a");
  18809. //DEBUG_INFO("data = %s\n", queuedata);
  18810. fputs(queuedata, outfile);
  18811. fputs("\n", outfile);
  18812. fclose (outfile);
  18813. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18814. }
  18815. void checkTempStopTransaction(int gun_index)
  18816. {
  18817. FILE *fptr1;
  18818. char ch;
  18819. char str[QUEUE_MESSAGE_LENGTH]={0};
  18820. char guid[37]={0};
  18821. char tempdata[65]={0};
  18822. char connectorStr[2]={0};
  18823. char TempStopTransaction[256];
  18824. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18825. fptr1 = fopen(TempStopTransaction, "r");
  18826. //TempStopTransaction格式: 槍號,StopTransaction封包
  18827. if (!fptr1)
  18828. {
  18829. //printf(" File not found or unable to open the input file!!\n");
  18830. return ;
  18831. }
  18832. ch=fgetc(fptr1);
  18833. //printf(" Now the content of the file %s is : \n",fname);
  18834. rewind(fptr1);
  18835. if(ch!=EOF)
  18836. {
  18837. // copy all contents to the temporary file except the specific line
  18838. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18839. {
  18840. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18841. if(str[0]=='\0')
  18842. {
  18843. break;
  18844. }
  18845. //TempStopTransaction格式: 槍號,StopTransaction封包
  18846. strncpy(connectorStr, str, 1);
  18847. if(atoi(connectorStr) != (gun_index+1))
  18848. {
  18849. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18850. fclose(fptr1);
  18851. return ;
  18852. }
  18853. //random_uuid(guid);
  18854. strncpy(guid, str+6, 36); //copy guid
  18855. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18856. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18857. {
  18858. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18859. }
  18860. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18861. OCPP_insert_transaction_msg(NO, str);
  18862. memset(str,0,ARRAY_SIZE(str));
  18863. }
  18864. }
  18865. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18866. fclose(fptr1);
  18867. remove(TempStopTransaction); // remove the original file
  18868. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18869. }
  18870. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18871. {
  18872. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18873. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18874. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18875. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18876. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18877. }
  18878. int GetWebSocketPingInterval(void)
  18879. {
  18880. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18881. }
  18882. int GetServerSign(void)
  18883. {
  18884. return server_sign;
  18885. }
  18886. uint8_t GetOcppSecurityProfile()
  18887. {
  18888. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18889. }
  18890. void GetOcppChargerBoxId(uint8_t *data)
  18891. {
  18892. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18893. }
  18894. void GetOcppSecurityPassword(uint8_t *data)
  18895. {
  18896. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18897. }
  18898. void SetOcppVersion(uint8_t *version)
  18899. {
  18900. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18901. DEBUG_INFO("ocpp version: %s\n", version);
  18902. if(strstr((char*)version, "ocpp1.6") != NULL)
  18903. {
  18904. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18905. }
  18906. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18907. {
  18908. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18909. system("pkill OcppBackend");
  18910. }
  18911. }
  18912. void SetServerSign(int value)
  18913. {
  18914. server_sign = value;
  18915. }
  18916. int GetBootNotificationInterval(void)
  18917. {
  18918. return BootNotificationInterval;
  18919. }
  18920. int GetInternetConn(void)
  18921. {
  18922. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18923. }
  18924. int GetBackendConnectionTimeout(void)
  18925. {
  18926. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18927. }
  18928. int isConnectorInitMode(int gun_index)
  18929. {
  18930. int tempIndex = 0;
  18931. int result = TRUE;
  18932. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18933. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18934. {
  18935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18936. {
  18937. tempIndex = ((gun_index==2) ? 1: 0);
  18938. }
  18939. else
  18940. {
  18941. tempIndex = gun_index;
  18942. }
  18943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18944. {
  18945. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18946. {
  18947. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18948. } //end of the same index
  18949. }//end of for CHAdeMO_QUANTITY
  18950. }
  18951. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18952. {
  18953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18954. {
  18955. tempIndex = ((gun_index==2) ? 1: 0);
  18956. }
  18957. else
  18958. {
  18959. tempIndex = gun_index;
  18960. }
  18961. for (int index = 0; index < CCS_QUANTITY; index++)
  18962. {
  18963. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18964. {
  18965. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18966. } //end of the same index
  18967. } // end of for CCS_QUANTITY
  18968. }
  18969. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18970. {
  18971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18972. {
  18973. tempIndex = ((gun_index==2) ? 1: 0);
  18974. }
  18975. else
  18976. {
  18977. tempIndex = gun_index;
  18978. }
  18979. for (int index = 0; index < GB_QUANTITY; index++)
  18980. {
  18981. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18982. {
  18983. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18984. } //end of the same index
  18985. } // end of for GB_QUANTITY
  18986. }
  18987. else if(gunType[gun_index] == GUN_TYPE_DO)
  18988. {
  18989. tempIndex = gun_index;
  18990. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18991. {
  18992. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18993. {
  18994. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18995. } //end of the same index
  18996. }
  18997. }
  18998. else
  18999. {
  19000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19001. {
  19002. tempIndex = 2;
  19003. }
  19004. else
  19005. {
  19006. tempIndex = gun_index;
  19007. }
  19008. for (int index = 0; index < AC_QUANTITY; index++)
  19009. {
  19010. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19011. {
  19012. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19013. }//end of the same index
  19014. }//end of for AC_QUANTITY
  19015. }
  19016. return result;
  19017. }
  19018. void refreshProcDogTimer()
  19019. {
  19020. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  19021. }
  19022. void InitialSystemValue(void)
  19023. {
  19024. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  19025. locallistVersion=0;
  19026. BootNotificationInterval = 0;
  19027. authorizeRetryTimes = 0;
  19028. GunStatusInterval = 10;
  19029. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  19030. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19031. //Heart Beat
  19032. HeartBeatWithNOResponse = 0;
  19033. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  19034. if(HeartBeatWaitTime == 0)
  19035. FirstHeartBeat = TRUE;
  19036. else
  19037. FirstHeartBeat = FALSE;
  19038. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  19039. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  19040. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19041. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19042. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19043. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19044. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19045. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19046. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19047. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19048. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19049. //Status && ConnectorPlugIn Setting
  19050. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19051. {
  19052. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19053. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19054. }
  19055. for (int index = 0; index < CCS_QUANTITY; index++)
  19056. {
  19057. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19058. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19059. }
  19060. for (int index = 0; index < GB_QUANTITY; index++)
  19061. {
  19062. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19063. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19064. }
  19065. for (int index = 0; index < AC_QUANTITY; index++)
  19066. {
  19067. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19068. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19069. }
  19070. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19071. {
  19072. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19073. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19074. }
  19075. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19076. {
  19077. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  19078. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  19079. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  19080. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19081. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  19082. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  19083. }
  19084. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  19085. refreshStartTimer(&clientTime.Heartbeat);
  19086. sleep(1);
  19087. }
  19088. void LWS_Send(char *str)
  19089. {
  19090. //=====================================================
  19091. // Check InternetConn 0: disconnected, 1: connected
  19092. //====================================================
  19093. if(GetOcppConnStatus() == 0)
  19094. {
  19095. DEBUG_INFO("offline now !!!\n");
  19096. return;
  19097. }
  19098. // Only disable isWebsocketSendable operation initiated by charger
  19099. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19100. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19101. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19102. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19103. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19104. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19105. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19106. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19107. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19108. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19109. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19110. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19111. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19112. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19113. {
  19114. isWebsocketSendable = 0;
  19115. }
  19116. pthread_mutex_lock(&lock_send);
  19117. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19118. sprintf((char *)SendBuffer, "%s", str);
  19119. SendBufLen = strlen(str);
  19120. pthread_mutex_unlock(&lock_send);
  19121. lws_callback_on_writable(wsi_client);
  19122. //lws_service(context, 0);
  19123. //sleep(1);
  19124. }
  19125. void LWS_SendNow(char *str)
  19126. {
  19127. //=====================================================
  19128. // Check InternetConn 0: disconnected, 1: connected
  19129. //====================================================
  19130. if(GetOcppConnStatus() == 0)
  19131. {
  19132. DEBUG_INFO("offline now !!!\n");
  19133. return;
  19134. }
  19135. // Only disable isWebsocketSendable operation initiated by charger
  19136. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19137. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19138. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19139. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19140. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19141. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19142. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19143. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19144. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19145. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19146. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19147. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19148. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19149. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19150. {
  19151. isWebsocketSendable = 0;
  19152. }
  19153. pthread_mutex_lock(&lock_send);
  19154. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19155. sprintf((char *)SendBuffer, "%s", str);
  19156. SendBufLen = strlen(str);
  19157. pthread_mutex_unlock(&lock_send);
  19158. lws_callback_on_writable(wsi_client);
  19159. lws_service(context, 0);
  19160. //sleep(1);
  19161. }