MessageHandler.c 835 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080
  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 int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  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. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct InterLock
  93. {
  94. unsigned char isGetDiagnosticGoing:1;
  95. unsigned char isUpdateFirmwareGoing:1;
  96. }interLock;
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char isOnCharging:1; //bit 4.
  117. unsigned char :3; //bit 5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // Save configuration
  357. //=========================================
  358. int runShellCmd(const char*cmd)
  359. {
  360. int result = FAIL;
  361. char buf[256];
  362. FILE *fp;
  363. fp = popen(cmd, "r");
  364. if(fp != NULL)
  365. {
  366. while(fgets(buf, sizeof(buf), fp) != NULL)
  367. {
  368. DEBUG_INFO("%s\n", buf);
  369. }
  370. result = PASS;
  371. }
  372. pclose(fp);
  373. return result;
  374. }
  375. int StoreUsrConfigData(struct SysConfigData *UsrData)
  376. {
  377. int result = PASS;
  378. int fd,wrd;
  379. unsigned int i,Chk;
  380. unsigned char *ptr, *BufTmp;
  381. int MtdBlockSize = 0x300000;
  382. Chk=0;
  383. ptr=(unsigned char *)UsrData;
  384. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  385. {
  386. memset(BufTmp,0,MtdBlockSize);
  387. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  388. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  389. Chk+=*(BufTmp+i);
  390. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  391. // Output configuration to file.
  392. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  393. if (fd < 0)
  394. {
  395. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  396. free(BufTmp);
  397. return 0;
  398. }
  399. wrd=write(fd, BufTmp, MtdBlockSize);
  400. close(fd);
  401. if(wrd<MtdBlockSize)
  402. {
  403. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  404. free(BufTmp);
  405. return 0;
  406. }
  407. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  408. DEBUG_INFO("Erase /dev/mtd10.\n");
  409. runShellCmd("flash_erase /dev/mtd10 0 0");
  410. DEBUG_INFO("Write /dev/mtd10.\n");
  411. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  412. DEBUG_INFO("Erase /dev/mtd11.\n");
  413. runShellCmd("flash_erase /dev/mtd11 0 0");
  414. DEBUG_INFO("Write /dev/mtd11.\n");
  415. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  416. system("rm -f /mnt/EvseConfig.bin");
  417. DEBUG_INFO("EvseConfig write to flash OK\n");
  418. }
  419. else
  420. {
  421. DEBUG_ERROR("alloc BlockSize NG\r\n");
  422. result = FAIL;
  423. }
  424. if(BufTmp!=NULL)
  425. free(BufTmp);
  426. return result;
  427. }
  428. //=========================================
  429. // Sqlite3 related function
  430. //=========================================
  431. static int selectSqlCount = 0;
  432. static int callback(void *data, int argc, char **argv, char **azColName){
  433. int i;
  434. //printf("%s: ", (const char*)data);
  435. selectSqlCount = argc;
  436. for(i = 0; i<argc; i++){
  437. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  438. }
  439. //printf("\n");
  440. return 0;
  441. }
  442. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  443. //int i;
  444. //printf("%s:\n", (const char*)data);
  445. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  446. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  447. return 0;
  448. }
  449. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  450. //printf("%s:\n", (const char*)data);
  451. //idTag
  452. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. //parentIdTag
  455. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  456. //expir_date
  457. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  458. //status
  459. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  460. //version
  461. if(columenCount > 5)
  462. idTagQuery.listVersionInt = atoi(columnValue[5]);
  463. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  464. return 0;
  465. }
  466. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  467. {
  468. // localversion = argv[5] ? atoi(argv[5]) : 0;
  469. // printf("localversion=%d\n", localversion);
  470. return 0;
  471. }
  472. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  473. {
  474. for (int i = 0; i < n_columns; i++)
  475. {
  476. DEBUG_INFO("%s\t", col_values[i]);
  477. }
  478. DEBUG_INFO("\n");
  479. return 0;
  480. }
  481. int OCPP_cleanLocalCache()
  482. {
  483. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  484. char *errMsg = 0;
  485. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  486. if (SQLITE_OK != rc)
  487. {
  488. DEBUG_INFO("SQL error: %s\n",errMsg);
  489. return FALSE;
  490. }
  491. return TRUE;
  492. }
  493. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  494. {
  495. int isSuccess = TRUE;
  496. int ret = 0;
  497. //const char* data = "Callback function called";
  498. char sql[300];
  499. char zErrMsg[200];
  500. memset(sql, 0, 300);
  501. memset(zErrMsg, 0, 200);
  502. 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);
  503. //* Execute SQL statement */
  504. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  505. if( ret != SQLITE_OK )
  506. {
  507. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  508. isSuccess = FALSE;
  509. }
  510. return isSuccess;
  511. }
  512. void OCPP_getIdTagFromLocalCache(char idTag[])
  513. {
  514. int rc = 0;
  515. char sql[100];
  516. char zErrMsg[100];
  517. memset(sql, 0, 100);
  518. memset(zErrMsg, 0, 100);
  519. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  520. memset(&idTagQuery, 0, sizeof(idTagQuery));
  521. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  522. /* Execute SQL statement */
  523. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  524. if( rc != SQLITE_OK )
  525. {
  526. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  527. }
  528. }
  529. void OCPP_getListVerion()
  530. {
  531. int rc = 0;
  532. // const char* data = "Callback function called";
  533. char sql[100];
  534. char zErrMsg[100];
  535. memset(sql, 0, 100);
  536. memset(zErrMsg, 0, 100);
  537. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. }
  545. void OCPP_get_TableAuthlocalAllData(void)
  546. {
  547. int rc = 0;
  548. char sql[100];
  549. char zErrMsg[100];
  550. memset(sql, 0, 100);
  551. memset(zErrMsg, 0, 100);
  552. sprintf(sql,"select * from ocpp_auth_local ");
  553. /* Execute SQL statement */
  554. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  555. if( rc != SQLITE_OK )
  556. {
  557. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  558. }
  559. //return ver;
  560. }
  561. int OCPP_cleanLocalList()
  562. {
  563. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  564. char *errMsg = 0;
  565. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  566. if (SQLITE_OK != rc)
  567. {
  568. DEBUG_INFO("%s\n",errMsg);
  569. return FALSE;
  570. }
  571. return TRUE;
  572. }
  573. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  574. {
  575. int isSuccess = FALSE;
  576. int ret = 0;
  577. //const char* data = "Callback function called";
  578. char sql[300];
  579. char zErrMsg[200];
  580. memset(sql, 0, 300);
  581. memset(zErrMsg, 0, 200);
  582. 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);
  583. //* Execute SQL statement */
  584. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  585. if( ret != SQLITE_OK )
  586. {
  587. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  588. return isSuccess;
  589. }
  590. memset(sql, 0, 300);
  591. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  592. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  593. if( ret != SQLITE_OK )
  594. {
  595. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  596. return isSuccess;
  597. }
  598. isSuccess = TRUE;
  599. return isSuccess;
  600. }
  601. void OCPP_getIdTagFromLocalList(char idTag[])
  602. {
  603. int rc = 0;
  604. // const char* data = "Callback function called";
  605. char sql[100];
  606. char zErrMsg[100];
  607. memset(sql, 0, 100);
  608. memset(zErrMsg, 0, 100);
  609. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  610. memset(&idTagQuery, 0, sizeof(idTagQuery));
  611. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  612. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  613. /* Execute SQL statement */
  614. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  615. if( rc != SQLITE_OK )
  616. {
  617. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  618. }
  619. //return ver;
  620. }
  621. void OCPP_deleteIdTagFromLocalList(char idTag[])
  622. {
  623. //int ver = 0;
  624. //int isSuccess = FALSE;
  625. int rc = 0;
  626. char sql[100];
  627. char zErrMsg[100];
  628. memset(sql, 0, 100);
  629. memset(zErrMsg, 0, 100);
  630. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  631. //* Execute SQL statement */
  632. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  633. if( rc != SQLITE_OK )
  634. {
  635. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  636. }
  637. }
  638. int getCurrentYear()
  639. {
  640. int result = 0;
  641. time_t CurrentTime;
  642. struct tm *tm;
  643. CurrentTime = time(NULL);
  644. tm=localtime(&CurrentTime);
  645. result = (tm->tm_year + 1900);
  646. return result;
  647. }
  648. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  649. {
  650. int result = PASS;
  651. char* errMsg = NULL;
  652. char sqlStr[8192];
  653. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  654. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  655. {
  656. result = FAIL;
  657. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  658. }
  659. 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));
  660. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  661. {
  662. result = FAIL;
  663. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  664. }
  665. return result;
  666. }
  667. //==========================================
  668. // Check time passed since today
  669. //==========================================
  670. long long DiffTimebWithNow(struct timeb ST)
  671. {
  672. //return milli-second
  673. struct timeb ET;
  674. long long StartTime,StopTime;
  675. ftime(&ET);
  676. StartTime=(long long)ST.time;
  677. StopTime=(long long)ET.time;
  678. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  679. }
  680. int getTimePassSinceToday(uint8_t gun_index)
  681. {
  682. int result = -1;
  683. static time_t lastTime[4];
  684. time_t t;
  685. struct tm *tmStartToday;
  686. struct timeb tbStartToday;
  687. t=time(NULL);
  688. if(difftime(t, lastTime[gun_index])>0)
  689. {
  690. tmStartToday=localtime(&t);
  691. tmStartToday->tm_hour = 0;
  692. tmStartToday->tm_min = 0;
  693. tmStartToday->tm_sec = 0;
  694. tbStartToday.time = mktime(tmStartToday);
  695. tbStartToday.millitm = 0;
  696. result = DiffTimebWithNow(tbStartToday)/1000;
  697. lastTime[gun_index] = t;
  698. }
  699. return result;
  700. }
  701. void getNowDatetime(uint8_t *data)
  702. {
  703. time_t t = time(NULL);
  704. struct tm tm = *localtime(&t);
  705. 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);
  706. }
  707. int syncDateTimeRTC(uint8_t *data)
  708. {
  709. struct ParsingResult
  710. {
  711. int result;
  712. int scanedElement;
  713. int year;
  714. int month;
  715. int mday;
  716. int hour;
  717. int min;
  718. int sec;
  719. int tz_hour;
  720. int tz_min;
  721. float minSec;
  722. }result;
  723. struct tm tmOrg;
  724. struct tm *tmTarget;
  725. struct timeb tbTarget;
  726. char buf[128];
  727. memset(&result, 0x00, sizeof(struct ParsingResult));
  728. result.result = PASS;
  729. if(strstr((char*)data, ".") != NULL)
  730. {
  731. // Original data with mini second
  732. if(strstr((char*)data, "Z") != NULL)
  733. {
  734. // Original data with Z
  735. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  736. &result.year,
  737. &result.month,
  738. &result.mday,
  739. &result.hour,
  740. &result.min,
  741. &result.sec,
  742. &result.minSec);
  743. }
  744. else
  745. {
  746. // Original data without Z
  747. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  748. &result.year,
  749. &result.month,
  750. &result.mday,
  751. &result.hour,
  752. &result.min,
  753. &result.sec,
  754. &result.minSec,
  755. &result.tz_hour,
  756. &result.tz_min);
  757. }
  758. }
  759. else
  760. {
  761. // Original data without mini second
  762. if(strstr((char*)data, "Z") != NULL)
  763. {
  764. // Original data with Z
  765. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  766. &result.year,
  767. &result.month,
  768. &result.mday,
  769. &result.hour,
  770. &result.min,
  771. &result.sec);
  772. }
  773. else
  774. {
  775. // Original data without Z
  776. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  777. &result.year,
  778. &result.month,
  779. &result.mday,
  780. &result.hour,
  781. &result.min,
  782. &result.sec,
  783. &result.tz_hour,
  784. &result.tz_min);
  785. }
  786. }
  787. tmOrg.tm_year = result.year - 1900;
  788. tmOrg.tm_mon = result.month - 1;
  789. tmOrg.tm_mday = result.mday;
  790. tmOrg.tm_hour = result.hour;
  791. tmOrg.tm_min = result.min;
  792. tmOrg.tm_sec = result.sec;
  793. tmOrg.tm_gmtoff = 0;
  794. tbTarget.time = mktime(&tmOrg);
  795. tbTarget.timezone = 0;
  796. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  797. tmTarget = gmtime(&tbTarget.time);
  798. 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);
  799. //DEBUG_INFO(" org date time: %s\n", data);
  800. //DEBUG_INFO("parse date time: %s\n", buf);
  801. system(buf);
  802. system("/sbin/hwclock -w --systohc");
  803. if(result.scanedElement < 6)
  804. result.result = FAIL;
  805. return result.result;
  806. }
  807. //==========================================
  808. // GetCompositeSchedule logic related function
  809. //==========================================
  810. int DiffTimebSec(struct timeb ST, struct timeb ET)
  811. {
  812. //return milli-second
  813. unsigned int StartTime,StopTime;
  814. StartTime=(unsigned int)ST.time;
  815. StopTime=(unsigned int)ET.time;
  816. return (StopTime-StartTime);
  817. }
  818. int DiffTimebWithNowSec(struct timeb ST)
  819. {
  820. //return milli-second
  821. struct timeb ET;
  822. unsigned int StartTime,StopTime;
  823. ftime(&ET);
  824. StartTime=(unsigned int)ST.time;
  825. StopTime=(unsigned int)ET.time;
  826. return (StopTime-StartTime);
  827. }
  828. int getStartStop(uint8_t *start, uint8_t *stop)
  829. {
  830. int result = -1;
  831. struct tm tmStart;
  832. struct timeb tbStart;
  833. struct tm tmStop;
  834. struct timeb tbStop;
  835. if((sscanf((char*)start, "%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) &&
  836. (sscanf((char*)stop, "%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))
  837. {
  838. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  839. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  840. tmStart.tm_year -= 1900;
  841. tmStart.tm_mon -= 1;
  842. tbStart.time = mktime(&tmStart);
  843. tbStart.millitm = 0;
  844. tmStop.tm_year -= 1900;
  845. tmStop.tm_mon -= 1;
  846. tbStop.time = mktime(&tmStop);
  847. tbStop.millitm = 0;
  848. result = DiffTimebSec(tbStart, tbStop);
  849. //DEBUG_INFO("getStartStop(): %d\n", result);
  850. }
  851. else
  852. {
  853. DEBUG_WARN("Start or stop date parsing error.\r\n");
  854. }
  855. return result;
  856. }
  857. int isOvertNow(uint8_t *start)
  858. {
  859. int result = NO;
  860. struct ParsingResult
  861. {
  862. int result;
  863. int scanedElement;
  864. int year;
  865. int month;
  866. int mday;
  867. int hour;
  868. int min;
  869. int sec;
  870. int tz_hour;
  871. int tz_min;
  872. float minSec;
  873. }parsingResult;
  874. struct tm tmStart;
  875. struct timeb tbStart;
  876. if(strstr((char*)start, ".") != NULL)
  877. {
  878. // Original data with mini second
  879. if(strstr((char*)start, "Z") != NULL)
  880. {
  881. // Original data with Z
  882. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  883. &parsingResult.year,
  884. &parsingResult.month,
  885. &parsingResult.mday,
  886. &parsingResult.hour,
  887. &parsingResult.min,
  888. &parsingResult.sec,
  889. &parsingResult.minSec);
  890. }
  891. else
  892. {
  893. // Original data without Z
  894. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  895. &parsingResult.year,
  896. &parsingResult.month,
  897. &parsingResult.mday,
  898. &parsingResult.hour,
  899. &parsingResult.min,
  900. &parsingResult.sec,
  901. &parsingResult.minSec,
  902. &parsingResult.tz_hour,
  903. &parsingResult.tz_min);
  904. }
  905. }
  906. else
  907. {
  908. // Original data without mini second
  909. if(strstr((char*)start, "Z") != NULL)
  910. {
  911. // Original data with Z
  912. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  913. &parsingResult.year,
  914. &parsingResult.month,
  915. &parsingResult.mday,
  916. &parsingResult.hour,
  917. &parsingResult.min,
  918. &parsingResult.sec);
  919. }
  920. else
  921. {
  922. // Original data without Z
  923. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  924. &parsingResult.year,
  925. &parsingResult.month,
  926. &parsingResult.mday,
  927. &parsingResult.hour,
  928. &parsingResult.min,
  929. &parsingResult.sec,
  930. &parsingResult.tz_hour,
  931. &parsingResult.tz_min);
  932. }
  933. }
  934. if(parsingResult.scanedElement >= 6)
  935. {
  936. tmStart.tm_year = parsingResult.year - 1900;
  937. tmStart.tm_mon = parsingResult.month - 1;
  938. tmStart.tm_mday = parsingResult.mday;
  939. tmStart.tm_hour = parsingResult.hour;
  940. tmStart.tm_min = parsingResult.min;
  941. tmStart.tm_sec = parsingResult.sec;
  942. tmStart.tm_gmtoff = 0;
  943. tbStart.time = mktime(&tmStart);
  944. tbStart.timezone = 0;
  945. tbStart.millitm = 0;
  946. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  947. if(DiffTimebWithNowSec(tbStart) <= 0)
  948. result = NO;
  949. else
  950. result = YES;
  951. }
  952. else
  953. {
  954. DEBUG_WARN("Start date parsing error.\n");
  955. }
  956. return result;
  957. }
  958. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  959. {
  960. int result = -1;
  961. struct tm tmStart;
  962. struct timeb tbStart;
  963. struct tm tmStop;
  964. struct timeb tbStop;
  965. if((sscanf((char*)start, "%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) &&
  966. (sscanf((char*)stop, "%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))
  967. {
  968. tmStart.tm_year -= 1900;
  969. tmStart.tm_mon -= 1;
  970. tbStart.time = mktime(&tmStart);
  971. tbStart.millitm = 0;
  972. tmStop.tm_year -= 1900;
  973. tmStop.tm_mon -= 1;
  974. tbStop.time = mktime(&tmStop);
  975. tbStop.millitm = 0;
  976. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  977. }
  978. return result;
  979. }
  980. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  981. {
  982. FILE *fp;
  983. char profileFileName[128];
  984. char *line = NULL;
  985. size_t len = 0;
  986. time_t CurrentTime;
  987. struct tm *tmComposite;
  988. struct StructChargingProfile maxProfile;
  989. uint8_t limitMax=0;
  990. int compositePeriodIdx = 0;
  991. CurrentTime = time(NULL);
  992. tmComposite=localtime(&CurrentTime);
  993. 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);
  994. if(isUnitA)
  995. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  996. else
  997. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  998. compositeProfile->ChargingSchedule.Duration = durationReq;
  999. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1000. {
  1001. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1002. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1003. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1004. }
  1005. compositeProfile->ChargingProfileId = 0;
  1006. compositeProfile->StackLevel = 99 ;
  1007. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1008. maxProfile.ChargingProfileId = -1;
  1009. maxProfile.ChargingSchedule.Duration = -1;
  1010. system("rm -f /tmp/*.json");
  1011. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1012. // Search max profile
  1013. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1014. if((access(profileFileName, F_OK))!=-1)
  1015. {
  1016. fp = fopen(profileFileName, "r");
  1017. while(getline(&line, &len, fp) != -1)
  1018. {
  1019. json_object *obj = NULL;
  1020. obj = json_tokener_parse(line);
  1021. if(is_error(obj))
  1022. {
  1023. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1024. }
  1025. else
  1026. {
  1027. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1028. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1029. )
  1030. {
  1031. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1032. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1033. )
  1034. {
  1035. struct tm tmFrom, tmTo;
  1036. struct timeb tbFrom, tbTo;
  1037. 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) &&
  1038. (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))
  1039. {
  1040. tmFrom.tm_year -= 1900;
  1041. tmFrom.tm_mon -= 1;
  1042. tbFrom.time = mktime(&tmFrom);
  1043. tmTo.tm_year -= 1900;
  1044. tmTo.tm_mon -= 1;
  1045. tbTo.time = mktime(&tmTo);
  1046. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1047. {
  1048. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1049. {
  1050. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1053. }
  1054. maxProfile.ChargingProfileId = -1;
  1055. maxProfile.StackLevel = -1;
  1056. if(maxProfile.ChargingProfileId == -1)
  1057. DEBUG_INFO("MaxProfile found.\n");
  1058. else
  1059. DEBUG_INFO("MaxProfile updated.\n");
  1060. // Required item
  1061. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1062. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1063. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1064. if(isUnitA)
  1065. {
  1066. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1067. 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++)
  1068. {
  1069. 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"));
  1070. 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?
  1071. 3:
  1072. 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")));
  1073. 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")));
  1074. }
  1075. }
  1076. else
  1077. {
  1078. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1079. 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++)
  1080. {
  1081. 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"));
  1082. 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?
  1083. 3:
  1084. 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")));
  1085. 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));
  1086. }
  1087. }
  1088. // Optional item
  1089. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1090. {
  1091. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1092. }
  1093. else
  1094. {
  1095. sprintf((char*)maxProfile.ValidFrom, " ");
  1096. }
  1097. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1098. {
  1099. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1100. }
  1101. else
  1102. {
  1103. sprintf((char*)maxProfile.ValidTo, " ");
  1104. }
  1105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1106. {
  1107. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1108. }
  1109. else
  1110. {
  1111. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1112. }
  1113. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1114. {
  1115. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1116. }
  1117. else
  1118. {
  1119. maxProfile.TransactionId = -1;
  1120. }
  1121. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1122. {
  1123. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1124. }
  1125. else
  1126. {
  1127. maxProfile.ChargingSchedule.Duration = 86400;
  1128. }
  1129. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1130. {
  1131. 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")));
  1132. }
  1133. else
  1134. {
  1135. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1136. }
  1137. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1138. {
  1139. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1140. }
  1141. else
  1142. {
  1143. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. else
  1149. {
  1150. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1151. {
  1152. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1155. }
  1156. maxProfile.ChargingProfileId = -1;
  1157. maxProfile.StackLevel = -1;
  1158. if(maxProfile.ChargingProfileId == -1)
  1159. DEBUG_INFO("MaxProfile found.\n");
  1160. else
  1161. DEBUG_INFO("MaxProfile updated.\n");
  1162. // Required item
  1163. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1164. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1165. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1166. if(isUnitA)
  1167. {
  1168. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1169. 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++)
  1170. {
  1171. 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"));
  1172. 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?
  1173. 3:
  1174. 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")));
  1175. 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")));
  1176. }
  1177. }
  1178. else
  1179. {
  1180. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1181. 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++)
  1182. {
  1183. 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"));
  1184. 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?
  1185. 3:
  1186. 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")));
  1187. 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));
  1188. }
  1189. }
  1190. // Optional item
  1191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1192. {
  1193. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1194. }
  1195. else
  1196. {
  1197. sprintf((char*)maxProfile.ValidFrom, " ");
  1198. }
  1199. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1200. {
  1201. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1202. }
  1203. else
  1204. {
  1205. sprintf((char*)maxProfile.ValidTo, " ");
  1206. }
  1207. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1208. {
  1209. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1210. }
  1211. else
  1212. {
  1213. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1214. }
  1215. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1216. {
  1217. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1218. }
  1219. else
  1220. {
  1221. maxProfile.TransactionId = -1;
  1222. }
  1223. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1224. {
  1225. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1226. }
  1227. else
  1228. {
  1229. maxProfile.ChargingSchedule.Duration = 86400;
  1230. }
  1231. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1232. {
  1233. 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")));
  1234. }
  1235. else
  1236. {
  1237. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1238. }
  1239. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1240. {
  1241. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1242. }
  1243. else
  1244. {
  1245. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. json_object_put(obj);
  1251. }
  1252. fclose(fp);
  1253. /*
  1254. if(maxProfile.ChargingProfileId !=-1)
  1255. {
  1256. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1257. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1258. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1259. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1260. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1261. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1262. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1263. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1264. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1265. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1266. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1270. {
  1271. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1272. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1273. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1274. }
  1275. }
  1276. }
  1277. else
  1278. DEBUG_INFO("MaxProfile not found.\n");
  1279. DEBUG_INFO("------------------------------------\n");*/
  1280. }
  1281. if(maxProfile.ChargingProfileId != -1)
  1282. {
  1283. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1284. {
  1285. if(maxProfile.ChargingSchedule.Duration != -1)
  1286. {
  1287. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1288. 0:
  1289. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1290. }
  1291. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1292. {
  1293. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1294. {
  1295. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1296. 0:
  1297. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1298. if(idxPeriod > 0)
  1299. {
  1300. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1301. {
  1302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1303. }
  1304. }
  1305. }
  1306. }
  1307. }
  1308. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1309. {
  1310. if(maxProfile.ChargingSchedule.Duration != -1)
  1311. {
  1312. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1313. }
  1314. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1315. {
  1316. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1317. {
  1318. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1319. if(idxPeriod > 0)
  1320. {
  1321. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1322. {
  1323. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1324. }
  1325. }
  1326. }
  1327. }
  1328. }
  1329. else
  1330. {
  1331. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1332. {
  1333. if(maxProfile.ChargingSchedule.Duration != -1)
  1334. {
  1335. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1336. 0:
  1337. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1338. }
  1339. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1340. {
  1341. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1342. {
  1343. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1344. 0:
  1345. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1346. if(idxPeriod > 0)
  1347. {
  1348. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1349. {
  1350. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1351. }
  1352. }
  1353. }
  1354. }
  1355. }
  1356. else
  1357. {
  1358. if(maxProfile.ChargingSchedule.Duration != -1)
  1359. {
  1360. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1361. 0:
  1362. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1363. }
  1364. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1365. {
  1366. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1367. {
  1368. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1369. 0:
  1370. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1371. if(idxPeriod > 0)
  1372. {
  1373. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1374. {
  1375. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. /*
  1383. DEBUG_INFO("MaxProfile after align.\n");
  1384. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1385. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1386. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1387. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1388. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1389. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1390. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1391. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1392. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1393. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1394. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1395. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1396. {
  1397. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1398. {
  1399. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1400. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1401. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1402. }
  1403. }
  1404. DEBUG_INFO("------------------------------------\n");*/
  1405. }
  1406. // Find each profile period quantity
  1407. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1408. {
  1409. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1410. limitMax = idx+1;
  1411. }
  1412. if(maxProfile.ChargingProfileId != -1)
  1413. {
  1414. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1415. {
  1416. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1417. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1418. (maxProfile.ChargingSchedule.Duration > 0))
  1419. {
  1420. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1421. {
  1422. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1423. compositePeriodIdx++;
  1424. }
  1425. else
  1426. {
  1427. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1428. }
  1429. }
  1430. }
  1431. }
  1432. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1433. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1434. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1435. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1436. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1437. {
  1438. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1439. {
  1440. compositeProfile->ChargingProfileId = 1;
  1441. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1442. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1443. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1444. }
  1445. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1446. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1447. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1448. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1449. }
  1450. if(line)
  1451. free(line);
  1452. }
  1453. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1454. {
  1455. FILE *fp;
  1456. char profileFileName[128];
  1457. char *line = NULL;
  1458. size_t len = 0;
  1459. time_t CurrentTime;
  1460. struct tm *tmComposite;
  1461. struct StructChargingProfile maxProfile;
  1462. struct StructChargingProfile defaultTxProfile;
  1463. struct StructChargingProfile txProfile;
  1464. struct StructChargingSchedulePeriod tmpPeriod;
  1465. uint8_t limitMax=0;
  1466. uint8_t limitDef=0;
  1467. uint8_t limitTx=0;
  1468. int compositePeriodIdx = 0;
  1469. CurrentTime = time(NULL);
  1470. tmComposite=localtime(&CurrentTime);
  1471. 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);
  1472. if(isUnitA)
  1473. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1474. else
  1475. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1476. compositeProfile->ChargingSchedule.Duration = durationReq;
  1477. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1478. {
  1479. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1480. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1481. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1482. }
  1483. compositeProfile->ChargingProfileId = 0;
  1484. compositeProfile->StackLevel = 99 ;
  1485. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1486. maxProfile.ChargingProfileId = -1;
  1487. defaultTxProfile.ChargingProfileId = -1;
  1488. txProfile.ChargingProfileId = -1;
  1489. maxProfile.ChargingSchedule.Duration = -1;
  1490. defaultTxProfile.ChargingSchedule.Duration = -1;
  1491. txProfile.ChargingSchedule.Duration = -1;
  1492. system("rm -f /tmp/*.json");
  1493. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1494. /*
  1495. * Search valid charging profile
  1496. */
  1497. //DEBUG_INFO("====================================\n");
  1498. // Search tx profile
  1499. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1500. if((access(profileFileName, F_OK))!=-1)
  1501. {
  1502. fp = fopen(profileFileName, "r");
  1503. while(getline(&line, &len, fp) != -1)
  1504. {
  1505. json_object *obj = NULL;
  1506. obj = json_tokener_parse(line);
  1507. if(is_error(obj))
  1508. {
  1509. DEBUG_ERROR("Parse txProfile from file error.\n");
  1510. }
  1511. else
  1512. {
  1513. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1514. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1515. )
  1516. {
  1517. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1518. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1519. )
  1520. {
  1521. struct tm tmFrom, tmTo;
  1522. struct timeb tbFrom, tbTo;
  1523. 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) &&
  1524. (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))
  1525. {
  1526. tmFrom.tm_year -= 1900;
  1527. tmFrom.tm_mon -= 1;
  1528. tbFrom.time = mktime(&tmFrom);
  1529. tmTo.tm_year -= 1900;
  1530. tmTo.tm_mon -= 1;
  1531. tbTo.time = mktime(&tmTo);
  1532. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1533. {
  1534. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1535. {
  1536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1539. }
  1540. txProfile.ChargingProfileId = -1;
  1541. txProfile.StackLevel = -1;
  1542. if(txProfile.ChargingProfileId == -1)
  1543. DEBUG_INFO("TxProfile found.\n");
  1544. else
  1545. DEBUG_INFO("TxProfile updated.\n");
  1546. // Required item
  1547. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1548. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1549. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1550. if(isUnitA)
  1551. {
  1552. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1553. 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++)
  1554. {
  1555. 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"));
  1556. 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?
  1557. 3:
  1558. 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")));
  1559. 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")));
  1560. }
  1561. }
  1562. else
  1563. {
  1564. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1565. 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++)
  1566. {
  1567. 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"));
  1568. 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?
  1569. 3:
  1570. 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")));
  1571. 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));
  1572. }
  1573. }
  1574. // Optional item
  1575. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1576. {
  1577. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1578. }
  1579. else
  1580. {
  1581. sprintf((char*)txProfile.ValidFrom, " ");
  1582. }
  1583. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1584. {
  1585. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1586. }
  1587. else
  1588. {
  1589. sprintf((char*)txProfile.ValidTo, " ");
  1590. }
  1591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1592. {
  1593. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1594. }
  1595. else
  1596. {
  1597. sprintf((char*)txProfile.RecurrencyKind, " ");
  1598. }
  1599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1600. {
  1601. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1602. }
  1603. else
  1604. {
  1605. txProfile.TransactionId = -1;
  1606. }
  1607. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1608. {
  1609. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1610. }
  1611. else
  1612. {
  1613. txProfile.ChargingSchedule.Duration = 86400;
  1614. }
  1615. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1616. {
  1617. 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")));
  1618. }
  1619. else
  1620. {
  1621. 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));
  1622. }
  1623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1624. {
  1625. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1626. }
  1627. else
  1628. {
  1629. txProfile.ChargingSchedule.MinChargingRate = -1;
  1630. }
  1631. }
  1632. }
  1633. }
  1634. else
  1635. {
  1636. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1637. {
  1638. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1640. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1641. }
  1642. txProfile.ChargingProfileId = -1;
  1643. txProfile.StackLevel = -1;
  1644. if(txProfile.ChargingProfileId == -1)
  1645. DEBUG_INFO("TxProfile found.\n");
  1646. else
  1647. DEBUG_INFO("TxProfile updated.\n");
  1648. // Required item
  1649. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1650. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1651. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1652. if(isUnitA)
  1653. {
  1654. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1655. 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++)
  1656. {
  1657. 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"));
  1658. 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?
  1659. 3:
  1660. 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")));
  1661. 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")));
  1662. }
  1663. }
  1664. else
  1665. {
  1666. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1667. 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++)
  1668. {
  1669. 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"));
  1670. 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?
  1671. 3:
  1672. 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")));
  1673. 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));
  1674. }
  1675. }
  1676. // Optional item
  1677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1678. {
  1679. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1680. }
  1681. else
  1682. {
  1683. sprintf((char*)txProfile.ValidFrom, " ");
  1684. }
  1685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1686. {
  1687. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1688. }
  1689. else
  1690. {
  1691. sprintf((char*)txProfile.ValidTo, " ");
  1692. }
  1693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1694. {
  1695. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1696. }
  1697. else
  1698. {
  1699. sprintf((char*)txProfile.RecurrencyKind, " ");
  1700. }
  1701. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1702. {
  1703. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1704. }
  1705. else
  1706. {
  1707. txProfile.TransactionId = -1;
  1708. }
  1709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1710. {
  1711. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1712. }
  1713. else
  1714. {
  1715. txProfile.ChargingSchedule.Duration = 86400;
  1716. }
  1717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1718. {
  1719. 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")));
  1720. }
  1721. else
  1722. {
  1723. 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));
  1724. }
  1725. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1726. {
  1727. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1728. }
  1729. else
  1730. {
  1731. txProfile.ChargingSchedule.MinChargingRate = -1;
  1732. }
  1733. }
  1734. }
  1735. }
  1736. json_object_put(obj);
  1737. }
  1738. fclose(fp);
  1739. /*
  1740. if(txProfile.ChargingProfileId != -1)
  1741. {
  1742. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1743. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1744. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1745. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1746. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1747. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1748. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1749. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1750. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1751. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1752. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1756. {
  1757. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1758. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1759. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1760. }
  1761. }
  1762. }
  1763. else
  1764. DEBUG_INFO("TxProfile not found.\n");*/
  1765. }
  1766. // Search default tx profile
  1767. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1768. if((access(profileFileName, F_OK))==-1)
  1769. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1770. if((access(profileFileName, F_OK))!=-1)
  1771. {
  1772. fp = fopen(profileFileName, "r");
  1773. while(getline(&line, &len, fp) != -1)
  1774. {
  1775. json_object *obj = NULL;
  1776. obj = json_tokener_parse(line);
  1777. if(is_error(obj))
  1778. {
  1779. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1780. }
  1781. else
  1782. {
  1783. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1784. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1785. )
  1786. {
  1787. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1788. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1789. )
  1790. {
  1791. struct tm tmFrom, tmTo;
  1792. struct timeb tbFrom, tbTo;
  1793. 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) &&
  1794. (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))
  1795. {
  1796. tmFrom.tm_year -= 1900;
  1797. tmFrom.tm_mon -= 1;
  1798. tbFrom.time = mktime(&tmFrom);
  1799. tmTo.tm_year -= 1900;
  1800. tmTo.tm_mon -= 1;
  1801. tbTo.time = mktime(&tmTo);
  1802. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1803. {
  1804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1805. {
  1806. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1807. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1809. }
  1810. defaultTxProfile.ChargingProfileId = -1;
  1811. defaultTxProfile.StackLevel = -1;
  1812. if(defaultTxProfile.ChargingProfileId == -1)
  1813. DEBUG_INFO("TxDefaultProfile found.\n");
  1814. else
  1815. DEBUG_INFO("TxDefaultProfile updated.\n");
  1816. // Required item
  1817. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1818. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1819. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1820. if(isUnitA)
  1821. {
  1822. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1823. 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++)
  1824. {
  1825. 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"));
  1826. 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?
  1827. 3:
  1828. 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")));
  1829. 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")));
  1830. }
  1831. }
  1832. else
  1833. {
  1834. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1835. 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++)
  1836. {
  1837. 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"));
  1838. 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?
  1839. 3:
  1840. 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")));
  1841. 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));
  1842. }
  1843. }
  1844. // Optional item
  1845. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1846. {
  1847. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1848. }
  1849. else
  1850. {
  1851. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1852. }
  1853. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1854. {
  1855. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1856. }
  1857. else
  1858. {
  1859. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1860. }
  1861. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1862. {
  1863. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1864. }
  1865. else
  1866. {
  1867. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1868. }
  1869. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1870. {
  1871. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1872. }
  1873. else
  1874. {
  1875. defaultTxProfile.TransactionId = -1;
  1876. }
  1877. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1880. }
  1881. else
  1882. {
  1883. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1884. }
  1885. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1886. {
  1887. 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")));
  1888. }
  1889. else
  1890. {
  1891. 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));
  1892. }
  1893. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1894. {
  1895. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1896. }
  1897. else
  1898. {
  1899. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1900. }
  1901. }
  1902. }
  1903. }
  1904. else
  1905. {
  1906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1907. {
  1908. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1909. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1911. }
  1912. defaultTxProfile.ChargingProfileId = -1;
  1913. defaultTxProfile.StackLevel = -1;
  1914. if(defaultTxProfile.ChargingProfileId == -1)
  1915. DEBUG_INFO("TxDefaultProfile found.\n");
  1916. else
  1917. DEBUG_INFO("TxDefaultProfile updated.\n");
  1918. // Required item
  1919. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1920. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1921. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1922. if(isUnitA)
  1923. {
  1924. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1925. 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++)
  1926. {
  1927. 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"));
  1928. 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?
  1929. 3:
  1930. 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")));
  1931. 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")));
  1932. }
  1933. }
  1934. else
  1935. {
  1936. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1937. 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++)
  1938. {
  1939. 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"));
  1940. 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?
  1941. 3:
  1942. 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")));
  1943. 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));
  1944. }
  1945. }
  1946. // Optional item
  1947. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1948. {
  1949. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1950. }
  1951. else
  1952. {
  1953. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1954. }
  1955. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1956. {
  1957. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1958. }
  1959. else
  1960. {
  1961. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1962. }
  1963. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1964. {
  1965. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1966. }
  1967. else
  1968. {
  1969. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1970. }
  1971. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1972. {
  1973. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1974. }
  1975. else
  1976. {
  1977. defaultTxProfile.TransactionId = -1;
  1978. }
  1979. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1980. {
  1981. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1982. }
  1983. else
  1984. {
  1985. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1986. }
  1987. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1988. {
  1989. 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")));
  1990. }
  1991. else
  1992. {
  1993. 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));
  1994. }
  1995. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1996. {
  1997. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1998. }
  1999. else
  2000. {
  2001. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2002. }
  2003. }
  2004. }
  2005. }
  2006. json_object_put(obj);
  2007. }
  2008. fclose(fp);
  2009. /*
  2010. if(defaultTxProfile.ChargingProfileId != -1)
  2011. {
  2012. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2013. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2014. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2015. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2016. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2017. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2018. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2019. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2020. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2021. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2022. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2023. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2024. {
  2025. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2026. {
  2027. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2028. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2029. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2030. }
  2031. }
  2032. }
  2033. else
  2034. DEBUG_INFO("TxDefaultProfile not found.\n");
  2035. DEBUG_INFO("------------------------------------\n");*/
  2036. }
  2037. // Search max profile
  2038. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2039. if((access(profileFileName, F_OK))!=-1)
  2040. {
  2041. fp = fopen(profileFileName, "r");
  2042. while(getline(&line, &len, fp) != -1)
  2043. {
  2044. json_object *obj = NULL;
  2045. obj = json_tokener_parse(line);
  2046. if(is_error(obj))
  2047. {
  2048. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2049. }
  2050. else
  2051. {
  2052. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2053. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2054. )
  2055. {
  2056. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2057. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2058. )
  2059. {
  2060. struct tm tmFrom, tmTo;
  2061. struct timeb tbFrom, tbTo;
  2062. 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) &&
  2063. (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))
  2064. {
  2065. tmFrom.tm_year -= 1900;
  2066. tmFrom.tm_mon -= 1;
  2067. tbFrom.time = mktime(&tmFrom);
  2068. tmTo.tm_year -= 1900;
  2069. tmTo.tm_mon -= 1;
  2070. tbTo.time = mktime(&tmTo);
  2071. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2072. {
  2073. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2074. {
  2075. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2076. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2077. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2078. }
  2079. maxProfile.ChargingProfileId = -1;
  2080. maxProfile.StackLevel = -1;
  2081. if(maxProfile.ChargingProfileId == -1)
  2082. DEBUG_INFO("MaxProfile found.\n");
  2083. else
  2084. DEBUG_INFO("MaxProfile updated.\n");
  2085. // Required item
  2086. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2087. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2088. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2089. if(isUnitA)
  2090. {
  2091. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2092. 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++)
  2093. {
  2094. 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"));
  2095. 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?
  2096. 3:
  2097. 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")));
  2098. 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")));
  2099. }
  2100. }
  2101. else
  2102. {
  2103. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2104. 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++)
  2105. {
  2106. 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"));
  2107. 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?
  2108. 3:
  2109. 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")));
  2110. 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));
  2111. }
  2112. }
  2113. // Optional item
  2114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2115. {
  2116. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2117. }
  2118. else
  2119. {
  2120. sprintf((char*)maxProfile.ValidFrom, " ");
  2121. }
  2122. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2123. {
  2124. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2125. }
  2126. else
  2127. {
  2128. sprintf((char*)maxProfile.ValidTo, " ");
  2129. }
  2130. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2131. {
  2132. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2133. }
  2134. else
  2135. {
  2136. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2137. }
  2138. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2139. {
  2140. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2141. }
  2142. else
  2143. {
  2144. maxProfile.TransactionId = -1;
  2145. }
  2146. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2147. {
  2148. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2149. }
  2150. else
  2151. {
  2152. maxProfile.ChargingSchedule.Duration = 86400;
  2153. }
  2154. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2155. {
  2156. 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")));
  2157. }
  2158. else
  2159. {
  2160. 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));
  2161. }
  2162. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2163. {
  2164. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2165. }
  2166. else
  2167. {
  2168. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2169. }
  2170. }
  2171. }
  2172. }
  2173. else
  2174. {
  2175. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2176. {
  2177. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2180. }
  2181. maxProfile.ChargingProfileId = -1;
  2182. maxProfile.StackLevel = -1;
  2183. if(maxProfile.ChargingProfileId == -1)
  2184. DEBUG_INFO("MaxProfile found.\n");
  2185. else
  2186. DEBUG_INFO("MaxProfile updated.\n");
  2187. // Required item
  2188. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2189. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2190. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2191. if(isUnitA)
  2192. {
  2193. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2194. 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++)
  2195. {
  2196. 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"));
  2197. 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?
  2198. 3:
  2199. 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")));
  2200. 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")));
  2201. }
  2202. }
  2203. else
  2204. {
  2205. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2206. 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++)
  2207. {
  2208. 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"));
  2209. 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?
  2210. 3:
  2211. 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")));
  2212. 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));
  2213. }
  2214. }
  2215. // Optional item
  2216. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2217. {
  2218. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2219. }
  2220. else
  2221. {
  2222. sprintf((char*)maxProfile.ValidFrom, " ");
  2223. }
  2224. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2225. {
  2226. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2227. }
  2228. else
  2229. {
  2230. sprintf((char*)maxProfile.ValidTo, " ");
  2231. }
  2232. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2233. {
  2234. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2235. }
  2236. else
  2237. {
  2238. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2239. }
  2240. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2241. {
  2242. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2243. }
  2244. else
  2245. {
  2246. maxProfile.TransactionId = -1;
  2247. }
  2248. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2249. {
  2250. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2251. }
  2252. else
  2253. {
  2254. maxProfile.ChargingSchedule.Duration = 86400;
  2255. }
  2256. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2257. {
  2258. 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")));
  2259. }
  2260. else
  2261. {
  2262. 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));
  2263. }
  2264. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2265. {
  2266. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2267. }
  2268. else
  2269. {
  2270. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2271. }
  2272. }
  2273. }
  2274. }
  2275. json_object_put(obj);
  2276. }
  2277. fclose(fp);
  2278. /*
  2279. if(maxProfile.ChargingProfileId !=-1)
  2280. {
  2281. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2282. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2283. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2284. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2285. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2286. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2287. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2288. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2289. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2290. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2291. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2293. {
  2294. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2295. {
  2296. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2297. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2298. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2299. }
  2300. }
  2301. }
  2302. else
  2303. DEBUG_INFO("MaxProfile not found.\n");
  2304. DEBUG_INFO("------------------------------------\n");*/
  2305. }
  2306. /*
  2307. * Align found profile start schedule & periods
  2308. */
  2309. //DEBUG_INFO("====================================\n");
  2310. /*
  2311. // For local test usage, force modify found profile start schedule info
  2312. 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);
  2313. 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);
  2314. 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);
  2315. */
  2316. if(txProfile.ChargingProfileId != -1)
  2317. {
  2318. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2319. {
  2320. if(txProfile.ChargingSchedule.Duration != -1)
  2321. {
  2322. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2323. 0:
  2324. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2325. }
  2326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2327. {
  2328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2329. {
  2330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2331. 0:
  2332. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2333. if(idxPeriod > 0)
  2334. {
  2335. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2336. {
  2337. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2344. {
  2345. if(txProfile.ChargingSchedule.Duration != -1)
  2346. {
  2347. 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?
  2348. 0:
  2349. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2350. }
  2351. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2352. {
  2353. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2354. {
  2355. 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?
  2356. 0:
  2357. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2358. if(idxPeriod > 0)
  2359. {
  2360. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2361. {
  2362. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2363. }
  2364. }
  2365. }
  2366. }
  2367. }
  2368. else
  2369. {
  2370. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2371. {
  2372. if(txProfile.ChargingSchedule.Duration != -1)
  2373. {
  2374. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2375. 0:
  2376. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2377. }
  2378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2379. {
  2380. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2381. {
  2382. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2383. 0:
  2384. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2385. if(idxPeriod > 0)
  2386. {
  2387. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2388. {
  2389. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2390. }
  2391. }
  2392. }
  2393. }
  2394. }
  2395. else
  2396. {
  2397. if(txProfile.ChargingSchedule.Duration != -1)
  2398. {
  2399. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2400. 0:
  2401. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2402. }
  2403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2404. {
  2405. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2406. {
  2407. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2408. 0:
  2409. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2410. if(idxPeriod > 0)
  2411. {
  2412. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2413. {
  2414. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. }
  2421. /*
  2422. DEBUG_INFO("txProfile after align.\n");
  2423. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2424. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2425. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2426. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2427. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2428. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2429. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2430. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2431. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2432. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2433. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2434. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2435. {
  2436. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2437. {
  2438. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2439. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2440. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2441. }
  2442. }*/
  2443. }
  2444. if(defaultTxProfile.ChargingProfileId != -1)
  2445. {
  2446. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2447. {
  2448. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2449. {
  2450. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2451. 0:
  2452. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2453. }
  2454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2455. {
  2456. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2457. {
  2458. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2459. 0:
  2460. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2462. {
  2463. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2464. }
  2465. if(idxPeriod > 0)
  2466. {
  2467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2468. {
  2469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2470. }
  2471. }
  2472. }
  2473. }
  2474. }
  2475. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2476. {
  2477. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2478. {
  2479. 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?
  2480. 0:
  2481. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2482. }
  2483. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2484. {
  2485. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2486. {
  2487. 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?
  2488. 0:
  2489. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2490. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2491. {
  2492. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2493. }
  2494. if(idxPeriod > 0)
  2495. {
  2496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2497. {
  2498. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. else
  2505. {
  2506. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2507. {
  2508. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2509. {
  2510. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2511. 0:
  2512. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2513. }
  2514. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2515. {
  2516. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2517. {
  2518. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2519. 0:
  2520. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2521. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2522. {
  2523. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2524. }
  2525. if(idxPeriod > 0)
  2526. {
  2527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2528. {
  2529. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2530. }
  2531. }
  2532. }
  2533. }
  2534. }
  2535. else
  2536. {
  2537. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2538. {
  2539. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2540. 0:
  2541. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2542. }
  2543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2544. {
  2545. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2546. {
  2547. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2548. 0:
  2549. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2550. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2551. {
  2552. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2553. }
  2554. if(idxPeriod > 0)
  2555. {
  2556. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2557. {
  2558. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2559. }
  2560. }
  2561. }
  2562. }
  2563. }
  2564. }
  2565. /*
  2566. DEBUG_INFO("defaultTxProfile after align.\n");
  2567. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2568. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2569. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2570. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2571. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2572. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2573. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2574. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2575. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2576. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2577. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2581. {
  2582. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2583. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2584. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2585. }
  2586. }
  2587. DEBUG_INFO("------------------------------------\n");*/
  2588. }
  2589. if(maxProfile.ChargingProfileId != -1)
  2590. {
  2591. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2592. {
  2593. if(maxProfile.ChargingSchedule.Duration != -1)
  2594. {
  2595. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2596. 0:
  2597. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2598. }
  2599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2600. {
  2601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2602. {
  2603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2604. 0:
  2605. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2606. if(idxPeriod > 0)
  2607. {
  2608. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2609. {
  2610. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2611. }
  2612. }
  2613. }
  2614. }
  2615. }
  2616. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2617. {
  2618. if(maxProfile.ChargingSchedule.Duration != -1)
  2619. {
  2620. 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?
  2621. 0:
  2622. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2623. }
  2624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2625. {
  2626. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2627. {
  2628. 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?
  2629. 0:
  2630. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2631. if(idxPeriod > 0)
  2632. {
  2633. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2634. {
  2635. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2636. }
  2637. }
  2638. }
  2639. }
  2640. }
  2641. else
  2642. {
  2643. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2644. {
  2645. if(maxProfile.ChargingSchedule.Duration != -1)
  2646. {
  2647. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2648. 0:
  2649. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2650. }
  2651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2652. {
  2653. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2654. {
  2655. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2656. 0:
  2657. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2658. if(idxPeriod > 0)
  2659. {
  2660. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2661. {
  2662. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2663. }
  2664. }
  2665. }
  2666. }
  2667. }
  2668. else
  2669. {
  2670. if(maxProfile.ChargingSchedule.Duration != -1)
  2671. {
  2672. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2673. 0:
  2674. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2675. }
  2676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2677. {
  2678. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2679. {
  2680. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2681. 0:
  2682. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2683. if(idxPeriod > 0)
  2684. {
  2685. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2686. {
  2687. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2688. }
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. /*
  2695. DEBUG_INFO("MaxProfile after align.\n");
  2696. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2697. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2698. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2699. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2700. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2701. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2702. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2703. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2704. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2705. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2706. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2707. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2708. {
  2709. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2710. {
  2711. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2712. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2713. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2714. }
  2715. }
  2716. DEBUG_INFO("------------------------------------\n");*/
  2717. }
  2718. /*
  2719. * Merge to conposite schedule
  2720. */
  2721. //DEBUG_INFO("====================================\n");
  2722. // Find each profile period quantity
  2723. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2724. {
  2725. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2726. limitMax = idx+1;
  2727. }
  2728. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2729. {
  2730. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2731. limitDef = idx+1;
  2732. }
  2733. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2734. {
  2735. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2736. limitTx = idx+1;
  2737. }
  2738. // TxProfile found, composite schedule based on it
  2739. if(txProfile.ChargingProfileId != -1)
  2740. {
  2741. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2742. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2743. {
  2744. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2745. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2746. (txProfile.ChargingSchedule.Duration > 0))
  2747. {
  2748. if(maxProfile.ChargingProfileId != -1)
  2749. {
  2750. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2751. {
  2752. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2753. {
  2754. if((maxProfile.ChargingSchedule.Duration > 0))
  2755. {
  2756. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2757. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2758. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2759. }
  2760. else
  2761. {
  2762. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2763. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2764. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2765. }
  2766. }
  2767. if(idxMaxPeriod == (limitMax-1))
  2768. {
  2769. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2770. {
  2771. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2772. {
  2773. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2774. compositePeriodIdx++;
  2775. }
  2776. else
  2777. {
  2778. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2779. }
  2780. }
  2781. }
  2782. }
  2783. }
  2784. else
  2785. {
  2786. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2787. {
  2788. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2789. compositePeriodIdx++;
  2790. }
  2791. else
  2792. {
  2793. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2794. }
  2795. }
  2796. }
  2797. if(idxTxPeriod == (limitTx-1))
  2798. {
  2799. if(defaultTxProfile.ChargingProfileId != -1)
  2800. {
  2801. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2802. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2803. {
  2804. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2805. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2806. (defaultTxProfile.ChargingSchedule.Duration>0))
  2807. {
  2808. if(maxProfile.ChargingProfileId != -1)
  2809. {
  2810. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2811. {
  2812. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2813. {
  2814. if((maxProfile.ChargingSchedule.Duration > 0))
  2815. {
  2816. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2817. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2818. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2819. }
  2820. else
  2821. {
  2822. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2823. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2824. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2825. }
  2826. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2827. {
  2828. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2829. {
  2830. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2831. compositePeriodIdx++;
  2832. }
  2833. else
  2834. {
  2835. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2836. }
  2837. }
  2838. // Delete duplicate period
  2839. if(compositePeriodIdx > 1)
  2840. {
  2841. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2842. {
  2843. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2844. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2845. compositePeriodIdx -= 1;
  2846. }
  2847. }
  2848. }
  2849. else
  2850. {
  2851. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2852. {
  2853. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2854. compositePeriodIdx++;
  2855. }
  2856. else
  2857. {
  2858. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2859. }
  2860. break;
  2861. }
  2862. }
  2863. }
  2864. else
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2867. {
  2868. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2869. compositePeriodIdx++;
  2870. }
  2871. else
  2872. {
  2873. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2874. }
  2875. }
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2883. else if(defaultTxProfile.ChargingProfileId != -1)
  2884. {
  2885. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2886. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2887. {
  2888. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2889. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2890. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2891. {
  2892. if(maxProfile.ChargingProfileId != -1)
  2893. {
  2894. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2895. {
  2896. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2897. {
  2898. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2899. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2900. if((maxProfile.ChargingSchedule.Duration > 0))
  2901. {
  2902. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2903. }
  2904. else
  2905. {
  2906. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2907. }
  2908. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2909. {
  2910. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2911. {
  2912. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2913. compositePeriodIdx++;
  2914. }
  2915. else
  2916. {
  2917. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2918. }
  2919. }
  2920. // Delete duplicate period
  2921. if(compositePeriodIdx > 1)
  2922. {
  2923. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2924. {
  2925. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2927. compositePeriodIdx -= 1;
  2928. }
  2929. }
  2930. }
  2931. else
  2932. {
  2933. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2934. {
  2935. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2936. compositePeriodIdx++;
  2937. }
  2938. else
  2939. {
  2940. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2941. }
  2942. break;
  2943. }
  2944. }
  2945. }
  2946. else
  2947. {
  2948. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2949. {
  2950. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2951. compositePeriodIdx++;
  2952. }
  2953. else
  2954. {
  2955. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2956. }
  2957. }
  2958. }
  2959. }
  2960. }
  2961. // Fill other period by MaxProfile
  2962. if(maxProfile.ChargingProfileId != -1)
  2963. {
  2964. if(compositePeriodIdx==0)
  2965. {
  2966. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2967. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2968. {
  2969. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2970. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2971. (maxProfile.ChargingSchedule.Duration > 0))
  2972. {
  2973. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2974. {
  2975. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2976. compositePeriodIdx++;
  2977. }
  2978. else
  2979. {
  2980. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2981. }
  2982. }
  2983. }
  2984. }
  2985. else
  2986. {
  2987. int lastCompositePeriodIdx = compositePeriodIdx;
  2988. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2989. {
  2990. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2991. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2992. (maxProfile.ChargingSchedule.Duration > 0))
  2993. {
  2994. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  2995. {
  2996. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  2997. {
  2998. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  2999. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3000. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3001. }
  3002. else
  3003. {
  3004. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3005. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3006. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3007. }
  3008. }
  3009. if(tmpPeriod.Limit != -1)
  3010. {
  3011. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3012. {
  3013. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3014. {
  3015. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3016. compositePeriodIdx++;
  3017. }
  3018. else
  3019. {
  3020. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3021. }
  3022. }
  3023. // Delete duplicate period
  3024. if(compositePeriodIdx > 1)
  3025. {
  3026. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3027. {
  3028. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3029. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3030. compositePeriodIdx -= 1;
  3031. }
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. }
  3038. compositeProfile->ChargingSchedule.Duration = durationReq;
  3039. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3040. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3041. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3042. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3043. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3044. {
  3045. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3046. {
  3047. compositeProfile->ChargingProfileId = 1;
  3048. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3049. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3050. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3051. }
  3052. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3053. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3054. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3055. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3056. }
  3057. if(line)
  3058. free(line);
  3059. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3060. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3061. }
  3062. //==========================================
  3063. // Init all share memory
  3064. //==========================================
  3065. int InitShareMemory()
  3066. {
  3067. int result = PASS;
  3068. int MeterSMId;
  3069. //creat ShmSysConfigAndInfo
  3070. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3071. {
  3072. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3073. result = FAIL;
  3074. }
  3075. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3076. {
  3077. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3078. result = FAIL;
  3079. }
  3080. else
  3081. {}
  3082. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3083. {
  3084. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3085. result = FAIL;
  3086. }
  3087. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3088. {
  3089. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3090. result = FAIL;
  3091. }
  3092. else
  3093. {}
  3094. //creat ShmPsuData
  3095. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3096. {
  3097. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3098. result = FAIL;
  3099. }
  3100. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3101. {
  3102. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3103. result = FAIL;
  3104. }
  3105. else
  3106. {}
  3107. //link ShmOCPP16Data
  3108. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3109. {
  3110. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3111. result = FAIL;
  3112. }
  3113. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3114. {
  3115. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3116. result = FAIL;
  3117. }
  3118. else
  3119. {}
  3120. //creat ShmOCPP16DataPH
  3121. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3122. {
  3123. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3124. result = FAIL;
  3125. }
  3126. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3127. {
  3128. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3129. result = FAIL;
  3130. }
  3131. else
  3132. {}
  3133. /****************************** For Initial Settings************************************************/
  3134. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3135. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3136. // allocate Configuration memory address
  3137. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3138. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3139. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3140. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3141. //offline MeterValue Interval
  3142. TempMeterValueInterval = 0;
  3143. return result;
  3144. }
  3145. int ProcessShareMemory()
  3146. {
  3147. int result = PASS;
  3148. ParsingRatedCur modelnameInfo={0};
  3149. if(InitShareMemory() == FAIL)
  3150. {
  3151. DEBUG_ERROR("InitShareMemory NG\n");
  3152. if(ShmStatusCodeData!=NULL)
  3153. {
  3154. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3155. }
  3156. result = FAIL;
  3157. }
  3158. // Model name parsing
  3159. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3160. {
  3161. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3162. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3163. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3164. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3165. ) // 'D' means DC
  3166. {
  3167. // DO series
  3168. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3169. {
  3170. SystemInitial += 1;
  3171. gunTotalNumber += 1;
  3172. gunType[gun_index] = GUN_TYPE_DO;
  3173. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3174. {
  3175. case Gun_Type_Chademo:
  3176. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3177. break;
  3178. case Gun_Type_CCS_2:
  3179. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3180. break;
  3181. case Gun_Type_GB:
  3182. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3183. break;
  3184. case Gun_Type_AC:
  3185. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3186. break;
  3187. default:
  3188. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3189. break;
  3190. }
  3191. }
  3192. }
  3193. else
  3194. {
  3195. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3196. {
  3197. SystemInitial += 1;
  3198. gunTotalNumber += 1;
  3199. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3200. {
  3201. case Gun_Type_Chademo:
  3202. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3203. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3204. break;
  3205. case Gun_Type_CCS_2:
  3206. gunType[gun_index] = GUN_TYPE_CCS;
  3207. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3208. break;
  3209. case Gun_Type_GB:
  3210. gunType[gun_index] = GUN_TYPE_GBT;
  3211. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3212. break;
  3213. case Gun_Type_AC:
  3214. gunType[gun_index] = GUN_TYPE_AC;
  3215. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3216. break;
  3217. default:
  3218. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3219. break;
  3220. }
  3221. }
  3222. }
  3223. }
  3224. else
  3225. {
  3226. DEBUG_ERROR("Model name parsing fail.\n");
  3227. result = FAIL;
  3228. }
  3229. if(result != PASS)sleep(5);
  3230. return result;
  3231. }
  3232. void CheckSystemValue(void)
  3233. {
  3234. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3235. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3236. char filenmae[100]={0};
  3237. char str[100]={0};
  3238. int tempIndex = 0;
  3239. //===============================
  3240. // send Heartbeat
  3241. //===============================
  3242. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3243. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3244. {
  3245. clientTime.Heartbeat=time((time_t*)NULL);
  3246. if(server_sign == TRUE)
  3247. {
  3248. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3249. }
  3250. else
  3251. {
  3252. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3253. }
  3254. }
  3255. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3256. {
  3257. //parameter for test
  3258. sendHeartbeatRequest(0);
  3259. //==============================================
  3260. // Reset Waiting Time
  3261. //==============================================
  3262. HeartBeatWithNOResponse += 2;
  3263. }
  3264. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3265. {
  3266. //==========================================
  3267. // csu trigger DataTransferReq
  3268. //==========================================
  3269. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3270. {
  3271. sendDataTransferRequest(gun_index);
  3272. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3273. }
  3274. //===============================
  3275. // CSU Trigger Authorize Request
  3276. //===============================
  3277. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3278. {
  3279. sendAuthorizeRequest(0);
  3280. authorizeRetryTimes = authorizeRetryTimes + 1;
  3281. if(authorizeRetryTimes < 3)
  3282. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3283. }
  3284. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3285. {
  3286. authorizeRetryTimes = 0;
  3287. SetOcppConnStatus(FALSE);
  3288. server_sign = FALSE;
  3289. }
  3290. 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))
  3291. {
  3292. sendAuthorizeRequest(0);
  3293. }
  3294. //==============================================
  3295. // Charger start transaction
  3296. //==============================================
  3297. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3298. {
  3299. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3300. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3301. sendStartTransactionRequest(gun_index);
  3302. clientTime.StartTransaction = time((time_t*)NULL);
  3303. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3304. storeTempStopTransaction(gun_index);
  3305. }
  3306. //==============================================
  3307. // Charger stop transaction
  3308. //==============================================
  3309. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3310. {
  3311. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3312. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3313. sendStopTransactionRequest(gun_index);
  3314. clientTime.StopTransaction = time((time_t*)NULL);
  3315. }
  3316. //==============================================
  3317. // Charger status report
  3318. //==============================================
  3319. //--- Check Mode Change ---//
  3320. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3321. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3322. {
  3323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3324. {
  3325. tempIndex = ((gun_index==2) ? 1: 0);
  3326. }
  3327. else
  3328. {
  3329. tempIndex = gun_index;
  3330. }
  3331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3332. {
  3333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3334. {
  3335. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3336. {
  3337. // Sent unplug message for California pricing logic
  3338. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3339. {
  3340. uint8_t ts[20];
  3341. getNowDatetime(ts);
  3342. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3343. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3344. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3345. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3346. }
  3347. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3348. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3349. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3350. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3351. {
  3352. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3353. if((access(filenmae,F_OK))!=-1)
  3354. {
  3355. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3356. sprintf(str,"rm -f %s",filenmae);
  3357. system(str);
  3358. }
  3359. }
  3360. }
  3361. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3362. #if 1 // for TempStopTransaction
  3363. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3364. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3365. {
  3366. checkTempStopTransaction(gun_index);
  3367. }
  3368. #endif
  3369. }
  3370. }
  3371. }
  3372. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3373. {
  3374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3375. {
  3376. tempIndex = ((gun_index==2) ? 1: 0);
  3377. }
  3378. else
  3379. {
  3380. tempIndex = gun_index;
  3381. }
  3382. for (int index = 0; index < CCS_QUANTITY; index++)
  3383. {
  3384. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3385. {
  3386. if((SystemInitial > 0) || (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]*/ )
  3387. {
  3388. // Sent unplug message for California pricing logic
  3389. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3390. {
  3391. uint8_t ts[20];
  3392. getNowDatetime(ts);
  3393. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3394. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3395. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3396. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3397. }
  3398. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3399. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3400. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3401. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3402. {
  3403. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3404. if((access(filenmae,F_OK))!=-1)
  3405. {
  3406. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3407. sprintf(str,"rm -f %s",filenmae);
  3408. system(str);
  3409. }
  3410. }
  3411. }
  3412. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3413. #if 1 // for TempStopTransaction
  3414. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3415. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3416. {
  3417. checkTempStopTransaction(gun_index);
  3418. }
  3419. #endif
  3420. }
  3421. }
  3422. }
  3423. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3424. {
  3425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3426. {
  3427. tempIndex = ((gun_index==2) ? 1: 0);
  3428. }
  3429. else
  3430. {
  3431. tempIndex = gun_index;
  3432. }
  3433. for (int index = 0; index < GB_QUANTITY; index++)
  3434. {
  3435. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3436. {
  3437. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3438. {
  3439. // Sent unplug message for California pricing logic
  3440. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3441. {
  3442. uint8_t ts[20];
  3443. getNowDatetime(ts);
  3444. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3445. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3446. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3447. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3448. }
  3449. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3450. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3451. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3452. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3453. {
  3454. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3455. if((access(filenmae,F_OK))!=-1)
  3456. {
  3457. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3458. sprintf(str,"rm -f %s",filenmae);
  3459. system(str);
  3460. }
  3461. }
  3462. }
  3463. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3464. #if 1 // for TempStopTransaction
  3465. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3466. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3467. {
  3468. checkTempStopTransaction(gun_index);
  3469. }
  3470. #endif
  3471. }
  3472. }
  3473. }
  3474. else if(gunType[gun_index] == GUN_TYPE_DO)
  3475. {
  3476. tempIndex = gun_index;
  3477. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3478. {
  3479. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3480. {
  3481. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3482. {
  3483. // Sent unplug message for California pricing logic
  3484. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3485. {
  3486. uint8_t ts[20];
  3487. getNowDatetime(ts);
  3488. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3489. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3490. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3491. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3492. }
  3493. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3494. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3495. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3496. 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
  3497. {
  3498. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3499. if((access(filenmae,F_OK))!=-1)
  3500. {
  3501. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3502. sprintf(str,"rm -f %s",filenmae);
  3503. system(str);
  3504. }
  3505. }
  3506. }
  3507. 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);
  3508. #if 1 // for TempStopTransaction
  3509. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3510. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3511. {
  3512. checkTempStopTransaction(gun_index);
  3513. }
  3514. #endif
  3515. }
  3516. }
  3517. }
  3518. else
  3519. {
  3520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3521. {
  3522. tempIndex = 2;
  3523. }
  3524. else
  3525. {
  3526. tempIndex = gun_index;
  3527. }
  3528. for (int index = 0; index < AC_QUANTITY; index++)
  3529. {
  3530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3531. {
  3532. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3533. {
  3534. // Sent unplug message for California pricing logic
  3535. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3536. {
  3537. uint8_t ts[20];
  3538. getNowDatetime(ts);
  3539. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3540. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3541. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3542. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3543. }
  3544. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3545. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3546. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3547. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3548. {
  3549. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3550. if((access(filenmae,F_OK))!=-1)
  3551. {
  3552. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3553. sprintf(str,"rm -f %s",filenmae);
  3554. system(str);
  3555. }
  3556. }
  3557. }
  3558. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3559. #if 1 // for TempStopTransaction
  3560. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3561. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3562. {
  3563. checkTempStopTransaction(gun_index);
  3564. }
  3565. #endif
  3566. }
  3567. }// END
  3568. }
  3569. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3570. (
  3571. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3572. )
  3573. )
  3574. {
  3575. if(SystemInitial > 0)
  3576. SystemInitial -= 1;
  3577. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3578. sendStatusNotificationRequest(gun_index);
  3579. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3580. }
  3581. //==============================================
  3582. // CSU Trigger Smart Charging Profilw
  3583. //==============================================
  3584. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3585. {
  3586. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3587. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3588. }
  3589. //==============================================
  3590. // Meter report
  3591. //==============================================
  3592. // Trigger MeterValue
  3593. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3594. {
  3595. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3596. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3597. }
  3598. // ClockAlign MeterValue
  3599. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3600. {
  3601. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3602. {
  3603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3604. {
  3605. tempIndex = ((gun_index==2) ? 1: 0);
  3606. }
  3607. else
  3608. {
  3609. tempIndex = gun_index;
  3610. }
  3611. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3612. {
  3613. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3614. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3615. {
  3616. reqClockAlignMeter[gun_index] = 1;
  3617. }
  3618. }// End for CHAdeMO
  3619. }
  3620. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3621. {
  3622. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3623. {
  3624. tempIndex = ((gun_index==2) ? 1: 0);
  3625. }
  3626. else
  3627. {
  3628. tempIndex = gun_index;
  3629. }
  3630. for (int index = 0; index < CCS_QUANTITY; index++)
  3631. {
  3632. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3633. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3634. {
  3635. reqClockAlignMeter[gun_index] = 1;
  3636. }
  3637. } // End for CCS
  3638. }
  3639. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3640. {
  3641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3642. {
  3643. tempIndex = ((gun_index==2) ? 1: 0);
  3644. }
  3645. else
  3646. {
  3647. tempIndex = gun_index;
  3648. }
  3649. for (int index = 0; index < GB_QUANTITY; index++)
  3650. {
  3651. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3652. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3653. {
  3654. reqClockAlignMeter[gun_index] = 1;
  3655. }
  3656. }// End for GB
  3657. }
  3658. else if(gunType[gun_index] == GUN_TYPE_DO)
  3659. {
  3660. tempIndex = gun_index;
  3661. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3662. {
  3663. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3664. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3665. {
  3666. reqClockAlignMeter[gun_index] = 1;
  3667. }
  3668. }
  3669. }
  3670. else
  3671. {
  3672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3673. {
  3674. tempIndex = 2;
  3675. }
  3676. else
  3677. {
  3678. tempIndex = gun_index;
  3679. }
  3680. for (int index = 0; index < AC_QUANTITY; index++)
  3681. {
  3682. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3683. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3684. {
  3685. reqClockAlignMeter[gun_index] = 1;
  3686. }
  3687. }//End for AC
  3688. }
  3689. if(reqClockAlignMeter[gun_index] == 1)
  3690. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3691. }
  3692. // Sample period MeterValue
  3693. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3694. {
  3695. //check Transaction active
  3696. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3697. {
  3698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3699. {
  3700. tempIndex = ((gun_index==2) ? 1: 0);
  3701. }
  3702. else
  3703. {
  3704. tempIndex = gun_index;
  3705. }
  3706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3707. {
  3708. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3709. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3710. {
  3711. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3712. {
  3713. reqSampleMeter[gun_index] = 1;
  3714. }
  3715. }
  3716. }// End for CHAdeMO
  3717. }
  3718. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3719. {
  3720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3721. {
  3722. tempIndex = ((gun_index==2) ? 1: 0);
  3723. }
  3724. else
  3725. {
  3726. tempIndex = gun_index;
  3727. }
  3728. for (int index = 0; index < CCS_QUANTITY; index++)
  3729. {
  3730. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3731. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3732. {
  3733. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3734. {
  3735. reqSampleMeter[gun_index] = 1;
  3736. }
  3737. }
  3738. } // End for CCS
  3739. }
  3740. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3741. {
  3742. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3743. {
  3744. tempIndex = ((gun_index==2) ? 1: 0);
  3745. }
  3746. else
  3747. {
  3748. tempIndex = gun_index;
  3749. }
  3750. for (int index = 0; index < GB_QUANTITY; index++)
  3751. {
  3752. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3753. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3754. {
  3755. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3756. {
  3757. reqSampleMeter[gun_index] = 1;
  3758. }
  3759. }
  3760. }// End for GB
  3761. }
  3762. else if(gunType[gun_index] == GUN_TYPE_DO)
  3763. {
  3764. tempIndex = gun_index;
  3765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3766. {
  3767. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3768. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3769. {
  3770. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3771. {
  3772. reqSampleMeter[gun_index] = 1;
  3773. }
  3774. }
  3775. }
  3776. }
  3777. else
  3778. {
  3779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3780. {
  3781. tempIndex = 2;
  3782. }
  3783. else
  3784. {
  3785. tempIndex = gun_index;
  3786. }
  3787. for (int index = 0; index < AC_QUANTITY; index++)
  3788. {
  3789. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3790. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3791. {
  3792. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3793. {
  3794. reqSampleMeter[gun_index] = 1;
  3795. }
  3796. }
  3797. }//End for AC
  3798. }
  3799. if(reqSampleMeter[gun_index] == 1)
  3800. {
  3801. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3802. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3803. storeTempStopTransaction(gun_index);
  3804. }
  3805. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3806. }
  3807. //==============================================
  3808. // Check Connector reserved
  3809. //==============================================
  3810. //===============================
  3811. // Check if Reserve is expired
  3812. //===============================
  3813. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3814. {
  3815. double diff_t;
  3816. struct tm tp;
  3817. // current time
  3818. time_t t = time(NULL);
  3819. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3820. tp.tm_isdst = -1;
  3821. time_t utc = mktime(&tp);
  3822. diff_t = difftime(utc, t);
  3823. if(diff_t <= 0)
  3824. {
  3825. DEBUG_INFO("reserve expired.\n");
  3826. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3827. }
  3828. }//END OF Check if Reserve is expired
  3829. //==========================================
  3830. // csu trigger FirmwareStatusNotificationReq
  3831. //==========================================
  3832. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3833. {
  3834. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3835. }
  3836. //==========================================
  3837. // csu trigger DiagnosticsStatusNotificationReq
  3838. //==========================================
  3839. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3840. {
  3841. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3842. }
  3843. //==========================================
  3844. // csu trigger CancelReservationConf
  3845. //==========================================
  3846. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3847. {
  3848. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3849. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3850. }
  3851. //==========================================
  3852. // csu trigger ChangeAvailabilityConf
  3853. //==========================================
  3854. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3855. {
  3856. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3857. }
  3858. //==========================================
  3859. // csu trigger UnlockConnectorConf
  3860. //==========================================
  3861. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3862. {
  3863. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3864. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3865. }
  3866. //==========================================
  3867. // csu trigger ReserveNowConf
  3868. //==========================================
  3869. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3870. {
  3871. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3872. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3873. }
  3874. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3875. {
  3876. sendSignCertificateRequest();
  3877. }
  3878. }
  3879. }
  3880. //==========================================
  3881. // send request routine
  3882. //==========================================
  3883. int sendAuthorizeRequest(int gun_index)
  3884. {
  3885. mtrace();
  3886. int result = FAIL;
  3887. char message[100]={0};
  3888. char guid[37];
  3889. char tempdata[65]={0};
  3890. DEBUG_INFO("sendAuthorizeRequest...\n");
  3891. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3892. //Local Authorize
  3893. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3894. {
  3895. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3896. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3897. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3898. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3899. result = PASS;
  3900. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3901. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3902. authorizeRetryTimes = 0;
  3903. return result;
  3904. }
  3905. 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))||
  3906. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3907. {
  3908. // Query from cache
  3909. DEBUG_INFO("Authorize from cache.\n");
  3910. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3911. // Query from list
  3912. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3913. {
  3914. DEBUG_INFO("Authorize from list.\n");
  3915. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3916. }
  3917. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3918. {
  3919. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3920. {
  3921. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3922. }
  3923. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3924. {
  3925. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3926. }
  3927. if(!GetOcppConnStatus())
  3928. {
  3929. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3930. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3931. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3932. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3933. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3934. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3935. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3936. authorizeRetryTimes = 0;
  3937. return result;
  3938. }
  3939. }
  3940. else
  3941. {
  3942. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3943. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3944. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3945. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3946. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3947. else
  3948. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3949. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3950. result = PASS;
  3951. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3952. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3953. authorizeRetryTimes = 0;
  3954. return result;
  3955. }
  3956. }
  3957. //initialize struct Authorize
  3958. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3959. //get data from shared memory
  3960. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3961. random_uuid(guid);
  3962. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3963. LWS_Send(message);
  3964. sprintf(tempdata, "Authorize,%d", gun_index);
  3965. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3966. {
  3967. result = PASS;
  3968. DEBUG_INFO("Authorize mapItem pass\n");
  3969. }
  3970. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3971. return result;
  3972. }
  3973. int sendBootNotificationRequest(void)
  3974. {
  3975. mtrace();
  3976. int result = FAIL;
  3977. char message[500]={0}, payload[700]={0};
  3978. char guid[37]={0};
  3979. char tempdata[65]={0};
  3980. // Fill BootNotification fields
  3981. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3982. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3983. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3984. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3985. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3986. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3987. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3988. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3989. ShmOCPP16DataPH->ChargeBoxId
  3990. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3991. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3992. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3993. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3994. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3995. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3996. random_uuid(guid);
  3997. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3998. LWS_Send(message);
  3999. sprintf(tempdata, "BootNotification,0");
  4000. 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*/)
  4001. {
  4002. result = PASS;
  4003. }
  4004. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4005. strcpy(queuedata,message);
  4006. return result;
  4007. }
  4008. int sendDataTransferRequest(int gun_index)
  4009. {
  4010. mtrace();
  4011. char message[1000]={0};
  4012. char guid[37]={0};
  4013. char tempdata[65]={0};
  4014. int result = FAIL;
  4015. random_uuid(guid);
  4016. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4017. MESSAGE_TYPE_CALL,
  4018. guid,
  4019. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4020. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4021. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4022. LWS_Send(message);
  4023. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4024. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4025. {
  4026. result = PASS;
  4027. DEBUG_INFO("DataTransfer mapItem pass\n");
  4028. }
  4029. return result;
  4030. }
  4031. int sendDiagnosticsStatusNotificationRequest(char *status)
  4032. {
  4033. mtrace();
  4034. int result = FAIL;
  4035. char message[110]={0};
  4036. char guid[37]={0};
  4037. char tempdata[65]={0};
  4038. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4039. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4040. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4041. random_uuid(guid);
  4042. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4043. LWS_SendNow(message);
  4044. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4045. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4046. {
  4047. result = PASS;
  4048. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4049. }
  4050. //#ifdef SystemLogMessage
  4051. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4052. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4053. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4054. //#endif
  4055. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4056. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4057. //record status
  4058. if(strcmp(status,"Idle")==0)
  4059. {
  4060. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4061. }
  4062. else if(strcmp(status,"Uploaded")==0)
  4063. {
  4064. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4065. }
  4066. else if(strcmp(status,"UploadFailed")==0)
  4067. {
  4068. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4069. }
  4070. else if(strcmp(status,"Uploading")==0)
  4071. {
  4072. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4073. }
  4074. return result;
  4075. }
  4076. int sendFirmwareStatusNotificationRequest(char *status)
  4077. {
  4078. mtrace();
  4079. int result = FAIL;
  4080. char message[110]={0};
  4081. char guid[37]={0};
  4082. char tempdata[65]={0};
  4083. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4084. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4085. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4086. random_uuid(guid);
  4087. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4088. LWS_SendNow(message);
  4089. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4090. 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*/)
  4091. {
  4092. result = PASS;
  4093. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4094. }
  4095. //#ifdef SystemLogMessage
  4096. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4097. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4098. //#endif
  4099. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4100. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4101. //record status
  4102. if(strcmp(status,"Downloaded")==0)
  4103. {
  4104. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4105. }
  4106. else if(strcmp(status,"DownloadFailed")==0)
  4107. {
  4108. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4109. }
  4110. else if(strcmp(status,"Downloading")==0)
  4111. {
  4112. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4113. }
  4114. else if(strcmp(status,"Idle")==0)
  4115. {
  4116. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4117. }
  4118. else if(strcmp(status,"InstallationFailed")==0)
  4119. {
  4120. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4121. }
  4122. else if(strcmp(status,"Installing")==0)
  4123. {
  4124. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4125. }
  4126. else if(strcmp(status,"Installed")==0)
  4127. {
  4128. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4129. }
  4130. return result;
  4131. }
  4132. int sendHeartbeatRequest(int gun_index)
  4133. {
  4134. mtrace();
  4135. int result = FAIL;
  4136. char message[80]={0};
  4137. char guid[37]={0};
  4138. char tempdata[65]={0};
  4139. random_uuid(guid);
  4140. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4141. , MESSAGE_TYPE_CALL
  4142. , guid );
  4143. LWS_Send(message);
  4144. sprintf(tempdata, "Heartbeat,%d", 0);
  4145. 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*/)
  4146. {
  4147. result = PASS;
  4148. }
  4149. return result;
  4150. }
  4151. int sendStartTransactionRequest(int gun_index)
  4152. {
  4153. mtrace();
  4154. int result = FAIL;
  4155. char message[250]={0};
  4156. char guid[37]={0};
  4157. struct timeval tmnow;
  4158. struct tm *tm;
  4159. char buf[28];//, usec_buf[6];
  4160. char tempdata[65]={0};
  4161. int tempIndex = 0;
  4162. DEBUG_INFO("sendStartTransactionRequest...\n");
  4163. gettimeofday(&tmnow, NULL);
  4164. time_t t;
  4165. t = time(NULL);
  4166. /*UTC time and date*/
  4167. tm = gmtime(&t);
  4168. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4169. #if 0 // remove temporally
  4170. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4171. strcat(buf,".");
  4172. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4173. strcat(buf,usec_buf);
  4174. #endif
  4175. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4176. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4177. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4178. // clear StartTransaction Response
  4179. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4180. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4181. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4182. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4183. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4184. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4185. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4186. {
  4187. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4188. {
  4189. tempIndex = ((gun_index==2) ? 1: 0);
  4190. }
  4191. else
  4192. {
  4193. tempIndex = gun_index;
  4194. }
  4195. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4196. {
  4197. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4198. {
  4199. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4200. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4201. }
  4202. }
  4203. }
  4204. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4205. {
  4206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4207. {
  4208. tempIndex = ((gun_index==2) ? 1: 0);
  4209. }
  4210. else
  4211. {
  4212. tempIndex = gun_index;
  4213. }
  4214. for (int index = 0; index < CCS_QUANTITY; index++)
  4215. {
  4216. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4217. {
  4218. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4219. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4220. }
  4221. }
  4222. }
  4223. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4224. {
  4225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4226. {
  4227. tempIndex = ((gun_index==2) ? 1: 0);
  4228. }
  4229. else
  4230. {
  4231. tempIndex = gun_index;
  4232. }
  4233. for (int index = 0; index < GB_QUANTITY; index++)
  4234. {
  4235. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4236. {
  4237. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4238. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4239. }
  4240. }
  4241. }
  4242. else if(gunType[gun_index] == GUN_TYPE_DO)
  4243. {
  4244. tempIndex = gun_index;
  4245. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4246. {
  4247. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4248. {
  4249. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4250. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4251. }
  4252. }
  4253. }
  4254. else
  4255. {
  4256. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4257. {
  4258. tempIndex = 2;
  4259. }
  4260. else
  4261. {
  4262. tempIndex = gun_index;
  4263. }
  4264. for (int index = 0; index < AC_QUANTITY; index++)
  4265. {
  4266. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4267. {
  4268. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4269. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4270. }
  4271. }
  4272. }
  4273. random_uuid(guid);
  4274. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4275. {
  4276. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4277. , gun_index +1
  4278. , MESSAGE_TYPE_CALL
  4279. , guid
  4280. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4281. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4282. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4283. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4284. }
  4285. else
  4286. {
  4287. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4288. , gun_index +1
  4289. , MESSAGE_TYPE_CALL
  4290. , guid
  4291. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4292. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4293. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4294. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4295. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4296. }
  4297. #if 1
  4298. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4299. 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*/)
  4300. {
  4301. result = PASS;
  4302. }
  4303. #endif
  4304. strcpy(queuedata, message);
  4305. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4306. OCPP_insert_transaction_msg(YES, queuedata);
  4307. return result;
  4308. }
  4309. int sendStatusNotificationRequest(int gun_index)
  4310. {
  4311. mtrace();
  4312. int result = FAIL;
  4313. char message[600]={0};
  4314. char guid[37];
  4315. int currentStatus = 0;
  4316. struct timeval tmnow;
  4317. struct tm *tm;
  4318. char buf[28];//, usec_buf[6];
  4319. char tempdata[65]={0};
  4320. int tempIndex = 0;
  4321. uint8_t isStateChanged = TRUE;
  4322. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4323. gettimeofday(&tmnow, NULL);
  4324. time_t t;
  4325. t = time(NULL);
  4326. /*UTC time and date*/
  4327. tm = gmtime(&t);
  4328. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4329. #if 0 // remove temporally
  4330. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4331. strcat(buf,".");
  4332. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4333. strcat(buf,usec_buf);
  4334. #endif
  4335. //printf("%s",buf);
  4336. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4337. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4338. // it's option
  4339. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4340. /*
  4341. enum _SYSTEM_STATUS
  4342. {
  4343. S_BOOTING = 0,
  4344. S_IDLE, = 1
  4345. S_AUTHORIZING, =2
  4346. S_REASSIGN_CHECK, =3
  4347. S_REASSIGN, =4
  4348. S_PRECHARGE, =5
  4349. S_PREPARING_FOR_EV, =6
  4350. S_PREPARING_FOR_EVSE, =7
  4351. S_CHARGING, =8
  4352. S_TERMINATING, =9
  4353. S_COMPLETE, =10
  4354. S_ALARM, =11
  4355. S_FAULT =12
  4356. }
  4357. */
  4358. //check Transaction active
  4359. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4360. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4361. {
  4362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4363. {
  4364. tempIndex = ((gun_index==2) ? 1: 0);
  4365. }
  4366. else
  4367. {
  4368. tempIndex = gun_index;
  4369. }
  4370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4371. {
  4372. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4373. {
  4374. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4375. {
  4376. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4377. {
  4378. currentStatus = Preparing; //OCPP Status: Preparing
  4379. }
  4380. else
  4381. {
  4382. currentStatus = Available; //OCPP Status: Available
  4383. }
  4384. }
  4385. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4386. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4387. ) //S_PRECHARGE
  4388. {
  4389. currentStatus = Preparing; //OCPP Status: Preparing
  4390. }
  4391. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4392. {
  4393. currentStatus = Charging; //OCPP Status: Charging
  4394. }
  4395. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4396. {
  4397. currentStatus = Finishing; //OCPP Status: Finishing
  4398. }
  4399. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4400. {
  4401. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4402. }
  4403. 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
  4404. {
  4405. currentStatus = Unavailable; //OCPP Status: Unavailable
  4406. }
  4407. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4408. {
  4409. currentStatus = Faulted; //OCPP Status: Faulted
  4410. }
  4411. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4412. {
  4413. currentStatus = Reserved; //OCPP Status: Reserved
  4414. }
  4415. } //end of the same index
  4416. }//end of for CHAdeMO_QUANTITY
  4417. }
  4418. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4419. {
  4420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4421. {
  4422. tempIndex = ((gun_index==2) ? 1: 0);
  4423. }
  4424. else
  4425. {
  4426. tempIndex = gun_index;
  4427. }
  4428. for (int index = 0; index < CCS_QUANTITY; index++)
  4429. {
  4430. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4431. {
  4432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4433. {
  4434. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4435. {
  4436. currentStatus = Preparing; //OCPP Status: Preparing
  4437. }
  4438. else
  4439. {
  4440. currentStatus = Available; //OCPP Status: Available
  4441. }
  4442. }
  4443. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4444. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4445. ) //S_PRECHARGE
  4446. {
  4447. currentStatus = Preparing; //OCPP Status: Preparing
  4448. }
  4449. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4450. {
  4451. currentStatus = Charging; //OCPP Status: Charging
  4452. }
  4453. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4454. {
  4455. currentStatus = Finishing; //OCPP Status: Finishing
  4456. }
  4457. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4458. {
  4459. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4460. }
  4461. 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
  4462. {
  4463. currentStatus = Unavailable; //OCPP Status : Unavailable
  4464. }
  4465. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4466. {
  4467. currentStatus = Faulted; //OCPP Status: Faulted
  4468. }
  4469. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4470. {
  4471. currentStatus = Reserved; //OCPP Status: Reserved
  4472. }
  4473. } //end of the same index
  4474. } // end of for CCS_QUANTITY
  4475. }
  4476. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4477. {
  4478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4479. {
  4480. tempIndex = ((gun_index==2) ? 1: 0);
  4481. }
  4482. else
  4483. {
  4484. tempIndex = gun_index;
  4485. }
  4486. for (int index = 0; index < GB_QUANTITY; index++)
  4487. {
  4488. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4489. {
  4490. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4491. {
  4492. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4493. {
  4494. currentStatus = Preparing; //OCPP Status: Preparing
  4495. }
  4496. else
  4497. {
  4498. currentStatus = Available; //OCPP Status: Available
  4499. }
  4500. }
  4501. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4502. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4503. ) //S_PRECHARGE
  4504. {
  4505. currentStatus = Preparing; //OCPP Status: Preparing
  4506. }
  4507. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4508. {
  4509. currentStatus = Charging; //OCPP Status: Charging
  4510. }
  4511. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4512. {
  4513. currentStatus = Finishing; //OCPP Status: Finishing
  4514. }
  4515. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4516. {
  4517. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4518. }
  4519. 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
  4520. {
  4521. currentStatus = Unavailable; //OCPP Status: Unavailable
  4522. }
  4523. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4524. {
  4525. currentStatus = Faulted; //OCPP Status: Faulted
  4526. }
  4527. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4528. {
  4529. currentStatus = Reserved; //OCPP Status: Reserved
  4530. }
  4531. } //end of the same index
  4532. } // end of for GB_QUANTITY
  4533. }
  4534. else if(gunType[gun_index] == GUN_TYPE_DO)
  4535. {
  4536. tempIndex = gun_index;
  4537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4538. {
  4539. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4540. {
  4541. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4542. {
  4543. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4544. {
  4545. currentStatus = Preparing; //OCPP Status: Preparing
  4546. }
  4547. else
  4548. {
  4549. currentStatus = Available; //OCPP Status: Available
  4550. }
  4551. }
  4552. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4553. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4554. ) //S_PRECHARGE
  4555. {
  4556. currentStatus = Preparing; //OCPP Status: Preparing
  4557. }
  4558. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4559. {
  4560. currentStatus = Charging; //OCPP Status: Charging
  4561. }
  4562. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4563. {
  4564. currentStatus = Finishing; //OCPP Status: Finishing
  4565. }
  4566. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4567. {
  4568. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4569. }
  4570. 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
  4571. {
  4572. currentStatus = Unavailable; //OCPP Status: Unavailable
  4573. }
  4574. 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
  4575. {
  4576. currentStatus = Faulted; //OCPP Status: Faulted
  4577. }
  4578. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4579. {
  4580. currentStatus = Reserved; //OCPP Status: Reserved
  4581. }
  4582. } //end of the same index
  4583. }
  4584. }
  4585. else
  4586. {
  4587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4588. {
  4589. tempIndex = 2;
  4590. }
  4591. else
  4592. {
  4593. tempIndex = gun_index;
  4594. }
  4595. for (int index = 0; index < AC_QUANTITY; index++)
  4596. {
  4597. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4600. {
  4601. 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))
  4602. {
  4603. currentStatus = Preparing; //OCPP Status: Preparing
  4604. }
  4605. else
  4606. {
  4607. currentStatus = Available; //OCPP Status: Available
  4608. }
  4609. }
  4610. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4611. {
  4612. currentStatus = Preparing; //OCPP Status: Preparing
  4613. }
  4614. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4615. {
  4616. currentStatus = Charging; //OCPP Status: Charging
  4617. }
  4618. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4619. {
  4620. currentStatus = Finishing; //OCPP Status: Finishing
  4621. }
  4622. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4623. {
  4624. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4625. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4626. else
  4627. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4628. }
  4629. 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
  4630. {
  4631. currentStatus = Unavailable; //OCPP Status: Unavailable
  4632. }
  4633. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4634. {
  4635. currentStatus = Faulted; //OCPP Status: Faulted
  4636. }
  4637. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4638. {
  4639. currentStatus = Reserved; //OCPP Status: Reserved
  4640. }
  4641. }//end of the same index
  4642. }//end of for AC_QUANTITY
  4643. }
  4644. //it's option
  4645. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4646. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4647. {
  4648. isStateChanged = FALSE;
  4649. }
  4650. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4651. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4652. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4653. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4654. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4655. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4656. random_uuid(guid);
  4657. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4658. , MESSAGE_TYPE_CALL
  4659. , guid
  4660. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4661. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4662. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4663. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4664. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4665. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4666. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4667. if((server_sign == TRUE) && isStateChanged)
  4668. {
  4669. LWS_Send(message);
  4670. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4671. 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*/)
  4672. {
  4673. //DEBUG_ERROR("statusNotification mapitem pass");
  4674. result = PASS;
  4675. }
  4676. }
  4677. else
  4678. {
  4679. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4680. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4681. result = PASS;
  4682. }
  4683. return result;
  4684. }
  4685. int sendStopTransactionRequest(int gun_index)
  4686. {
  4687. mtrace();
  4688. int result = FAIL;
  4689. //char message[1500]={0};
  4690. char guid[37]={0};
  4691. char tempdata[65]={0};
  4692. int tempIndex = 0;
  4693. char TempStopTransaction[256];
  4694. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4695. //int idx_sample=0;
  4696. DEBUG_INFO("sendStopTransactionRequest \n");
  4697. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4698. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4699. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4700. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4701. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4702. {
  4703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4704. {
  4705. tempIndex = ((gun_index==2) ? 1: 0);
  4706. }
  4707. else
  4708. {
  4709. tempIndex = gun_index;
  4710. }
  4711. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4712. {
  4713. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4714. {
  4715. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4716. }
  4717. }// END OF CHAdeMO_QUANTITY
  4718. }
  4719. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4720. {
  4721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4722. {
  4723. tempIndex = ((gun_index==2) ? 1: 0);
  4724. }
  4725. else
  4726. {
  4727. tempIndex = gun_index;
  4728. }
  4729. for (int index = 0; index < CCS_QUANTITY; index++)
  4730. {
  4731. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4732. {
  4733. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4734. }
  4735. }// END OF CCS_QUANTITY
  4736. }
  4737. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4738. {
  4739. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4740. {
  4741. tempIndex = ((gun_index==2) ? 1: 0);
  4742. }
  4743. else
  4744. {
  4745. tempIndex = gun_index;
  4746. }
  4747. for (int index = 0; index < GB_QUANTITY; index++)
  4748. {
  4749. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4750. {
  4751. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4752. }
  4753. }// END OF GB_QUANTITY
  4754. }
  4755. else if(gunType[gun_index] == GUN_TYPE_DO)
  4756. {
  4757. tempIndex = gun_index;
  4758. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4759. {
  4760. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4761. {
  4762. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4763. }
  4764. }// END OF GB_QUANTITY
  4765. }
  4766. else
  4767. {
  4768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4769. {
  4770. tempIndex = 2;
  4771. }
  4772. else
  4773. {
  4774. tempIndex = gun_index;
  4775. }
  4776. for (int index = 0; index < AC_QUANTITY; index++)
  4777. {
  4778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4779. {
  4780. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4781. }
  4782. }// END OF AC_QUANTITY
  4783. }
  4784. //====================================== Stop Transaction Time =====================================================
  4785. struct timeval tmnow;
  4786. struct tm *tm;
  4787. char buf[28];//, usec_buf[6];
  4788. gettimeofday(&tmnow, NULL);
  4789. time_t t;
  4790. t = time(NULL);
  4791. /*UTC time and date*/
  4792. tm = gmtime(&t);
  4793. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4794. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4795. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4796. random_uuid(guid);
  4797. /***********************************transactionData******************************************************/
  4798. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4800. //=================================
  4801. // Transaction_Begin
  4802. //=================================
  4803. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4804. {
  4805. //============================================ Energy.Active.Import.Interval ================================
  4806. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4810. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4811. 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))
  4812. {
  4813. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4814. }
  4815. else
  4816. {
  4817. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4818. }
  4819. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4820. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4821. }
  4822. //=================================
  4823. // Transaction_End
  4824. //=================================
  4825. // ================================= Current.Import L1 ===============================================
  4826. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4827. {
  4828. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4829. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4830. {
  4831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4832. {
  4833. tempIndex = ((gun_index==2) ? 1: 0);
  4834. }
  4835. else
  4836. {
  4837. tempIndex = gun_index;
  4838. }
  4839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4840. {
  4841. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4842. {
  4843. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4844. }
  4845. }// End of for CHAdeMO_QUANTITY
  4846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4847. }
  4848. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4849. {
  4850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4851. {
  4852. tempIndex = ((gun_index==2) ? 1: 0);
  4853. }
  4854. else
  4855. {
  4856. tempIndex = gun_index;
  4857. }
  4858. for (int index = 0; index < CCS_QUANTITY; index++)
  4859. {
  4860. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4861. {
  4862. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4863. }
  4864. }// End of for CCS_QUANTITY
  4865. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4866. }
  4867. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4868. {
  4869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4870. {
  4871. tempIndex = ((gun_index==2) ? 1: 0);
  4872. }
  4873. else
  4874. {
  4875. tempIndex = gun_index;
  4876. }
  4877. for (int index = 0; index < GB_QUANTITY; index++)
  4878. {
  4879. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4880. {
  4881. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4882. }
  4883. }// End of for GB_QUANTITY
  4884. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4885. }
  4886. else if(gunType[gun_index] == GUN_TYPE_DO)
  4887. {
  4888. tempIndex = gun_index;
  4889. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4890. {
  4891. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4892. {
  4893. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4894. }
  4895. }
  4896. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4897. }
  4898. else
  4899. {
  4900. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4901. {
  4902. tempIndex = 2;
  4903. }
  4904. else
  4905. {
  4906. tempIndex = gun_index;
  4907. }
  4908. for (int index = 0; index < AC_QUANTITY; index++)
  4909. {
  4910. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4911. {
  4912. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4913. }
  4914. }// End of for AC_QUANTITY
  4915. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4916. }
  4917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4922. }
  4923. // ================================= Energy.Active.Import.Interval ==============================================
  4924. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4925. {
  4926. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4927. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4928. {
  4929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4930. {
  4931. tempIndex = ((gun_index==2) ? 1: 0);
  4932. }
  4933. else
  4934. {
  4935. tempIndex = gun_index;
  4936. }
  4937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4938. {
  4939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4940. {
  4941. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4942. }
  4943. }// END OF CHAdeMO_QUANTITY
  4944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4945. }
  4946. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4947. {
  4948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4949. {
  4950. tempIndex = ((gun_index==2) ? 1: 0);
  4951. }
  4952. else
  4953. {
  4954. tempIndex = gun_index;
  4955. }
  4956. for (int index = 0; index < CCS_QUANTITY; index++)
  4957. {
  4958. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4959. {
  4960. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4961. }
  4962. }// END OF CCS_QUANTITY
  4963. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4964. }
  4965. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4966. {
  4967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4968. {
  4969. tempIndex = ((gun_index==2) ? 1: 0);
  4970. }
  4971. else
  4972. {
  4973. tempIndex = gun_index;
  4974. }
  4975. for (int index = 0; index < GB_QUANTITY; index++)
  4976. {
  4977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4978. {
  4979. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4980. }
  4981. }// END OF GB_QUANTITY
  4982. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4983. }
  4984. else if(gunType[gun_index] == GUN_TYPE_DO)
  4985. {
  4986. tempIndex = gun_index;
  4987. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4988. {
  4989. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4990. {
  4991. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4992. }
  4993. }
  4994. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4995. }
  4996. else
  4997. {
  4998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4999. {
  5000. tempIndex = 2;
  5001. }
  5002. else
  5003. {
  5004. tempIndex = gun_index;
  5005. }
  5006. for (int index = 0; index < AC_QUANTITY; index++)
  5007. {
  5008. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5009. {
  5010. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5011. }
  5012. }// END OF AC_QUANTITY
  5013. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5014. }
  5015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5020. }
  5021. //=================================== Power.Active.Import ==================================================
  5022. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5023. {
  5024. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5025. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5026. {
  5027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5028. {
  5029. tempIndex = ((gun_index==2) ? 1: 0);
  5030. }
  5031. else
  5032. {
  5033. tempIndex = gun_index;
  5034. }
  5035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5036. {
  5037. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5038. {
  5039. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5040. }
  5041. } // End for CHAdeMO_QUANTITY
  5042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5043. }
  5044. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5045. {
  5046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5047. {
  5048. tempIndex = ((gun_index==2) ? 1: 0);
  5049. }
  5050. else
  5051. {
  5052. tempIndex = gun_index;
  5053. }
  5054. for (int index = 0; index < CCS_QUANTITY; index++)
  5055. {
  5056. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5057. {
  5058. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5059. }
  5060. } // END for CCS_QUANTITY
  5061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5062. }
  5063. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5064. {
  5065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5066. {
  5067. tempIndex = ((gun_index==2) ? 1: 0);
  5068. }
  5069. else
  5070. {
  5071. tempIndex = gun_index;
  5072. }
  5073. for (int index = 0; index < GB_QUANTITY; index++)
  5074. {
  5075. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5076. {
  5077. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5078. }
  5079. }// END for GB_QUANTITY
  5080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5081. }
  5082. else if(gunType[gun_index] == GUN_TYPE_DO)
  5083. {
  5084. tempIndex = gun_index;
  5085. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5086. {
  5087. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5088. {
  5089. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5090. }
  5091. }
  5092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5093. }
  5094. else
  5095. {
  5096. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5097. {
  5098. tempIndex = 2;
  5099. }
  5100. else
  5101. {
  5102. tempIndex = gun_index;
  5103. }
  5104. for (int index = 0; index < AC_QUANTITY; index++)
  5105. {
  5106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5107. {
  5108. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5109. }
  5110. } // END for AC_QUANTITY
  5111. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5112. }
  5113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5118. }
  5119. //============================ Voltage L1 ====================================
  5120. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5121. {
  5122. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5123. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5124. {
  5125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5126. {
  5127. tempIndex = ((gun_index==2) ? 1: 0);
  5128. }
  5129. else
  5130. {
  5131. tempIndex = gun_index;
  5132. }
  5133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5134. {
  5135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5136. {
  5137. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5138. }
  5139. } // END OF FOR CHAdeMO_QUANTITY
  5140. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5141. }
  5142. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5143. {
  5144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5145. {
  5146. tempIndex = ((gun_index==2) ? 1: 0);
  5147. }
  5148. else
  5149. {
  5150. tempIndex = gun_index;
  5151. }
  5152. for (int index = 0; index < CCS_QUANTITY; index++)
  5153. {
  5154. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5155. {
  5156. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5157. }
  5158. } // END OF FOR CCS_QUANTITY
  5159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5160. }
  5161. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5162. {
  5163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5164. {
  5165. tempIndex = ((gun_index==2) ? 1: 0);
  5166. }
  5167. else
  5168. {
  5169. tempIndex = gun_index;
  5170. }
  5171. for (int index = 0; index < GB_QUANTITY; index++)
  5172. {
  5173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5174. {
  5175. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5176. }
  5177. } // END OF FOR GB_QUANTITY
  5178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5179. }
  5180. else if(gunType[gun_index] == GUN_TYPE_DO)
  5181. {
  5182. tempIndex = gun_index;
  5183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5184. {
  5185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5186. {
  5187. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5188. }
  5189. }
  5190. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5191. }
  5192. else
  5193. {
  5194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5195. {
  5196. tempIndex = 2;
  5197. }
  5198. else
  5199. {
  5200. tempIndex = gun_index;
  5201. }
  5202. for (int index = 0; index < AC_QUANTITY; index++)
  5203. {
  5204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5205. {
  5206. 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
  5207. }
  5208. } // END OF FOR AC_QUANTITY
  5209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5210. }
  5211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5212. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5216. }
  5217. //====================== End SoC ================================
  5218. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5219. {
  5220. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5221. 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))
  5222. {
  5223. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5224. {
  5225. tempIndex = ((gun_index==2) ? 1: 0);
  5226. }
  5227. else
  5228. {
  5229. tempIndex = gun_index;
  5230. }
  5231. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5232. {
  5233. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5234. {
  5235. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5236. {
  5237. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5238. }
  5239. }
  5240. }
  5241. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5242. {
  5243. for (int index = 0; index < CCS_QUANTITY; index++)
  5244. {
  5245. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5246. {
  5247. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5248. }
  5249. }
  5250. }
  5251. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5252. {
  5253. for (int index = 0; index < GB_QUANTITY; index++)
  5254. {
  5255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5256. {
  5257. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5258. }
  5259. }
  5260. }
  5261. else if(gunType[gun_index] == GUN_TYPE_DO)
  5262. {
  5263. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5264. {
  5265. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5266. {
  5267. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5268. }
  5269. }
  5270. }
  5271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5274. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5277. } // END FOR DC CASE
  5278. }
  5279. // ================================= Current.Import L2 ===============================================
  5280. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5281. {
  5282. // AC 3 phse L2 current
  5283. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5284. {
  5285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5286. {
  5287. tempIndex = 2;
  5288. }
  5289. else
  5290. {
  5291. tempIndex = gun_index;
  5292. }
  5293. for (int index = 0; index < AC_QUANTITY; index++)
  5294. {
  5295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5296. {
  5297. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5298. }
  5299. }// End of for AC_QUANTITY
  5300. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5301. }
  5302. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5305. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5307. }
  5308. // ================================= Current.Import L3 ===============================================
  5309. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5310. {
  5311. // AC 3 phse L3 current
  5312. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5313. {
  5314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5315. {
  5316. tempIndex = 2;
  5317. }
  5318. else
  5319. {
  5320. tempIndex = gun_index;
  5321. }
  5322. for (int index = 0; index < AC_QUANTITY; index++)
  5323. {
  5324. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5325. {
  5326. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5327. }
  5328. }// End of for AC_QUANTITY
  5329. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5330. }
  5331. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5332. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5333. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5335. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5336. }
  5337. //============================ Voltage L2 ====================================
  5338. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5339. {
  5340. // AC 3 phse L2 voltage
  5341. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5342. {
  5343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5344. {
  5345. tempIndex = 2;
  5346. }
  5347. else
  5348. {
  5349. tempIndex = gun_index;
  5350. }
  5351. for (int index = 0; index < AC_QUANTITY; index++)
  5352. {
  5353. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5354. {
  5355. 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
  5356. }
  5357. } // END OF FOR AC_QUANTITY
  5358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5359. }
  5360. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5362. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5363. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5364. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5365. }
  5366. //============================ Voltage L3 ====================================
  5367. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5368. {
  5369. // AC 3 phse L3 voltage
  5370. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5371. {
  5372. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5373. {
  5374. tempIndex = 2;
  5375. }
  5376. else
  5377. {
  5378. tempIndex = gun_index;
  5379. }
  5380. for (int index = 0; index < AC_QUANTITY; index++)
  5381. {
  5382. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5383. {
  5384. 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
  5385. }
  5386. } // END OF FOR AC_QUANTITY
  5387. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5388. }
  5389. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5390. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5391. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5392. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5393. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5394. }
  5395. //====================== Start SoC ================================
  5396. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5397. {
  5398. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5399. 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))
  5400. {
  5401. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5402. {
  5403. tempIndex = ((gun_index==2) ? 1: 0);
  5404. }
  5405. else
  5406. {
  5407. tempIndex = gun_index;
  5408. }
  5409. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5410. {
  5411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5412. {
  5413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5414. {
  5415. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5416. }
  5417. }
  5418. }
  5419. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5420. {
  5421. for (int index = 0; index < CCS_QUANTITY; index++)
  5422. {
  5423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5424. {
  5425. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5426. }
  5427. }
  5428. }
  5429. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5430. {
  5431. for (int index = 0; index < GB_QUANTITY; index++)
  5432. {
  5433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5434. {
  5435. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5436. }
  5437. }
  5438. }
  5439. else if(gunType[gun_index] == GUN_TYPE_DO)
  5440. {
  5441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5442. {
  5443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5444. {
  5445. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5446. }
  5447. }
  5448. }
  5449. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5450. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5451. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5455. } // END FOR DC CASE
  5456. }
  5457. //================================================ Message create ====================================================
  5458. json_object *StopTransaction = json_object_new_object();
  5459. json_object *transactionDatas = json_object_new_array();
  5460. json_object *sampledValues = json_object_new_array();
  5461. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5462. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5463. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5464. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5465. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5466. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5467. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5468. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5469. {
  5470. json_object *transactionData = json_object_new_object();
  5471. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5472. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5473. {
  5474. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5475. {
  5476. json_object *sampledValue = json_object_new_object();
  5477. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5478. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5479. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5480. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5481. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5482. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5483. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5484. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5485. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5486. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5487. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5488. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5489. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5490. json_object_array_add(sampledValues, sampledValue);
  5491. }
  5492. }
  5493. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5494. json_object_array_add(transactionDatas, transactionData);
  5495. }
  5496. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5497. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5498. ,MESSAGE_TYPE_CALL
  5499. ,guid
  5500. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5501. json_object_put(StopTransaction);
  5502. #if 1 // for TempStopTransaction
  5503. //Delete TempStopTransaction
  5504. if((access(TempStopTransaction,F_OK))!=-1)
  5505. {
  5506. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5507. }
  5508. #endif
  5509. #if 1
  5510. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5511. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5512. {
  5513. result = PASS;
  5514. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5515. }
  5516. #endif
  5517. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5518. OCPP_insert_transaction_msg(NO, queuedata);
  5519. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5520. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5521. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5522. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5523. {
  5524. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5525. }
  5526. //for test
  5527. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5528. return result;
  5529. }
  5530. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5531. {
  5532. mtrace();
  5533. int result = FAIL;
  5534. char guid[37]={0};
  5535. char tempdata[65]={0};
  5536. int tempIndex = 0;
  5537. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5538. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5539. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5540. //set value
  5541. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5542. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5543. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5544. -1);
  5545. random_uuid(guid);
  5546. //UTC Date time
  5547. struct timeval tmnow;
  5548. struct tm *tm;
  5549. char buf[28];//, usec_buf[6];
  5550. gettimeofday(&tmnow, NULL);
  5551. time_t t;
  5552. t = time(NULL);
  5553. /*UTC time and date*/
  5554. tm = gmtime(&t);
  5555. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5556. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5557. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5558. //********************************(1)Current.Import L1************************************************/
  5559. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5560. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5561. (dataType == ReadingContext_Trigger))
  5562. {
  5563. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5564. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5565. {
  5566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5567. {
  5568. tempIndex = ((gun_index==2) ? 1: 0);
  5569. }
  5570. else
  5571. {
  5572. tempIndex = gun_index;
  5573. }
  5574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5575. {
  5576. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5577. {
  5578. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5579. }
  5580. }
  5581. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5582. }
  5583. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5584. {
  5585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5586. {
  5587. tempIndex = ((gun_index==2) ? 1: 0);
  5588. }
  5589. else
  5590. {
  5591. tempIndex = gun_index;
  5592. }
  5593. for (int index = 0; index < CCS_QUANTITY; index++)
  5594. {
  5595. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5596. {
  5597. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5598. }
  5599. }
  5600. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5601. }
  5602. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5603. {
  5604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5605. {
  5606. tempIndex = ((gun_index==2) ? 1: 0);
  5607. }
  5608. else
  5609. {
  5610. tempIndex = gun_index;
  5611. }
  5612. for (int index = 0; index < GB_QUANTITY; index++)
  5613. {
  5614. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5615. {
  5616. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5617. }
  5618. }
  5619. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5620. }
  5621. else if(gunType[gun_index] == GUN_TYPE_DO)
  5622. {
  5623. tempIndex = gun_index;
  5624. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5625. {
  5626. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5627. {
  5628. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5629. }
  5630. }
  5631. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5632. }
  5633. else
  5634. {
  5635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5636. {
  5637. tempIndex = 2;
  5638. }
  5639. else
  5640. {
  5641. tempIndex = gun_index;
  5642. }
  5643. for (int index = 0; index < AC_QUANTITY; index++)
  5644. {
  5645. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5646. {
  5647. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5648. }
  5649. }
  5650. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5651. }
  5652. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5653. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5654. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5655. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5656. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5657. }
  5658. //********************************(2)Energy.Active.Import.Register ************************************************/
  5659. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5660. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5661. (dataType == ReadingContext_Trigger))
  5662. {
  5663. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5664. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5665. {
  5666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5667. {
  5668. tempIndex = ((gun_index==2) ? 1: 0);
  5669. }
  5670. else
  5671. {
  5672. tempIndex = gun_index;
  5673. }
  5674. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5675. {
  5676. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5677. {
  5678. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5679. }
  5680. }
  5681. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5682. }
  5683. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5684. {
  5685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5686. {
  5687. tempIndex = ((gun_index==2) ? 1: 0);
  5688. }
  5689. else
  5690. {
  5691. tempIndex = gun_index;
  5692. }
  5693. for (int index = 0; index < CCS_QUANTITY; index++)
  5694. {
  5695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5696. {
  5697. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5698. }
  5699. }
  5700. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5701. }
  5702. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5703. {
  5704. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5705. {
  5706. tempIndex = ((gun_index==2) ? 1: 0);
  5707. }
  5708. else
  5709. {
  5710. tempIndex = gun_index;
  5711. }
  5712. for (int index = 0; index < GB_QUANTITY; index++)
  5713. {
  5714. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5715. {
  5716. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5717. }
  5718. }
  5719. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5720. }
  5721. else if(gunType[gun_index] == GUN_TYPE_DO)
  5722. {
  5723. tempIndex = gun_index;
  5724. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5725. {
  5726. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5727. {
  5728. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5729. }
  5730. }
  5731. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5732. }
  5733. else
  5734. {
  5735. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5736. {
  5737. tempIndex = 2;
  5738. }
  5739. else
  5740. {
  5741. tempIndex = gun_index;
  5742. }
  5743. for (int index = 0; index < AC_QUANTITY; index++)
  5744. {
  5745. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5746. {
  5747. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5748. }
  5749. }
  5750. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5751. }
  5752. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5753. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5754. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5755. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5756. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5757. }
  5758. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5759. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5760. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5761. (dataType == ReadingContext_Trigger))
  5762. {
  5763. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5764. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5765. {
  5766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5767. {
  5768. tempIndex = ((gun_index==2) ? 1: 0);
  5769. }
  5770. else
  5771. {
  5772. tempIndex = gun_index;
  5773. }
  5774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5775. {
  5776. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5777. {
  5778. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5779. }
  5780. } // END OF FOR CHAdeMO_QUANTITY
  5781. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5782. }
  5783. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5784. {
  5785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5786. {
  5787. tempIndex = ((gun_index==2) ? 1: 0);
  5788. }
  5789. else
  5790. {
  5791. tempIndex = gun_index;
  5792. }
  5793. for (int index = 0; index < CCS_QUANTITY; index++)
  5794. {
  5795. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5796. {
  5797. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5798. }
  5799. } // END OF CCS_QUANTITY
  5800. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5801. }
  5802. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5803. {
  5804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5805. {
  5806. tempIndex = ((gun_index==2) ? 1: 0);
  5807. }
  5808. else
  5809. {
  5810. tempIndex = gun_index;
  5811. }
  5812. for (int index = 0; index < GB_QUANTITY; index++)
  5813. {
  5814. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5815. {
  5816. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5817. }
  5818. } // END OF GB_QUANTITY
  5819. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5820. }
  5821. else if(gunType[gun_index] == GUN_TYPE_DO)
  5822. {
  5823. tempIndex = gun_index;
  5824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5825. {
  5826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5827. {
  5828. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5829. }
  5830. }
  5831. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5832. }
  5833. else
  5834. {
  5835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5836. {
  5837. tempIndex = 2;
  5838. }
  5839. else
  5840. {
  5841. tempIndex = gun_index;
  5842. }
  5843. for (int index = 0; index < AC_QUANTITY; index++)
  5844. {
  5845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5846. {
  5847. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5848. }
  5849. }
  5850. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5851. }
  5852. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5853. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5854. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5855. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5856. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5857. }
  5858. //********************************(4)Power.Active.Import************************************************/
  5859. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5860. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5861. (dataType == ReadingContext_Trigger))
  5862. {
  5863. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5865. {
  5866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5867. {
  5868. tempIndex = ((gun_index==2) ? 1: 0);
  5869. }
  5870. else
  5871. {
  5872. tempIndex = gun_index;
  5873. }
  5874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5877. {
  5878. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5879. }
  5880. } // END OF FOR
  5881. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5882. }
  5883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5884. {
  5885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5886. {
  5887. tempIndex = ((gun_index==2) ? 1: 0);
  5888. }
  5889. else
  5890. {
  5891. tempIndex = gun_index;
  5892. }
  5893. for (int index = 0; index < CCS_QUANTITY; index++)
  5894. {
  5895. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5896. {
  5897. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5898. }
  5899. }
  5900. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5901. }
  5902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5903. {
  5904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5905. {
  5906. tempIndex = ((gun_index==2) ? 1: 0);
  5907. }
  5908. else
  5909. {
  5910. tempIndex = gun_index;
  5911. }
  5912. for (int index = 0; index < GB_QUANTITY; index++)
  5913. {
  5914. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5915. {
  5916. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5917. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5918. }
  5919. }
  5920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5921. }
  5922. else if(gunType[gun_index] == GUN_TYPE_DO)
  5923. {
  5924. tempIndex = gun_index;
  5925. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5926. {
  5927. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5928. {
  5929. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5930. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5931. }
  5932. }
  5933. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5934. }
  5935. else
  5936. {
  5937. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5938. {
  5939. tempIndex = 2;
  5940. }
  5941. else
  5942. {
  5943. tempIndex = gun_index;
  5944. }
  5945. for (int index = 0; index < AC_QUANTITY; index++)
  5946. {
  5947. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5948. {
  5949. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5950. }
  5951. }
  5952. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5953. }
  5954. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5955. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5956. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5957. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5958. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5959. }
  5960. //***********************************************(5)VOLTAGE L1******************************************************/
  5961. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5962. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5963. (dataType == ReadingContext_Trigger))
  5964. {
  5965. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5966. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5967. {
  5968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5969. {
  5970. tempIndex = ((gun_index==2) ? 1: 0);
  5971. }
  5972. else
  5973. {
  5974. tempIndex = gun_index;
  5975. }
  5976. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5977. {
  5978. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5979. {
  5980. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5981. }
  5982. }
  5983. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5984. }
  5985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5986. {
  5987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5988. {
  5989. tempIndex = ((gun_index==2) ? 1: 0);
  5990. }
  5991. else
  5992. {
  5993. tempIndex = gun_index;
  5994. }
  5995. for (int index = 0; index < CCS_QUANTITY; index++)
  5996. {
  5997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5998. {
  5999. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6000. }
  6001. }
  6002. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6003. }
  6004. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6005. {
  6006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6007. {
  6008. tempIndex = ((gun_index==2) ? 1: 0);
  6009. }
  6010. else
  6011. {
  6012. tempIndex = gun_index;
  6013. }
  6014. for (int index = 0; index < GB_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6017. {
  6018. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6019. }
  6020. }
  6021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6022. }
  6023. else if(gunType[gun_index] == GUN_TYPE_DO)
  6024. {
  6025. tempIndex = gun_index;
  6026. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6027. {
  6028. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6029. {
  6030. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6031. }
  6032. }
  6033. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6034. }
  6035. else
  6036. {
  6037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6038. {
  6039. tempIndex = 2;
  6040. }
  6041. else
  6042. {
  6043. tempIndex = gun_index;
  6044. }
  6045. for (int index = 0; index < AC_QUANTITY; index++)
  6046. {
  6047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6048. {
  6049. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6050. }
  6051. }
  6052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6053. }
  6054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6056. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6057. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6058. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6059. }
  6060. //***********************************************(6)SOC******************************************************/
  6061. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6062. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6063. (dataType == ReadingContext_Trigger))
  6064. {
  6065. 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))
  6066. {
  6067. //idx_sample=5;
  6068. //sampledValue = NULL;
  6069. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6070. {
  6071. tempIndex = ((gun_index==2) ? 1: 0);
  6072. }
  6073. else
  6074. {
  6075. tempIndex = gun_index;
  6076. }
  6077. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6078. {
  6079. //tempIndex = ((gun_index==2) ? 1: 0);
  6080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6081. {
  6082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6083. {
  6084. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6085. }
  6086. }
  6087. }
  6088. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6089. {
  6090. //tempIndex = ((gun_index==2) ? 1: 0);
  6091. for (int index = 0; index < CCS_QUANTITY; index++)
  6092. {
  6093. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6094. {
  6095. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6096. }
  6097. }
  6098. }
  6099. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6100. {
  6101. //tempIndex = ((gun_index==2) ? 1: 0);
  6102. for (int index = 0; index < GB_QUANTITY; index++)
  6103. {
  6104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6105. {
  6106. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6107. }
  6108. }
  6109. }
  6110. else if(gunType[gun_index] == GUN_TYPE_DO)
  6111. {
  6112. //tempIndex = ((gun_index==2) ? 1: 0);
  6113. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6114. {
  6115. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6116. {
  6117. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6118. }
  6119. }
  6120. }
  6121. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6122. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6123. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6124. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6125. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6126. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6127. }
  6128. }
  6129. //********************************(7)Current.Import L2************************************************/
  6130. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6131. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6132. (dataType == ReadingContext_Trigger))
  6133. {
  6134. // Only for AC 3 phase
  6135. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6136. {
  6137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6138. {
  6139. tempIndex = 2;
  6140. }
  6141. else
  6142. {
  6143. tempIndex = gun_index;
  6144. }
  6145. for (int index = 0; index < AC_QUANTITY; index++)
  6146. {
  6147. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6148. {
  6149. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6150. }
  6151. }
  6152. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6153. }
  6154. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6155. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6156. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6157. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6158. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6159. }
  6160. //********************************(8)Current.Import L3************************************************/
  6161. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6162. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6163. (dataType == ReadingContext_Trigger))
  6164. {
  6165. // Only for AC 3 phase
  6166. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6167. {
  6168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6169. {
  6170. tempIndex = 2;
  6171. }
  6172. else
  6173. {
  6174. tempIndex = gun_index;
  6175. }
  6176. for (int index = 0; index < AC_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6179. {
  6180. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6181. }
  6182. }
  6183. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6184. }
  6185. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6186. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6187. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6188. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6189. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6190. }
  6191. //***********************************************(9)VOLTAGE L2******************************************************/
  6192. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6193. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6194. (dataType == ReadingContext_Trigger))
  6195. {
  6196. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6197. {
  6198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6199. {
  6200. tempIndex = 2;
  6201. }
  6202. else
  6203. {
  6204. tempIndex = gun_index;
  6205. }
  6206. for (int index = 0; index < AC_QUANTITY; index++)
  6207. {
  6208. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6209. {
  6210. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6211. }
  6212. }
  6213. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6214. }
  6215. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6216. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6217. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6220. }
  6221. //***********************************************(10)VOLTAGE L3******************************************************/
  6222. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6223. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6224. (dataType == ReadingContext_Trigger))
  6225. {
  6226. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6227. {
  6228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6229. {
  6230. tempIndex = 2;
  6231. }
  6232. else
  6233. {
  6234. tempIndex = gun_index;
  6235. }
  6236. for (int index = 0; index < AC_QUANTITY; index++)
  6237. {
  6238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6239. {
  6240. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6241. }
  6242. }
  6243. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6244. }
  6245. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6246. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6247. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6248. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6250. }
  6251. //***********************************************(11)Current.Offered******************************************************/
  6252. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6253. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6254. (dataType == ReadingContext_Trigger))
  6255. {
  6256. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6257. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6258. {
  6259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6260. {
  6261. tempIndex = ((gun_index==2) ? 1: 0);
  6262. }
  6263. else
  6264. {
  6265. tempIndex = gun_index;
  6266. }
  6267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6268. {
  6269. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6270. {
  6271. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6272. }
  6273. } // END OF FOR CHAdeMO_QUANTITY
  6274. }
  6275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6276. {
  6277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6278. {
  6279. tempIndex = ((gun_index==2) ? 1: 0);
  6280. }
  6281. else
  6282. {
  6283. tempIndex = gun_index;
  6284. }
  6285. for (int index = 0; index < CCS_QUANTITY; index++)
  6286. {
  6287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6288. {
  6289. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6290. }
  6291. } // END OF CCS_QUANTITY
  6292. }
  6293. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6294. {
  6295. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6296. {
  6297. tempIndex = ((gun_index==2) ? 1: 0);
  6298. }
  6299. else
  6300. {
  6301. tempIndex = gun_index;
  6302. }
  6303. for (int index = 0; index < GB_QUANTITY; index++)
  6304. {
  6305. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6306. {
  6307. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6308. }
  6309. } // END OF GB_QUANTITY
  6310. }
  6311. else if(gunType[gun_index] == GUN_TYPE_DO)
  6312. {
  6313. tempIndex = gun_index;
  6314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6315. {
  6316. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6317. {
  6318. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6319. }
  6320. }
  6321. }
  6322. else
  6323. {
  6324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6325. {
  6326. tempIndex = 2;
  6327. }
  6328. else
  6329. {
  6330. tempIndex = gun_index;
  6331. }
  6332. for (int index = 0; index < AC_QUANTITY; index++)
  6333. {
  6334. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6335. {
  6336. uint16_t currentOffer;
  6337. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6338. {
  6339. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6340. }
  6341. else
  6342. {
  6343. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6344. }
  6345. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6346. }
  6347. }
  6348. }
  6349. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6350. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6351. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6352. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6353. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6354. }
  6355. //***********************************************(12)Power.Offered******************************************************/
  6356. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6357. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6358. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6359. {
  6360. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6361. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6362. {
  6363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6364. {
  6365. tempIndex = ((gun_index==2) ? 1: 0);
  6366. }
  6367. else
  6368. {
  6369. tempIndex = gun_index;
  6370. }
  6371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6372. {
  6373. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6374. {
  6375. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6376. }
  6377. } // END OF FOR CHAdeMO_QUANTITY
  6378. }
  6379. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6380. {
  6381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6382. {
  6383. tempIndex = ((gun_index==2) ? 1: 0);
  6384. }
  6385. else
  6386. {
  6387. tempIndex = gun_index;
  6388. }
  6389. for (int index = 0; index < CCS_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6392. {
  6393. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6394. }
  6395. } // END OF CCS_QUANTITY
  6396. }
  6397. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6398. {
  6399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6400. {
  6401. tempIndex = ((gun_index==2) ? 1: 0);
  6402. }
  6403. else
  6404. {
  6405. tempIndex = gun_index;
  6406. }
  6407. for (int index = 0; index < GB_QUANTITY; index++)
  6408. {
  6409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6410. {
  6411. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6412. }
  6413. } // END OF GB_QUANTITY
  6414. }
  6415. else if(gunType[gun_index] == GUN_TYPE_DO)
  6416. {
  6417. tempIndex = gun_index;
  6418. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6419. {
  6420. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6421. {
  6422. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6423. }
  6424. }
  6425. }
  6426. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6427. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6428. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6429. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6430. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6431. }
  6432. // Message create ====================================================================================================
  6433. if(TRUE)
  6434. {
  6435. json_object *MeterValueReq = json_object_new_object();
  6436. json_object *MeterValues = json_object_new_array();
  6437. json_object *sampledValues = json_object_new_array();
  6438. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6439. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6440. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6441. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6442. {
  6443. json_object *MeterValue = json_object_new_object();
  6444. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6445. {
  6446. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6447. {
  6448. json_object *sampledValue = json_object_new_object();
  6449. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6450. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6451. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6452. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6453. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6454. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6455. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6456. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6457. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6458. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6459. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6460. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6461. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6462. json_object_array_add(sampledValues, sampledValue);
  6463. }
  6464. }
  6465. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6466. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6467. json_object_array_add(MeterValues, MeterValue);
  6468. }
  6469. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6470. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6471. ,gun_index + 1
  6472. ,MESSAGE_TYPE_CALL
  6473. ,guid
  6474. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6475. json_object_put(MeterValueReq);
  6476. }
  6477. // Put request guid to hash map
  6478. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6479. 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*/)
  6480. {
  6481. result = PASS;
  6482. //DEBUG_INFO("MeterValues mapitem pass\n");
  6483. }
  6484. if((dataType != ReadingContext_Trigger) &&
  6485. (dataType != ReadingContext_Sample_Clock) &&
  6486. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6487. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6488. else
  6489. {
  6490. if(FirstHeartBeat)
  6491. LWS_Send(queuedata +2);
  6492. }
  6493. return result;
  6494. }
  6495. int sendLogStatusNotificationRequest(char *status)
  6496. {
  6497. mtrace();
  6498. int result = PASS;
  6499. char message[4096]={0};
  6500. char guid[37]={0};
  6501. char tempdata[128]={0};
  6502. json_object *LogStatusNotification = json_object_new_object();
  6503. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6504. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6505. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6506. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6507. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6508. random_uuid(guid);
  6509. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6510. json_object_put(LogStatusNotification);
  6511. LWS_Send(message);
  6512. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6513. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6514. {
  6515. result = PASS;
  6516. }
  6517. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6518. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6519. return result;
  6520. }
  6521. int sendSecurityEventNotificationRequest()
  6522. {
  6523. mtrace();
  6524. int result = PASS;
  6525. char message[4096]={0};
  6526. char guid[37]={0};
  6527. char tempdata[128]={0};
  6528. json_object *SecurityEventNotification = json_object_new_object();
  6529. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6530. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6531. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6532. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6533. random_uuid(guid);
  6534. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6535. json_object_put(SecurityEventNotification);
  6536. LWS_Send(message);
  6537. sprintf(tempdata, "SecurityEventNotification,0");
  6538. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6539. {
  6540. result = PASS;
  6541. }
  6542. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6543. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6544. return result;
  6545. }
  6546. int sendSignCertificateRequest()
  6547. {
  6548. mtrace();
  6549. int result = PASS;
  6550. char message[4096]={0};
  6551. char guid[37]={0};
  6552. char tempdata[128]={0};
  6553. json_object *SignCertificate = json_object_new_object();
  6554. DEBUG_INFO("sendSignCertificateRequest...\n");
  6555. // Read csr file content
  6556. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6557. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6558. char *line = NULL;
  6559. size_t len = 0;
  6560. while(getline(&line, &len, fp) != -1)
  6561. {
  6562. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6563. {
  6564. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6565. }
  6566. }
  6567. fclose(fp);
  6568. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6569. random_uuid(guid);
  6570. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6571. json_object_put(SignCertificate);
  6572. LWS_Send(message);
  6573. sprintf(tempdata, "SignCertificate,0");
  6574. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6575. {
  6576. result = PASS;
  6577. }
  6578. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6579. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6580. return result;
  6581. }
  6582. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6583. {
  6584. mtrace();
  6585. int result = PASS;
  6586. char message[110]={0};
  6587. char guid[37]={0};
  6588. char tempdata[65]={0};
  6589. json_object *FirmwareStatusNotification = json_object_new_object();
  6590. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6591. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6592. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6593. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6594. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6595. random_uuid(guid);
  6596. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6597. json_object_put(FirmwareStatusNotification);
  6598. LWS_Send(message);
  6599. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6600. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6601. {
  6602. result = PASS;
  6603. }
  6604. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6605. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6606. return result;
  6607. }
  6608. //==========================================
  6609. // send confirm routine
  6610. //==========================================
  6611. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6612. {
  6613. mtrace();
  6614. int result = FAIL;
  6615. char message[100]={0};
  6616. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6617. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6618. LWS_Send(message);
  6619. result = TRUE;
  6620. return result;
  6621. }
  6622. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6623. {
  6624. mtrace();
  6625. int result = FAIL;
  6626. char message[100]={0};
  6627. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6628. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6629. LWS_Send(message);
  6630. result = TRUE;
  6631. return result;
  6632. }
  6633. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6634. {
  6635. mtrace();
  6636. int result = FAIL;
  6637. char message[100]={0};
  6638. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6639. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6640. LWS_Send(message);
  6641. result = TRUE;
  6642. return result;
  6643. }
  6644. int sendClearCacheConfirmation(char *uuid,char *payload)
  6645. {
  6646. mtrace();
  6647. int result = FAIL;
  6648. char message[500]={0};
  6649. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6650. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6651. LWS_Send(message);
  6652. return result;
  6653. }
  6654. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6655. {
  6656. mtrace();
  6657. int result = FAIL;
  6658. char message[500]={0};
  6659. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6660. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6661. LWS_Send(message);
  6662. return result;
  6663. }
  6664. int sendDataTransferConfirmation(char *uuid,char *payload)
  6665. {
  6666. mtrace();
  6667. char statusStr[20]={0};
  6668. char dataStr[10]={0};
  6669. char sstr[20]={0};
  6670. int c = 0;
  6671. char *loc;
  6672. int result = FAIL;
  6673. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6674. /**********************status**************************/
  6675. loc = strstr(payload, "status");
  6676. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6677. c = 0;
  6678. while (loc[3+strlen("status")+c] != '\"')
  6679. {
  6680. sstr[c] = loc[3+strlen("status")+c];
  6681. c++;
  6682. }
  6683. sstr[c] = '\0';
  6684. strcpy(statusStr, sstr);
  6685. /**********************data**************************/
  6686. loc = strstr(payload, "data");
  6687. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6688. c = 0;
  6689. while (loc[3+strlen("data")+c] != '\"')
  6690. {
  6691. sstr[c] = loc[3+strlen("data")+c];
  6692. c++;
  6693. }
  6694. sstr[c] = '\0';
  6695. strcpy(dataStr, sstr);
  6696. return result;
  6697. }
  6698. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6699. {
  6700. mtrace();
  6701. int result = FAIL;
  6702. char message[1000]={0};
  6703. int CompositeScheduleIndex = 0;
  6704. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6705. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6706. if(nPeriod == 0)
  6707. {
  6708. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6709. {
  6710. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6711. ,MESSAGE_TYPE_CALLRESULT
  6712. ,uuid
  6713. ,payload
  6714. ,connectorIdInt);
  6715. }
  6716. else
  6717. {
  6718. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6719. ,MESSAGE_TYPE_CALLRESULT
  6720. ,uuid
  6721. ,payload
  6722. ,connectorIdInt
  6723. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6724. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6725. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6726. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6727. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6728. }
  6729. }
  6730. else
  6731. {
  6732. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6733. ,MESSAGE_TYPE_CALLRESULT
  6734. ,uuid
  6735. ,payload
  6736. ,connectorIdInt
  6737. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6738. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6739. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6740. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6741. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6742. {
  6743. if (idx_sample == 0)
  6744. {
  6745. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6746. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6747. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6748. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6749. }
  6750. else
  6751. {
  6752. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6753. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6754. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6755. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6756. }
  6757. }
  6758. sprintf(message + strlen(message), "]}}]");
  6759. }
  6760. LWS_Send(message);
  6761. result = TRUE;
  6762. return result;
  6763. }
  6764. int sendGetConfigurationConfirmation(char *uuid)
  6765. {
  6766. mtrace();
  6767. int result = FAIL;
  6768. int MaxKeySupported = 0;
  6769. int sentConfigurationNumber= 0;
  6770. int sentunConfigurationNumber= 0;
  6771. char message[1024*10]={0};
  6772. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6773. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6774. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6775. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6776. ,MESSAGE_TYPE_CALLRESULT
  6777. ,uuid );
  6778. //configuration key
  6779. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6780. {
  6781. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6782. {
  6783. if (sentConfigurationNumber == 0)
  6784. {
  6785. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6786. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6787. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6788. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6789. }
  6790. else
  6791. {
  6792. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6793. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6794. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6795. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6796. }
  6797. sentConfigurationNumber = sentConfigurationNumber + 1;
  6798. }
  6799. }
  6800. sprintf(message + strlen(message), "]");
  6801. if(UnknownKeynum != 0)
  6802. {
  6803. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6804. //unkown key
  6805. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6806. {
  6807. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6808. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6809. if(sentunConfigurationNumber == 0)
  6810. {
  6811. sprintf(message + strlen(message), "\"%s\""
  6812. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6813. }
  6814. else
  6815. {
  6816. sprintf(message + strlen(message), ",\"%s\""
  6817. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6818. }
  6819. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6820. }
  6821. sprintf(message + strlen(message), "]");
  6822. }
  6823. sprintf(message + strlen(message), "}]");
  6824. LWS_Send(message);
  6825. return result;
  6826. }
  6827. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6828. {
  6829. mtrace();
  6830. int result = FAIL;
  6831. char message[400]={0};
  6832. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6833. if(strcmp(payload,"")==0)
  6834. {
  6835. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6836. }
  6837. else
  6838. {
  6839. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6840. }
  6841. LWS_Send(message);
  6842. result = TRUE;
  6843. return result;
  6844. }
  6845. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6846. {
  6847. mtrace();
  6848. int result = FAIL;
  6849. char message[80]={0};
  6850. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6851. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  6852. LWS_Send(message);
  6853. result = TRUE;
  6854. return result;
  6855. }
  6856. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6857. {
  6858. mtrace();
  6859. int result = FAIL;
  6860. char message[80]={0};
  6861. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6862. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6863. LWS_Send(message);
  6864. result = TRUE;
  6865. return result;
  6866. }
  6867. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6868. {
  6869. mtrace();
  6870. int result = FAIL;
  6871. char message[80]={0};
  6872. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6873. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6874. LWS_Send(message);
  6875. result = TRUE;
  6876. return result;
  6877. }
  6878. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6879. {
  6880. mtrace();
  6881. int result = FAIL;
  6882. char message[80]={0};
  6883. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6884. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6885. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6886. LWS_Send(message);
  6887. result = TRUE;
  6888. return result;
  6889. }
  6890. int sendResetConfirmation(char *uuid,char *payload)
  6891. {
  6892. mtrace();
  6893. int result = FAIL;
  6894. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6895. char message[80]={0};
  6896. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6897. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6898. LWS_Send(message);
  6899. result = TRUE;
  6900. return result;
  6901. }
  6902. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6903. {
  6904. mtrace();
  6905. int result = FAIL;
  6906. char message[500]={0};
  6907. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6908. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6909. LWS_Send(message);
  6910. result = TRUE;
  6911. return result;
  6912. }
  6913. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6914. {
  6915. mtrace();
  6916. int result = FAIL;
  6917. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6918. char message[80]={0};
  6919. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6920. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6921. LWS_Send(message);
  6922. result = TRUE;
  6923. return result;
  6924. }
  6925. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6926. {
  6927. mtrace();
  6928. int result = FAIL;
  6929. char message[80]={0};
  6930. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6931. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6932. LWS_Send(message);
  6933. result = TRUE;
  6934. return result;
  6935. }
  6936. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6937. {
  6938. mtrace();
  6939. int result = FAIL;
  6940. char message[80]={0};
  6941. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6942. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6943. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6944. LWS_Send(message);
  6945. result = TRUE;
  6946. return result;
  6947. }
  6948. int sendUpdateFirmwareConfirmation(char *uuid)
  6949. {
  6950. mtrace();
  6951. int result = FAIL;
  6952. char message[60]={0};
  6953. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6954. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6955. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6956. LWS_Send(message);
  6957. result = TRUE;
  6958. return result;
  6959. }
  6960. int sendCertificateSignedConfirmation(char *uuid)
  6961. {
  6962. mtrace();
  6963. int result = PASS;
  6964. char message[4096]={0};
  6965. json_object *CertificateSigned = json_object_new_object();
  6966. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6967. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6968. sprintf(message,"[%d,\"%s\",%s]"
  6969. ,MESSAGE_TYPE_CALLRESULT
  6970. ,uuid
  6971. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6972. json_object_put(CertificateSigned);
  6973. LWS_Send(message);
  6974. return result;
  6975. }
  6976. int sendDeleteCertificateConfirmation(char *uuid)
  6977. {
  6978. mtrace();
  6979. int result = PASS;
  6980. char message[4096]={0};
  6981. json_object *DeleteCertificate = json_object_new_object();
  6982. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6983. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6984. sprintf(message,"[%d,\"%s\",%s]"
  6985. ,MESSAGE_TYPE_CALLRESULT
  6986. ,uuid
  6987. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6988. json_object_put(DeleteCertificate);
  6989. LWS_Send(message);
  6990. return result;
  6991. }
  6992. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6993. {
  6994. mtrace();
  6995. int result = PASS;
  6996. char message[4096]={0};
  6997. json_object *ExtendedTriggerMessage = json_object_new_object();
  6998. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6999. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7000. sprintf(message,"[%d,\"%s\",%s]"
  7001. ,MESSAGE_TYPE_CALLRESULT
  7002. ,uuid
  7003. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7004. json_object_put(ExtendedTriggerMessage);
  7005. LWS_Send(message);
  7006. return result;
  7007. }
  7008. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7009. {
  7010. mtrace();
  7011. int result = PASS;
  7012. char message[4096]={0};
  7013. json_object *GetInstalledCertificateIds = json_object_new_object();
  7014. json_object *certificateHashDataDatas = json_object_new_array();
  7015. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7016. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7017. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7018. {
  7019. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7020. {
  7021. json_object *certificateHashData = json_object_new_object();
  7022. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7023. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7024. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7025. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7026. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7027. }
  7028. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7029. }
  7030. else
  7031. {
  7032. json_object_put(certificateHashDataDatas);
  7033. }
  7034. sprintf(message,"[%d,\"%s\",%s]"
  7035. ,MESSAGE_TYPE_CALLRESULT
  7036. ,uuid
  7037. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7038. json_object_put(GetInstalledCertificateIds);
  7039. LWS_Send(message);
  7040. return result;
  7041. }
  7042. int sendGetLogConfirmation(char *uuid)
  7043. {
  7044. mtrace();
  7045. int result = PASS;
  7046. char message[4096]={0};
  7047. json_object *GetLog = json_object_new_object();
  7048. DEBUG_INFO("sendGetLogConfirmation...\n");
  7049. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7050. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7051. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7052. sprintf(message,"[%d,\"%s\",%s]"
  7053. ,MESSAGE_TYPE_CALLRESULT
  7054. ,uuid
  7055. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7056. json_object_put(GetLog);
  7057. LWS_Send(message);
  7058. return result;
  7059. }
  7060. int sendInstallCertificateConfirmation(char *uuid)
  7061. {
  7062. mtrace();
  7063. int result = PASS;
  7064. char message[4096]={0};
  7065. json_object *InstallCertificate = json_object_new_object();
  7066. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7067. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7068. sprintf(message,"[%d,\"%s\",%s]"
  7069. ,MESSAGE_TYPE_CALLRESULT
  7070. ,uuid
  7071. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7072. json_object_put(InstallCertificate);
  7073. LWS_Send(message);
  7074. return result;
  7075. }
  7076. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7077. {
  7078. mtrace();
  7079. int result = PASS;
  7080. char message[4096]={0};
  7081. json_object *SignedUpdateFirmware = json_object_new_object();
  7082. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7083. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7084. sprintf(message,"[%d,\"%s\",%s]"
  7085. ,MESSAGE_TYPE_CALLRESULT
  7086. ,uuid
  7087. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7088. json_object_put(SignedUpdateFirmware);
  7089. LWS_Send(message);
  7090. return result;
  7091. }
  7092. int sendUnknownConfirmation(char *uuid)
  7093. {
  7094. mtrace();
  7095. int result = PASS;
  7096. char message[256]={0};
  7097. DEBUG_INFO("sendUnknownConfirmation...\n");
  7098. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7099. LWS_Send(message);
  7100. return result;
  7101. }
  7102. //==========================================
  7103. // Handle server request routine Start
  7104. //==========================================
  7105. int handleCancelReservationRequest(char *uuid, char *payload)
  7106. {
  7107. mtrace();
  7108. int result = FAIL;
  7109. int gunNO = 0;
  7110. int reservationIdInt = -1;
  7111. char comfirmstr[20];
  7112. DEBUG_INFO("handleCancelReservationRequest...\n");
  7113. json_object *CancelReservation;
  7114. CancelReservation = json_tokener_parse(payload);
  7115. if(!is_error(CancelReservation))
  7116. {
  7117. // Required data
  7118. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7119. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7120. }
  7121. json_object_put(CancelReservation);
  7122. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7123. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7124. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7125. if(reservationIdInt != -1)
  7126. {
  7127. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7128. //check Transaction active
  7129. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7131. {
  7132. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7133. {
  7134. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7135. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7136. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7137. {
  7138. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7139. }
  7140. else
  7141. {
  7142. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7143. }
  7144. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7145. goto end;
  7146. }
  7147. }
  7148. for (int index = 0; index < CCS_QUANTITY; index++)
  7149. {
  7150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7151. {
  7152. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7153. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7154. if(gunType[2] == GUN_TYPE_CCS)
  7155. {
  7156. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7157. }
  7158. else
  7159. {
  7160. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7161. }
  7162. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7163. goto end;
  7164. }
  7165. }
  7166. for (int index = 0; index < GB_QUANTITY; index++)
  7167. {
  7168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7169. {
  7170. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7171. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7172. if(gunType[2] == GUN_TYPE_GBT)
  7173. {
  7174. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7175. }
  7176. else
  7177. {
  7178. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7179. }
  7180. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7181. goto end;
  7182. }
  7183. }
  7184. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7185. {
  7186. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7187. {
  7188. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7189. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7190. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7191. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7192. goto end;
  7193. }
  7194. }
  7195. for (int index = 0; index < AC_QUANTITY; index++)
  7196. {
  7197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7198. {
  7199. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7200. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7202. {
  7203. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7204. }
  7205. else
  7206. {
  7207. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7208. }
  7209. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7210. goto end;
  7211. }
  7212. }
  7213. }
  7214. //The reservationId does NOT match the reservationId
  7215. sendCancelReservationConfirmation(uuid, comfirmstr);
  7216. end:
  7217. // Fill in ocpp packet uuid
  7218. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7219. return result;
  7220. }
  7221. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7222. {
  7223. mtrace();
  7224. int result = FAIL;
  7225. int gunIndex = 0;
  7226. char typeStr[16]={0};
  7227. char comfirmstr[20];
  7228. int specificId = FALSE;
  7229. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7230. json_object *ChangeAvailability;
  7231. ChangeAvailability = json_tokener_parse(payload);
  7232. if(!is_error(ChangeAvailability))
  7233. {
  7234. // Required data
  7235. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7236. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7237. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7238. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7239. }
  7240. json_object_put(ChangeAvailability);
  7241. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7242. {
  7243. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7244. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7245. }
  7246. else if(gunIndex == 0)
  7247. {
  7248. for(int i=0; i < gunTotalNumber; i++)
  7249. {
  7250. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7251. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7252. }
  7253. }
  7254. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7255. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7256. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7257. {
  7258. specificId = TRUE;
  7259. }
  7260. if(specificId == FALSE)
  7261. goto end;
  7262. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7263. {
  7264. //----------------------gunIndex is 0 ------------------------------------------------//
  7265. if(gunIndex == 0)
  7266. {
  7267. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7268. {
  7269. for(int i=0; i < gunTotalNumber; i++)
  7270. {
  7271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7272. {
  7273. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7274. {
  7275. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7276. {
  7277. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7278. goto end;
  7279. }
  7280. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7281. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7282. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7283. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7284. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7285. {
  7286. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7287. goto end;
  7288. }
  7289. }
  7290. }//END FOR CHAdeMO_QUANTITY
  7291. for (int index = 0; index < CCS_QUANTITY; index++)
  7292. {
  7293. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7294. {
  7295. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7296. {
  7297. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7298. goto end;
  7299. }
  7300. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7301. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7302. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7303. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7304. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7305. {
  7306. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7307. goto end;
  7308. }
  7309. }
  7310. }//END FOR CCS_QUANTITY
  7311. for (int index = 0; index < GB_QUANTITY; index++)
  7312. {
  7313. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7314. {
  7315. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7316. {
  7317. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7318. goto end;
  7319. }
  7320. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7321. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7322. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7323. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7324. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7325. {
  7326. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7327. goto end;
  7328. }
  7329. }
  7330. }// END FOR GB_QUANTITY
  7331. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7332. {
  7333. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7334. {
  7335. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7336. {
  7337. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7338. goto end;
  7339. }
  7340. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7341. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7342. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7343. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7344. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7345. {
  7346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7347. goto end;
  7348. }
  7349. }
  7350. }// END FOR GENERAL_GUN_QUANTITY
  7351. for (int index = 0; index < AC_QUANTITY; index++)
  7352. {
  7353. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7354. {
  7355. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7356. {
  7357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7358. goto end;
  7359. }
  7360. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7361. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7362. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7363. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7364. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7365. {
  7366. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7367. goto end;
  7368. }
  7369. }
  7370. }//END FOR AC_QUANTITY
  7371. }// END FOR gunTotalNumber
  7372. }
  7373. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7374. {
  7375. for(int i=0; i < gunTotalNumber; i++)
  7376. {
  7377. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7378. {
  7379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7380. goto end;
  7381. }
  7382. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7383. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7384. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7385. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7386. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7387. {
  7388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7389. goto end;
  7390. }
  7391. }
  7392. }
  7393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7394. goto end;
  7395. }
  7396. //----------------------gunIndex is not 0 ------------------------------------------------//
  7397. //check Transaction active
  7398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7399. {
  7400. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7401. {
  7402. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7403. {
  7404. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7405. goto end;
  7406. }
  7407. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7408. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7409. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7410. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7411. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7412. {
  7413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7414. goto end;
  7415. }
  7416. else
  7417. {
  7418. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7419. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7420. goto end;
  7421. }
  7422. }
  7423. }//END FOR CHAdeMO_QUANTITY
  7424. for (int index = 0; index < CCS_QUANTITY; index++)
  7425. {
  7426. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7427. {
  7428. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7429. {
  7430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7431. goto end;
  7432. }
  7433. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7434. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7435. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7436. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7437. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7438. {
  7439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7440. goto end;
  7441. }
  7442. else
  7443. {
  7444. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7446. goto end;
  7447. }
  7448. }
  7449. }//END FOR CCS_QUANTITY
  7450. for (int index = 0; index < GB_QUANTITY; index++)
  7451. {
  7452. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7453. {
  7454. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7455. {
  7456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7457. goto end;
  7458. }
  7459. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7460. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7461. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7462. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7463. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7464. {
  7465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7466. goto end;
  7467. }
  7468. else
  7469. {
  7470. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7472. goto end;
  7473. }
  7474. }
  7475. }// END FOR GB_QUANTITY
  7476. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7477. {
  7478. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7479. {
  7480. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7481. {
  7482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7483. goto end;
  7484. }
  7485. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7486. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7487. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7488. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7489. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7490. {
  7491. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7492. goto end;
  7493. }
  7494. else
  7495. {
  7496. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7497. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7498. goto end;
  7499. }
  7500. }
  7501. }// END FOR GENERAL_GUN_QUANTITY
  7502. for (int index = 0; index < AC_QUANTITY; index++)
  7503. {
  7504. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7505. {
  7506. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7507. {
  7508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7509. goto end;
  7510. }
  7511. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7512. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7513. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7514. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7515. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7516. {
  7517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7518. goto end;
  7519. }
  7520. else
  7521. {
  7522. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7524. goto end;
  7525. }
  7526. }
  7527. }//END FOR AC_QUANTITY
  7528. }//END FOR AvailabilityTypeStr[Inoperative]
  7529. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7530. {
  7531. //----------------------gunIndex is 0 ------------------------------------------------//
  7532. if(gunIndex == 0)
  7533. {
  7534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7535. {
  7536. for(int i=0; i < gunTotalNumber; i++)
  7537. {
  7538. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7539. {
  7540. 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
  7541. {
  7542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7543. goto end;
  7544. }
  7545. }//END FOR CHAdeMO_QUANTITY
  7546. for (int index = 0; index < CCS_QUANTITY; index++)
  7547. {
  7548. 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
  7549. {
  7550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7551. goto end;
  7552. }
  7553. }//END FOR CCS_QUANTITY
  7554. for (int index = 0; index < GB_QUANTITY; index++)
  7555. {
  7556. 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
  7557. {
  7558. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7560. goto end;
  7561. }
  7562. }// END FOR GB_QUANTITY
  7563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7564. {
  7565. 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
  7566. {
  7567. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7568. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7569. goto end;
  7570. }
  7571. }// END FOR GENERAL_GUN_QUANTITY
  7572. for (int index = 0; index < AC_QUANTITY; index++)
  7573. {
  7574. 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
  7575. {
  7576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7577. goto end;
  7578. }
  7579. }//END FOR CHAdeMO_QUANTITY
  7580. }// END FOR gunTotalNumber
  7581. }
  7582. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7583. {
  7584. for(int i=0; i < gunTotalNumber; i++)
  7585. {
  7586. for (int index = 0; index < AC_QUANTITY; index++)
  7587. {
  7588. 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
  7589. {
  7590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7591. goto end;
  7592. }
  7593. }//END FOR CHAdeMO_QUANTITY
  7594. } // END FOR gunTotalNumber
  7595. }
  7596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7597. goto end;
  7598. }
  7599. //----------------------gunIndex is not 0 ------------------------------------------------//
  7600. //check Transaction active
  7601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7602. {
  7603. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7604. {
  7605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7606. goto end;
  7607. }
  7608. }//END FOR CHAdeMO_QUANTITY
  7609. for (int index = 0; index < CCS_QUANTITY; index++)
  7610. {
  7611. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7612. {
  7613. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7614. goto end;
  7615. }
  7616. }//END FOR CCS_QUANTITY
  7617. for (int index = 0; index < GB_QUANTITY; index++)
  7618. {
  7619. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7620. {
  7621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7622. goto end;
  7623. }
  7624. }// END FOR GB_QUANTITY
  7625. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7626. {
  7627. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7628. {
  7629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7630. goto end;
  7631. }
  7632. }// END FOR GENERAL_GUN_QUANTITY
  7633. for (int index = 0; index < AC_QUANTITY; index++)
  7634. {
  7635. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7636. {
  7637. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7638. goto end;
  7639. }
  7640. }//END FOR AC_QUANTITY
  7641. }//END FOR AvailabilityTypeStr[Operative]
  7642. end:
  7643. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7644. {
  7645. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7646. }
  7647. else
  7648. {
  7649. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7650. }
  7651. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7652. {
  7653. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7654. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7655. }
  7656. else if(gunIndex == 0)
  7657. {
  7658. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7659. {
  7660. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7661. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7662. }
  7663. }
  7664. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7665. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7666. return result;
  7667. }
  7668. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7669. {
  7670. mtrace();
  7671. int result = FAIL;
  7672. char keystr[40]={0};
  7673. char valuestr[256]={0};
  7674. char comfirmstr[20]={0};
  7675. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7676. json_object *ChangeConfiguration;
  7677. ChangeConfiguration = json_tokener_parse(payload);
  7678. if(!is_error(ChangeConfiguration))
  7679. {
  7680. // Required data
  7681. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7682. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7683. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7684. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7685. }
  7686. json_object_put(ChangeConfiguration);
  7687. if((uuid==NULL) || (payload ==NULL) )
  7688. {
  7689. DEBUG_ERROR("Payload is null\n");
  7690. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7691. }
  7692. else
  7693. {
  7694. int status = setKeyValue(keystr, valuestr);
  7695. switch(status)
  7696. {
  7697. case ConfigurationStatus_Accepted:
  7698. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7699. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7700. StoreConfigurationTable();
  7701. break;
  7702. case RebootRequired:
  7703. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7704. StoreConfigurationTable();
  7705. break;
  7706. case NotSupported:
  7707. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7708. break;
  7709. case ConfigurationStatus_Rejected:
  7710. default:
  7711. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7712. break;
  7713. }
  7714. }
  7715. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7716. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7717. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  7718. {
  7719. ChageWebSocketPingInterval(atoi(valuestr));
  7720. }
  7721. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7722. {
  7723. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7724. SetOcppConnStatus(FALSE);
  7725. }
  7726. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7727. {
  7728. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7729. }
  7730. return result;
  7731. }
  7732. int handleClearCacheRequest(char *uuid, char *payload)
  7733. {
  7734. mtrace();
  7735. int result = FAIL;
  7736. char comfirmstr[20];
  7737. char rmFileCmd[100]={0};
  7738. struct stat stats;
  7739. DEBUG_INFO("handleClearCacheRequest...\n");
  7740. stat("/Storage/OCPP_PH", &stats);
  7741. // Check for directory existence
  7742. if (S_ISDIR(stats.st_mode) == 1)
  7743. {}
  7744. else
  7745. {
  7746. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7747. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  7748. system(rmFileCmd);
  7749. }
  7750. if(OCPP_cleanLocalCache())
  7751. {
  7752. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7753. }
  7754. else
  7755. {
  7756. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7757. }
  7758. sendClearCacheConfirmation(uuid, comfirmstr);
  7759. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7760. return result;
  7761. }
  7762. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7763. {
  7764. mtrace();
  7765. int result = FAIL;
  7766. int resultRename;
  7767. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7768. char chargingProfilePurposeStr[26]={0};
  7769. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7770. char tempchargingProfilePurposeStr[26]={0};
  7771. char str[100]={0};
  7772. char fname[200]={0};
  7773. char comfirmstr[20]={0};
  7774. char word[1600]={0};
  7775. int clearflag = FALSE;
  7776. int chargingProfileIdIsNULL = FALSE;
  7777. int connectorIsNULL = FALSE;
  7778. int chargingProfilePurposeIsNULL = FALSE;
  7779. int stackLevelIsNULL = FALSE;
  7780. //int GotoEnd = FALSE;
  7781. FILE *fptr1, *fptr2;
  7782. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  7783. int n_chargingProfile=0;
  7784. int isEmptyFile = FALSE;
  7785. char sLineWord[1600]={0};
  7786. char chargingProfiles[10][100]={0};
  7787. int ChargeProfileCount = 0;
  7788. int ch;
  7789. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7790. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7791. json_object *ClearChargingProfile;
  7792. ClearChargingProfile = json_tokener_parse(payload);
  7793. if(!is_error(ClearChargingProfile))
  7794. {
  7795. // Optional data
  7796. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7797. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7798. else
  7799. chargingProfileIdIsNULL = TRUE;
  7800. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7801. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7802. else
  7803. connectorIsNULL = TRUE;
  7804. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7805. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7806. else
  7807. chargingProfilePurposeIsNULL = TRUE;
  7808. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7809. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7810. else
  7811. stackLevelIsNULL = TRUE;
  7812. }
  7813. json_object_put(ClearChargingProfile);
  7814. if(connectorIsNULL == FALSE)
  7815. {
  7816. switch(connectorIdInt)
  7817. {
  7818. case 0:
  7819. if(chargingProfilePurposeIsNULL == TRUE)
  7820. {
  7821. int l = 0;
  7822. strcpy(fname, ChargePointMaxProfile_JSON);
  7823. if((access(fname,F_OK))!=-1)
  7824. {
  7825. strcpy(chargingProfiles[l], fname);
  7826. l = l + 1;
  7827. }
  7828. strcpy(fname, TxDefaultProfile_0_JSON);
  7829. if((access(fname,F_OK))!=-1)
  7830. {
  7831. strcpy(chargingProfiles[l], fname);
  7832. l = l + 1;
  7833. }
  7834. ChargeProfileCount = l;
  7835. }
  7836. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7837. {
  7838. strcpy(fname, ChargePointMaxProfile_JSON);
  7839. if((access(fname,F_OK))!=-1)
  7840. {
  7841. strcpy(chargingProfiles[0], fname);
  7842. ChargeProfileCount = 1;
  7843. }
  7844. }
  7845. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7846. {
  7847. strcpy(fname, TxDefaultProfile_0_JSON);
  7848. if((access(fname,F_OK))!=-1)
  7849. {
  7850. strcpy(chargingProfiles[0], fname);
  7851. ChargeProfileCount = 1;
  7852. }
  7853. }
  7854. break;
  7855. default:
  7856. if(chargingProfilePurposeIsNULL == TRUE)
  7857. {
  7858. int m = 0;
  7859. memset(fname, 0, ARRAY_SIZE(fname));
  7860. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7861. if((access(fname,F_OK))!=-1)
  7862. {
  7863. strcpy(chargingProfiles[m], fname);
  7864. m = m + 1;
  7865. }
  7866. memset(fname, 0, ARRAY_SIZE(fname));
  7867. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7868. if((access(fname,F_OK))!=-1)
  7869. {
  7870. strcpy(chargingProfiles[m], fname);
  7871. m = m + 1;
  7872. }
  7873. ChargeProfileCount = m;
  7874. }
  7875. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7876. {
  7877. //strcpy(fname, TxDefaultProfile_1_JSON);
  7878. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7879. if((access(fname,F_OK))!=-1)
  7880. {
  7881. strcpy(chargingProfiles[0], fname);
  7882. ChargeProfileCount = 1;
  7883. }
  7884. }
  7885. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7886. {
  7887. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7888. if((access(fname,F_OK))!=-1)
  7889. {
  7890. strcpy(chargingProfiles[0], fname);
  7891. ChargeProfileCount = 1;
  7892. }
  7893. //strcpy(fname, TxProfile_1_JSON);
  7894. }
  7895. //strcpy(fname, ChargePointMaxProfile_JSON );
  7896. break;
  7897. }
  7898. }
  7899. else // Check all Charging Profiles
  7900. {
  7901. int i = 0;
  7902. char fnametemp[200]={0};
  7903. ChargeProfileCount = 0;
  7904. //Check ChargePointMaxProfile.json exit
  7905. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7906. {
  7907. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7908. i = i + 1;
  7909. }
  7910. //Check TxDefaultProfile_0.json exit
  7911. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7912. {
  7913. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7914. i = i + 1;
  7915. }
  7916. //Check TxDefaultProfile_%d.json
  7917. for(int j=1; j <= gunTotalNumber; j++)
  7918. {
  7919. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7920. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7921. if((access(fnametemp,F_OK))!=-1)
  7922. {
  7923. strcpy(chargingProfiles[i], fnametemp);
  7924. i = i + 1;
  7925. }
  7926. }
  7927. //Check TxProfile_%d.json
  7928. for(int j=1; j <= gunTotalNumber; j++)
  7929. {
  7930. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7931. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7932. if((access(fnametemp,F_OK))!=-1)
  7933. {
  7934. strcpy(chargingProfiles[i], fnametemp);
  7935. i = i + 1;
  7936. }
  7937. }
  7938. ChargeProfileCount = i;
  7939. }// End connectorIsNULL is TRUE
  7940. if(ChargeProfileCount == 0)
  7941. {
  7942. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7943. goto end;
  7944. }
  7945. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7946. {
  7947. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7948. goto end;
  7949. }
  7950. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7951. {
  7952. memset(str, 0, ARRAY_SIZE(str));
  7953. // clear temp file
  7954. sprintf(str,"rm -f %s",temp);
  7955. system(str);
  7956. for(int k=0; k < ChargeProfileCount; k++)
  7957. {
  7958. memset(str, 0, ARRAY_SIZE(str));
  7959. //clear file in C
  7960. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7961. system(str);
  7962. }
  7963. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7964. goto end;
  7965. }
  7966. else if(connectorIsNULL == TRUE)
  7967. {
  7968. for(int k=0; k < ChargeProfileCount; k++)
  7969. {
  7970. fptr1 = fopen(chargingProfiles[k], "r");
  7971. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7972. //Check Charging Profile Count
  7973. while(fscanf(fptr1, "%s", word) != EOF)
  7974. {
  7975. //DEBUG_INFO("word=%s\n",word);
  7976. if(strstr(word, "chargingProfileId")!= NULL)
  7977. {
  7978. //DEBUG_INFO("test chargingProfileId \n");
  7979. n_chargingProfile = n_chargingProfile + 1;
  7980. //DEBUG_INFO("chargingProfileId Found\n");
  7981. }
  7982. }
  7983. rewind(fptr1);
  7984. //search Charging Profile Element
  7985. //int i= 0;
  7986. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7987. {
  7988. json_object *tmpProfilee;
  7989. tmpProfilee = json_tokener_parse(sLineWord);
  7990. if(!is_error(tmpProfilee))
  7991. {
  7992. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7993. {
  7994. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7995. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7996. }
  7997. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7998. {
  7999. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8000. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8001. }
  8002. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8003. {
  8004. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8005. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8006. }
  8007. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8008. {
  8009. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8010. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8011. }
  8012. }
  8013. json_object_put(tmpProfilee);
  8014. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8015. {
  8016. //------- not write to fptr2-------//
  8017. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8018. //clearflag = TRUE;
  8019. }
  8020. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8021. {
  8022. //------- not write to fptr2-------//
  8023. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8024. }
  8025. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8026. {
  8027. //------- not write to fptr2-------//
  8028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8029. }
  8030. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8031. {
  8032. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8033. }
  8034. else
  8035. {
  8036. fprintf(fptr2, sLineWord);//writing data into file
  8037. }
  8038. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8039. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8040. if(clearflag == TRUE)
  8041. {
  8042. fclose(fptr1);
  8043. fclose(fptr2);
  8044. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8045. system(str);
  8046. // clear temp file
  8047. sprintf(str,"rm -f %s",temp);
  8048. system(str);
  8049. }
  8050. else
  8051. {
  8052. fclose(fptr1);
  8053. fclose(fptr2);
  8054. memset(str, 0, ARRAY_SIZE(str));
  8055. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8056. system(str);
  8057. resultRename = rename(temp, chargingProfiles[k]);
  8058. if(resultRename == 0)
  8059. {
  8060. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8061. }
  8062. else
  8063. {
  8064. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8065. }
  8066. if(comfirmstr[0]== 0)
  8067. {
  8068. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8069. }
  8070. //Check chargingProfile is empty file
  8071. /*------ Read the file ----------------*/
  8072. fptr1=fopen(chargingProfiles[k],"r");
  8073. ch=fgetc(fptr1);
  8074. rewind(fptr1);
  8075. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8076. if(ch!=EOF)
  8077. {
  8078. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8079. {
  8080. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8081. if(sLineWord[0]=='\0')
  8082. {
  8083. isEmptyFile = TRUE;
  8084. break;
  8085. }
  8086. else
  8087. {
  8088. isEmptyFile = FALSE;
  8089. break;
  8090. }
  8091. }
  8092. }
  8093. else
  8094. isEmptyFile = TRUE;
  8095. fclose(fptr1);
  8096. if(isEmptyFile == TRUE)
  8097. {
  8098. memset(str, 0, ARRAY_SIZE(str));
  8099. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8100. system(str);
  8101. }
  8102. }
  8103. }// End of while(int k=0; k < ChargePointCount; k++)
  8104. }
  8105. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8106. {
  8107. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8108. for(int k=0; k < ChargeProfileCount; k++)
  8109. {
  8110. fptr1 = fopen(chargingProfiles[k], "r");
  8111. fptr2 = fopen(temp, "w+");
  8112. //Check Charging Profile Count
  8113. while(fscanf(fptr1, "%s", word) != EOF)
  8114. {
  8115. //DEBUG_INFO("word=%s\n",word);
  8116. if(strstr(word, "chargingProfileId")!= NULL)
  8117. {
  8118. n_chargingProfile = n_chargingProfile + 1;
  8119. }
  8120. }
  8121. rewind(fptr1);
  8122. //search Charging Profile Element
  8123. //int i= 0;
  8124. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8125. {
  8126. json_object *tmpProfilee;
  8127. tmpProfilee = json_tokener_parse(sLineWord);
  8128. if(!is_error(tmpProfilee))
  8129. {
  8130. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8131. {
  8132. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8133. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8134. }
  8135. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8136. {
  8137. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8138. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8139. }
  8140. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8141. {
  8142. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8143. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8144. }
  8145. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8146. {
  8147. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8148. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8149. }
  8150. }
  8151. json_object_put(tmpProfilee);
  8152. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8153. {
  8154. //------- not write to fptr2-------//
  8155. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8156. //clearflag = TRUE;
  8157. }
  8158. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8159. {
  8160. //------- not write to fptr2-------//
  8161. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8162. }
  8163. else if(stackLevelIsNULL == TRUE)
  8164. {
  8165. //Clear Whole File
  8166. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8167. clearflag = TRUE;
  8168. break;
  8169. }
  8170. else
  8171. {
  8172. fprintf(fptr2, sLineWord);//writing data into file
  8173. }
  8174. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8175. }
  8176. if(clearflag == TRUE)
  8177. {
  8178. fclose(fptr1);
  8179. fclose(fptr2);
  8180. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8181. system(str);
  8182. // clear temp file
  8183. sprintf(str,"rm -f %s",temp);
  8184. system(str);
  8185. }
  8186. else
  8187. {
  8188. fclose(fptr1);
  8189. fclose(fptr2);
  8190. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8191. system(str);
  8192. resultRename = rename(temp, chargingProfiles[k]);
  8193. if(resultRename == 0)
  8194. {
  8195. DEBUG_INFO("File ChargingProfile renamed successfully");
  8196. }
  8197. else
  8198. {
  8199. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8200. }
  8201. if(comfirmstr[0]== 0)
  8202. {
  8203. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8204. }
  8205. //Check chargingProfile is empty file
  8206. /*------ Read the file ----------------*/
  8207. fptr1=fopen(chargingProfiles[k],"r");
  8208. ch=fgetc(fptr1);
  8209. rewind(fptr1);
  8210. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8211. if(ch!=EOF)
  8212. {
  8213. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8214. {
  8215. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8216. if(sLineWord[0]=='\0')
  8217. {
  8218. isEmptyFile = TRUE;
  8219. break;
  8220. }
  8221. else
  8222. {
  8223. isEmptyFile = FALSE;
  8224. break;
  8225. }
  8226. }
  8227. }
  8228. else
  8229. isEmptyFile = TRUE;
  8230. fclose(fptr1);
  8231. if(isEmptyFile == TRUE)
  8232. {
  8233. memset(str, 0, ARRAY_SIZE(str));
  8234. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8235. system(str);
  8236. }
  8237. /*------- End of reading ---------------*/
  8238. }
  8239. } // while(int k=0; k < ChargeProfileCount; k++)
  8240. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8241. end:
  8242. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8243. {
  8244. if(connectorIdInt == 0)
  8245. {
  8246. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8247. {
  8248. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8249. }
  8250. }
  8251. else
  8252. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8253. }
  8254. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8255. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8256. return result;
  8257. }
  8258. void createFirmwareVersionByDataTransfer(void)
  8259. {
  8260. json_object *FirmwareDataTransfer = json_object_new_object();
  8261. // AC & DC model
  8262. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8263. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8264. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8265. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8266. // DC model
  8267. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8268. {
  8269. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8270. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8271. (gunType[3] != GUN_TYPE_UNKNOWN))
  8272. {
  8273. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8274. }
  8275. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8276. {
  8277. // DS DM DW
  8278. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8279. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8280. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8281. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8282. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8283. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8284. }
  8285. else
  8286. {
  8287. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8288. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8289. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8290. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8291. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8292. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8293. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8294. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8295. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8296. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8297. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8298. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8299. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8300. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8301. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8302. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8303. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8304. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8305. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8306. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8307. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8308. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8309. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8310. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8311. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8312. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8313. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8314. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8315. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8316. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8317. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8318. }
  8319. }
  8320. // 4G model
  8321. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8322. {
  8323. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8324. }
  8325. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8326. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8327. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8328. json_object_put(FirmwareDataTransfer);
  8329. }
  8330. int handleDataTransferRequest(char *uuid, char *payload)
  8331. {
  8332. mtrace();
  8333. json_object *response = json_object_new_object();
  8334. int result = FAIL;
  8335. char tempvendorId[255]={0};
  8336. char tempmessageId[50]={0};
  8337. char tempdata[512]={0};
  8338. char message[2048]={0};
  8339. DEBUG_INFO("handleDataTransferRequest...\n");
  8340. if((uuid != NULL) && (payload != NULL))
  8341. {
  8342. json_object *DataTransfer;
  8343. DataTransfer = json_tokener_parse(payload);
  8344. if(!is_error(DataTransfer))
  8345. {
  8346. // Required data
  8347. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8348. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8349. // Optional data
  8350. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8351. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8352. if(json_object_object_get(DataTransfer, "data") != NULL)
  8353. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8354. result = PASS;
  8355. }
  8356. json_object_put(DataTransfer);
  8357. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8358. {
  8359. // Send all moudle firmware version on EVSE
  8360. createFirmwareVersionByDataTransfer();
  8361. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8362. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  8363. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8364. json_object_put(response);
  8365. }
  8366. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8367. {
  8368. system("/usr/bin/run_tmate_restart.sh &");
  8369. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8370. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8371. json_object_put(response);
  8372. }
  8373. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8374. {
  8375. json_object *data;
  8376. data = json_tokener_parse(tempdata);
  8377. if(!is_error(data))
  8378. {
  8379. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8380. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8381. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8382. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8383. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8384. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8385. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8386. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8387. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8388. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8389. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8390. }
  8391. else
  8392. {
  8393. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8394. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8395. }
  8396. json_object_put(data);
  8397. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8398. json_object_put(response);
  8399. }
  8400. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8401. {
  8402. json_object *data;
  8403. data = json_tokener_parse(tempdata);
  8404. if(!is_error(data))
  8405. {
  8406. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8407. if(json_object_object_get(data, "idToken") != NULL)
  8408. {
  8409. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8410. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8411. }
  8412. if(json_object_object_get(data, "price") != NULL)
  8413. {
  8414. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8415. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8416. }
  8417. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8418. }
  8419. else
  8420. {
  8421. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8422. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8423. }
  8424. json_object_put(data);
  8425. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8426. json_object_put(response);
  8427. }
  8428. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8429. {
  8430. json_object *data;
  8431. data = json_tokener_parse(tempdata);
  8432. if(!is_error(data))
  8433. {
  8434. if(json_object_object_get(data, "txId") != NULL)
  8435. {
  8436. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8437. for(int idx = 0;idx<gunTotalNumber;idx++)
  8438. {
  8439. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8440. {
  8441. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8442. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8443. if(json_object_object_get(data, "description") != NULL)
  8444. {
  8445. // California pricing V1.0
  8446. DEBUG_INFO("California pricing V1.0\n");
  8447. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8448. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8449. }
  8450. else
  8451. {
  8452. // California pricing V1.1
  8453. DEBUG_INFO("California pricing V1.1\n");
  8454. if(json_object_object_get(data, "timestamp") != NULL)
  8455. {
  8456. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8457. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8458. }
  8459. if(json_object_object_get(data, "meterValue") != NULL)
  8460. {
  8461. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8462. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8463. }
  8464. if(json_object_object_get(data, "cost") != NULL)
  8465. {
  8466. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8467. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8468. }
  8469. if(json_object_object_get(data, "state") != NULL)
  8470. {
  8471. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8472. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8473. }
  8474. if(json_object_object_get(data, "chargingPrice") != NULL)
  8475. {
  8476. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8477. {
  8478. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8479. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8480. }
  8481. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8482. {
  8483. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8484. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8485. }
  8486. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8487. {
  8488. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8489. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8490. }
  8491. }
  8492. if(json_object_object_get(data, "idlePrice") != NULL)
  8493. {
  8494. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8495. {
  8496. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8497. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8498. }
  8499. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8500. {
  8501. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8502. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8503. }
  8504. }
  8505. if(json_object_object_get(data, "nextPeriod") != NULL)
  8506. {
  8507. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8508. {
  8509. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8510. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8511. }
  8512. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8513. {
  8514. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8515. {
  8516. 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")));
  8517. 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"));
  8518. }
  8519. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8520. {
  8521. 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")));
  8522. 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"));
  8523. }
  8524. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8525. {
  8526. 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")));
  8527. 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"));
  8528. }
  8529. }
  8530. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8531. {
  8532. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8533. {
  8534. 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")));
  8535. 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"));
  8536. }
  8537. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8538. {
  8539. 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")));
  8540. 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"));
  8541. }
  8542. }
  8543. }
  8544. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8545. {
  8546. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8547. {
  8548. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8549. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8550. }
  8551. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8552. {
  8553. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8554. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8555. }
  8556. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8557. {
  8558. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8559. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8560. }
  8561. }
  8562. }
  8563. }
  8564. }
  8565. }
  8566. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8567. }
  8568. else
  8569. {
  8570. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8571. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8572. }
  8573. json_object_put(data);
  8574. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8575. json_object_put(response);
  8576. }
  8577. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8578. {
  8579. json_object *data;
  8580. data = json_tokener_parse(tempdata);
  8581. if(!is_error(data))
  8582. {
  8583. if(json_object_object_get(data, "txId") != NULL)
  8584. {
  8585. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8586. for(int idx = 0;idx<gunTotalNumber;idx++)
  8587. {
  8588. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8589. {
  8590. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8591. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8592. if(json_object_object_get(data, "description") != NULL)
  8593. {
  8594. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8595. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8596. }
  8597. }
  8598. }
  8599. }
  8600. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8601. }
  8602. else
  8603. {
  8604. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8605. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8606. }
  8607. json_object_put(data);
  8608. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8609. json_object_put(response);
  8610. }
  8611. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8612. {
  8613. json_object *data;
  8614. data = json_tokener_parse(tempdata);
  8615. if(!is_error(data))
  8616. {
  8617. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8618. if(json_object_object_get(data, "Content_Type") != NULL)
  8619. {
  8620. 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))
  8621. {
  8622. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8623. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8624. {
  8625. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8626. }
  8627. }
  8628. else
  8629. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8630. }
  8631. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8632. }
  8633. else
  8634. {
  8635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8636. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8637. }
  8638. json_object_put(data);
  8639. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8640. json_object_put(response);
  8641. }
  8642. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8643. {
  8644. json_object *data;
  8645. data = json_tokener_parse(tempdata);
  8646. if(!is_error(data))
  8647. {
  8648. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8649. if(json_object_object_get(data, "Page_Index") != NULL)
  8650. {
  8651. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8652. }
  8653. if(json_object_object_get(data, "Duration") != NULL)
  8654. {
  8655. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8656. }
  8657. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8658. }
  8659. else
  8660. {
  8661. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8662. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8663. }
  8664. json_object_put(data);
  8665. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8666. json_object_put(response);
  8667. }
  8668. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8669. {
  8670. json_object *data;
  8671. data = json_tokener_parse(tempdata);
  8672. if(!is_error(data))
  8673. {
  8674. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8675. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8676. {
  8677. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8678. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8679. else
  8680. {
  8681. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8682. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8683. }
  8684. }
  8685. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8686. {
  8687. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8688. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8689. else
  8690. {
  8691. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8692. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8693. }
  8694. }
  8695. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8696. {
  8697. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8698. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8699. else
  8700. {
  8701. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8702. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8703. }
  8704. }
  8705. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8706. {
  8707. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8708. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8709. else
  8710. {
  8711. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8712. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8713. }
  8714. }
  8715. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8716. {
  8717. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8718. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8719. else
  8720. {
  8721. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8722. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8723. }
  8724. }
  8725. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8726. {
  8727. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8728. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8729. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8730. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8731. else
  8732. {
  8733. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8734. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8735. }
  8736. }
  8737. if(json_object_object_get(data, "isAuthentication") != NULL)
  8738. {
  8739. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8740. {
  8741. case 0:
  8742. case 1:
  8743. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8744. break;
  8745. default:
  8746. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8747. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8748. break;
  8749. }
  8750. }
  8751. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8752. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8753. }
  8754. else
  8755. {
  8756. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8757. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8758. }
  8759. json_object_put(data);
  8760. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8761. json_object_put(response);
  8762. }
  8763. else
  8764. {
  8765. // Can not find valid message id
  8766. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8767. }
  8768. }
  8769. else
  8770. {
  8771. // Payload is null
  8772. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8773. }
  8774. LWS_Send(message);
  8775. return result;
  8776. }
  8777. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8778. {
  8779. mtrace();
  8780. int result = FAIL;
  8781. int connectorIdInt, durationInt;
  8782. char chargingRateUnitStr[4]={0};
  8783. char comfirmstr[20];
  8784. int confirmPeriods = 0;
  8785. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8786. json_object *GetCompositeSchedule;
  8787. GetCompositeSchedule = json_tokener_parse(payload);
  8788. if(!is_error(GetCompositeSchedule))
  8789. {
  8790. // Required data
  8791. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8792. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8793. else
  8794. connectorIdInt = -1;
  8795. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8796. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8797. else
  8798. durationInt = 86400;
  8799. // Optional data
  8800. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8801. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8802. }
  8803. json_object_put(GetCompositeSchedule);
  8804. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8805. if((connectorIdInt == 0) ||
  8806. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8807. {
  8808. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8809. struct StructChargingProfile tmpProfile[1];
  8810. if(strstr(chargingRateUnitStr, "W") != NULL)
  8811. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8812. else
  8813. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8814. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8815. {
  8816. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8817. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8818. }
  8819. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8820. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8821. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8822. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8823. {
  8824. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8825. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8826. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8827. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8828. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8829. {
  8830. confirmPeriods = idx;
  8831. break;
  8832. }
  8833. }
  8834. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8835. {
  8836. confirmPeriods += 1;
  8837. }
  8838. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8839. }
  8840. else
  8841. {
  8842. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8843. }
  8844. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8845. return result;
  8846. }
  8847. int handleGetConfigurationRequest(char *uuid, char *payload)
  8848. {
  8849. mtrace();
  8850. int result = FAIL;
  8851. int MaxKeySupported = 0;
  8852. int n_keys = 0;
  8853. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8854. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8855. json_object *GetConfiguration;
  8856. GetConfiguration = json_tokener_parse(payload);
  8857. if(!is_error(GetConfiguration))
  8858. {
  8859. // Optional data
  8860. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8861. {
  8862. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8863. {
  8864. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8865. n_keys = idx + 1;
  8866. }
  8867. }
  8868. }
  8869. json_object_put(GetConfiguration);
  8870. UnknownKeynum = 0;
  8871. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8872. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8873. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8874. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8875. if(n_keys != 0)
  8876. {
  8877. for(int i=0;i<n_keys;i++)
  8878. {
  8879. getKeyValue(requestKey[i]);
  8880. }
  8881. }
  8882. else
  8883. {
  8884. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8885. getKeyValue("");
  8886. }
  8887. processUnkownKey();
  8888. sendGetConfigurationConfirmation(uuid);
  8889. return result;
  8890. }
  8891. static char fnamePlusPath[100]={0};
  8892. static char fnamePWithNoPath[60]={0};
  8893. void checkUploadLog(void)
  8894. {
  8895. FILE *fp;
  8896. /* Open the command for reading. */
  8897. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8898. if (fp == NULL) {
  8899. DEBUG_WARN("Failed to run command\n" );
  8900. exit(1);
  8901. }
  8902. int ftppathlen = 0;
  8903. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8904. int i = 0;
  8905. /* Read the output a line at a time - output it. */
  8906. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8907. if(i==0)
  8908. {
  8909. ftppathlen = strlen(fnamePlusPath);
  8910. DEBUG_INFO("%s\n", fnamePlusPath);
  8911. fnamePlusPath[ftppathlen]='\0';
  8912. break;
  8913. }
  8914. i= i+1;
  8915. }
  8916. /* close */
  8917. pclose(fp);
  8918. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8919. {
  8920. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8921. {
  8922. fnamePlusPath[k]='\0';
  8923. }
  8924. }
  8925. i=1;
  8926. //char fname[60]={0};
  8927. while(i < ftppathlen)
  8928. {
  8929. int len=ftppathlen-i;
  8930. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8931. {
  8932. DEBUG_INFO("compare '/' all right\n");
  8933. break;
  8934. }
  8935. i=i+1;
  8936. }
  8937. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8938. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8939. fnamePWithNoPath[i+1] = '\0';
  8940. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8941. {
  8942. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8943. {
  8944. fnamePWithNoPath[j]='\0';
  8945. }
  8946. }
  8947. FILE* fp1 = fopen(fnamePlusPath, "r");
  8948. if (fp1)
  8949. {
  8950. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8951. // file exists
  8952. fclose(fp1);
  8953. }
  8954. else
  8955. {
  8956. // file doesn't exist
  8957. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8958. }
  8959. }
  8960. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8961. {
  8962. mtrace();
  8963. int result = FAIL;
  8964. time_t CurrentTime;
  8965. struct tm *tm;
  8966. pthread_t th_Status;
  8967. CurrentTime = time(NULL);
  8968. tm = localtime(&CurrentTime);
  8969. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  8970. 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);
  8971. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8972. if(!interLock.isGetDiagnosticGoing)
  8973. {
  8974. interLock.isGetDiagnosticGoing = 1;
  8975. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8976. sleep(1);
  8977. }
  8978. else
  8979. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  8980. return result;
  8981. }
  8982. void* GetDiagnosticsProcess(void* data)
  8983. {
  8984. pthread_detach(pthread_self());
  8985. mtrace();
  8986. int retriesInt=0, retryIntervalInt=0;
  8987. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8988. 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};
  8989. int port=0;
  8990. int isSuccess = FALSE;
  8991. char ftpbuf[200]={0};
  8992. char cmdBuf[2048];
  8993. struct tm *tmNow;
  8994. time_t CurrentTime;
  8995. struct tm tmStart;
  8996. struct tm tmStop;
  8997. CurrentTime = time(NULL);
  8998. tmNow=localtime(&CurrentTime);
  8999. uint16_t targetYear, targetMonth;
  9000. json_object *GetDiagnostics;
  9001. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9002. GetDiagnostics = json_tokener_parse(data);
  9003. if(!is_error(GetDiagnostics))
  9004. {
  9005. // Required data
  9006. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9007. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9008. // Optional data
  9009. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9010. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9011. else
  9012. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9013. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9014. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9015. else
  9016. retryIntervalInt = 30;
  9017. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9018. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9019. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9020. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9021. }
  9022. json_object_put(GetDiagnostics);
  9023. // Pack log to compress file
  9024. 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) &&
  9025. (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))
  9026. {
  9027. // Pack system log
  9028. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9029. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9030. targetYear = tmStart.tm_year;
  9031. targetMonth = tmStart.tm_mon;
  9032. do
  9033. {
  9034. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9035. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9036. if(targetMonth+1>=13)
  9037. {
  9038. targetYear += 1;
  9039. targetMonth = 1;
  9040. }
  9041. else
  9042. {
  9043. targetMonth += 1;
  9044. }
  9045. }while((targetYear < (tmNow->tm_year+1900)) ||
  9046. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9047. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9048. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9049. system(cmdBuf);
  9050. // Pack charging & event log
  9051. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9052. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9053. targetYear = tmStart.tm_year;
  9054. targetMonth = tmStart.tm_mon;
  9055. do
  9056. {
  9057. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9058. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9059. if(targetMonth+1>=13)
  9060. {
  9061. targetYear += 1;
  9062. targetMonth = 1;
  9063. }
  9064. else
  9065. {
  9066. targetMonth += 1;
  9067. }
  9068. }while((targetYear < (tmNow->tm_year+1900)) ||
  9069. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9070. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9071. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9072. system(cmdBuf);
  9073. // Combine log file
  9074. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9075. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9076. }
  9077. else
  9078. {
  9079. system("exec /root/logPackTools 'log' 6");
  9080. }
  9081. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9082. system(cmdBuf);
  9083. checkUploadLog();
  9084. //****************location*******************/
  9085. if(strcmp(locationstr,"")==0)
  9086. {
  9087. DEBUG_INFO("location is <Empty>!\n");
  9088. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9089. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9090. goto end;
  9091. }
  9092. memset(protocol, 0, ARRAY_SIZE(protocol));
  9093. memset(user, 0, ARRAY_SIZE(user) );
  9094. memset(password, 0, ARRAY_SIZE(password));
  9095. memset(host, 0, ARRAY_SIZE(host));
  9096. memset(path, 0, ARRAY_SIZE(path));
  9097. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9098. memset(host1, 0, ARRAY_SIZE(host1));
  9099. memset(path1, 0, ARRAY_SIZE(path1));
  9100. /*location: ftp://user:password@host:port/path*/
  9101. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9102. if((access(fnamePlusPath,F_OK))!=-1)
  9103. {
  9104. DEBUG_INFO("fnamePlusPath exist.\n");
  9105. }
  9106. else
  9107. {
  9108. DEBUG_INFO("fnamePlusPath not exist!\n");
  9109. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9110. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9111. goto end;
  9112. }
  9113. if(strchr(locationstr,'@')==NULL)
  9114. {
  9115. sscanf(locationstr,
  9116. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9117. protocol, host, &port, path);
  9118. strcpy(user,"anonymous");
  9119. strcpy(password,"");
  9120. }
  9121. else
  9122. {
  9123. //DEBUG_INFO("pch=%s\n", pch);
  9124. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9125. protocol, user, password, host, &port, path);
  9126. }
  9127. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9128. {
  9129. DEBUG_INFO("protocol is not ftp/http ! \n");
  9130. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9131. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9132. goto end;
  9133. }
  9134. if(strncmp(locationstr,"http", 4) == 0)
  9135. {
  9136. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9137. sprintf(ftppath,"/%s", path);
  9138. do
  9139. {
  9140. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9141. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9142. sleep(3);
  9143. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9144. if(!isSuccess)
  9145. {
  9146. DEBUG_INFO("Diagnostics fail.\n");
  9147. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9148. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9149. sleep(retryIntervalInt);
  9150. }
  9151. else
  9152. {
  9153. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9154. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9155. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9156. }
  9157. retriesInt--;
  9158. }while((isSuccess == 0)&&(retriesInt >= 0));
  9159. }
  9160. else
  9161. {
  9162. sscanf(host,"%[^/]%s",host1, path1);
  9163. if(strlen(path) > 0)
  9164. sprintf(ftppath,"/%s", path);
  9165. else
  9166. sprintf(ftppath,"/%s", path1);
  9167. int ftppathlen=strlen(ftppath);
  9168. int i=1;
  9169. char filenametemp[50];
  9170. while(i < ftppathlen)
  9171. {
  9172. int len=ftppathlen-i;
  9173. if(ftppath[len]== 47) // '/' ascll code: 47
  9174. {
  9175. DEBUG_INFO("find '/' all right\n");
  9176. break;
  9177. }
  9178. i=i+1;
  9179. }
  9180. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9181. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9182. filenametemp[i+1] = 0;
  9183. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9184. if(port == 0)
  9185. port = 21;
  9186. do
  9187. {
  9188. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9189. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9190. sleep(3);
  9191. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9192. if(!isSuccess)
  9193. {
  9194. DEBUG_INFO("Diagnostics fail.\n");
  9195. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9196. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9197. sleep(retryIntervalInt);
  9198. }
  9199. else
  9200. {
  9201. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9202. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9203. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9204. }
  9205. retriesInt--;
  9206. }while((!isSuccess)&&(retriesInt >= 0));
  9207. }
  9208. end:
  9209. system("rm -f /mnt/*");
  9210. sleep(5);
  9211. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9212. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9213. interLock.isGetDiagnosticGoing = 0;
  9214. pthread_exit(NULL);
  9215. }
  9216. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9217. {
  9218. mtrace();
  9219. int result = FAIL;
  9220. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9221. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9222. {
  9223. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9224. locallistVersion = -1;
  9225. }
  9226. else
  9227. {
  9228. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9229. OCPP_getListVerion();
  9230. }
  9231. //from db.OCPP_getListVerion
  9232. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9233. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9234. sendGetLocalListVersionConfirmation(uuid,"");
  9235. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9236. return result;
  9237. }
  9238. int handleRemoteStartRequest(char *uuid, char *payload)
  9239. {
  9240. mtrace();
  9241. int result = FAIL;
  9242. int connectorIdInt=-1;
  9243. int tempIndex = 0;
  9244. int connectorIdIsNULL, chargingProfileIsNULL;
  9245. char comfirmstr[20]={0};
  9246. char cmdBuf[512];
  9247. json_object *RemoteStartTransaction;
  9248. FILE *fp;
  9249. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9250. if(server_pending == TRUE)
  9251. {
  9252. return 0;
  9253. }
  9254. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9255. RemoteStartTransaction = json_tokener_parse(payload);
  9256. if(!is_error(RemoteStartTransaction))
  9257. {
  9258. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9259. {
  9260. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9261. }
  9262. else
  9263. {
  9264. connectorIdIsNULL = TRUE;
  9265. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9266. {
  9267. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9268. {
  9269. connectorIdIsNULL = FALSE;
  9270. connectorIdInt = (gun_index+1);
  9271. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9272. break;
  9273. }
  9274. }
  9275. }
  9276. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9277. {
  9278. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9279. // Required data
  9280. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9281. // Optional data
  9282. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9283. {
  9284. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9285. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9286. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9287. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9288. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9289. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9290. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9291. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9292. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9293. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9294. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9295. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9296. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9297. {
  9298. 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")));
  9299. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9300. 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"));
  9301. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9302. 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"));
  9303. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9304. 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")));
  9305. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9306. {
  9307. 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++)
  9308. {
  9309. 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"));
  9310. 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"));
  9311. 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)
  9312. 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"));
  9313. }
  9314. }
  9315. }
  9316. }
  9317. else
  9318. {
  9319. chargingProfileIsNULL = TRUE;
  9320. }
  9321. }
  9322. }
  9323. else
  9324. {
  9325. connectorIdIsNULL = TRUE;
  9326. }
  9327. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9328. {
  9329. DEBUG_WARN("Connector id is NULL\n.");
  9330. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9331. goto end;
  9332. }
  9333. /*
  9334. enum _SYSTEM_STATUS
  9335. {
  9336. S_BOOTING = 0,
  9337. S_IDLE, = 1
  9338. S_AUTHORIZING, = 2
  9339. S_REASSIGN_CHECK, = 3
  9340. S_REASSIGN, = 4
  9341. S_PRECHARGE, = 5
  9342. S_PREPARING_FOR_EV, = 6
  9343. S_PREPARING_FOR_EVSE, = 7
  9344. S_CHARGING, = 8
  9345. S_TERMINATING, = 9
  9346. S_COMPLETE, = 10
  9347. S_ALARM, = 11
  9348. S_FAULT = 12
  9349. }
  9350. */
  9351. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9352. {
  9353. //check Transaction active
  9354. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9355. {
  9356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9357. {
  9358. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9359. }
  9360. else
  9361. {
  9362. tempIndex = connectorIdInt -1;
  9363. }
  9364. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9365. {
  9366. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9367. {
  9368. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9369. {
  9370. //Reserved
  9371. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9372. }
  9373. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9374. {
  9375. //Reserved
  9376. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9377. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9378. goto end;
  9379. }
  9380. else
  9381. {
  9382. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9383. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9384. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9385. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9386. {
  9387. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9388. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9389. goto end;
  9390. }
  9391. }//END FOR ELSE
  9392. }
  9393. }// END FOR CHAdeMO_QUANTITY
  9394. }
  9395. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9396. {
  9397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9398. {
  9399. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9400. }
  9401. else
  9402. {
  9403. tempIndex = connectorIdInt -1;
  9404. }
  9405. for (int index = 0; index < CCS_QUANTITY; index++)
  9406. {
  9407. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9408. {
  9409. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9410. {
  9411. //Reserved
  9412. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9413. }
  9414. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9415. {
  9416. //Reserved
  9417. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9418. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9419. goto end;
  9420. }
  9421. else
  9422. {
  9423. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9424. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9425. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9426. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9427. {
  9428. DEBUG_WARN("CCS connector not allow start\n.");
  9429. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9430. goto end;
  9431. }
  9432. }// END FOR ELSE
  9433. }
  9434. }// END FOR CCS_QUANTITY
  9435. }
  9436. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9437. {
  9438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9439. {
  9440. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9441. }
  9442. else
  9443. {
  9444. tempIndex = connectorIdInt -1;
  9445. }
  9446. for (int index = 0; index < GB_QUANTITY; index++)
  9447. {
  9448. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9449. {
  9450. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9451. {
  9452. //Reserved
  9453. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9454. }
  9455. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9456. {
  9457. //Reserved
  9458. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9460. goto end;
  9461. }
  9462. else
  9463. {
  9464. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9465. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9466. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9467. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9468. {
  9469. DEBUG_WARN("GB connector not allow start\n.");
  9470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9471. goto end;
  9472. }
  9473. }// END FOR ELSE
  9474. }
  9475. } // END FOR GB_QUANTITY
  9476. }
  9477. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9478. {
  9479. tempIndex = connectorIdInt -1;
  9480. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9481. {
  9482. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9483. {
  9484. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9485. {
  9486. //Reserved
  9487. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9488. }
  9489. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9490. {
  9491. //Reserved
  9492. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9493. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9494. goto end;
  9495. }
  9496. else
  9497. {
  9498. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9499. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9500. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9501. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9502. {
  9503. DEBUG_WARN("GB connector not allow start\n.");
  9504. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9505. goto end;
  9506. }
  9507. }// END FOR ELSE
  9508. }
  9509. } // END FOR GB_QUANTITY
  9510. }
  9511. else
  9512. {
  9513. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9514. {
  9515. tempIndex = 2;
  9516. }
  9517. else
  9518. {
  9519. tempIndex = connectorIdInt -1;
  9520. }
  9521. for (int index = 0; index < AC_QUANTITY; index++)
  9522. {
  9523. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9524. {
  9525. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9526. {
  9527. //Reserved
  9528. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9529. }
  9530. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9531. {
  9532. //Reserved
  9533. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9534. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9535. goto end;
  9536. }
  9537. else
  9538. {
  9539. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9540. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9541. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9542. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9543. {
  9544. DEBUG_WARN("AC connector not allow start\n.");
  9545. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9546. goto end;
  9547. }
  9548. }//END FOR ELSE
  9549. }
  9550. }// END FOR AC_QUANTITY
  9551. }
  9552. if(chargingProfileIsNULL == FALSE)
  9553. {
  9554. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9555. {
  9556. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9557. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9558. //memset idTag
  9559. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9560. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9561. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9562. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9563. // Save profile to file
  9564. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9565. system(cmdBuf);
  9566. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9567. fp = fopen(cmdBuf, "w");
  9568. 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));
  9569. fclose(fp);
  9570. }
  9571. else
  9572. {
  9573. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9574. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9575. }
  9576. }
  9577. else
  9578. {
  9579. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9581. //memset idTag
  9582. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9583. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9584. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9586. }
  9587. }
  9588. else
  9589. {
  9590. DEBUG_WARN("Connector id over\n.");
  9591. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9592. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9593. }
  9594. end:
  9595. json_object_put(RemoteStartTransaction);
  9596. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9597. {
  9598. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9599. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9600. }
  9601. //OCPP send RemoteStartConfirmation by first.
  9602. sendRemoteStartConfirmation(uuid, comfirmstr);
  9603. return result;
  9604. }
  9605. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9606. {
  9607. mtrace();
  9608. int result = FAIL;
  9609. int match = FALSE;
  9610. int GunNO = 0;
  9611. int tempIndex = 0;
  9612. int transactionIdInt=0;
  9613. int transactionIdIsNULL= TRUE;
  9614. char comfirmstr[20];
  9615. json_object *RemoteStopTransaction;
  9616. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9617. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9618. if(server_pending == TRUE)
  9619. {
  9620. return 0;
  9621. }
  9622. RemoteStopTransaction = json_tokener_parse(payload);
  9623. if(!is_error(RemoteStopTransaction))
  9624. {
  9625. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9626. {
  9627. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9628. transactionIdIsNULL = FALSE;
  9629. }
  9630. }
  9631. json_object_put(RemoteStopTransaction);
  9632. if(transactionIdIsNULL == FALSE)
  9633. {
  9634. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9635. {
  9636. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9637. {
  9638. //check Transaction active
  9639. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9640. {
  9641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9642. {
  9643. tempIndex = ((gun_index==2) ? 1: 0);
  9644. }
  9645. else
  9646. {
  9647. tempIndex = gun_index;
  9648. }
  9649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9650. {
  9651. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9652. {
  9653. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9654. {
  9655. match = TRUE;
  9656. GunNO = gun_index;
  9657. }
  9658. }
  9659. }// END FOR CHAdeMO_QUANTITY
  9660. }
  9661. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9662. {
  9663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9664. {
  9665. tempIndex = ((gun_index==2) ? 1: 0);
  9666. }
  9667. else
  9668. {
  9669. tempIndex = gun_index;
  9670. }
  9671. for (int index = 0; index < CCS_QUANTITY; index++)
  9672. {
  9673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9674. {
  9675. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9676. {
  9677. match = TRUE;
  9678. GunNO = gun_index;
  9679. }
  9680. }
  9681. }// END FOR CCS_QUANTITY
  9682. }
  9683. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9684. {
  9685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9686. {
  9687. tempIndex = ((gun_index==2) ? 1: 0);
  9688. }
  9689. else
  9690. {
  9691. tempIndex = gun_index;
  9692. }
  9693. for (int index = 0; index < GB_QUANTITY; index++)
  9694. {
  9695. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9696. {
  9697. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9698. {
  9699. match = TRUE;
  9700. GunNO = gun_index;
  9701. }
  9702. }
  9703. }// END FOR GB_QUANTITY
  9704. }
  9705. else if(gunType[gun_index] == GUN_TYPE_DO)
  9706. {
  9707. tempIndex = gun_index;
  9708. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9709. {
  9710. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9711. {
  9712. 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
  9713. {
  9714. match = TRUE;
  9715. GunNO = gun_index;
  9716. }
  9717. }
  9718. }// END FOR GB_QUANTITY
  9719. }
  9720. else
  9721. {
  9722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9723. {
  9724. tempIndex = 2;
  9725. }
  9726. else
  9727. {
  9728. tempIndex = gun_index;
  9729. }
  9730. for (int index = 0; index < AC_QUANTITY; index++)
  9731. {
  9732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9733. {
  9734. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9735. {
  9736. match = TRUE;
  9737. GunNO = gun_index;
  9738. }
  9739. }
  9740. }// END FOR CHAdeMO_QUANTITY
  9741. } // END FOR AC ELSE
  9742. }// CHECK IF ResponseTransactionId == transactionIdInt
  9743. }//END FOR
  9744. if( match == TRUE)
  9745. {
  9746. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9747. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9748. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9749. }
  9750. else
  9751. {
  9752. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9753. }
  9754. }
  9755. else
  9756. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9757. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9758. return result;
  9759. }
  9760. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9761. {
  9762. mtrace();
  9763. int result = FAIL;
  9764. int connectorIdInt=0, reservationIdInt=0;
  9765. int tempIndex = 0;
  9766. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9767. char comfirmstr[20]={0};
  9768. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9769. int c = 0;
  9770. char *loc;
  9771. //char *ptr;
  9772. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9773. strcpy(sstrtemp, stringtrimspace(payload));
  9774. //***(1)connectorId ****/
  9775. c=0;
  9776. loc = strstr(sstrtemp, "connectorId");
  9777. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9778. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9779. {
  9780. sstr[c] = loc[strlen("connectorId")+2+c];
  9781. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9782. c++;
  9783. }
  9784. sstr[c] = '\0';
  9785. connectorIdInt = atoi(sstr);
  9786. //***(2)expiryDate ****/
  9787. loc = strstr(sstrtemp, "expiryDate");
  9788. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9789. c = 0;
  9790. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9791. {
  9792. sstr[c] = loc[3+strlen("expiryDate")+c];
  9793. c++;
  9794. }
  9795. sstr[c] = '\0';
  9796. strcpy(expiryDatestr, sstr);
  9797. //***(3)idTag ****/
  9798. loc = strstr(sstrtemp, "idTag");
  9799. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9800. c = 0;
  9801. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9802. {
  9803. sstr[c] = loc[3+strlen("idTag")+c];
  9804. c++;
  9805. }
  9806. sstr[c] = '\0';
  9807. strcpy(idTagstr, sstr);
  9808. //***(4)parentIdTag ****/
  9809. loc = strstr(sstrtemp, "parentIdTag");
  9810. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9811. c = 0;
  9812. if(loc == NULL)
  9813. {
  9814. strcpy(parentIdTagstr, "");
  9815. }
  9816. else
  9817. {
  9818. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9819. {
  9820. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9821. c++;
  9822. }
  9823. sstr[c] = '\0';
  9824. strcpy(parentIdTagstr, sstr);
  9825. }
  9826. //***(5)reservationId ****/
  9827. c=0;
  9828. loc = strstr(sstrtemp, "reservationId");
  9829. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9830. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9831. {
  9832. sstr[c] = loc[strlen("reservationId")+2+c];
  9833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9834. c++;
  9835. }
  9836. sstr[c] = '\0';
  9837. reservationIdInt = atoi(sstr);
  9838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9839. /*
  9840. enum SYSTEM_STATUS
  9841. {
  9842. SYS_MODE_BOOTING = 0,
  9843. SYS_MODE_IDLE = 1,
  9844. SYS_MODE_AUTHORIZING = 2,
  9845. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9846. SYS_MODE_REASSIGN = 4,
  9847. SYS_MODE_PREPARING = 5,
  9848. SYS_MODE_PREPARE_FOR_EV = 6,
  9849. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9850. SYS_MODE_CHARGING = 8,
  9851. SYS_MODE_TERMINATING = 9,
  9852. SYS_MODE_COMPLETE = 10,
  9853. SYS_MODE_ALARM = 11,
  9854. SYS_MODE_FAULT = 12,
  9855. SYS_MODE_RESERVATION = 13,
  9856. SYS_MODE_BOOKING = 14,
  9857. SYS_MODE_MAINTAIN = 15,
  9858. SYS_MODE_DEBUG = 16,
  9859. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9860. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9861. SYS_MODE_UPDATE = 19
  9862. };
  9863. */
  9864. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9865. {
  9866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9867. goto end;
  9868. }
  9869. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9870. {
  9871. //check Transaction active
  9872. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9873. {
  9874. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9875. {
  9876. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9877. }
  9878. else
  9879. {
  9880. tempIndex = connectorIdInt -1;
  9881. }
  9882. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9883. {
  9884. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9885. {
  9886. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9887. {
  9888. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9889. {
  9890. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9891. {
  9892. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9894. }
  9895. 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'))
  9896. {
  9897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9898. }
  9899. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9900. {
  9901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9902. }
  9903. else
  9904. {
  9905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9906. }
  9907. }
  9908. 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
  9909. {
  9910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9911. }
  9912. }
  9913. else
  9914. {
  9915. //replace reservation
  9916. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9918. }
  9919. }
  9920. } // END FOR CHAdeMO_QUANTITY
  9921. }
  9922. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9923. {
  9924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9925. {
  9926. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9927. }
  9928. else
  9929. {
  9930. tempIndex = connectorIdInt -1;
  9931. }
  9932. for (int index = 0; index < CCS_QUANTITY; index++)
  9933. {
  9934. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9935. {
  9936. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9937. {
  9938. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9939. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9940. {
  9941. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9942. {
  9943. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9945. }
  9946. 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'))
  9947. {
  9948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9949. }
  9950. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9951. {
  9952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9953. }
  9954. else
  9955. {
  9956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9957. }
  9958. }
  9959. 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
  9960. {
  9961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9962. }
  9963. }
  9964. else
  9965. {
  9966. //replace reservation
  9967. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9969. }
  9970. }
  9971. } // END FOR CCS_QUANTITY
  9972. }
  9973. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9974. {
  9975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9976. {
  9977. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9978. }
  9979. else
  9980. {
  9981. tempIndex = connectorIdInt -1;
  9982. }
  9983. for (int index = 0; index < GB_QUANTITY; index++)
  9984. {
  9985. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9986. {
  9987. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9988. {
  9989. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9990. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9991. {
  9992. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9993. {
  9994. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9996. }
  9997. 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'))
  9998. {
  9999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10000. }
  10001. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10002. {
  10003. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10004. }
  10005. else
  10006. {
  10007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10008. }
  10009. }
  10010. 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
  10011. {
  10012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10013. }
  10014. }
  10015. else
  10016. {
  10017. //replace reservation
  10018. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10020. }
  10021. }
  10022. }// END FOR GB_QUANTITY
  10023. }
  10024. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10025. {
  10026. tempIndex = connectorIdInt -1;
  10027. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10028. {
  10029. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10030. {
  10031. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10032. {
  10033. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10034. 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
  10035. {
  10036. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10037. {
  10038. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10040. }
  10041. 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'))
  10042. {
  10043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10044. }
  10045. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10046. {
  10047. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10048. }
  10049. else
  10050. {
  10051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10052. }
  10053. }
  10054. 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
  10055. {
  10056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10057. }
  10058. }
  10059. else
  10060. {
  10061. //replace reservation
  10062. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10064. }
  10065. }
  10066. }// END FOR GB_QUANTITY
  10067. }
  10068. else
  10069. {
  10070. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10071. {
  10072. tempIndex = 2;
  10073. }
  10074. else
  10075. {
  10076. tempIndex = (connectorIdInt -1);
  10077. }
  10078. for (int index = 0; index < AC_QUANTITY; index++)
  10079. {
  10080. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10081. {
  10082. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10083. {
  10084. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10085. {
  10086. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10087. {
  10088. 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))
  10089. {
  10090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10091. }
  10092. else
  10093. {
  10094. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10096. }
  10097. }
  10098. 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'))
  10099. {
  10100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10101. }
  10102. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10103. {
  10104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10105. }
  10106. else
  10107. {
  10108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10109. }
  10110. }
  10111. 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
  10112. {
  10113. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10114. }
  10115. }
  10116. else
  10117. {
  10118. //replace reservation
  10119. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10121. }
  10122. }
  10123. } // END FOR AC_QUANTITY
  10124. }
  10125. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10126. }
  10127. else if(connectorIdInt == 0)
  10128. {
  10129. //check Transaction active
  10130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10131. {
  10132. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10133. {
  10134. 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'))
  10135. {
  10136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10137. goto end;
  10138. }
  10139. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10140. {
  10141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10142. goto end;
  10143. }
  10144. 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
  10145. {
  10146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10147. goto end;
  10148. }
  10149. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10150. {
  10151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10152. goto end;
  10153. }
  10154. }
  10155. }// END FOR CHAdeMO_QUANTITY
  10156. for (int index = 0; index < CCS_QUANTITY; index++)
  10157. {
  10158. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10159. {
  10160. 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'))
  10161. {
  10162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10163. goto end;
  10164. }
  10165. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10166. {
  10167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10168. goto end;
  10169. }
  10170. 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
  10171. {
  10172. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10173. goto end;
  10174. }
  10175. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10176. {
  10177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10178. goto end;
  10179. }
  10180. }
  10181. } // END FOR CCS_QUANTITY
  10182. for (int index = 0; index < GB_QUANTITY; index++)
  10183. {
  10184. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10185. {
  10186. 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'))
  10187. {
  10188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10189. goto end;
  10190. }
  10191. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10192. {
  10193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10194. goto end;
  10195. }
  10196. 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
  10197. {
  10198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10199. goto end;
  10200. }
  10201. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10202. {
  10203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10204. goto end;
  10205. }
  10206. }
  10207. } // END FOR GB_QUANTITY
  10208. for (int index = 0; index < AC_QUANTITY; index++)
  10209. {
  10210. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10211. {
  10212. 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'))
  10213. {
  10214. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10215. goto end;
  10216. }
  10217. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10218. {
  10219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10220. goto end;
  10221. }
  10222. 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
  10223. {
  10224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10225. goto end;
  10226. }
  10227. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10228. {
  10229. 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))
  10230. {
  10231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10232. goto end;
  10233. }
  10234. }
  10235. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10236. {
  10237. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10238. goto end;
  10239. }
  10240. }
  10241. }// END FOR AC_QUANTITY
  10242. //The connectorId is 0
  10243. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10244. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10245. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10246. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10247. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10248. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10249. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10250. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  10251. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  10252. result = TRUE;
  10253. return result;
  10254. }
  10255. else
  10256. {
  10257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10258. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10259. }
  10260. if(strcmp(comfirmstr,"Accepted") == 0)
  10261. {
  10262. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10263. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10264. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10265. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10266. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10267. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  10268. result = TRUE;
  10269. return result;
  10270. }
  10271. end:
  10272. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10273. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10274. return result;
  10275. }
  10276. int handleResetRequest(char *uuid, char *payload)
  10277. {
  10278. mtrace();
  10279. int result = FAIL;
  10280. char sstr[10]={0},sstrtemp[30]={ 0 };
  10281. char typestr[10]={0};
  10282. char comfirmstr[20]={0};
  10283. int c = 0;
  10284. char *loc;
  10285. DEBUG_INFO("handleResetRequest...\n");
  10286. strcpy(sstrtemp, stringtrimspace(payload));
  10287. loc = strstr(sstrtemp, "type");
  10288. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10289. c = 0;
  10290. while (loc[3+strlen("type")+c] != '\"')
  10291. {
  10292. sstr[c] = loc[3+strlen("type")+c];
  10293. c++;
  10294. }
  10295. sstr[c] = '\0';
  10296. strcpy(typestr,sstr);
  10297. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  10298. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10299. {
  10300. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  10301. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  10302. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10303. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10304. }
  10305. else
  10306. {
  10307. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10308. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10309. result = PASS;
  10310. }
  10311. sendResetConfirmation(uuid, comfirmstr);
  10312. return result;
  10313. }
  10314. int handleSendLocalListRequest(char *uuid, char *payload)
  10315. {
  10316. mtrace();
  10317. int result = FAIL;
  10318. char comfirmstr[20];
  10319. int checkState_Faulted = FALSE;
  10320. json_object *SendLocalList;
  10321. DEBUG_INFO("handleSendLocalListRequest...\n");
  10322. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10323. {
  10324. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10325. goto end;
  10326. }
  10327. //check Charge Point state
  10328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10329. {
  10330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10331. {
  10332. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10333. }
  10334. }
  10335. for (int index = 0; index < CCS_QUANTITY; index++)
  10336. {
  10337. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10338. {
  10339. checkState_Faulted = TRUE; //OCPP Status
  10340. }
  10341. }
  10342. for (int index = 0; index < GB_QUANTITY; index++)
  10343. {
  10344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10345. {
  10346. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10347. }
  10348. }
  10349. //check Charge Point state
  10350. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10351. {
  10352. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10353. {
  10354. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10355. }
  10356. }
  10357. //check Charge Point state
  10358. for (int index = 0; index < AC_QUANTITY; index++)
  10359. {
  10360. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10361. {
  10362. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10363. }
  10364. }
  10365. if(checkState_Faulted == TRUE)
  10366. {
  10367. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10368. goto end;
  10369. }
  10370. // Parsing payload
  10371. SendLocalList = json_tokener_parse(payload);
  10372. if(!is_error(SendLocalList))
  10373. {
  10374. // Required data
  10375. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10376. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10377. // Optional data
  10378. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10379. {
  10380. //Check UpdateType
  10381. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10382. {
  10383. //Local list full update
  10384. DEBUG_INFO("Local list full update.\n");
  10385. OCPP_getListVerion();
  10386. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10387. {
  10388. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10389. goto end;
  10390. }
  10391. OCPP_cleanLocalList();
  10392. }
  10393. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10394. {
  10395. //Local list different update
  10396. DEBUG_INFO("Local list different update.\n");
  10397. OCPP_getListVerion();
  10398. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10399. {
  10400. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10401. goto end;
  10402. }
  10403. }
  10404. else
  10405. {
  10406. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10407. goto end;
  10408. }
  10409. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10410. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10411. {
  10412. 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")));
  10413. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10414. {
  10415. 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")));
  10416. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10417. 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")));
  10418. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10419. 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")));
  10420. }
  10421. // Add to db
  10422. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10423. {
  10424. //Local list full update
  10425. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10426. idx,
  10427. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10428. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10429. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10430. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10431. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10432. // update list
  10433. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10434. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10435. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10436. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10437. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10438. }
  10439. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10440. {
  10441. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10442. idx,
  10443. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10444. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10445. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10446. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10447. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10448. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10449. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10450. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10451. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10452. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10453. }
  10454. }
  10455. }
  10456. else
  10457. {
  10458. //Check UpdateType
  10459. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10460. {
  10461. //Local list full update
  10462. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10463. OCPP_cleanLocalList();
  10464. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10465. goto end;
  10466. }
  10467. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10468. {
  10469. //Local list different update
  10470. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10471. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10472. goto end;
  10473. }
  10474. }
  10475. result = PASS;
  10476. }
  10477. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10478. end:
  10479. json_object_put(SendLocalList);
  10480. sendSendLocalListConfirmation(uuid, comfirmstr);
  10481. return result;
  10482. }
  10483. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10484. {
  10485. mtrace();
  10486. int result = FAIL;
  10487. struct StructSetChargingProfile SetProfileReq = {0};
  10488. int tempchargingProfileIdInt;
  10489. int chargingSchedulePeriodCount = 0;
  10490. char comfirmstr[20]={0};
  10491. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10492. char rmFileCmd[128]={0};
  10493. int profileQuantity = 0;
  10494. json_object *SetChargingProfile;
  10495. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10496. SetChargingProfile = json_tokener_parse(payload);
  10497. if(!is_error(SetChargingProfile))
  10498. {
  10499. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10500. {
  10501. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10502. }
  10503. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10504. {
  10505. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10506. {
  10507. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10508. }
  10509. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10510. {
  10511. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10512. }
  10513. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10514. {
  10515. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10516. }
  10517. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10518. {
  10519. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10520. }
  10521. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10522. {
  10523. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10524. }
  10525. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10526. {
  10527. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10528. }
  10529. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10530. {
  10531. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10532. }
  10533. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10534. {
  10535. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10536. }
  10537. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10538. {
  10539. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10540. {
  10541. 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")));
  10542. }
  10543. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10544. {
  10545. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10546. }
  10547. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10548. {
  10549. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10550. }
  10551. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10552. {
  10553. 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")));
  10554. }
  10555. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10556. {
  10557. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10558. if(chargingSchedulePeriodCount <= 10)
  10559. {
  10560. 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++)
  10561. {
  10562. 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)
  10563. {
  10564. 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"));
  10565. }
  10566. 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)
  10567. {
  10568. 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"));
  10569. }
  10570. 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)
  10571. {
  10572. 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"));
  10573. }
  10574. }
  10575. }
  10576. }
  10577. }
  10578. }
  10579. }
  10580. // Profile periods quantity check
  10581. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10582. {
  10583. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10584. goto end;
  10585. }
  10586. // Profile purpose info check
  10587. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10588. {
  10589. FILE *fp;
  10590. char dataLine[4096]={0};
  10591. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  10592. if(SetProfileReq.ConnectorId != 0)
  10593. {
  10594. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10595. goto end;
  10596. }
  10597. fp = fopen(ChargePointMaxProfile_JSON, "r");
  10598. if (!fp)
  10599. {
  10600. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  10601. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  10602. }
  10603. else
  10604. {
  10605. while(fscanf(fp, "%s", dataLine) != EOF)
  10606. {
  10607. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10608. {
  10609. profileQuantity += 1;
  10610. }
  10611. }
  10612. }
  10613. fclose(fp);
  10614. }
  10615. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10616. {
  10617. FILE *fp;
  10618. char dataLine[4096]={0};
  10619. char filename[128]={0};
  10620. int tmpProfileQuantity;
  10621. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  10622. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10623. {
  10624. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10625. goto end;
  10626. }
  10627. if(SetProfileReq.ConnectorId == 0)
  10628. {
  10629. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  10630. {
  10631. tmpProfileQuantity = 0;
  10632. memset(filename, 0, ARRAY_SIZE(filename));
  10633. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10634. fp = fopen(filename, "r");
  10635. if (!fp)
  10636. {
  10637. DEBUG_INFO("%s does not create.\n", filename);
  10638. fp = fopen(filename, "w+");
  10639. }
  10640. else
  10641. {
  10642. while(fscanf(fp, "%s", dataLine) != EOF)
  10643. {
  10644. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10645. {
  10646. tmpProfileQuantity += 1;
  10647. }
  10648. }
  10649. }
  10650. fclose(fp);
  10651. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  10652. }
  10653. }
  10654. else
  10655. {
  10656. memset(filename, 0, ARRAY_SIZE(filename));
  10657. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10658. fp = fopen(filename, "r");
  10659. if (!fp)
  10660. {
  10661. DEBUG_INFO("%s does not create.\n", filename);
  10662. fp = fopen(filename, "w+");
  10663. }
  10664. else
  10665. {
  10666. while(fscanf(fp, "%s", dataLine) != EOF)
  10667. {
  10668. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10669. {
  10670. profileQuantity += 1;
  10671. }
  10672. }
  10673. }
  10674. fclose(fp);
  10675. }
  10676. }
  10677. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10678. {
  10679. int isMatchTransactiodId= FALSE;
  10680. FILE *fp;
  10681. char dataLine[4096]={0};
  10682. char filename[128]={0};
  10683. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  10684. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10685. if(SetProfileReq.ConnectorId == 0)
  10686. {
  10687. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10688. goto end;
  10689. }
  10690. int tempIndex = 0;
  10691. //check Transaction active
  10692. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  10693. {
  10694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10695. {
  10696. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10697. }
  10698. else
  10699. {
  10700. tempIndex = SetProfileReq.ConnectorId -1;
  10701. }
  10702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10703. {
  10704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10705. {
  10706. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10707. {
  10708. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10709. {
  10710. isMatchTransactiodId = TRUE;
  10711. break;
  10712. }
  10713. }
  10714. }
  10715. }
  10716. }
  10717. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  10718. {
  10719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10720. {
  10721. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10722. }
  10723. else
  10724. {
  10725. tempIndex = SetProfileReq.ConnectorId -1;
  10726. }
  10727. for (int index = 0; index < CCS_QUANTITY; index++)
  10728. {
  10729. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10730. {
  10731. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  10732. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  10733. {
  10734. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10735. {
  10736. isMatchTransactiodId = TRUE;
  10737. break;
  10738. }
  10739. }
  10740. }
  10741. }
  10742. }
  10743. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  10744. {
  10745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10746. {
  10747. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10748. }
  10749. else
  10750. {
  10751. tempIndex = SetProfileReq.ConnectorId -1;
  10752. }
  10753. for (int index = 0; index < GB_QUANTITY; index++)
  10754. {
  10755. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10756. {
  10757. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10758. {
  10759. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10760. {
  10761. isMatchTransactiodId = TRUE;
  10762. break;
  10763. }
  10764. }
  10765. }
  10766. }
  10767. }
  10768. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  10769. {
  10770. tempIndex = SetProfileReq.ConnectorId -1;
  10771. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10772. {
  10773. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10774. {
  10775. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  10776. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  10777. {
  10778. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10779. {
  10780. isMatchTransactiodId = TRUE;
  10781. break;
  10782. }
  10783. }
  10784. }
  10785. }
  10786. }
  10787. else
  10788. {
  10789. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10790. {
  10791. tempIndex = 2;
  10792. }
  10793. else
  10794. {
  10795. tempIndex = (SetProfileReq.ConnectorId -1);
  10796. }
  10797. for (int index = 0; index < AC_QUANTITY; index++)
  10798. {
  10799. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10800. {
  10801. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10802. {
  10803. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10804. {
  10805. isMatchTransactiodId = TRUE;
  10806. break;
  10807. }
  10808. }
  10809. }
  10810. }
  10811. }
  10812. //check Transaction active
  10813. if(isMatchTransactiodId == FALSE)
  10814. {
  10815. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10816. goto end;
  10817. }
  10818. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10819. {
  10820. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10821. goto end;
  10822. }
  10823. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10824. fp = fopen(filename, "r");
  10825. if (!fp)
  10826. {
  10827. DEBUG_INFO("%s does not create.\n", filename);
  10828. fp = fopen(filename, "w+");
  10829. }
  10830. else
  10831. {
  10832. //Check Charging Profile Count
  10833. while(fscanf(fp, "%s", dataLine) != EOF)
  10834. {
  10835. //DEBUG_INFO("word=%s\n",word);
  10836. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10837. {
  10838. profileQuantity += 1;
  10839. }
  10840. }
  10841. }
  10842. fclose(fp);
  10843. }
  10844. // Check ChargeProfileMaxStackLevel
  10845. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  10846. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10847. {
  10848. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10849. goto end;
  10850. }
  10851. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10852. {
  10853. FILE *fp;
  10854. char dataLine[4096]={0};
  10855. char fnametemp[128]={0};
  10856. int tmpProfileQuantity;
  10857. //Check ChargePointMaxProfile.json exit
  10858. profileQuantity = 0;
  10859. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10860. {
  10861. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10862. //Check Charging Profile Count
  10863. tmpProfileQuantity = 0;
  10864. while(fscanf(fp, "%s", dataLine) != EOF)
  10865. {
  10866. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10867. {
  10868. profileQuantity += 1;
  10869. tmpProfileQuantity += 1;
  10870. }
  10871. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10872. }
  10873. fclose(fp);
  10874. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  10875. }
  10876. //Check TxDefaultProfile_%d.json
  10877. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  10878. {
  10879. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10880. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10881. if((access(fnametemp,F_OK))!=-1)
  10882. {
  10883. fp = fopen(fnametemp, "r");
  10884. //Check Charging Profile Count
  10885. tmpProfileQuantity = 0;
  10886. while(fscanf(fp, "%s", dataLine) != EOF)
  10887. {
  10888. //DEBUG_INFO("word=%s\n",word);
  10889. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10890. {
  10891. profileQuantity += 1;
  10892. tmpProfileQuantity += 1;
  10893. }
  10894. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10895. }
  10896. fclose(fp);
  10897. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  10898. }
  10899. }
  10900. //Check TxProfile_%d.json
  10901. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  10902. {
  10903. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10904. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  10905. if((access(fnametemp,F_OK))!=-1)
  10906. {
  10907. fp = fopen(fnametemp, "r");
  10908. //Check Charging Profile Count
  10909. tmpProfileQuantity = 0;
  10910. while(fscanf(fp, "%s", dataLine) != EOF)
  10911. {
  10912. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10913. {
  10914. profileQuantity += 1;
  10915. tmpProfileQuantity += 1;
  10916. }
  10917. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10918. }
  10919. fclose(fp);
  10920. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  10921. }
  10922. }
  10923. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  10924. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10925. {
  10926. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10927. goto end;
  10928. }
  10929. }
  10930. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10931. //**********************************Write to File********************************************************/
  10932. {
  10933. FILE *infile;
  10934. FILE *outfile;
  10935. char dataLine[4096]={0};
  10936. char filename[128]={0};
  10937. int chkChar=0;
  10938. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  10939. {
  10940. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10941. {
  10942. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  10943. }
  10944. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10945. {
  10946. if(SetProfileReq.ConnectorId==0)
  10947. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10948. else
  10949. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10950. }
  10951. else
  10952. {
  10953. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10954. }
  10955. infile = fopen (filename, "r");
  10956. outfile = fopen (tempfile, "w");
  10957. chkChar = fgetc(infile);
  10958. rewind(infile);
  10959. if(chkChar == EOF)
  10960. {
  10961. // Profile is empty
  10962. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10963. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10964. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10965. fclose(infile);
  10966. fclose(outfile);
  10967. sprintf(rmFileCmd,"rm -f %s",filename);
  10968. system(rmFileCmd);
  10969. rename(tempfile, filename);
  10970. }
  10971. else
  10972. {
  10973. // Profile is not empty
  10974. int ChargingProfileAdded = FALSE;
  10975. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  10976. {
  10977. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  10978. json_object *tmpChargingProfile;
  10979. tmpChargingProfile = json_tokener_parse(dataLine);
  10980. if(!is_error(SetChargingProfile))
  10981. {
  10982. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10983. {
  10984. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10985. {
  10986. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10987. }
  10988. }
  10989. }
  10990. json_object_put(tmpChargingProfile);
  10991. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  10992. {
  10993. if(ChargingProfileAdded == FALSE)
  10994. {
  10995. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10996. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10997. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10998. ChargingProfileAdded = TRUE;
  10999. }
  11000. }
  11001. else
  11002. {
  11003. fprintf(outfile,"%s\n",dataLine);
  11004. if(ChargingProfileAdded == FALSE)
  11005. {
  11006. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11007. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11008. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11009. ChargingProfileAdded = TRUE;
  11010. }
  11011. }
  11012. } // end of while loop
  11013. fclose(infile);
  11014. fclose(outfile);
  11015. sprintf(rmFileCmd,"rm -f %s",filename);
  11016. system(rmFileCmd);
  11017. rename(tempfile, filename);
  11018. }
  11019. }
  11020. sleep(1);
  11021. result = TRUE;
  11022. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11023. }
  11024. end:
  11025. json_object_put(SetChargingProfile);
  11026. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11027. {
  11028. if(SetProfileReq.ConnectorId == 0)
  11029. {
  11030. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11031. {
  11032. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11033. }
  11034. }
  11035. else
  11036. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11037. }
  11038. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11039. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11040. return result;
  11041. }
  11042. int handleTriggerMessageRequest(char *uuid, char *payload)
  11043. {
  11044. mtrace();
  11045. int result = FAIL;
  11046. int connectorIdIsNULL = FALSE;
  11047. int connectorIdInt =0;
  11048. char sstr[40]={0},sstrtemp[100]={ 0 };
  11049. char requestedMessagestr[40]={0};
  11050. char comfirmstr[20]={0};
  11051. int c = 0;
  11052. char *loc;
  11053. DEBUG_INFO("handleTriggerMessageRequest\n");
  11054. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11055. strcpy(sstrtemp, stringtrimspace(payload));
  11056. c = 0;
  11057. loc = strstr(sstrtemp, "requestedMessage");
  11058. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11059. {
  11060. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11061. c++;
  11062. }
  11063. sstr[c] = '\0';
  11064. strcpy(requestedMessagestr, sstr);
  11065. c = 0;
  11066. loc = strstr(sstrtemp, "connectorId");
  11067. if(loc == NULL)
  11068. {
  11069. connectorIdIsNULL = TRUE;
  11070. }
  11071. else
  11072. {
  11073. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11074. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11075. {
  11076. sstr[c] = loc[strlen("connectorId")+2+c];
  11077. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11078. c++;
  11079. }
  11080. sstr[c] = '\0';
  11081. connectorIdInt = atoi(sstr);
  11082. }
  11083. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11084. {
  11085. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11086. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11087. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11088. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11089. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11090. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11091. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11092. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11093. {
  11094. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11095. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11096. return TRUE;
  11097. }
  11098. else
  11099. {
  11100. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11101. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11102. }
  11103. }
  11104. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11105. {
  11106. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11107. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11108. return TRUE;
  11109. }
  11110. //==========================
  11111. // Trigger message
  11112. //==========================
  11113. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11114. {
  11115. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11116. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11117. {
  11118. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11119. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11120. }
  11121. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11122. }
  11123. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11124. {
  11125. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11126. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11127. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11128. }
  11129. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11130. {
  11131. //sendBootNotificationRequest();
  11132. server_sign = FALSE;
  11133. }
  11134. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11135. {
  11136. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11137. }
  11138. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11139. {
  11140. if(connectorIdIsNULL == FALSE)
  11141. {
  11142. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11143. {
  11144. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11145. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11146. }
  11147. }
  11148. else
  11149. {
  11150. for(int idx=0;idx< gunTotalNumber;idx++)
  11151. {
  11152. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11153. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11154. }
  11155. }
  11156. }
  11157. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11158. {
  11159. if(connectorIdIsNULL == FALSE)
  11160. {
  11161. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11162. {
  11163. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11164. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11165. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11166. }
  11167. }
  11168. else
  11169. {
  11170. for(int idx=0;idx< gunTotalNumber;idx++)
  11171. {
  11172. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11173. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11174. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11175. }
  11176. }
  11177. }
  11178. return result;
  11179. }
  11180. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11181. {
  11182. mtrace();
  11183. int result = FAIL;
  11184. int connectorIdInt =0;
  11185. char comfirmstr[20]={0};
  11186. int tempIndex = 0;
  11187. json_object *UnlockConnector;
  11188. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11189. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11190. UnlockConnector = json_tokener_parse(payload);
  11191. if(!is_error(UnlockConnector))
  11192. {
  11193. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11194. {
  11195. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11196. }
  11197. }
  11198. json_object_put(UnlockConnector);
  11199. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11200. if(gunTotalNumber == 0)
  11201. {
  11202. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11203. goto end;
  11204. }
  11205. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11206. {
  11207. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11208. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11209. goto end;
  11210. }
  11211. else
  11212. {
  11213. //check Transaction active
  11214. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11215. {
  11216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11217. {
  11218. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11219. }
  11220. else
  11221. {
  11222. tempIndex = connectorIdInt -1;
  11223. }
  11224. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11225. {
  11226. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  11227. {
  11228. //stop Transaction
  11229. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11230. }
  11231. }
  11232. }
  11233. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11234. {
  11235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11236. {
  11237. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11238. }
  11239. else
  11240. {
  11241. tempIndex = connectorIdInt -1;
  11242. }
  11243. for (int index = 0; index < CCS_QUANTITY; index++)
  11244. {
  11245. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  11246. {
  11247. //stop Transaction
  11248. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11249. }
  11250. }
  11251. }
  11252. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11253. {
  11254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11255. {
  11256. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11257. }
  11258. else
  11259. {
  11260. tempIndex = connectorIdInt -1;
  11261. }
  11262. for (int index = 0; index < GB_QUANTITY; index++)
  11263. {
  11264. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  11265. {
  11266. //stop Transaction
  11267. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11268. }
  11269. }
  11270. }
  11271. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11272. {
  11273. tempIndex = connectorIdInt -1;
  11274. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11275. {
  11276. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  11277. {
  11278. //stop Transaction
  11279. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11280. }
  11281. }
  11282. }
  11283. else
  11284. {
  11285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11286. {
  11287. tempIndex = 2;
  11288. }
  11289. else
  11290. {
  11291. tempIndex = connectorIdInt-1;
  11292. }
  11293. for (int index = 0; index < AC_QUANTITY; index++)
  11294. {
  11295. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  11296. {
  11297. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11298. }
  11299. }
  11300. }
  11301. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11302. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  11303. result = TRUE;
  11304. return result;
  11305. }
  11306. end:
  11307. //json_object_put(obj); --- remove temporally
  11308. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11309. return result;
  11310. }
  11311. static char UpdateFirmwarepayloadData[300]={0};
  11312. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11313. {
  11314. mtrace();
  11315. int result = FAIL;
  11316. pthread_t t;
  11317. sendUpdateFirmwareConfirmation(uuid);
  11318. memset(UpdateFirmwarepayloadData, 0, 300);
  11319. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11320. if(!interLock.isUpdateFirmwareGoing)
  11321. {
  11322. interLock.isUpdateFirmwareGoing = 1;
  11323. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11324. sleep(1);
  11325. }
  11326. else
  11327. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11328. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  11329. return result;
  11330. }
  11331. void *UpdateFirmwareProcess(void *data)
  11332. {
  11333. pthread_detach(pthread_self());
  11334. mtrace();
  11335. int retriesInt =0, retryIntervalInt=0;
  11336. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  11337. int port=0;
  11338. char locationstr[512]={0}, retrieveDatestr[36]={0};
  11339. int isSuccess = 0;
  11340. char ftpbuf[512];
  11341. char temp[100];
  11342. char * pch;
  11343. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11344. json_object *UpdateFirmware;
  11345. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11346. if(!is_error(UpdateFirmware))
  11347. {
  11348. // Required data
  11349. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11350. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11351. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11352. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11353. // Optional data
  11354. if(json_object_object_get(UpdateFirmware, "retries"))
  11355. {
  11356. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11357. }
  11358. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11359. {
  11360. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11361. }
  11362. }
  11363. json_object_put(UpdateFirmware);
  11364. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11365. memset(path, 0, ARRAY_SIZE(path));
  11366. // Wait retrieveData
  11367. if(strlen(retrieveDatestr) > 10)
  11368. {
  11369. do
  11370. {
  11371. sleep(1);
  11372. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11373. }
  11374. // Ready to download
  11375. system("rm -f /mnt/*");
  11376. if(strncmp(locationstr,"http", 4) == 0)
  11377. {
  11378. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11379. sprintf(ftppath,"/%s", path);
  11380. DEBUG_INFO("locationstr: %s\n", locationstr);
  11381. DEBUG_INFO("protocol: %s\n",protocol);
  11382. DEBUG_INFO("host: %s\n",host);
  11383. DEBUG_INFO("path: %s\n",path);
  11384. DEBUG_INFO("ftppath: %s\n",ftppath);
  11385. int ftppathlen=strlen(ftppath);
  11386. int i=1;
  11387. char filenametemp[50];
  11388. while(i < ftppathlen)
  11389. {
  11390. int len=ftppathlen-i;
  11391. if(ftppath[len]== 47) // '/' ascll code: 47
  11392. {
  11393. DEBUG_INFO("compare '/' all right\n");
  11394. break;
  11395. }
  11396. i=i+1;
  11397. }
  11398. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11399. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11400. filenametemp[i+1] = 0;
  11401. do
  11402. {
  11403. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11404. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11405. sleep(1);
  11406. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11407. if(!isSuccess)
  11408. {
  11409. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11410. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11411. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11412. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11413. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11414. }
  11415. else
  11416. {
  11417. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11418. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11419. }
  11420. retriesInt--;
  11421. }while((isSuccess == 0)&&(retriesInt >= 0));
  11422. }
  11423. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11424. {
  11425. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11426. memset(temp, 0, ARRAY_SIZE(temp));
  11427. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11428. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11429. int ftppathlen=strlen(ftpbuf);
  11430. int i=1;
  11431. char filenametemp[50];
  11432. while(i < ftppathlen)
  11433. {
  11434. int len=ftppathlen-i;
  11435. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11436. {
  11437. DEBUG_INFO(" compare '/' all right\n");
  11438. break;
  11439. }
  11440. i=i+1;
  11441. }
  11442. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11443. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11444. filenametemp[i+1] = 0;
  11445. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11446. pch=strchr(temp,'@');
  11447. if(pch==NULL)
  11448. {
  11449. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11450. protocol, host, &port, path);
  11451. strcpy(user,"anonymous");
  11452. strcpy(password,"");
  11453. }
  11454. else
  11455. {
  11456. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11457. protocol, user, password, host, &port, path);
  11458. }
  11459. sscanf(host,"%[^/]%s",host1, path1);
  11460. sprintf(ftppath,"%s", path1);
  11461. //DEBUG_INFO("protocol =%s\n",protocol);
  11462. //DEBUG_INFO("user =%s\n",user);
  11463. //DEBUG_INFO("password =%s\n",password);
  11464. //DEBUG_INFO("host1 =%s\n",host1);
  11465. //DEBUG_INFO("port =%d\n",port);
  11466. //DEBUG_INFO("path1 =%s\n",path1);
  11467. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11468. //ftpFile(host, user, password, port, ftppath, fname);
  11469. //download firmware pthred
  11470. if(port == 0)
  11471. {
  11472. port = 21;
  11473. }
  11474. do
  11475. {
  11476. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11477. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11478. sleep(1);
  11479. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11480. if(!isSuccess)
  11481. {
  11482. //BulldogUtil.sleepMs(interval*1000);
  11483. DEBUG_INFO("Update firmware request and download file fail.\n");
  11484. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11485. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11486. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11487. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11488. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11489. }
  11490. else
  11491. {
  11492. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11493. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11494. }
  11495. retriesInt--;
  11496. }while((!isSuccess)&&(retriesInt >= 0));
  11497. }
  11498. else
  11499. {
  11500. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11501. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11502. sleep(1);
  11503. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11504. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11505. }
  11506. // OCPPPH only, must announce CSU upgrade firmware
  11507. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  11508. interLock.isUpdateFirmwareGoing = 0;
  11509. pthread_exit(NULL);
  11510. }
  11511. int handleCertificateSignedRequest(char *uuid, char *payload)
  11512. {
  11513. mtrace();
  11514. int result = PASS;
  11515. json_object *CertificateSigned;
  11516. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11517. CertificateSigned = json_tokener_parse(payload);
  11518. if(!is_error(CertificateSigned))
  11519. {
  11520. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11521. }
  11522. json_object_put(CertificateSigned);
  11523. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  11524. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  11525. fclose(fp);
  11526. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11527. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  11528. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  11529. sendCertificateSignedConfirmation(uuid);
  11530. return result;
  11531. }
  11532. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11533. {
  11534. mtrace();
  11535. int result = PASS;
  11536. json_object *DeleteCertificate;
  11537. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11538. DeleteCertificate = json_tokener_parse(payload);
  11539. if(!is_error(DeleteCertificate))
  11540. {
  11541. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11542. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11543. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11544. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11545. }
  11546. json_object_put(DeleteCertificate);
  11547. /*
  11548. * TODO: Delete certificateSigned process
  11549. */
  11550. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  11551. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  11552. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  11553. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  11554. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  11555. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  11556. sendDeleteCertificateConfirmation(uuid);
  11557. return result;
  11558. }
  11559. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11560. {
  11561. mtrace();
  11562. int result = PASS;
  11563. json_object *ExtendedTriggerMessage;
  11564. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11565. ExtendedTriggerMessage = json_tokener_parse(payload);
  11566. if(!is_error(ExtendedTriggerMessage))
  11567. {
  11568. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11569. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11570. {
  11571. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11572. }
  11573. else
  11574. {
  11575. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  11576. }
  11577. }
  11578. json_object_put(ExtendedTriggerMessage);
  11579. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  11580. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  11581. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11582. {
  11583. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11584. }
  11585. else
  11586. {
  11587. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11588. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11589. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11590. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11591. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11592. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11593. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11594. {
  11595. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11596. }
  11597. else
  11598. {
  11599. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11600. }
  11601. }
  11602. sendExtendedTriggerMessageConfirmation(uuid);
  11603. //==========================
  11604. // Trigger message
  11605. //==========================
  11606. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11607. {
  11608. //sendBootNotificationRequest();
  11609. server_sign = FALSE;
  11610. }
  11611. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11612. {
  11613. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  11614. }
  11615. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11616. {
  11617. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11618. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11619. {
  11620. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11621. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11622. }
  11623. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11624. }
  11625. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11626. {
  11627. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11628. }
  11629. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11630. {
  11631. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11632. {
  11633. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11634. }
  11635. else
  11636. {
  11637. for(int idx=0;idx< gunTotalNumber;idx++)
  11638. {
  11639. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11640. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11641. }
  11642. }
  11643. }
  11644. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11645. {
  11646. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  11647. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  11648. {
  11649. 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\" &");
  11650. }
  11651. }
  11652. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11653. {
  11654. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11655. {
  11656. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11657. }
  11658. else
  11659. {
  11660. for(int idx=0;idx< gunTotalNumber;idx++)
  11661. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11662. }
  11663. }
  11664. return result;
  11665. }
  11666. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11667. {
  11668. mtrace();
  11669. int result = PASS;
  11670. json_object *GetInstalledCertificateIds;
  11671. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11672. GetInstalledCertificateIds = json_tokener_parse(payload);
  11673. if(!is_error(GetInstalledCertificateIds))
  11674. {
  11675. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11676. }
  11677. json_object_put(GetInstalledCertificateIds);
  11678. /*
  11679. * TODO: Return installed certificate process
  11680. */
  11681. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11682. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  11683. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11684. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  11685. sendGetInstalledCertificateIdsConfirmation(uuid);
  11686. return result;
  11687. }
  11688. int handleGetLogRequest(char *uuid, char *payload)
  11689. {
  11690. mtrace();
  11691. int result = PASS;
  11692. json_object *GetLog;
  11693. DEBUG_INFO("handleGetLogRequest...\n");
  11694. GetLog = json_tokener_parse(payload);
  11695. if(!is_error(GetLog))
  11696. {
  11697. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11698. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11699. if(json_object_object_get(GetLog, "retries") != NULL)
  11700. {
  11701. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11702. }
  11703. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11704. {
  11705. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11706. }
  11707. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11708. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11709. {
  11710. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11711. }
  11712. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11713. {
  11714. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11715. }
  11716. }
  11717. json_object_put(GetLog);
  11718. /*
  11719. * TODO: Upload log process
  11720. */
  11721. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  11722. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  11723. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  11724. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  11725. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  11726. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  11727. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  11728. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  11729. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  11730. sendGetLogConfirmation(uuid);
  11731. return result;
  11732. }
  11733. int handleInstallCertificateRequest(char *uuid, char *payload)
  11734. {
  11735. mtrace();
  11736. int result = PASS;
  11737. json_object *InstallCertificate;
  11738. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11739. InstallCertificate = json_tokener_parse(payload);
  11740. if(!is_error(InstallCertificate))
  11741. {
  11742. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11743. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11744. /*
  11745. * TODO: Install certificate process
  11746. */
  11747. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11748. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11749. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11750. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11751. sendInstallCertificateConfirmation(uuid);
  11752. }
  11753. json_object_put(InstallCertificate);
  11754. return result;
  11755. }
  11756. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11757. {
  11758. mtrace();
  11759. int result = PASS;
  11760. json_object *SignedUpdateFirmware;
  11761. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11762. SignedUpdateFirmware = json_tokener_parse(payload);
  11763. if(!is_error(SignedUpdateFirmware))
  11764. {
  11765. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11766. {
  11767. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11768. }
  11769. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11770. {
  11771. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11772. }
  11773. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11774. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11775. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11776. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11777. {
  11778. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11779. }
  11780. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11781. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11782. }
  11783. json_object_put(SignedUpdateFirmware);
  11784. /*
  11785. * TODO: Upgrade firmware process
  11786. */
  11787. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11788. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11789. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11790. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11791. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11792. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11793. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11794. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11795. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11796. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11797. sendInstallCertificateConfirmation(uuid);
  11798. return result;
  11799. }
  11800. int handleUnknownRequest(char *uuid, char *payload)
  11801. {
  11802. mtrace();
  11803. int result = PASS;
  11804. DEBUG_INFO("handleUnknownRequest...\n");
  11805. sendUnknownConfirmation(uuid);
  11806. result = PASS;
  11807. return result;
  11808. }
  11809. //==========================================
  11810. // Handle server response routine
  11811. //==========================================
  11812. void handleAuthorizeResponse(char *payload, int gun_index)
  11813. {
  11814. mtrace();
  11815. char expiryDatestr[30]={0};
  11816. char parentIdTagstr[20]={0};
  11817. char statusstr[20]={0};
  11818. int expiryDateISNULL=FALSE;
  11819. int parentIdTagISNULL=FALSE;
  11820. DEBUG_INFO("handleAuthorizeResponse...\n");
  11821. json_object *Authorize;
  11822. Authorize = json_tokener_parse(payload);
  11823. if(!is_error(Authorize))
  11824. {
  11825. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11826. {
  11827. // Required data
  11828. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11829. // Optional data
  11830. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11831. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11832. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11833. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11834. }
  11835. }
  11836. json_object_put(Authorize);
  11837. if(expiryDateISNULL == FALSE)
  11838. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11839. if(parentIdTagISNULL == FALSE)
  11840. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11841. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11842. //Update idTag information to authorization cache if supproted
  11843. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11844. {
  11845. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11846. }
  11847. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11848. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11849. authorizeRetryTimes = 0;
  11850. }
  11851. void handleBootNotificationResponse(char *payload, int gun_index)
  11852. {
  11853. mtrace();
  11854. char statusStr[12]={0};
  11855. char currentTimeStr[30]={0};
  11856. int intervalInt = 0;
  11857. DEBUG_INFO("handleBootNotificationResponse...\n");
  11858. json_object *BootNotification;
  11859. BootNotification = json_tokener_parse(payload);
  11860. if(!is_error(BootNotification))
  11861. {
  11862. // Required data
  11863. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11864. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11865. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11866. }
  11867. json_object_put(BootNotification);
  11868. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11869. BootNotificationInterval = intervalInt;
  11870. HeartBeatWaitTime = intervalInt;
  11871. //write back to ShmOCPP16DataPH->BootNotification
  11872. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11873. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11874. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11875. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11876. {
  11877. server_sign = TRUE;
  11878. server_pending =FALSE;
  11879. }
  11880. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11881. {
  11882. server_pending = TRUE;
  11883. }
  11884. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11885. srand(time(NULL));
  11886. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11887. SetOcppConnStatus(TRUE);
  11888. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11889. }
  11890. void handleDataTransferResponse(char *payload, int gun_index)
  11891. {
  11892. char sstr[160]={0};//sstr[200]={ 0 };
  11893. int c = 0;
  11894. char *loc;
  11895. DEBUG_INFO("handleDataTransferResponse ...\n");
  11896. loc = strstr(payload, "status");
  11897. c = 0;
  11898. while (loc[3+strlen("status")+c] != '\"')
  11899. {
  11900. sstr[c] = loc[3+strlen("status")+c];
  11901. c++;
  11902. }
  11903. sstr[c] = '\0';
  11904. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11905. }
  11906. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11907. {
  11908. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11909. //struct json_object *obj;
  11910. // obj = json_tokener_parse(payload);
  11911. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11912. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11913. //No fields are defined.
  11914. }
  11915. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11916. {
  11917. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11918. //struct json_object *obj;
  11919. // obj = json_tokener_parse(payload);
  11920. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11921. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11922. //No fields are defined.
  11923. }
  11924. void handleHeartbeatResponse(char *payload, int gun_index)
  11925. {
  11926. mtrace();
  11927. DEBUG_INFO("handleHeartbeatResponse...\n");
  11928. json_object *Heartbeat;
  11929. Heartbeat = json_tokener_parse(payload);
  11930. if(!is_error(Heartbeat))
  11931. {
  11932. // Required data
  11933. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11934. }
  11935. json_object_put(Heartbeat);
  11936. if(FirstHeartBeat == 0)
  11937. {
  11938. FirstHeartBeat = 1;
  11939. DEBUG_INFO("FirstHeartBeat \n");
  11940. }
  11941. HeartBeatWithNOResponse = 0;
  11942. clientTime.Heartbeat=time((time_t*)NULL);
  11943. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11944. }
  11945. void handleMeterValuesResponse(char *payload, int gun_index)
  11946. {
  11947. mtrace();
  11948. DEBUG_INFO("handleMeterValuesResponse...\n");
  11949. }
  11950. void handleStartTransactionResponse(char *payload, int gun_index)
  11951. {
  11952. mtrace();
  11953. //int transactionIdInt = 0;
  11954. FILE *outfile;
  11955. char data[100]={0};
  11956. DEBUG_INFO("handleStartTransactionResponse...\n");
  11957. json_object *StartTransaction;
  11958. StartTransaction = json_tokener_parse(payload);
  11959. if(!is_error(StartTransaction))
  11960. {
  11961. // Required data
  11962. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11963. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11964. // Optional data
  11965. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11966. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11967. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11968. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11969. }
  11970. json_object_put(StartTransaction);
  11971. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11972. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11973. //-----------Start : write to the Queue TransactionId file -----------------//
  11974. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11975. {}
  11976. else
  11977. {
  11978. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11979. if(log == NULL)
  11980. {
  11981. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11982. return ;
  11983. }
  11984. else
  11985. {
  11986. fclose(log);
  11987. }
  11988. }
  11989. // open file for writing
  11990. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11991. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11992. {
  11993. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11994. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11995. fputs(data, outfile);
  11996. fclose (outfile);
  11997. }
  11998. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11999. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12000. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12001. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12002. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12003. }
  12004. void handleStatusNotificationResponse(char *payload, int gun_index)
  12005. {
  12006. mtrace();
  12007. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12008. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12009. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12010. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12011. }
  12012. void handleStopTransactionnResponse(char *payload, int gun_index)
  12013. {
  12014. mtrace();
  12015. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12016. json_object *StopTransaction;
  12017. StopTransaction = json_tokener_parse(payload);
  12018. if(!is_error(StopTransaction))
  12019. {
  12020. // Optional data
  12021. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12022. {
  12023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12024. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12025. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12026. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12027. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12028. }
  12029. }
  12030. json_object_put(StopTransaction);
  12031. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12032. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12033. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12034. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12035. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12036. }
  12037. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12038. {
  12039. mtrace();
  12040. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12041. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12042. }
  12043. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12044. {
  12045. mtrace();
  12046. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12047. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12048. }
  12049. void handleSignCertificateResponse(char *payload, int gun_index)
  12050. {
  12051. mtrace();
  12052. DEBUG_INFO("handleSignCertificateResponse...\n");
  12053. json_object *SignCertificate;
  12054. SignCertificate = json_tokener_parse(payload);
  12055. if(!is_error(SignCertificate))
  12056. {
  12057. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12058. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12059. }
  12060. json_object_put(SignCertificate);
  12061. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12062. }
  12063. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12064. {
  12065. mtrace();
  12066. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12067. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12068. }
  12069. //==========================================
  12070. // Handle Error routine
  12071. //==========================================
  12072. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12073. {
  12074. mtrace();
  12075. #ifdef SystemLogMessage
  12076. DEBUG_INFO("errorCode: %s\n", errorCode);
  12077. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12078. DEBUG_INFO("errorDetails: %s\n", payload);
  12079. #endif
  12080. }
  12081. //===============================================
  12082. // Common routine
  12083. //===============================================
  12084. int initialConfigurationTable(void)
  12085. {
  12086. //clock_t start_t, end_t, total_t;
  12087. FILE *fp;
  12088. FILE *outfile;
  12089. char str[512]={0};
  12090. char sstr[256]={0};
  12091. int c = 0;
  12092. char *loc;
  12093. int confVersion = 10;
  12094. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12095. //start_t = clock();
  12096. //printf("Starting of the program, start_t = %ld\n", start_t);
  12097. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12098. // Check configuration file size is correct
  12099. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12100. {
  12101. struct stat st;
  12102. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12103. if(st.st_size < 3100)
  12104. {
  12105. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12106. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12107. }
  12108. }
  12109. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12110. {
  12111. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12112. if(outfile == NULL)
  12113. {
  12114. DEBUG_INFO("Error opening file\n");
  12115. return FALSE;
  12116. }
  12117. /*Core Profile*/
  12118. //AllowOfflineTxForUnknownId
  12119. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12123. //AuthorizationCacheEnabled
  12124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12128. //AuthorizeRemoteTxRequests
  12129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12133. //BlinkRepeat
  12134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12138. //ClockAlignedDataInterval
  12139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12143. //ConnectionTimeOut
  12144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12148. //GetConfigurationMaxKeys
  12149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12151. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12153. // HeartbeatInterval
  12154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12158. // LightIntensity
  12159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12163. // LocalAuthorizeOffline
  12164. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12168. // LocalPreAuthorize
  12169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12173. // MaxEnergyOnInvalidId
  12174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12178. // MeterValuesAlignedData
  12179. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12182. 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" );
  12183. else
  12184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12186. // MeterValuesAlignedDataMaxLength
  12187. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12191. else
  12192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12194. // MeterValuesSampledData
  12195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12198. 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" );
  12199. else
  12200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12202. // MeterValuesSampledDataMaxLength
  12203. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12207. else
  12208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12210. // MeterValueSampleInterval
  12211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12215. // MinimumStatusDuration
  12216. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12219. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12221. // NumberOfConnectors
  12222. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12225. {
  12226. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12227. }
  12228. else
  12229. {
  12230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12231. }
  12232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12233. // ResetRetries
  12234. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12236. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12238. // ConnectorPhaseRotation
  12239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12243. // ConnectorPhaseRotationMaxLength
  12244. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12248. // StopTransactionOnEVSideDisconnect
  12249. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12251. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12253. // StopTransactionOnInvalidId
  12254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12256. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12258. // StopTxnAlignedData
  12259. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12263. // StopTxnAlignedDataMaxLength
  12264. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12268. // StopTxnSampledData
  12269. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12272. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12273. else
  12274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12276. // StopTxnSampledDataMaxLength
  12277. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12280. {
  12281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12282. }
  12283. else
  12284. {
  12285. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12286. }
  12287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12288. // SupportedFeatureProfiles
  12289. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12293. // SupportedFeatureProfilesMaxLength
  12294. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12298. // TransactionMessageAttempts
  12299. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12302. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12304. // TransactionMessageRetryInterval
  12305. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12308. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12310. // UnlockConnectorOnEVSideDisconnect
  12311. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12315. // WebSocketPingInterval
  12316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12320. // QueueOffLineMeterValues
  12321. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12325. // AuthorizationKey
  12326. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  12329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12330. // SecurityProfile
  12331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12335. // DefaultPrice
  12336. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12340. // CustomDisplayCostAndPrice
  12341. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12345. // CustomIdleFeeAfterStop
  12346. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12350. // SystemUptimeSec
  12351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  12352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  12353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  12354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  12355. // FreeVend
  12356. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  12357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  12358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  12359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  12360. // Configuration Version
  12361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12363. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12365. //* Local Auth List Management Profile*/
  12366. #if 0
  12367. //For OCTT Test Case
  12368. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12371. #endif
  12372. #if 1
  12373. //LocalAuthListEnabled
  12374. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12378. #endif
  12379. //LocalAuthListMaxLength
  12380. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12384. //SendLocalListMaxLength
  12385. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12386. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12387. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12389. //ReserveConnectorZeroSupported
  12390. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12391. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12392. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12394. //* Smart Charging Profile */
  12395. //ChargeProfileMaxStackLevel
  12396. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12400. // ChargingScheduleAllowedChargingRateUnit
  12401. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12405. // ChargingScheduleMaxPeriods
  12406. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12408. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12410. // ConnectorSwitch3to1PhaseSupported
  12411. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12415. // MaxChargingProfilesInstalled
  12416. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12418. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12420. fclose(outfile);
  12421. }
  12422. else
  12423. {
  12424. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  12425. char keystr[60]={0};
  12426. char readonlystr[10]={0};
  12427. char valuestr[256]={0};
  12428. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  12429. if(fp == NULL) {
  12430. DEBUG_INFO("Error opening file");
  12431. return FALSE;
  12432. }
  12433. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12434. {
  12435. //DEBUG_INFO("Get Configuration \n");
  12436. if(strlen(str) > 0)
  12437. {
  12438. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12439. //*************************key*********************************/
  12440. if(strstr(str, "key") != NULL)
  12441. {
  12442. loc = strstr(str, "key");
  12443. c = 0;
  12444. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12445. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12446. {
  12447. sstr[c] = loc[strlen("key")+3+c];
  12448. c++;
  12449. }
  12450. sstr[c] = '\0';
  12451. strcpy(keystr,sstr);
  12452. }
  12453. //*************************readonly*********************************/
  12454. if(strstr(str, "readonly") != NULL)
  12455. {
  12456. loc = strstr(str, "readonly");
  12457. c = 0;
  12458. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12459. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12460. {
  12461. sstr[c] = loc[strlen("readonly")+2+c];
  12462. c++;
  12463. }
  12464. sstr[c] = '\0';
  12465. strcpy(readonlystr,sstr);
  12466. }
  12467. //*************************value*********************************/
  12468. if(strstr(str, "value") != NULL)
  12469. {
  12470. loc = strstr(str, "value");
  12471. c = 0;
  12472. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12473. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12474. {
  12475. sstr[c] = loc[strlen("value")+3+c];
  12476. c++;
  12477. }
  12478. sstr[c] = '\0';
  12479. strcpy(valuestr,sstr);
  12480. }
  12481. // DEBUG_INFO("keystr=%s\n",keystr);
  12482. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12483. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12484. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12485. {
  12486. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12487. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12488. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12489. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12490. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12491. }
  12492. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12493. {
  12494. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12495. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12496. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12497. }
  12498. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12499. {
  12500. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12501. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12502. }
  12503. if(strcmp(keystr, "BlinkRepeat") == 0)
  12504. {
  12505. //Charger.BlinkRepeat = Integer.parseInt(value);
  12506. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12507. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12508. }
  12509. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12510. {
  12511. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12512. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12513. }
  12514. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12515. {
  12516. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12517. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12518. }
  12519. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12520. {
  12521. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12522. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12523. }
  12524. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12525. {
  12526. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12527. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12528. HeartBeatWaitTime = atoi(valuestr);
  12529. }
  12530. if(strcmp(keystr, "LightIntensity") == 0)
  12531. {
  12532. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12533. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12534. }
  12535. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12536. {
  12537. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12538. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12539. }
  12540. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12541. {
  12542. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12543. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12544. }
  12545. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12546. {
  12547. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12548. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12549. }
  12550. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12551. {
  12552. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12553. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12554. }
  12555. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12556. {
  12557. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12558. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12559. }
  12560. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12561. {
  12562. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12563. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12564. }
  12565. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12566. {
  12567. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12568. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12569. }
  12570. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12571. {
  12572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12573. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12574. }
  12575. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12576. {
  12577. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12579. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12580. }
  12581. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12582. {
  12583. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12584. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12585. }
  12586. if(strcmp(keystr, "ResetRetries") == 0)
  12587. {
  12588. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12589. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12590. }
  12591. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12592. {
  12593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12594. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12595. }
  12596. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12597. {
  12598. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12599. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12600. }
  12601. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12602. {
  12603. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12604. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12605. }
  12606. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12607. {
  12608. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12609. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12610. }
  12611. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12612. {
  12613. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12614. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12615. }
  12616. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12617. {
  12618. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12620. }
  12621. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12622. {
  12623. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12624. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12625. }
  12626. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12627. {
  12628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12629. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12630. }
  12631. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12632. {
  12633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12635. }
  12636. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12637. {
  12638. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12640. }
  12641. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12642. {
  12643. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12644. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12645. TransactionMessageAttemptsValue = atoi(valuestr);
  12646. }
  12647. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12648. {
  12649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12650. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12651. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12652. }
  12653. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12654. {
  12655. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12656. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12657. }
  12658. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12659. {
  12660. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12661. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12662. }
  12663. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12664. {
  12665. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12666. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12667. }
  12668. if(strcmp(keystr, "AuthorizationKey") == 0)
  12669. {
  12670. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12671. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12672. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12673. }
  12674. if(strcmp(keystr, "SecurityProfile") == 0)
  12675. {
  12676. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12677. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  12678. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12679. }
  12680. if(strcmp(keystr, "DefaultPrice") == 0)
  12681. {
  12682. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12683. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12684. }
  12685. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12686. {
  12687. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12688. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12689. }
  12690. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12691. {
  12692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12693. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12694. }
  12695. if(strcmp(keystr, "SystemUptimeSec") == 0)
  12696. {
  12697. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12698. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  12699. }
  12700. if(strcmp(keystr, "FreeVend") == 0)
  12701. {
  12702. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  12704. }
  12705. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12706. {
  12707. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12708. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12709. }
  12710. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12711. {
  12712. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12713. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12714. }
  12715. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12716. {
  12717. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12719. }
  12720. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12721. {
  12722. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12723. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12724. }
  12725. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12726. {
  12727. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12729. }
  12730. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12731. {
  12732. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12733. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12734. }
  12735. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12736. {
  12737. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12738. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12739. }
  12740. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12741. {
  12742. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12743. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12744. }
  12745. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12746. {
  12747. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12748. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12749. }
  12750. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12751. {
  12752. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12754. }
  12755. }
  12756. }
  12757. fclose(fp);
  12758. }
  12759. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12760. {
  12761. return PASS;
  12762. }
  12763. else
  12764. {
  12765. return FAIL;
  12766. }
  12767. }
  12768. void StoreConfigurationTable(void)
  12769. {
  12770. FILE *outfile;
  12771. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12772. if(outfile == NULL)
  12773. {
  12774. DEBUG_INFO("Error opening file");
  12775. return ;
  12776. }
  12777. /*Core Profile*/
  12778. //AllowOfflineTxForUnknownId
  12779. /*
  12780. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12781. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12782. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12783. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12784. */
  12785. //DEBUG_INFO("data=%s\n",data);
  12786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12787. //AuthorizationCacheEnabled
  12788. /*
  12789. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12792. */
  12793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12794. //AuthorizeRemoteTxRequests
  12795. /*
  12796. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12797. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12799. */
  12800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12801. //BlinkRepeat
  12802. /*
  12803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12806. */
  12807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12808. //ClockAlignedDataInterval
  12809. /*
  12810. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12811. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12813. */
  12814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12815. //ConnectionTimeOut
  12816. /*
  12817. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12818. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12820. */
  12821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12822. //GetConfigurationMaxKeys
  12823. /*
  12824. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12827. */
  12828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12829. // HeartbeatInterval
  12830. /*
  12831. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12834. */
  12835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12836. // LightIntensity
  12837. /*
  12838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12841. */
  12842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12843. // LocalAuthorizeOffline
  12844. /*
  12845. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12848. */
  12849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12850. // LocalPreAuthorize
  12851. /*
  12852. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12855. */
  12856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12857. // MaxEnergyOnInvalidId
  12858. /*
  12859. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12862. */
  12863. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12865. // MeterValuesAlignedData
  12866. /*
  12867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12870. */
  12871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12872. // MeterValuesAlignedDataMaxLength
  12873. /*
  12874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12877. */
  12878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12879. // MeterValuesSampledData
  12880. /*
  12881. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12884. */
  12885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12886. // MeterValuesSampledDataMaxLength
  12887. /*
  12888. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12891. */
  12892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12893. // MeterValueSampleInterval
  12894. /*
  12895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12898. */
  12899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12900. // MinimumStatusDuration
  12901. /*
  12902. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12905. */
  12906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12907. // NumberOfConnectors
  12908. /*
  12909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12912. {
  12913. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12914. }
  12915. else
  12916. {
  12917. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12918. }
  12919. */
  12920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12921. // ResetRetries
  12922. /*
  12923. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12926. */
  12927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12928. // ConnectorPhaseRotation
  12929. /*
  12930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12933. */
  12934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12935. // ConnectorPhaseRotationMaxLength
  12936. /*
  12937. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12940. */
  12941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12942. // StopTransactionOnEVSideDisconnect
  12943. /*
  12944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12947. */
  12948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12949. // StopTransactionOnInvalidId
  12950. /*
  12951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12954. */
  12955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12956. // StopTxnAlignedData
  12957. /*
  12958. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12961. */
  12962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12963. // StopTxnAlignedDataMaxLength
  12964. /*
  12965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12968. */
  12969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12970. // StopTxnSampledData
  12971. /*
  12972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12975. */
  12976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12977. // StopTxnSampledDataMaxLength
  12978. /*
  12979. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12982. */
  12983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12984. // SupportedFeatureProfiles
  12985. /*
  12986. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12989. */
  12990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12991. // SupportedFeatureProfilesMaxLength
  12992. /*
  12993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12996. */
  12997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12998. // TransactionMessageAttempts
  12999. /*
  13000. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13003. */
  13004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13005. // TransactionMessageRetryInterval
  13006. /*
  13007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13010. */
  13011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13012. // UnlockConnectorOnEVSideDisconnect
  13013. /*
  13014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13017. */
  13018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13019. // WebSocketPingInterval
  13020. /*
  13021. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13024. */
  13025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13026. // QueueOffLineMeterValues
  13027. /*
  13028. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13031. */
  13032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13033. // AuthorizationKey
  13034. /*
  13035. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13038. */
  13039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13040. // SecurityProfile
  13041. /*
  13042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13045. */
  13046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13047. // DefaultPrice
  13048. /*
  13049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13052. */
  13053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13054. // CustomDisplayCostAndPrice
  13055. /*
  13056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13059. */
  13060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13061. // CustomIdleFeeAfterStop
  13062. /*
  13063. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13066. */
  13067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13068. // SystemUptimeSec
  13069. /*
  13070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13073. */
  13074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13075. // FreeVend
  13076. /*
  13077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  13080. */
  13081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13082. // ConfigurationVersion
  13083. /*
  13084. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13087. */
  13088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13089. //* Local Auth List Management Profile*/
  13090. //LocalAuthListEnabled
  13091. /*
  13092. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13095. */
  13096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13097. //LocalAuthListMaxLength
  13098. /*
  13099. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13102. */
  13103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13104. //SendLocalListMaxLength
  13105. /*
  13106. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13109. */
  13110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13111. //ReserveConnectorZeroSupported
  13112. /*
  13113. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13116. */
  13117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13118. //* Smart Charging Profile */
  13119. //ChargeProfileMaxStackLevel
  13120. /*
  13121. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13124. */
  13125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13126. // ChargingScheduleAllowedChargingRateUnit
  13127. /*
  13128. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13131. */
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13133. // ChargingScheduleMaxPeriods
  13134. /*
  13135. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13138. */
  13139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13140. // ConnectorSwitch3to1PhaseSupported
  13141. /*
  13142. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13145. */
  13146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13147. // MaxChargingProfilesInstalled
  13148. /*
  13149. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13152. */
  13153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13154. fclose(outfile);
  13155. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13156. }
  13157. void getKeyValue(char *keyReq)
  13158. {
  13159. int isEmpty = FALSE;
  13160. int isKnowKey = FALSE;
  13161. DEBUG_INFO("keyReq = %s\n", keyReq);
  13162. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13163. isEmpty = TRUE;
  13164. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13165. {
  13166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13168. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13169. {
  13170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13171. }
  13172. else
  13173. {
  13174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13175. }
  13176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13177. isKnowKey = TRUE;
  13178. }
  13179. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13180. {
  13181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13183. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13184. {
  13185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13186. }
  13187. else
  13188. {
  13189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13190. }
  13191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13192. isKnowKey = TRUE;
  13193. }
  13194. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13195. {
  13196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13198. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13199. {
  13200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13201. }
  13202. else
  13203. {
  13204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13205. }
  13206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13207. isKnowKey = TRUE;
  13208. }
  13209. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13210. {
  13211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13213. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13214. {
  13215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13216. }
  13217. else
  13218. {
  13219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13220. }
  13221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13222. isKnowKey = TRUE;
  13223. }
  13224. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13225. {
  13226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13228. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13229. {
  13230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13231. }
  13232. else
  13233. {
  13234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13235. }
  13236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13237. isKnowKey = TRUE;
  13238. }
  13239. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13240. {
  13241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13243. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13244. {
  13245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13246. }
  13247. else
  13248. {
  13249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13250. }
  13251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13252. isKnowKey = TRUE;
  13253. }
  13254. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13255. {
  13256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13258. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13259. {
  13260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13261. }
  13262. else
  13263. {
  13264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13265. }
  13266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13267. isKnowKey = TRUE;
  13268. }
  13269. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13270. {
  13271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13273. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13274. {
  13275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13276. }
  13277. else
  13278. {
  13279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13280. }
  13281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13282. isKnowKey = TRUE;
  13283. }
  13284. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13285. {
  13286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13288. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13289. {
  13290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13291. }
  13292. else
  13293. {
  13294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13295. }
  13296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13297. isKnowKey = TRUE;
  13298. }
  13299. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13300. {
  13301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13303. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13304. {
  13305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13306. }
  13307. else
  13308. {
  13309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13310. }
  13311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13312. isKnowKey = TRUE;
  13313. }
  13314. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13315. {
  13316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13318. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13319. {
  13320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13321. }
  13322. else
  13323. {
  13324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13325. }
  13326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13327. isKnowKey = TRUE;
  13328. }
  13329. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13330. {
  13331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13333. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13334. {
  13335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13336. }
  13337. else
  13338. {
  13339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13340. }
  13341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13342. isKnowKey = TRUE;
  13343. }
  13344. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13345. {
  13346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13348. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13349. {
  13350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13351. }
  13352. else
  13353. {
  13354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13355. }
  13356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13357. isKnowKey = TRUE;
  13358. }
  13359. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13360. {
  13361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13363. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13364. {
  13365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13366. }
  13367. else
  13368. {
  13369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13370. }
  13371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13372. isKnowKey = TRUE;
  13373. }
  13374. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13375. {
  13376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13378. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13379. {
  13380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13381. }
  13382. else
  13383. {
  13384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13385. }
  13386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13387. isKnowKey = TRUE;
  13388. }
  13389. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13390. {
  13391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13393. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13394. {
  13395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13396. }
  13397. else
  13398. {
  13399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13400. }
  13401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13402. isKnowKey = TRUE;
  13403. }
  13404. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13405. {
  13406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13408. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13409. {
  13410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13411. }
  13412. else
  13413. {
  13414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13415. }
  13416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13417. isKnowKey = TRUE;
  13418. }
  13419. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13420. {
  13421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13423. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13424. {
  13425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13426. }
  13427. else
  13428. {
  13429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13430. }
  13431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  13432. isKnowKey = TRUE;
  13433. }
  13434. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13435. {
  13436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13438. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13439. {
  13440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13441. }
  13442. else
  13443. {
  13444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13445. }
  13446. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13448. isKnowKey = TRUE;
  13449. }
  13450. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13451. {
  13452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13454. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13455. {
  13456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13457. }
  13458. else
  13459. {
  13460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13461. }
  13462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13463. isKnowKey = TRUE;
  13464. }
  13465. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13466. {
  13467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13469. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13470. {
  13471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13472. }
  13473. else
  13474. {
  13475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13476. }
  13477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13478. isKnowKey = TRUE;
  13479. }
  13480. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13481. {
  13482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13484. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13485. {
  13486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13487. }
  13488. else
  13489. {
  13490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13491. }
  13492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13493. isKnowKey = TRUE;
  13494. }
  13495. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13496. {
  13497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13499. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13500. {
  13501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13502. }
  13503. else
  13504. {
  13505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13506. }
  13507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13508. isKnowKey = TRUE;
  13509. }
  13510. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13511. {
  13512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13514. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13515. {
  13516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13517. }
  13518. else
  13519. {
  13520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13521. }
  13522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13523. isKnowKey = TRUE;
  13524. }
  13525. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13526. {
  13527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13529. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13530. {
  13531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13532. }
  13533. else
  13534. {
  13535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13536. }
  13537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13538. isKnowKey = TRUE;
  13539. }
  13540. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13541. {
  13542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13544. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13545. {
  13546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13547. }
  13548. else
  13549. {
  13550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13551. }
  13552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13553. isKnowKey = TRUE;
  13554. }
  13555. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13556. {
  13557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13559. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13560. {
  13561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13562. }
  13563. else
  13564. {
  13565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13566. }
  13567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13568. isKnowKey = TRUE;
  13569. }
  13570. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13571. {
  13572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13574. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13575. {
  13576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13577. }
  13578. else
  13579. {
  13580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13581. }
  13582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13583. isKnowKey = TRUE;
  13584. }
  13585. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13586. {
  13587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13589. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13590. {
  13591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13592. }
  13593. else
  13594. {
  13595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13596. }
  13597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13598. isKnowKey = TRUE;
  13599. }
  13600. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13601. {
  13602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13604. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13605. {
  13606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13607. }
  13608. else
  13609. {
  13610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13611. }
  13612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13613. isKnowKey = TRUE;
  13614. }
  13615. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13616. {
  13617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13619. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13620. {
  13621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13622. }
  13623. else
  13624. {
  13625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13626. }
  13627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13628. isKnowKey = TRUE;
  13629. }
  13630. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13631. {
  13632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13634. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13635. {
  13636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13637. }
  13638. else
  13639. {
  13640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13641. }
  13642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13643. isKnowKey = TRUE;
  13644. }
  13645. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13646. {
  13647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13649. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13650. {
  13651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13652. }
  13653. else
  13654. {
  13655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13656. }
  13657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13658. isKnowKey = TRUE;
  13659. }
  13660. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13661. {
  13662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13664. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13665. {
  13666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13667. }
  13668. else
  13669. {
  13670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13671. }
  13672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13673. isKnowKey = TRUE;
  13674. }
  13675. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13676. {
  13677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13679. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13680. {
  13681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13682. }
  13683. else
  13684. {
  13685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13686. }
  13687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13688. isKnowKey = TRUE;
  13689. }
  13690. /*
  13691. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13692. {
  13693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13695. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13696. {
  13697. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13698. }
  13699. else
  13700. {
  13701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13702. }
  13703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13704. isKnowKey = TRUE;
  13705. }*/
  13706. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13707. {
  13708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13710. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13711. {
  13712. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13713. }
  13714. else
  13715. {
  13716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13717. }
  13718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13719. isKnowKey = TRUE;
  13720. }
  13721. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13722. {
  13723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13725. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13726. {
  13727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13728. }
  13729. else
  13730. {
  13731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13732. }
  13733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13734. isKnowKey = TRUE;
  13735. }
  13736. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13737. {
  13738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13740. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13741. {
  13742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13743. }
  13744. else
  13745. {
  13746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13747. }
  13748. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13749. isKnowKey = TRUE;
  13750. }
  13751. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13752. {
  13753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13755. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13756. {
  13757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13758. }
  13759. else
  13760. {
  13761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13762. }
  13763. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13764. isKnowKey = TRUE;
  13765. }
  13766. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  13767. {
  13768. struct sysinfo s_info;
  13769. int error = sysinfo(&s_info);
  13770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  13771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  13772. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  13773. {
  13774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  13775. }
  13776. else
  13777. {
  13778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  13779. }
  13780. if(error != 0)
  13781. {
  13782. DEBUG_WARN("System uptime get error: %d\n", error);
  13783. }
  13784. else
  13785. {
  13786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  13787. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  13788. }
  13789. isKnowKey = TRUE;
  13790. }
  13791. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  13792. {
  13793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  13794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  13795. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  13796. {
  13797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  13798. }
  13799. else
  13800. {
  13801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  13802. }
  13803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13804. isKnowKey = TRUE;
  13805. }
  13806. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13807. {
  13808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13810. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13811. {
  13812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13813. }
  13814. else
  13815. {
  13816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13817. }
  13818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13819. isKnowKey = TRUE;
  13820. }
  13821. #if 1
  13822. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13823. {
  13824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13826. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13827. {
  13828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13829. }
  13830. else
  13831. {
  13832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13833. }
  13834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13835. isKnowKey = TRUE;
  13836. }
  13837. #endif
  13838. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13839. {
  13840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13842. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13843. {
  13844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13845. }
  13846. else
  13847. {
  13848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13849. }
  13850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13851. isKnowKey = TRUE;
  13852. }
  13853. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13854. {
  13855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13856. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13857. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13858. {
  13859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13860. }
  13861. else
  13862. {
  13863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13864. }
  13865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13866. isKnowKey = TRUE;
  13867. }
  13868. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13869. {
  13870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13872. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13873. {
  13874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13875. }
  13876. else
  13877. {
  13878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13879. }
  13880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13881. isKnowKey = TRUE;
  13882. }
  13883. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13884. {
  13885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13886. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13887. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13888. {
  13889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13890. }
  13891. else
  13892. {
  13893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13894. }
  13895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13896. isKnowKey = TRUE;
  13897. }
  13898. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13899. {
  13900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13902. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13903. {
  13904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13905. }
  13906. else
  13907. {
  13908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13909. }
  13910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13911. isKnowKey = TRUE;
  13912. }
  13913. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13914. {
  13915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13917. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13918. {
  13919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13920. }
  13921. else
  13922. {
  13923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13924. }
  13925. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13926. isKnowKey = TRUE;
  13927. }
  13928. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13929. {
  13930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13931. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13932. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13933. {
  13934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13935. }
  13936. else
  13937. {
  13938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13939. }
  13940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13941. isKnowKey = TRUE;
  13942. }
  13943. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13944. {
  13945. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13947. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13948. {
  13949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13950. }
  13951. else
  13952. {
  13953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13954. }
  13955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13956. isKnowKey = TRUE;
  13957. }
  13958. //=========================================================
  13959. if(!isEmpty && !isKnowKey)
  13960. {
  13961. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13962. strcpy(unknownkey[UnknownKeynum], keyReq);
  13963. UnknownKeynum = UnknownKeynum + 1;
  13964. }
  13965. }
  13966. void processUnkownKey(void)
  13967. {
  13968. DEBUG_INFO("processUnkownKey...\n");
  13969. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13970. for(int index=0; index < UnknownKeynum; index++)
  13971. {
  13972. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13973. {
  13974. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13975. }
  13976. }
  13977. }
  13978. int setKeyValue(char *key, char *value)
  13979. {
  13980. int isSuccess = NotSupported;
  13981. int check_ascii=0;
  13982. char str[256]={0};
  13983. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13984. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13985. {
  13986. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13987. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13988. {
  13989. strcpy(str, (const char*)value);
  13990. for(int i = 0; str[i]; i++){
  13991. str[i] = tolower(str[i]);
  13992. }
  13993. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13994. isSuccess = ConfigurationStatus_Accepted;
  13995. }
  13996. else
  13997. {
  13998. isSuccess = ConfigurationStatus_Rejected;
  13999. }
  14000. }
  14001. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14002. {
  14003. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14004. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14005. {
  14006. strcpy(str, (const char*)value);
  14007. for(int i = 0; str[i]; i++){
  14008. str[i] = tolower(str[i]);
  14009. }
  14010. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14011. isSuccess = ConfigurationStatus_Accepted;
  14012. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  14013. }
  14014. else
  14015. {
  14016. isSuccess = ConfigurationStatus_Rejected;
  14017. }
  14018. }
  14019. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14020. {
  14021. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14022. {
  14023. strcpy(str, (const char*)value);
  14024. for(int i = 0; str[i]; i++)
  14025. {
  14026. str[i] = tolower(str[i]);
  14027. }
  14028. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14029. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14030. isSuccess = ConfigurationStatus_Accepted;
  14031. }
  14032. else
  14033. {
  14034. isSuccess = ConfigurationStatus_Rejected;
  14035. }
  14036. }
  14037. if(strcmp(key, "BlinkRepeat") == 0)
  14038. {
  14039. //Charger.BlinkRepeat = Integer.parseInt(value);
  14040. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14041. {
  14042. check_ascii = value[0];
  14043. if( (check_ascii < 48) || (check_ascii > 57) )
  14044. {
  14045. isSuccess = ConfigurationStatus_Rejected;
  14046. }
  14047. else
  14048. {
  14049. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14050. isSuccess = ConfigurationStatus_Accepted;
  14051. }
  14052. }
  14053. else
  14054. {
  14055. isSuccess = ConfigurationStatus_Rejected;
  14056. }
  14057. }
  14058. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14059. {
  14060. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14061. {
  14062. check_ascii = value[0];
  14063. if( (check_ascii < 48) || (check_ascii > 57) )
  14064. {
  14065. isSuccess = ConfigurationStatus_Rejected;
  14066. }
  14067. else
  14068. {
  14069. if((atoi(value) == 0) || (atoi(value) >= 10))
  14070. {
  14071. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14072. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14073. isSuccess = ConfigurationStatus_Accepted;
  14074. }
  14075. else
  14076. isSuccess = ConfigurationStatus_Rejected;
  14077. }
  14078. }
  14079. else
  14080. {
  14081. isSuccess = ConfigurationStatus_Rejected;
  14082. }
  14083. }
  14084. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14085. {
  14086. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14087. {
  14088. check_ascii = value[0];
  14089. if( (check_ascii < 48) || (check_ascii > 57) )
  14090. {
  14091. isSuccess = ConfigurationStatus_Rejected;
  14092. }
  14093. else
  14094. {
  14095. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14097. isSuccess = ConfigurationStatus_Accepted;
  14098. }
  14099. }
  14100. else
  14101. {
  14102. isSuccess = ConfigurationStatus_Rejected;
  14103. }
  14104. }
  14105. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14106. {
  14107. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14108. {
  14109. check_ascii = value[0];
  14110. if( (check_ascii < 48) || (check_ascii > 57) )
  14111. {
  14112. isSuccess = ConfigurationStatus_Rejected;
  14113. }
  14114. else
  14115. {
  14116. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14117. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14118. isSuccess = ConfigurationStatus_Accepted;
  14119. }
  14120. }
  14121. else
  14122. {
  14123. isSuccess = ConfigurationStatus_Rejected;
  14124. }
  14125. }
  14126. if(strcmp(key, "HeartbeatInterval") == 0)
  14127. {
  14128. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14129. {
  14130. check_ascii = value[0];
  14131. if( (check_ascii < 48) || (check_ascii > 57) )
  14132. {
  14133. isSuccess = ConfigurationStatus_Rejected;
  14134. }
  14135. else
  14136. {
  14137. if((atoi(value) == 0) || (atoi(value) >= 10))
  14138. {
  14139. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14140. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14141. HeartBeatWaitTime = atoi(value);
  14142. isSuccess = ConfigurationStatus_Accepted;
  14143. }
  14144. else
  14145. {
  14146. isSuccess = ConfigurationStatus_Rejected;
  14147. }
  14148. }
  14149. }
  14150. else
  14151. {
  14152. isSuccess = ConfigurationStatus_Rejected;
  14153. }
  14154. }
  14155. if(strcmp(key, "LightIntensity") == 0)
  14156. {
  14157. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14158. {
  14159. check_ascii = value[0];
  14160. if( (check_ascii < 48) || (check_ascii > 57) )
  14161. {
  14162. isSuccess = ConfigurationStatus_Rejected;
  14163. }
  14164. else
  14165. {
  14166. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14167. isSuccess = ConfigurationStatus_Accepted;
  14168. }
  14169. }
  14170. else
  14171. {
  14172. isSuccess = ConfigurationStatus_Rejected;
  14173. }
  14174. }
  14175. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14176. {
  14177. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14178. {
  14179. strcpy(str, (const char*)value);
  14180. for(int i = 0; str[i]; i++)
  14181. {
  14182. str[i] = tolower(str[i]);
  14183. }
  14184. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14185. isSuccess = ConfigurationStatus_Accepted;
  14186. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14187. }
  14188. else
  14189. {
  14190. isSuccess = ConfigurationStatus_Rejected;
  14191. }
  14192. }
  14193. if(strcmp(key, "LocalPreAuthorize") == 0)
  14194. {
  14195. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14196. {
  14197. strcpy(str, (const char*)value);
  14198. for(int i = 0; str[i]; i++)
  14199. {
  14200. str[i] = tolower(str[i]);
  14201. }
  14202. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14203. isSuccess = ConfigurationStatus_Accepted;
  14204. }
  14205. else
  14206. {
  14207. isSuccess = ConfigurationStatus_Rejected;
  14208. }
  14209. }
  14210. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14211. {
  14212. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14213. {
  14214. check_ascii = value[0];
  14215. if( (check_ascii < 48) || (check_ascii > 57) )
  14216. {
  14217. isSuccess = ConfigurationStatus_Rejected;
  14218. }
  14219. else
  14220. {
  14221. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14222. isSuccess = ConfigurationStatus_Accepted;
  14223. }
  14224. }
  14225. else
  14226. {
  14227. isSuccess = ConfigurationStatus_Rejected;
  14228. }
  14229. }
  14230. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14231. {
  14232. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14233. {
  14234. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14235. isSuccess = ConfigurationStatus_Accepted;
  14236. }
  14237. else
  14238. {
  14239. isSuccess = ConfigurationStatus_Rejected;
  14240. }
  14241. }
  14242. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14243. {
  14244. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14245. {
  14246. check_ascii = value[0];
  14247. if( (check_ascii < 48) || (check_ascii > 57) )
  14248. {
  14249. isSuccess = ConfigurationStatus_Rejected;
  14250. }
  14251. else
  14252. {
  14253. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14254. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14255. isSuccess = ConfigurationStatus_Accepted;
  14256. }
  14257. }
  14258. else
  14259. {
  14260. isSuccess = ConfigurationStatus_Rejected;
  14261. }
  14262. }
  14263. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14264. {
  14265. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14266. {
  14267. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14268. isSuccess = ConfigurationStatus_Accepted;
  14269. }
  14270. else
  14271. {
  14272. isSuccess = ConfigurationStatus_Rejected;
  14273. }
  14274. }
  14275. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14276. {
  14277. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14278. {
  14279. check_ascii = value[0];
  14280. if( (check_ascii < 48) || (check_ascii > 57) )
  14281. {
  14282. isSuccess = ConfigurationStatus_Rejected;
  14283. }
  14284. else
  14285. {
  14286. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14287. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14288. isSuccess = ConfigurationStatus_Accepted;
  14289. }
  14290. }
  14291. else
  14292. {
  14293. isSuccess = ConfigurationStatus_Rejected;
  14294. }
  14295. }
  14296. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14297. {
  14298. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14299. {
  14300. check_ascii = value[0];
  14301. if( (check_ascii < 48) || (check_ascii > 57) )
  14302. {
  14303. isSuccess = ConfigurationStatus_Rejected;
  14304. }
  14305. else
  14306. {
  14307. if((atoi(value) == 0) || (atoi(value) >= 10))
  14308. {
  14309. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14310. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14311. isSuccess = ConfigurationStatus_Accepted;
  14312. }
  14313. else
  14314. {
  14315. isSuccess = ConfigurationStatus_Rejected;
  14316. }
  14317. }
  14318. }
  14319. else
  14320. {
  14321. isSuccess = ConfigurationStatus_Rejected;
  14322. }
  14323. }
  14324. if(strcmp(key, "MinimumStatusDuration") == 0)
  14325. {
  14326. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14327. {
  14328. check_ascii = value[0];
  14329. if( (check_ascii < 48) || (check_ascii > 57) )
  14330. {
  14331. isSuccess = ConfigurationStatus_Rejected;
  14332. }
  14333. else
  14334. {
  14335. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14336. {
  14337. isSuccess = ConfigurationStatus_Rejected;
  14338. }
  14339. else
  14340. {
  14341. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14342. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14343. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14344. isSuccess = ConfigurationStatus_Accepted;
  14345. }
  14346. }
  14347. }
  14348. else
  14349. {
  14350. isSuccess = ConfigurationStatus_Rejected;
  14351. }
  14352. }
  14353. if(strcmp(key, "NumberOfConnectors") == 0)
  14354. {
  14355. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14356. {
  14357. check_ascii = value[0];
  14358. if( (check_ascii < 48) || (check_ascii > 57) )
  14359. {
  14360. isSuccess = ConfigurationStatus_Rejected;
  14361. }
  14362. else
  14363. {
  14364. //Charger.ResetRetries = Integer.parseInt(value);
  14365. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14366. isSuccess = ConfigurationStatus_Accepted;
  14367. }
  14368. }
  14369. else
  14370. {
  14371. isSuccess = ConfigurationStatus_Rejected;
  14372. }
  14373. }
  14374. if(strcmp(key, "ResetRetries") == 0)
  14375. {
  14376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14377. {
  14378. check_ascii = value[0];
  14379. if( (check_ascii < 48) || (check_ascii > 57) )
  14380. {
  14381. isSuccess = ConfigurationStatus_Rejected;
  14382. }
  14383. else
  14384. {
  14385. //Charger.ResetRetries = Integer.parseInt(value);
  14386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14387. isSuccess = ConfigurationStatus_Accepted;
  14388. }
  14389. }
  14390. else
  14391. {
  14392. isSuccess = ConfigurationStatus_Rejected;
  14393. }
  14394. }
  14395. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14396. {
  14397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14398. {
  14399. strcpy(str, (const char*)value);
  14400. for(int i = 0; str[i]; i++)
  14401. {
  14402. str[i] = tolower(str[i]);
  14403. }
  14404. if(strcmp(str, "notapplicable")== 0)
  14405. {
  14406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14407. isSuccess = ConfigurationStatus_Accepted;
  14408. }
  14409. else if(strcmp(str, "unknown")== 0)
  14410. {
  14411. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14412. isSuccess = ConfigurationStatus_Accepted;
  14413. }
  14414. else if(strcmp(str, "rst")== 0)
  14415. {
  14416. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14417. isSuccess = ConfigurationStatus_Accepted;
  14418. }
  14419. else if(strcmp(str, "rts")== 0)
  14420. {
  14421. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14422. isSuccess = ConfigurationStatus_Accepted;
  14423. }
  14424. else if(strcmp(str, "srt")== 0)
  14425. {
  14426. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14427. isSuccess = ConfigurationStatus_Accepted;
  14428. }
  14429. else if(strcmp(str, "str")== 0)
  14430. {
  14431. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14432. isSuccess = ConfigurationStatus_Accepted;
  14433. }
  14434. else if(strcmp(str, "trs")== 0)
  14435. {
  14436. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14437. isSuccess = ConfigurationStatus_Accepted;
  14438. }
  14439. else if(strcmp(str, "tsr")== 0)
  14440. {
  14441. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14442. isSuccess = ConfigurationStatus_Accepted;
  14443. }
  14444. else
  14445. {
  14446. isSuccess = ConfigurationStatus_Rejected;
  14447. }
  14448. }
  14449. else
  14450. {
  14451. isSuccess = ConfigurationStatus_Rejected;
  14452. }
  14453. }
  14454. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14455. {
  14456. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14457. {
  14458. check_ascii = value[0];
  14459. if( (check_ascii < 48) || (check_ascii > 57) )
  14460. {
  14461. isSuccess = ConfigurationStatus_Rejected;
  14462. }
  14463. else
  14464. {
  14465. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14466. isSuccess = ConfigurationStatus_Accepted;
  14467. }
  14468. }
  14469. else
  14470. {
  14471. isSuccess = ConfigurationStatus_Rejected;
  14472. }
  14473. }
  14474. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14475. {
  14476. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14477. {
  14478. strcpy(str, (const char*)value);
  14479. for(int i = 0; str[i]; i++)
  14480. {
  14481. str[i] = tolower(str[i]);
  14482. }
  14483. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14484. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14485. isSuccess = ConfigurationStatus_Accepted;
  14486. }
  14487. else
  14488. {
  14489. isSuccess = ConfigurationStatus_Rejected;
  14490. }
  14491. }
  14492. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14493. {
  14494. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14495. {
  14496. strcpy(str, (const char*)value);
  14497. for(int i = 0; str[i]; i++)
  14498. {
  14499. str[i] = tolower(str[i]);
  14500. }
  14501. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14502. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14503. isSuccess = ConfigurationStatus_Accepted;
  14504. }
  14505. else
  14506. {
  14507. isSuccess = ConfigurationStatus_Rejected;
  14508. }
  14509. }
  14510. if(strcmp(key, "StopTxnAlignedData") == 0)
  14511. {
  14512. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14513. {
  14514. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14515. isSuccess = ConfigurationStatus_Accepted;
  14516. }
  14517. else
  14518. {
  14519. isSuccess = ConfigurationStatus_Rejected;
  14520. }
  14521. }
  14522. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14523. {
  14524. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14525. {
  14526. check_ascii = value[0];
  14527. if( (check_ascii < 48) || (check_ascii > 57) )
  14528. {
  14529. isSuccess = ConfigurationStatus_Rejected;
  14530. }
  14531. else
  14532. {
  14533. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14534. isSuccess = ConfigurationStatus_Accepted;
  14535. }
  14536. }
  14537. else
  14538. {
  14539. isSuccess = ConfigurationStatus_Rejected;
  14540. }
  14541. }
  14542. if(strcmp(key, "StopTxnSampledData") == 0)
  14543. {
  14544. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14545. {
  14546. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14547. isSuccess = ConfigurationStatus_Accepted;
  14548. }
  14549. else
  14550. {
  14551. isSuccess = ConfigurationStatus_Rejected;
  14552. }
  14553. }
  14554. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14555. {
  14556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14557. {
  14558. check_ascii = value[0];
  14559. if( (check_ascii < 48) || (check_ascii > 57) )
  14560. {
  14561. isSuccess = ConfigurationStatus_Rejected;
  14562. }
  14563. else
  14564. {
  14565. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14566. isSuccess = ConfigurationStatus_Accepted;
  14567. }
  14568. }
  14569. else
  14570. {
  14571. isSuccess = ConfigurationStatus_Rejected;
  14572. }
  14573. }
  14574. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14575. {
  14576. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14577. {
  14578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14579. isSuccess = ConfigurationStatus_Accepted;
  14580. }
  14581. else
  14582. {
  14583. isSuccess = ConfigurationStatus_Rejected;
  14584. }
  14585. }
  14586. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14587. {
  14588. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14589. {
  14590. check_ascii = value[0];
  14591. if( (check_ascii < 48) || (check_ascii > 57) )
  14592. {
  14593. isSuccess = ConfigurationStatus_Rejected;
  14594. }
  14595. else
  14596. {
  14597. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14598. isSuccess = ConfigurationStatus_Accepted;
  14599. }
  14600. }
  14601. else
  14602. {
  14603. isSuccess = ConfigurationStatus_Rejected;
  14604. }
  14605. }
  14606. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14607. {
  14608. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14609. {
  14610. check_ascii = value[0];
  14611. if( (check_ascii < 48) || (check_ascii > 57) )
  14612. {
  14613. isSuccess = ConfigurationStatus_Rejected;
  14614. }
  14615. else
  14616. {
  14617. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14619. TransactionMessageAttemptsValue = atoi(value);
  14620. isSuccess = ConfigurationStatus_Accepted;
  14621. }
  14622. }
  14623. else
  14624. {
  14625. isSuccess = ConfigurationStatus_Rejected;
  14626. }
  14627. }
  14628. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14629. {
  14630. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14631. {
  14632. check_ascii = value[0];
  14633. if( (check_ascii < 48) || (check_ascii > 57) )
  14634. {
  14635. isSuccess = ConfigurationStatus_Rejected;
  14636. }
  14637. else
  14638. {
  14639. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14641. TransactionMessageRetryIntervalValue = atoi(value);
  14642. isSuccess = ConfigurationStatus_Accepted;
  14643. }
  14644. }
  14645. else
  14646. {
  14647. isSuccess = ConfigurationStatus_Rejected;
  14648. }
  14649. }
  14650. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14651. {
  14652. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14653. {
  14654. strcpy(str, (const char*)value);
  14655. for(int i = 0; str[i]; i++)
  14656. {
  14657. str[i] = tolower(str[i]);
  14658. }
  14659. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14660. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14661. isSuccess = ConfigurationStatus_Accepted;
  14662. }
  14663. else
  14664. {
  14665. isSuccess = ConfigurationStatus_Rejected;
  14666. }
  14667. }
  14668. if(strcmp(key, "WebSocketPingInterval") == 0)
  14669. {
  14670. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14671. {
  14672. check_ascii = value[0];
  14673. if( (check_ascii < 48) || (check_ascii > 57) )
  14674. {
  14675. isSuccess = ConfigurationStatus_Rejected;
  14676. }
  14677. else
  14678. {
  14679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14680. isSuccess = ConfigurationStatus_Accepted;
  14681. }
  14682. }
  14683. else
  14684. {
  14685. isSuccess = ConfigurationStatus_Rejected;
  14686. }
  14687. }
  14688. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14689. {
  14690. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14691. {
  14692. strcpy(str, (const char*)value);
  14693. for(int i = 0; str[i]; i++)
  14694. {
  14695. str[i] = tolower(str[i]);
  14696. }
  14697. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14698. isSuccess = ConfigurationStatus_Accepted;
  14699. }
  14700. else
  14701. {
  14702. isSuccess = ConfigurationStatus_Rejected;
  14703. }
  14704. }
  14705. if(strcmp(key, "AuthorizationKey") == 0)
  14706. {
  14707. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14708. {
  14709. strcpy(str, (const char*)value);
  14710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14711. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14712. isSuccess = ConfigurationStatus_Accepted;
  14713. }
  14714. else
  14715. {
  14716. isSuccess = ConfigurationStatus_Rejected;
  14717. }
  14718. }
  14719. if(strcmp(key, "SecurityProfile") == 0)
  14720. {
  14721. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14722. {
  14723. check_ascii = value[0];
  14724. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14725. {
  14726. isSuccess = ConfigurationStatus_Rejected;
  14727. }
  14728. else if(check_ascii == 0x33)
  14729. {
  14730. isSuccess = NotSupported;
  14731. }
  14732. else
  14733. {
  14734. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14735. {
  14736. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14737. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14738. isSuccess = ConfigurationStatus_Accepted;
  14739. }
  14740. else
  14741. isSuccess = ConfigurationStatus_Rejected;
  14742. }
  14743. }
  14744. else
  14745. {
  14746. isSuccess = ConfigurationStatus_Rejected;
  14747. }
  14748. }
  14749. if(strcmp(key, "DefaultPrice") == 0)
  14750. {
  14751. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14752. {
  14753. strcpy(str, (const char*)value);
  14754. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14755. isSuccess = ConfigurationStatus_Accepted;
  14756. }
  14757. else
  14758. {
  14759. isSuccess = ConfigurationStatus_Rejected;
  14760. }
  14761. }
  14762. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14763. {
  14764. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14765. {
  14766. strcpy(str, (const char*)value);
  14767. for(int i = 0; str[i]; i++)
  14768. {
  14769. str[i] = tolower(str[i]);
  14770. }
  14771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14772. isSuccess = ConfigurationStatus_Accepted;
  14773. }
  14774. else
  14775. {
  14776. isSuccess = ConfigurationStatus_Rejected;
  14777. }
  14778. }
  14779. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14780. {
  14781. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14782. {
  14783. strcpy(str, (const char*)value);
  14784. for(int i = 0; str[i]; i++)
  14785. {
  14786. str[i] = tolower(str[i]);
  14787. }
  14788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14789. isSuccess = ConfigurationStatus_Accepted;
  14790. }
  14791. else
  14792. {
  14793. isSuccess = ConfigurationStatus_Rejected;
  14794. }
  14795. }
  14796. if(strcmp(key, "SystemUptimeSec") == 0)
  14797. {
  14798. isSuccess = NotSupported;
  14799. }
  14800. if(strcmp(key, "FreeVend") == 0)
  14801. {
  14802. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14803. {
  14804. strcpy(str, (const char*)value);
  14805. for(int i = 0; str[i]; i++)
  14806. {
  14807. str[i] = tolower(str[i]);
  14808. }
  14809. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  14810. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14811. isSuccess = ConfigurationStatus_Accepted;
  14812. }
  14813. else
  14814. {
  14815. isSuccess = ConfigurationStatus_Rejected;
  14816. }
  14817. }
  14818. #if 0
  14819. //For OCPP Test Case
  14820. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14821. {
  14822. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14823. {
  14824. strcpy(str, (const char*)value);
  14825. for(int i = 0; str[i]; i++)
  14826. {
  14827. str[i] = tolower(str[i]);
  14828. }
  14829. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14830. isSuccess = ConfigurationStatus_Accepted;
  14831. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14832. }
  14833. else
  14834. {
  14835. isSuccess = ConfigurationStatus_Rejected;
  14836. }
  14837. }
  14838. #endif
  14839. #if 1
  14840. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14841. {
  14842. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14843. {
  14844. strcpy(str, (const char*)value);
  14845. for(int i = 0; str[i]; i++)
  14846. {
  14847. str[i] = tolower(str[i]);
  14848. }
  14849. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14850. isSuccess = ConfigurationStatus_Accepted;
  14851. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14852. }
  14853. else
  14854. {
  14855. isSuccess = ConfigurationStatus_Rejected;
  14856. }
  14857. }
  14858. #endif
  14859. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14860. {
  14861. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14862. {
  14863. check_ascii = value[0];
  14864. if( (check_ascii < 48) || (check_ascii > 57) )
  14865. {
  14866. isSuccess = ConfigurationStatus_Rejected;
  14867. }
  14868. else
  14869. {
  14870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14871. isSuccess = ConfigurationStatus_Accepted;
  14872. }
  14873. }
  14874. else
  14875. {
  14876. isSuccess = ConfigurationStatus_Rejected;
  14877. }
  14878. }
  14879. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14880. {
  14881. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14882. {
  14883. check_ascii = value[0];
  14884. if( (check_ascii < 48) || (check_ascii > 57) )
  14885. {
  14886. isSuccess = ConfigurationStatus_Rejected;
  14887. }
  14888. else
  14889. {
  14890. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14891. isSuccess = ConfigurationStatus_Accepted;
  14892. }
  14893. }
  14894. else
  14895. {
  14896. isSuccess = ConfigurationStatus_Rejected;
  14897. }
  14898. }
  14899. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14900. {
  14901. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14902. {
  14903. strcpy(str, (const char*)value);
  14904. for(int i = 0; str[i]; i++)
  14905. {
  14906. str[i] = tolower(str[i]);
  14907. }
  14908. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14909. isSuccess = ConfigurationStatus_Accepted;
  14910. }
  14911. else
  14912. {
  14913. isSuccess = ConfigurationStatus_Rejected;
  14914. }
  14915. }
  14916. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14917. {
  14918. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14919. {
  14920. check_ascii = value[0];
  14921. if( (check_ascii < 48) || (check_ascii > 57) )
  14922. {
  14923. isSuccess = ConfigurationStatus_Rejected;
  14924. }
  14925. else
  14926. {
  14927. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14928. isSuccess = ConfigurationStatus_Accepted;
  14929. }
  14930. }
  14931. else
  14932. {
  14933. isSuccess = ConfigurationStatus_Rejected;
  14934. }
  14935. }
  14936. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14937. {
  14938. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14939. {
  14940. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14941. isSuccess = ConfigurationStatus_Accepted;
  14942. }
  14943. else
  14944. {
  14945. isSuccess = ConfigurationStatus_Rejected;
  14946. }
  14947. }
  14948. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14949. {
  14950. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14951. {
  14952. check_ascii = value[0];
  14953. if( (check_ascii < 48) || (check_ascii > 57) )
  14954. {
  14955. isSuccess = ConfigurationStatus_Rejected;
  14956. }
  14957. else
  14958. {
  14959. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14960. isSuccess = ConfigurationStatus_Accepted;
  14961. }
  14962. }
  14963. else
  14964. {
  14965. isSuccess = ConfigurationStatus_Rejected;
  14966. }
  14967. }
  14968. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14969. {
  14970. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14971. {
  14972. strcpy(str, (const char*)value);
  14973. for(int i = 0; str[i]; i++)
  14974. {
  14975. str[i] = tolower(str[i]);
  14976. }
  14977. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14978. isSuccess = ConfigurationStatus_Accepted;
  14979. }
  14980. else
  14981. {
  14982. isSuccess = ConfigurationStatus_Rejected;
  14983. }
  14984. }
  14985. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14986. {
  14987. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14988. {
  14989. check_ascii = value[0];
  14990. if( (check_ascii < 48) || (check_ascii > 57) )
  14991. {
  14992. isSuccess = ConfigurationStatus_Rejected;
  14993. }
  14994. else
  14995. {
  14996. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14997. isSuccess = ConfigurationStatus_Accepted;
  14998. }
  14999. }
  15000. else
  15001. {
  15002. isSuccess = ConfigurationStatus_Rejected;
  15003. }
  15004. }
  15005. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15006. return isSuccess;
  15007. }
  15008. int TransactionMessageAttemptsGet(void)
  15009. {
  15010. return TransactionMessageAttemptsValue;
  15011. }
  15012. int FirstHeartBeatResponse(void)
  15013. {
  15014. return FirstHeartBeat;
  15015. }
  15016. int TransactionMessageRetryIntervalGet(void)
  15017. {
  15018. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15019. }
  15020. int ReadHttpStatus(int sock)
  15021. {
  15022. //char c;
  15023. char buff[1024]="",*ptr=buff+1;
  15024. int bytes_received, status;
  15025. DEBUG_INFO("Begin Response ..\n");
  15026. while((bytes_received = recv(sock, ptr, 1, 0))){
  15027. if(bytes_received==-1){
  15028. perror("ReadHttpStatus");
  15029. exit(1);
  15030. }
  15031. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15032. ptr++;
  15033. }
  15034. *ptr=0;
  15035. ptr=buff+1;
  15036. sscanf(ptr,"%*s %d ", &status);
  15037. DEBUG_INFO("%s\n",ptr);
  15038. DEBUG_INFO("status=%d\n",status);
  15039. DEBUG_INFO("End Response ..\n");
  15040. return (bytes_received>0)?status:0;
  15041. }
  15042. //the only filed that it parsed is 'Content-Length'
  15043. int ParseHeader(int sock)
  15044. {
  15045. //char c;
  15046. char buff[1024]="",*ptr=buff+4;
  15047. int bytes_received;
  15048. DEBUG_INFO("Begin HEADER ..\n");
  15049. while((bytes_received = recv(sock, ptr, 1, 0))){
  15050. if(bytes_received==-1){
  15051. perror("Parse Header");
  15052. exit(1);
  15053. }
  15054. if(
  15055. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15056. (ptr[-1]=='\r') && (*ptr=='\n' )
  15057. ) break;
  15058. ptr++;
  15059. }
  15060. *ptr=0;
  15061. ptr=buff+4;
  15062. //printf("%s",ptr);
  15063. if(bytes_received){
  15064. ptr=strstr(ptr,"Content-Length:");
  15065. if(ptr){
  15066. sscanf(ptr,"%*s %d",&bytes_received);
  15067. }else
  15068. bytes_received=-1; //unknown size
  15069. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15070. }
  15071. DEBUG_INFO("End HEADER ..\n");
  15072. return bytes_received ;
  15073. }
  15074. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15075. {
  15076. int result = TRUE;
  15077. char rmFileCmd[100]={0};
  15078. char FilePath[100]={0};
  15079. char ftpbuf[200];
  15080. int systemresult;
  15081. sprintf(FilePath,"/mnt/%s",filename);
  15082. system("ping 8.8.8.8 &");
  15083. if((access(FilePath,F_OK))!=-1)
  15084. {
  15085. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15086. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15087. system(rmFileCmd);
  15088. }
  15089. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15090. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15091. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15092. systemresult = system(ftpbuf);
  15093. if(systemresult != 0)
  15094. {
  15095. DEBUG_INFO("http DownLoad error!\n");
  15096. result = FALSE;
  15097. }
  15098. system("pkill ping");
  15099. return result;
  15100. }
  15101. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15102. {
  15103. int result = TRUE;
  15104. char rmFileCmd[100]={0};
  15105. char FilePath[100]={0};
  15106. char ftpbuf[200];
  15107. int systemresult;
  15108. sprintf(FilePath,"/mnt/%s",filename);
  15109. system("ping 8.8.8.8 &");
  15110. if((access(FilePath,F_OK))!=-1)
  15111. {
  15112. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15113. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15114. system(rmFileCmd);
  15115. }
  15116. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15117. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15118. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15119. systemresult = system(ftpbuf);
  15120. if(systemresult != 0)
  15121. {
  15122. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15123. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15124. systemresult = system(ftpbuf);
  15125. if(systemresult != 0)
  15126. {
  15127. DEBUG_WARN("wget error!\n");
  15128. result = FALSE;
  15129. }
  15130. }
  15131. system("pkill ping");
  15132. return result;
  15133. }
  15134. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15135. {
  15136. char rmFileCmd[100]={0};
  15137. char FilePath[100]={0};
  15138. char buf[512];
  15139. int systemresult = 0;
  15140. //DEBUG_INFO("filename=%s\n",filename);
  15141. //DEBUG_INFO("url=%s\n",url);
  15142. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15143. if((access(FilePath,F_OK))!=-1)
  15144. {
  15145. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15146. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15147. system(rmFileCmd);
  15148. }
  15149. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15150. if(fp == NULL)
  15151. {
  15152. DEBUG_INFO("log is NULL\n");
  15153. return FALSE;
  15154. }
  15155. else
  15156. {
  15157. fprintf(fp, "%s\n", url);
  15158. fprintf(fp, "%s\n", filename);
  15159. fclose(fp);
  15160. }
  15161. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15162. if(phpFP == NULL)
  15163. {
  15164. DEBUG_INFO("PHP upload fail.\n");
  15165. return FALSE;
  15166. }
  15167. else
  15168. {
  15169. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15170. {
  15171. if(strstr(buf, "result") != NULL)
  15172. {
  15173. sscanf(buf, "result: %d", &systemresult);
  15174. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15175. }
  15176. }
  15177. pclose(phpFP);
  15178. }
  15179. if(systemresult != 1)
  15180. {
  15181. DEBUG_INFO("HTTP upload error!\n");
  15182. return FALSE;
  15183. }
  15184. return TRUE;
  15185. }
  15186. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15187. {
  15188. struct hostent* server;
  15189. char *IPbuffer;
  15190. char ftpbuf[200];
  15191. int systemresult;
  15192. // To retrieve host information
  15193. server = gethostbyname(location);
  15194. // To convert an Internet network
  15195. // address into ASCII string
  15196. IPbuffer = inet_ntoa(*((struct in_addr*)
  15197. server->h_addr_list[0]));
  15198. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15199. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15200. /* format : ftpput -u username -p passwd IP target source*/
  15201. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15202. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15203. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15204. systemresult = system(ftpbuf);
  15205. DEBUG_INFO("systemresult=%d\n",systemresult);
  15206. if(systemresult != 0)
  15207. {
  15208. DEBUG_INFO("ftpput error!\n");
  15209. return FALSE;
  15210. }
  15211. return TRUE;
  15212. }
  15213. int GetOcppServerURL()
  15214. {
  15215. int result = FALSE;
  15216. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15217. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15218. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15219. struct yuarel url;
  15220. char urlStr[512];
  15221. // OCPPPH only
  15222. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  15223. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  15224. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  15225. {
  15226. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  15227. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15228. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15229. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  15230. if(yuarel_parse(&url, urlStr) != -1)
  15231. {
  15232. sprintf(OcppProtocol, "%s", url.scheme);
  15233. sprintf(OcppHost, "%s", url.host);
  15234. if(url.path == NULL)
  15235. OcppTempPath[0] = '\0';
  15236. else
  15237. sprintf(OcppTempPath, "%s", url.path);
  15238. if(url.port == 0)
  15239. {
  15240. if(strcmp(OcppProtocol, "wss") == 0)
  15241. OcppPort = 443;
  15242. else
  15243. OcppPort = 80;
  15244. }
  15245. else
  15246. OcppPort = url.port;
  15247. result = TRUE;
  15248. }
  15249. }
  15250. else
  15251. {
  15252. strcpy(OcppHost,"");
  15253. }
  15254. return result;
  15255. }
  15256. int GetOcppPath()
  15257. {
  15258. int result = FALSE;
  15259. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  15260. {
  15261. if(OcppTempPath == NULL)
  15262. {
  15263. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  15264. }
  15265. else
  15266. {
  15267. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  15268. }
  15269. result = TRUE;
  15270. goto End;
  15271. }
  15272. else
  15273. {
  15274. strcpy(OcppPath,"");
  15275. }
  15276. End:
  15277. return result;
  15278. }
  15279. int GetOcppPort()
  15280. {
  15281. return OcppPort;
  15282. }
  15283. int GetOcppConnStatus(void)
  15284. {
  15285. return ShmOCPP16DataPH->OcppConnStatus;
  15286. }
  15287. void SetOcppConnStatus(uint8_t status)
  15288. {
  15289. ShmOCPP16DataPH->OcppConnStatus = status;
  15290. }
  15291. int GetHeartBeatWithNOResponse(void)
  15292. {
  15293. return HeartBeatWithNOResponse;
  15294. }
  15295. void SetHeartBeatWithNOResponse(void)
  15296. {
  15297. HeartBeatWithNOResponse = 0;
  15298. }
  15299. void GetStartTransactionIdTag(int gun_index)
  15300. {
  15301. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15302. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15303. }
  15304. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15305. {
  15306. char ch;
  15307. FILE *fptr1;
  15308. int temptransactionId;
  15309. char str[100]={0};
  15310. temptransactionId = 0;
  15311. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15312. {
  15313. DEBUG_INFO("IdTag is empty.\n");
  15314. return temptransactionId;
  15315. }
  15316. /*------ Read the file ----------------*/
  15317. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  15318. if (!fptr1)
  15319. {
  15320. DEBUG_INFO("QueueTransactionId file open error.\n");
  15321. //printf(" File not found or unable to open the input file!!\n");
  15322. return temptransactionId;
  15323. }
  15324. ch=fgetc(fptr1);
  15325. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  15326. rewind(fptr1);
  15327. if(ch!=EOF)
  15328. {
  15329. // printf("%c",ch);
  15330. while (fgets(str, 100, fptr1) != NULL)
  15331. {
  15332. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15333. if(str[0]=='\0')
  15334. {
  15335. break;
  15336. }
  15337. char *revbuf[8] = {0}; // Variable store string split
  15338. int num = 0;// Quantity after string split
  15339. DEBUG_INFO("Transaction queue data= %s\n", str);
  15340. splitstring(str,",",revbuf,&num); // String split
  15341. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15342. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15343. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15344. DEBUG_INFO("------------------------------\n");
  15345. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15346. {
  15347. if(isStopTransaction)
  15348. {
  15349. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15350. {
  15351. temptransactionId = atoi(revbuf[2]);
  15352. //break;
  15353. }
  15354. }
  15355. else
  15356. {
  15357. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15358. {
  15359. temptransactionId = atoi(revbuf[2]);
  15360. //break;
  15361. }
  15362. }
  15363. }
  15364. }
  15365. }
  15366. else
  15367. DEBUG_INFO("EOF\n");
  15368. fclose(fptr1);
  15369. /*------- End of reading ---------------*/
  15370. return temptransactionId;
  15371. }
  15372. void SetTransactionIdZero(int transactionId)
  15373. {
  15374. char ch;
  15375. FILE *fptr1, *fptr2;
  15376. int temptransactionId = 0;
  15377. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  15378. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  15379. if (!fptr1)
  15380. {
  15381. //printf(" File not found or unable to open the input file!!\n");
  15382. return ;
  15383. }
  15384. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15385. if (!fptr2)
  15386. {
  15387. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15388. fclose(fptr1);
  15389. return ;
  15390. }
  15391. ch=fgetc(fptr1);
  15392. rewind(fptr1);
  15393. if(ch!=EOF)
  15394. {
  15395. // copy all contents to the temporary file except the specific line
  15396. while (fgets(str, 100, fptr1) != NULL)
  15397. {
  15398. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15399. if(str[0]=='\0')
  15400. {
  15401. break;
  15402. }
  15403. char *revbuf[8] = {0};
  15404. int num = 0;
  15405. strcpy(strtemp, str);
  15406. splitstring(str,",",revbuf,&num);
  15407. if(revbuf[2][0] != '\0')
  15408. {
  15409. temptransactionId = atoi(revbuf[2]);
  15410. if(transactionId != temptransactionId)
  15411. {
  15412. fprintf(fptr2, "%s\n", strtemp);
  15413. }
  15414. }
  15415. }
  15416. }
  15417. fclose(fptr1);
  15418. fclose(fptr2);
  15419. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  15420. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  15421. /*------ Read the file ----------------*/
  15422. }
  15423. int InternetDisconnect(void)
  15424. {
  15425. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15426. }
  15427. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15428. void storeTempStopTransaction(int gun_index)
  15429. {
  15430. char guid[37]={0};
  15431. int tempIndex = 0;
  15432. char TempStopTransaction[256];
  15433. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15434. DEBUG_INFO("storeTempStopTransaction...\n");
  15435. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15436. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  15437. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15438. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15439. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15440. {
  15441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15442. {
  15443. tempIndex = ((gun_index==2) ? 1: 0);
  15444. }
  15445. else
  15446. {
  15447. tempIndex = gun_index;
  15448. }
  15449. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15450. {
  15451. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15452. {
  15453. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15454. }
  15455. }// END OF CHAdeMO_QUANTITY
  15456. }
  15457. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15458. {
  15459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15460. {
  15461. tempIndex = ((gun_index==2) ? 1: 0);
  15462. }
  15463. else
  15464. {
  15465. tempIndex = gun_index;
  15466. }
  15467. for (int index = 0; index < CCS_QUANTITY; index++)
  15468. {
  15469. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15470. {
  15471. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15472. }
  15473. }// END OF CCS_QUANTITY
  15474. }
  15475. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15476. {
  15477. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15478. {
  15479. tempIndex = ((gun_index==2) ? 1: 0);
  15480. }
  15481. else
  15482. {
  15483. tempIndex = gun_index;
  15484. }
  15485. for (int index = 0; index < GB_QUANTITY; index++)
  15486. {
  15487. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15488. {
  15489. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15490. }
  15491. }// END OF GB_QUANTITY
  15492. }
  15493. else if(gunType[gun_index] == GUN_TYPE_DO)
  15494. {
  15495. tempIndex = gun_index;
  15496. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15497. {
  15498. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15499. {
  15500. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15501. }
  15502. }
  15503. }
  15504. else
  15505. {
  15506. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15507. {
  15508. tempIndex = 2;
  15509. }
  15510. else
  15511. {
  15512. tempIndex = gun_index;
  15513. }
  15514. for (int index = 0; index < AC_QUANTITY; index++)
  15515. {
  15516. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15517. {
  15518. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15519. }
  15520. }// END OF AC_QUANTITY
  15521. }
  15522. //Stop Transaction Time
  15523. struct timeval tmnow;
  15524. struct tm *tm;
  15525. char buf[28];//, usec_buf[6];
  15526. gettimeofday(&tmnow, NULL);
  15527. time_t t;
  15528. t = time(NULL);
  15529. /*UTC time and date*/
  15530. tm = gmtime(&t);
  15531. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15532. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  15533. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  15534. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15535. random_uuid(guid);
  15536. /***********************************transactionData******************************************************/
  15537. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15539. //=================================
  15540. //1. Transaction_Begin
  15541. //=================================
  15542. //============================== Energy.Active.Import.Interval ===========================================
  15543. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15544. {
  15545. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15546. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15548. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  15549. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15550. 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))
  15551. {
  15552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15553. }
  15554. else
  15555. {
  15556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15557. }
  15558. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15560. }
  15561. //=================================
  15562. //2. Transaction_End
  15563. //=================================
  15564. //2.1====================================== Current.Import L1 ==============================================
  15565. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15566. {
  15567. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15568. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15569. {
  15570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15571. {
  15572. tempIndex = ((gun_index==2) ? 1: 0);
  15573. }
  15574. else
  15575. {
  15576. tempIndex = gun_index;
  15577. }
  15578. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15579. {
  15580. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15581. {
  15582. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15583. }
  15584. }// End of for CHAdeMO_QUANTITY
  15585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15586. }
  15587. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15588. {
  15589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15590. {
  15591. tempIndex = ((gun_index==2) ? 1: 0);
  15592. }
  15593. else
  15594. {
  15595. tempIndex = gun_index;
  15596. }
  15597. for (int index = 0; index < CCS_QUANTITY; index++)
  15598. {
  15599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15600. {
  15601. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15602. }
  15603. }// End of for CCS_QUANTITY
  15604. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15605. }
  15606. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15607. {
  15608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15609. {
  15610. tempIndex = ((gun_index==2) ? 1: 0);
  15611. }
  15612. else
  15613. {
  15614. tempIndex = gun_index;
  15615. }
  15616. for (int index = 0; index < GB_QUANTITY; index++)
  15617. {
  15618. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15619. {
  15620. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15621. }
  15622. }// End of for GB_QUANTITY
  15623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15624. }
  15625. else if(gunType[gun_index] == GUN_TYPE_DO)
  15626. {
  15627. tempIndex = gun_index;
  15628. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15629. {
  15630. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15631. {
  15632. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15633. }
  15634. }
  15635. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15636. }
  15637. else
  15638. {
  15639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15640. {
  15641. tempIndex = 2;
  15642. }
  15643. else
  15644. {
  15645. tempIndex = gun_index;
  15646. }
  15647. for (int index = 0; index < AC_QUANTITY; index++)
  15648. {
  15649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15650. {
  15651. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15652. }
  15653. }// End of for AC_QUANTITY
  15654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15655. }
  15656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15659. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15661. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15662. }
  15663. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15664. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15665. {
  15666. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15667. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15668. {
  15669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15670. {
  15671. tempIndex = ((gun_index==2) ? 1: 0);
  15672. }
  15673. else
  15674. {
  15675. tempIndex = gun_index;
  15676. }
  15677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15678. {
  15679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15680. {
  15681. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15682. }
  15683. }// END OF CHAdeMO_QUANTITY
  15684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15685. }
  15686. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15687. {
  15688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15689. {
  15690. tempIndex = ((gun_index==2) ? 1: 0);
  15691. }
  15692. else
  15693. {
  15694. tempIndex = gun_index;
  15695. }
  15696. for (int index = 0; index < CCS_QUANTITY; index++)
  15697. {
  15698. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15699. {
  15700. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15701. }
  15702. }// END OF CCS_QUANTITY
  15703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15704. }
  15705. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15706. {
  15707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15708. {
  15709. tempIndex = ((gun_index==2) ? 1: 0);
  15710. }
  15711. else
  15712. {
  15713. tempIndex = gun_index;
  15714. }
  15715. for (int index = 0; index < GB_QUANTITY; index++)
  15716. {
  15717. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15718. {
  15719. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15720. }
  15721. }// END OF GB_QUANTITY
  15722. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15723. }
  15724. else if(gunType[gun_index] == GUN_TYPE_DO)
  15725. {
  15726. tempIndex = gun_index;
  15727. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15728. {
  15729. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15730. {
  15731. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15732. }
  15733. }
  15734. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15735. }
  15736. else
  15737. {
  15738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15739. {
  15740. tempIndex = 2;
  15741. }
  15742. else
  15743. {
  15744. tempIndex = gun_index;
  15745. }
  15746. for (int index = 0; index < AC_QUANTITY; index++)
  15747. {
  15748. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15749. {
  15750. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15751. }
  15752. }// END OF AC_QUANTITY
  15753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15754. }
  15755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15756. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15757. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15758. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15761. }
  15762. //2.3====================================== Power.Active.Import =========================================
  15763. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15764. {
  15765. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15766. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15767. {
  15768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15769. {
  15770. tempIndex = ((gun_index==2) ? 1: 0);
  15771. }
  15772. else
  15773. {
  15774. tempIndex = gun_index;
  15775. }
  15776. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15777. {
  15778. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15779. {
  15780. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15781. }
  15782. } // End for CHAdeMO_QUANTITY
  15783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15784. }
  15785. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15786. {
  15787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15788. {
  15789. tempIndex = ((gun_index==2) ? 1: 0);
  15790. }
  15791. else
  15792. {
  15793. tempIndex = gun_index;
  15794. }
  15795. for (int index = 0; index < CCS_QUANTITY; index++)
  15796. {
  15797. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15798. {
  15799. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15800. }
  15801. } // END for CCS_QUANTITY
  15802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15803. }
  15804. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15805. {
  15806. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15807. {
  15808. tempIndex = ((gun_index==2) ? 1: 0);
  15809. }
  15810. else
  15811. {
  15812. tempIndex = gun_index;
  15813. }
  15814. for (int index = 0; index < GB_QUANTITY; index++)
  15815. {
  15816. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15817. {
  15818. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15819. }
  15820. }// END for GB_QUANTITY
  15821. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15822. }
  15823. else if(gunType[gun_index] == GUN_TYPE_DO)
  15824. {
  15825. tempIndex = gun_index;
  15826. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15827. {
  15828. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15829. {
  15830. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15831. }
  15832. }
  15833. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15834. }
  15835. else
  15836. {
  15837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15838. {
  15839. tempIndex = 2;
  15840. }
  15841. else
  15842. {
  15843. tempIndex = gun_index;
  15844. }
  15845. for (int index = 0; index < AC_QUANTITY; index++)
  15846. {
  15847. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15848. {
  15849. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15850. }
  15851. } // END for AC_QUANTITY
  15852. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15853. }
  15854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15855. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15856. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15857. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15860. }
  15861. //2.4====================================== Voltage L1 ====================================================
  15862. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15863. {
  15864. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15865. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15866. {
  15867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15868. {
  15869. tempIndex = ((gun_index==2) ? 1: 0);
  15870. }
  15871. else
  15872. {
  15873. tempIndex = gun_index;
  15874. }
  15875. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15876. {
  15877. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15878. {
  15879. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15880. }
  15881. } // END OF FOR CHAdeMO_QUANTITY
  15882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15883. }
  15884. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15885. {
  15886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15887. {
  15888. tempIndex = ((gun_index==2) ? 1: 0);
  15889. }
  15890. else
  15891. {
  15892. tempIndex = gun_index;
  15893. }
  15894. for (int index = 0; index < CCS_QUANTITY; index++)
  15895. {
  15896. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15897. {
  15898. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15899. }
  15900. } // END OF FOR CCS_QUANTITY
  15901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15902. }
  15903. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15904. {
  15905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15906. {
  15907. tempIndex = ((gun_index==2) ? 1: 0);
  15908. }
  15909. else
  15910. {
  15911. tempIndex = gun_index;
  15912. }
  15913. for (int index = 0; index < GB_QUANTITY; index++)
  15914. {
  15915. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15916. {
  15917. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15918. }
  15919. } // END OF FOR GB_QUANTITY
  15920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15921. }
  15922. else if(gunType[gun_index] == GUN_TYPE_DO)
  15923. {
  15924. tempIndex = gun_index;
  15925. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15926. {
  15927. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15928. {
  15929. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15930. }
  15931. }
  15932. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15933. }
  15934. else
  15935. {
  15936. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15937. {
  15938. tempIndex = 2;
  15939. }
  15940. else
  15941. {
  15942. tempIndex = gun_index;
  15943. }
  15944. for (int index = 0; index < AC_QUANTITY; index++)
  15945. {
  15946. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15947. {
  15948. 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
  15949. }
  15950. } // END OF FOR AC_QUANTITY
  15951. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15952. }
  15953. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15954. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15956. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15958. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15959. }
  15960. //2.5============================================== End SoC =========================================================
  15961. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  15962. {
  15963. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15964. 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))
  15965. {
  15966. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15967. {
  15968. tempIndex = ((gun_index==2) ? 1: 0);
  15969. }
  15970. else
  15971. {
  15972. tempIndex = gun_index;
  15973. }
  15974. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15975. {
  15976. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15977. {
  15978. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15979. {
  15980. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15981. }
  15982. }
  15983. }
  15984. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15985. {
  15986. for (int index = 0; index < CCS_QUANTITY; index++)
  15987. {
  15988. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15989. {
  15990. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15991. }
  15992. }
  15993. }
  15994. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15995. {
  15996. for (int index = 0; index < GB_QUANTITY; index++)
  15997. {
  15998. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15999. {
  16000. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16001. }
  16002. }
  16003. }
  16004. else if(gunType[gun_index] == GUN_TYPE_DO)
  16005. {
  16006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16007. {
  16008. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16009. {
  16010. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16011. }
  16012. }
  16013. }
  16014. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16015. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16020. } // END FOR DC CASE
  16021. }
  16022. //2.6====================================== Current.Import L2 ==============================================
  16023. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16024. {
  16025. // AC 3 phase L2 current
  16026. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16027. {
  16028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16029. {
  16030. tempIndex = 2;
  16031. }
  16032. else
  16033. {
  16034. tempIndex = gun_index;
  16035. }
  16036. for (int index = 0; index < AC_QUANTITY; index++)
  16037. {
  16038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16039. {
  16040. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16041. }
  16042. }// End of for AC_QUANTITY
  16043. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16044. }
  16045. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16046. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16047. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16048. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16049. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16050. }
  16051. //2.7====================================== Current.Import L3 ==============================================
  16052. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16053. {
  16054. // AC 3 phase L3 current
  16055. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16056. {
  16057. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16058. {
  16059. tempIndex = 2;
  16060. }
  16061. else
  16062. {
  16063. tempIndex = gun_index;
  16064. }
  16065. for (int index = 0; index < AC_QUANTITY; index++)
  16066. {
  16067. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16068. {
  16069. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16070. }
  16071. }// End of for AC_QUANTITY
  16072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16073. }
  16074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16075. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16076. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16078. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16079. }
  16080. //2.9====================================== Voltage L2 ====================================================
  16081. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16082. {
  16083. // AC 3 phase L2 volatge
  16084. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16085. {
  16086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16087. {
  16088. tempIndex = 2;
  16089. }
  16090. else
  16091. {
  16092. tempIndex = gun_index;
  16093. }
  16094. for (int index = 0; index < AC_QUANTITY; index++)
  16095. {
  16096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16097. {
  16098. 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
  16099. }
  16100. } // END OF FOR AC_QUANTITY
  16101. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16102. }
  16103. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16108. }
  16109. //2.10====================================== Voltage L3 ====================================================
  16110. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16111. {
  16112. // AC 3 phase L3 volatge
  16113. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16114. {
  16115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16116. {
  16117. tempIndex = 2;
  16118. }
  16119. else
  16120. {
  16121. tempIndex = gun_index;
  16122. }
  16123. for (int index = 0; index < AC_QUANTITY; index++)
  16124. {
  16125. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16126. {
  16127. 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
  16128. }
  16129. } // END OF FOR AC_QUANTITY
  16130. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16131. }
  16132. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16133. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16134. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16135. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16136. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16137. }
  16138. //====================== Start SoC ================================
  16139. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16140. {
  16141. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16142. 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))
  16143. {
  16144. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16145. {
  16146. tempIndex = ((gun_index==2) ? 1: 0);
  16147. }
  16148. else
  16149. {
  16150. tempIndex = gun_index;
  16151. }
  16152. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16153. {
  16154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16155. {
  16156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16157. {
  16158. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16159. }
  16160. }
  16161. }
  16162. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16163. {
  16164. for (int index = 0; index < CCS_QUANTITY; index++)
  16165. {
  16166. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16167. {
  16168. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16169. }
  16170. }
  16171. }
  16172. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16173. {
  16174. for (int index = 0; index < GB_QUANTITY; index++)
  16175. {
  16176. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16177. {
  16178. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16179. }
  16180. }
  16181. }
  16182. else if(gunType[gun_index] == GUN_TYPE_DO)
  16183. {
  16184. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16185. {
  16186. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16187. {
  16188. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16189. }
  16190. }
  16191. }
  16192. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16193. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16194. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16195. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16196. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16197. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16198. } // END FOR DC CASE
  16199. }
  16200. //======================================== Message create ==============================================
  16201. json_object *StopTransaction = json_object_new_object();
  16202. json_object *transactionDatas = json_object_new_array();
  16203. json_object *sampledValues = json_object_new_array();
  16204. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  16205. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  16206. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  16207. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  16208. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  16209. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16210. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  16211. {
  16212. json_object *transactionData = json_object_new_object();
  16213. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16214. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16215. {
  16216. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16217. {
  16218. json_object *sampledValue = json_object_new_object();
  16219. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16220. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16221. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16222. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16223. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16224. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16225. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16226. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16227. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16228. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16229. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16230. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16231. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16232. json_object_array_add(sampledValues, sampledValue);
  16233. }
  16234. }
  16235. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16236. json_object_array_add(transactionDatas, transactionData);
  16237. }
  16238. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16239. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16240. ,MESSAGE_TYPE_CALL
  16241. ,guid
  16242. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16243. json_object_put(StopTransaction);
  16244. // Check File "TempStopTransaction" Exist
  16245. if((access(TempStopTransaction,F_OK))!=-1)
  16246. {
  16247. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16248. fclose(fopen(TempStopTransaction, "w"));
  16249. }
  16250. else
  16251. {
  16252. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16253. FILE *log = fopen(TempStopTransaction, "w+");
  16254. if(log == NULL)
  16255. {
  16256. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16257. return ;
  16258. }
  16259. else
  16260. {
  16261. fclose(log);
  16262. }
  16263. }
  16264. //Add TempStopTransaction | Update TempStopTransaction
  16265. // open file for writing
  16266. FILE *outfile;
  16267. outfile = fopen (TempStopTransaction, "a");
  16268. //DEBUG_INFO("data = %s\n", queuedata);
  16269. fputs(queuedata, outfile);
  16270. fputs("\n", outfile);
  16271. fclose (outfile);
  16272. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16273. }
  16274. void checkTempStopTransaction(int gun_index)
  16275. {
  16276. FILE *fptr1;
  16277. char ch;
  16278. char str[QUEUE_MESSAGE_LENGTH]={0};
  16279. char guid[37]={0};
  16280. char tempdata[65]={0};
  16281. char connectorStr[2]={0};
  16282. char TempStopTransaction[256];
  16283. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16284. fptr1 = fopen(TempStopTransaction, "r");
  16285. //TempStopTransaction格式: 槍號,StopTransaction封包
  16286. if (!fptr1)
  16287. {
  16288. //printf(" File not found or unable to open the input file!!\n");
  16289. return ;
  16290. }
  16291. ch=fgetc(fptr1);
  16292. //printf(" Now the content of the file %s is : \n",fname);
  16293. rewind(fptr1);
  16294. if(ch!=EOF)
  16295. {
  16296. // copy all contents to the temporary file except the specific line
  16297. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16298. {
  16299. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16300. if(str[0]=='\0')
  16301. {
  16302. break;
  16303. }
  16304. //TempStopTransaction格式: 槍號,StopTransaction封包
  16305. strncpy(connectorStr, str, 1);
  16306. if(atoi(connectorStr) != (gun_index+1))
  16307. {
  16308. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16309. fclose(fptr1);
  16310. return ;
  16311. }
  16312. //random_uuid(guid);
  16313. strncpy(guid, str+6, 36); //copy guid
  16314. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16315. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16316. {
  16317. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16318. }
  16319. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16320. OCPP_insert_transaction_msg(NO, str);
  16321. memset(str,0,ARRAY_SIZE(str));
  16322. }
  16323. }
  16324. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16325. fclose(fptr1);
  16326. remove(TempStopTransaction); // remove the original file
  16327. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16328. }
  16329. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16330. {
  16331. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16332. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16333. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16334. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16335. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16336. }
  16337. int GetWebSocketPingInterval(void)
  16338. {
  16339. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16340. }
  16341. int GetServerSign(void)
  16342. {
  16343. return server_sign;
  16344. }
  16345. uint8_t GetOcppSecurityProfile()
  16346. {
  16347. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16348. }
  16349. void GetOcppChargerBoxId(uint8_t *data)
  16350. {
  16351. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  16352. }
  16353. void GetOcppSecurityPassword(uint8_t *data)
  16354. {
  16355. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16356. }
  16357. void SetOcppVersion(uint8_t *version)
  16358. {
  16359. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16360. DEBUG_INFO("ocpp version: %s\n", version);
  16361. if(strstr((char*)version, "ocpp1.6") != NULL)
  16362. {
  16363. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16364. }
  16365. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16366. {
  16367. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16368. system("pkill OcppBackend");
  16369. }
  16370. }
  16371. void SetServerSign(int value)
  16372. {
  16373. server_sign = value;
  16374. }
  16375. int GetBootNotificationInterval(void)
  16376. {
  16377. return BootNotificationInterval;
  16378. }
  16379. int GetInternetConn(void)
  16380. {
  16381. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16382. }
  16383. int GetBackendConnectionTimeout(void)
  16384. {
  16385. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16386. }
  16387. int isConnectorInitMode(int gun_index)
  16388. {
  16389. int tempIndex = 0;
  16390. int result = TRUE;
  16391. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16392. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16393. {
  16394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16395. {
  16396. tempIndex = ((gun_index==2) ? 1: 0);
  16397. }
  16398. else
  16399. {
  16400. tempIndex = gun_index;
  16401. }
  16402. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16403. {
  16404. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16405. {
  16406. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16407. } //end of the same index
  16408. }//end of for CHAdeMO_QUANTITY
  16409. }
  16410. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16411. {
  16412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16413. {
  16414. tempIndex = ((gun_index==2) ? 1: 0);
  16415. }
  16416. else
  16417. {
  16418. tempIndex = gun_index;
  16419. }
  16420. for (int index = 0; index < CCS_QUANTITY; index++)
  16421. {
  16422. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16423. {
  16424. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16425. } //end of the same index
  16426. } // end of for CCS_QUANTITY
  16427. }
  16428. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16429. {
  16430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16431. {
  16432. tempIndex = ((gun_index==2) ? 1: 0);
  16433. }
  16434. else
  16435. {
  16436. tempIndex = gun_index;
  16437. }
  16438. for (int index = 0; index < GB_QUANTITY; index++)
  16439. {
  16440. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16441. {
  16442. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16443. } //end of the same index
  16444. } // end of for GB_QUANTITY
  16445. }
  16446. else if(gunType[gun_index] == GUN_TYPE_DO)
  16447. {
  16448. tempIndex = gun_index;
  16449. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16450. {
  16451. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16452. {
  16453. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16454. } //end of the same index
  16455. }
  16456. }
  16457. else
  16458. {
  16459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16460. {
  16461. tempIndex = 2;
  16462. }
  16463. else
  16464. {
  16465. tempIndex = gun_index;
  16466. }
  16467. for (int index = 0; index < AC_QUANTITY; index++)
  16468. {
  16469. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16470. {
  16471. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16472. }//end of the same index
  16473. }//end of for AC_QUANTITY
  16474. }
  16475. return result;
  16476. }
  16477. void refreshProcDogTimer()
  16478. {
  16479. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  16480. }
  16481. void InitialSystemValue(void)
  16482. {
  16483. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16484. locallistVersion=0;
  16485. BootNotificationInterval = 0;
  16486. authorizeRetryTimes = 0;
  16487. GunStatusInterval = 10;
  16488. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16489. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16490. //Hear Beat
  16491. HeartBeatWithNOResponse = 0;
  16492. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16493. FirstHeartBeat = 0;
  16494. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16495. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16496. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16497. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16498. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16499. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16500. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16501. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16502. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16503. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16504. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16505. //Status && ConnectorPlugIn Setting
  16506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16507. {
  16508. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16509. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16510. }
  16511. for (int index = 0; index < CCS_QUANTITY; index++)
  16512. {
  16513. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16514. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16515. }
  16516. for (int index = 0; index < GB_QUANTITY; index++)
  16517. {
  16518. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16519. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16520. }
  16521. for (int index = 0; index < AC_QUANTITY; index++)
  16522. {
  16523. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16524. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16525. }
  16526. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16527. {
  16528. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16529. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16530. }
  16531. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16532. {
  16533. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16534. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16535. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16536. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16537. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16538. }
  16539. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16540. clientTime.Heartbeat=time((time_t*)NULL);
  16541. sleep(1);
  16542. }
  16543. void LWS_Send(char *str)
  16544. {
  16545. //=====================================================
  16546. // Check InternetConn 0: disconnected, 1: connected
  16547. //====================================================
  16548. if(GetOcppConnStatus() == 0)
  16549. {
  16550. DEBUG_INFO("offline now !!!\n");
  16551. return;
  16552. }
  16553. // Only disable isWebsocketSendable operation initiated by charger
  16554. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16555. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16556. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16557. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16558. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16559. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16560. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16561. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16562. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16563. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16564. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16565. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16566. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16567. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16568. {
  16569. isWebsocketSendable = 0;
  16570. }
  16571. pthread_mutex_lock(&lock_send);
  16572. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16573. sprintf((char *)SendBuffer, "%s", str);
  16574. SendBufLen = strlen(str);
  16575. pthread_mutex_unlock(&lock_send);
  16576. lws_callback_on_writable(wsi_client);
  16577. //lws_service(context, 0);
  16578. //sleep(1);
  16579. }
  16580. void LWS_SendNow(char *str)
  16581. {
  16582. //=====================================================
  16583. // Check InternetConn 0: disconnected, 1: connected
  16584. //====================================================
  16585. if(GetOcppConnStatus() == 0)
  16586. {
  16587. DEBUG_INFO("offline now !!!\n");
  16588. return;
  16589. }
  16590. // Only disable isWebsocketSendable operation initiated by charger
  16591. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16592. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16593. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16594. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16595. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16596. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16597. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16598. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16599. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16600. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16601. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16602. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16603. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16604. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16605. {
  16606. isWebsocketSendable = 0;
  16607. }
  16608. pthread_mutex_lock(&lock_send);
  16609. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16610. sprintf((char *)SendBuffer, "%s", str);
  16611. SendBufLen = strlen(str);
  16612. pthread_mutex_unlock(&lock_send);
  16613. lws_callback_on_writable(wsi_client);
  16614. lws_service(context, 0);
  16615. //sleep(1);
  16616. }