MessageHandler.c 944 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  56. //========================================
  57. // OCPP status/previous related variables
  58. //========================================
  59. static int GunStatusInterval = 10;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //=============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. extern sqlite3 *db;
  91. int TransactionMessageAttemptsGet(void);
  92. int TransactionMessageRetryIntervalGet(void);
  93. int GetOcppConnStatus(void);
  94. void SetOcppConnStatus(uint8_t status);
  95. int setKeyValue(char *key, char *value);
  96. void OCPP_get_TableAuthlocalAllData(void);
  97. void processUnkownKey(void);
  98. struct InterLock
  99. {
  100. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  101. unsigned char isGetDiagnosticGoing:1;
  102. unsigned char isUpdateFirmwareGoing:1;
  103. }interLock;
  104. struct ClientTime
  105. {
  106. struct timespec Heartbeat;
  107. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  108. struct timespec StartTransaction;
  109. struct timespec StopTransaction;
  110. struct timespec MeterValues[CONNECTOR_QUANTITY];
  111. struct timespec RemoteStartWait;
  112. struct timespec TcciQueryDeduct;
  113. }clientTime;
  114. typedef union
  115. {
  116. //Operations Initiated by Central System
  117. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  118. struct
  119. {
  120. //CsMsgValue[0]
  121. unsigned char StatusNotificationReq:1; //bit 0,
  122. unsigned char StatusNotificationConf:1; //bit 1,
  123. unsigned char TriggerMeterValue:1; //bit 2,
  124. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  125. unsigned char isOnCharging:1; //bit 4.
  126. unsigned char :3; //bit 5~7
  127. }bits[CONNECTOR_QUANTITY];
  128. }CpinitiateMsg;
  129. CpinitiateMsg cpinitateMsg;
  130. //GetConfiguration Array
  131. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  134. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  135. #if 0
  136. static char *ChargePointErrorCodeStr[] = {
  137. MACROSTR(ConnectorLockFailure),
  138. MACROSTR(EVCommunicationError),
  139. MACROSTR(GroundFailure),
  140. MACROSTR(HighTemperature),
  141. MACROSTR(InternalError),
  142. MACROSTR(LocalListConflict),
  143. MACROSTR(NoError),
  144. MACROSTR(OtherError),
  145. MACROSTR(OverCurrentFailure),
  146. MACROSTR(OverVoltage),
  147. MACROSTR(PowerMeterFailure),
  148. MACROSTR(PowerSwitchFailure),
  149. MACROSTR(ReaderFailure),
  150. MACROSTR(ResetFailure),
  151. MACROSTR(UnderVoltage),
  152. MACROSTR(WeakSignal)
  153. };
  154. #endif
  155. static char * ChargePointStatusStr[] = {
  156. MACROSTR(Available),
  157. MACROSTR(Preparing),
  158. MACROSTR(Charging),
  159. MACROSTR(SuspendedEVSE),
  160. MACROSTR(SuspendedEV),
  161. MACROSTR(Finishing),
  162. MACROSTR(Reserved),
  163. MACROSTR(Unavailable),
  164. MACROSTR(Faulted)
  165. };
  166. static char *RegistrationStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Pending),
  169. MACROSTR(Rejected)
  170. };
  171. static char *AvailabilityTypeStr[] = {
  172. MACROSTR(Inoperative),
  173. MACROSTR(Operative)
  174. };
  175. static char *AvailabilityStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected),
  178. MACROSTR(Scheduled)
  179. };
  180. static char *ConfigurationStatusStr[] = {
  181. MACROSTR(Accepted),
  182. MACROSTR(Rejected),
  183. MACROSTR(RebootRequired),
  184. MACROSTR(NotSupported)
  185. };
  186. static char *ClearCacheStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected)
  189. };
  190. static char *ChargingProfilePurposeTypeStr[] = {
  191. MACROSTR(ChargePointMaxProfile),
  192. MACROSTR(TxDefaultProfile),
  193. MACROSTR(TxProfile)
  194. };
  195. static char *ChargingProfileStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected),
  198. MACROSTR(NotSupported)
  199. };
  200. static char *ClearChargingProfileStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Unknown)
  203. };
  204. static char *GetCompositeScheduleStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Rejected)
  207. };
  208. static char *UpdateTypeStr[] = {
  209. MACROSTR(Differential),
  210. MACROSTR(Full)
  211. };
  212. static char *UpdateStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Failed),
  215. MACROSTR(NotSupported),
  216. MACROSTR(VersionMismatch)
  217. };
  218. static char *RemoteStartStopStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Rejected)
  221. };
  222. static char *ReservationStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Faulted),
  225. MACROSTR(Occupied),
  226. MACROSTR(Rejected),
  227. MACROSTR(Unavailable)
  228. };
  229. static char *ResetTypeStr[] = {
  230. MACROSTR(Hard),
  231. MACROSTR(Soft)
  232. };
  233. static char *ResetStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected)
  236. };
  237. static char * DiagnosticsStatusStr[] = {
  238. MACROSTR(Idle),
  239. MACROSTR(Uploaded),
  240. MACROSTR(UploadFailed),
  241. MACROSTR(Uploading)
  242. };
  243. static char * FirmwareStatusStr[] = {
  244. MACROSTR(Downloaded),
  245. MACROSTR(DownloadFailed),
  246. MACROSTR(Downloading),
  247. MACROSTR(Idle),
  248. MACROSTR(InstallationFailed),
  249. MACROSTR(Installing),
  250. MACROSTR(Installed)
  251. };
  252. static char * MessageTriggerStr[] = {
  253. MACROSTR(BootNotification),
  254. MACROSTR(DiagnosticsStatusNotification),
  255. MACROSTR(FirmwareStatusNotification),
  256. MACROSTR(Heartbeat),
  257. MACROSTR(MeterValues),
  258. MACROSTR(StatusNotification)
  259. };
  260. static char * TriggerMessageStatusStr[] = {
  261. MACROSTR(Accepted),
  262. MACROSTR(Rejected),
  263. MACROSTR(NotImplemented)
  264. };
  265. static char * UnlockStatusStr[] = {
  266. MACROSTR(Unlocked),
  267. MACROSTR(UnlockFailed),
  268. MACROSTR(NotSupported)
  269. };
  270. #if 0
  271. static char * StopTransactionReasonStr[] = {
  272. MACROSTR(EmergencyStop),
  273. MACROSTR(EVDisconnected),
  274. MACROSTR(HardReset),
  275. MACROSTR(Local),
  276. MACROSTR(Other),
  277. MACROSTR(PowerLoss),
  278. MACROSTR(Reboot),
  279. MACROSTR(Remote),
  280. MACROSTR(SoftReset),
  281. MACROSTR(UnlockCommand),
  282. MACROSTR(DeAuthorized)
  283. };
  284. #endif
  285. static char * CancelReservationStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. static char * ReadingContextStr[] = {
  290. MACROSTR(Interruption.Begin),
  291. MACROSTR(Interruption.End),
  292. MACROSTR(Other),
  293. MACROSTR(Sample.Clock),
  294. MACROSTR(Sample.Periodic),
  295. MACROSTR(Transaction.Begin),
  296. MACROSTR(Transaction.End),
  297. MACROSTR(Trigger)
  298. };
  299. static char * ValueFormatStr[] = {
  300. MACROSTR(Raw),
  301. MACROSTR(SignedData)
  302. };
  303. static char * MeasurandStr[] = {
  304. MACROSTR(Current.Export),
  305. MACROSTR(Current.Import),
  306. MACROSTR(Current.Offered),
  307. MACROSTR(Energy.Active.Export.Register),
  308. MACROSTR(Energy.Active.Import.Register),
  309. MACROSTR(Energy.Reactive.Export.Register),
  310. MACROSTR(Energy.Reactive.Import.Register),
  311. MACROSTR(Energy.Active.Export.Interval),
  312. MACROSTR(Energy.Active.Import.Interval),
  313. MACROSTR(Energy.Reactive.Export.Interval),
  314. MACROSTR(Energy.Reactive.Import.Interval),
  315. MACROSTR(Frequency),
  316. MACROSTR(Power.Active.Export),
  317. MACROSTR(Power.Active.Import),
  318. MACROSTR(Power.Factor),
  319. MACROSTR(Power.Offered),
  320. MACROSTR(Power.Reactive.ExportMACROSTR),
  321. MACROSTR(Power.Reactive.Import),
  322. MACROSTR(RPM),
  323. MACROSTR(SoC),
  324. MACROSTR(Temperature),
  325. MACROSTR(Voltage)
  326. };
  327. static char * LocationStr[] = {
  328. MACROSTR(Body),
  329. MACROSTR(Cable),
  330. MACROSTR(EV),
  331. MACROSTR(Inlet),
  332. MACROSTR(Outlet)
  333. };
  334. static char * PhaseStr[] = {
  335. MACROSTR(L1),
  336. MACROSTR(L2),
  337. MACROSTR(L3),
  338. MACROSTR(N),
  339. MACROSTR(L1-N),
  340. MACROSTR(L2-N),
  341. MACROSTR(L3-N),
  342. MACROSTR(L1-L2),
  343. MACROSTR(L2-L3),
  344. MACROSTR(L3-L1)
  345. };
  346. static char * UnitOfMeasureStr[] = {
  347. MACROSTR(Wh),
  348. MACROSTR(kWh),
  349. MACROSTR(varh),
  350. MACROSTR(kvarh),
  351. MACROSTR(W),
  352. MACROSTR(kW),
  353. MACROSTR(VA),
  354. MACROSTR(kVA),
  355. MACROSTR(var),
  356. MACROSTR(kvar),
  357. MACROSTR(A),
  358. MACROSTR(V),
  359. MACROSTR(Celsius),
  360. MACROSTR(Fahrenheit),
  361. MACROSTR(K),
  362. MACROSTR(Percent)
  363. };
  364. //=========================================
  365. // Save configuration
  366. //=========================================
  367. int runShellCmd(const char*cmd)
  368. {
  369. int result = FAIL;
  370. char buf[256];
  371. FILE *fp;
  372. fp = popen(cmd, "r");
  373. if(fp != NULL)
  374. {
  375. while(fgets(buf, sizeof(buf), fp) != NULL)
  376. {
  377. DEBUG_INFO("%s\n", buf);
  378. }
  379. result = PASS;
  380. }
  381. pclose(fp);
  382. return result;
  383. }
  384. int StoreUsrConfigData(struct SysConfigData *UsrData)
  385. {
  386. int result = PASS;
  387. int fd,wrd;
  388. unsigned int i,Chk;
  389. unsigned char *ptr, *BufTmp;
  390. int MtdBlockSize = 0x300000;
  391. Chk=0;
  392. ptr=(unsigned char *)UsrData;
  393. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  394. {
  395. memset(BufTmp,0,MtdBlockSize);
  396. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  397. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  398. Chk+=*(BufTmp+i);
  399. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  400. // Output configuration to file.
  401. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  402. if (fd < 0)
  403. {
  404. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  405. free(BufTmp);
  406. return 0;
  407. }
  408. wrd=write(fd, BufTmp, MtdBlockSize);
  409. close(fd);
  410. if(wrd<MtdBlockSize)
  411. {
  412. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  413. free(BufTmp);
  414. return 0;
  415. }
  416. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  417. DEBUG_INFO("Erase /dev/mtd10.\n");
  418. runShellCmd("flash_erase /dev/mtd10 0 0");
  419. DEBUG_INFO("Write /dev/mtd10.\n");
  420. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  421. DEBUG_INFO("Erase /dev/mtd11.\n");
  422. runShellCmd("flash_erase /dev/mtd11 0 0");
  423. DEBUG_INFO("Write /dev/mtd11.\n");
  424. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  425. system("rm -f /mnt/EvseConfig.bin");
  426. DEBUG_INFO("EvseConfig write to flash OK\n");
  427. }
  428. else
  429. {
  430. DEBUG_ERROR("alloc BlockSize NG\r\n");
  431. result = FAIL;
  432. }
  433. if(BufTmp!=NULL)
  434. free(BufTmp);
  435. return result;
  436. }
  437. //=========================================
  438. // Sqlite3 related function
  439. //=========================================
  440. static int selectSqlCount = 0;
  441. static int callback(void *data, int argc, char **argv, char **azColName){
  442. int i;
  443. //printf("%s: ", (const char*)data);
  444. selectSqlCount = argc;
  445. for(i = 0; i<argc; i++){
  446. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  447. }
  448. //printf("\n");
  449. return 0;
  450. }
  451. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  452. //int i;
  453. //printf("%s:\n", (const char*)data);
  454. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  455. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  456. return 0;
  457. }
  458. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  459. //printf("%s:\n", (const char*)data);
  460. //idTag
  461. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  462. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  463. //parentIdTag
  464. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  465. //expir_date
  466. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  467. //status
  468. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  469. //version
  470. if(columenCount > 5)
  471. idTagQuery.listVersionInt = atoi(columnValue[5]);
  472. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  473. return 0;
  474. }
  475. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  476. {
  477. // localversion = argv[5] ? atoi(argv[5]) : 0;
  478. // printf("localversion=%d\n", localversion);
  479. return 0;
  480. }
  481. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  482. {
  483. for (int i = 0; i < n_columns; i++)
  484. {
  485. DEBUG_INFO("%s\t", col_values[i]);
  486. }
  487. DEBUG_INFO("\n");
  488. return 0;
  489. }
  490. int OCPP_cleanLocalCache()
  491. {
  492. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  493. char *errMsg = 0;
  494. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  495. if (SQLITE_OK != rc)
  496. {
  497. DEBUG_INFO("SQL error: %s\n",errMsg);
  498. return FALSE;
  499. }
  500. return TRUE;
  501. }
  502. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  503. {
  504. int isSuccess = TRUE;
  505. int ret = 0;
  506. //const char* data = "Callback function called";
  507. char sql[300];
  508. char zErrMsg[200];
  509. memset(sql, 0, 300);
  510. memset(zErrMsg, 0, 200);
  511. 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);
  512. //* Execute SQL statement */
  513. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  514. if( ret != SQLITE_OK )
  515. {
  516. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  517. isSuccess = FALSE;
  518. }
  519. return isSuccess;
  520. }
  521. void OCPP_getIdTagFromLocalCache(char idTag[])
  522. {
  523. int rc = 0;
  524. char sql[100];
  525. char zErrMsg[100];
  526. memset(sql, 0, 100);
  527. memset(zErrMsg, 0, 100);
  528. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  529. memset(&idTagQuery, 0, sizeof(idTagQuery));
  530. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  531. /* Execute SQL statement */
  532. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  533. if( rc != SQLITE_OK )
  534. {
  535. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  536. }
  537. }
  538. void OCPP_getListVerion()
  539. {
  540. int rc = 0;
  541. // const char* data = "Callback function called";
  542. char sql[100];
  543. char zErrMsg[100];
  544. memset(sql, 0, 100);
  545. memset(zErrMsg, 0, 100);
  546. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  547. /* Execute SQL statement */
  548. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  549. if( rc != SQLITE_OK )
  550. {
  551. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  552. }
  553. }
  554. void OCPP_get_TableAuthlocalAllData(void)
  555. {
  556. int rc = 0;
  557. char sql[100];
  558. char zErrMsg[100];
  559. memset(sql, 0, 100);
  560. memset(zErrMsg, 0, 100);
  561. sprintf(sql,"select * from ocpp_auth_local ");
  562. /* Execute SQL statement */
  563. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  564. if( rc != SQLITE_OK )
  565. {
  566. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  567. }
  568. //return ver;
  569. }
  570. int OCPP_cleanLocalList()
  571. {
  572. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  573. char *errMsg = 0;
  574. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  575. if (SQLITE_OK != rc)
  576. {
  577. DEBUG_INFO("%s\n",errMsg);
  578. return FALSE;
  579. }
  580. return TRUE;
  581. }
  582. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  583. {
  584. int isSuccess = FALSE;
  585. int ret = 0;
  586. //const char* data = "Callback function called";
  587. char sql[300];
  588. char zErrMsg[200];
  589. memset(sql, 0, 300);
  590. memset(zErrMsg, 0, 200);
  591. 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);
  592. //* Execute SQL statement */
  593. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  594. if( ret != SQLITE_OK )
  595. {
  596. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  597. return isSuccess;
  598. }
  599. memset(sql, 0, 300);
  600. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  601. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  602. if( ret != SQLITE_OK )
  603. {
  604. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  605. return isSuccess;
  606. }
  607. isSuccess = TRUE;
  608. return isSuccess;
  609. }
  610. void OCPP_getIdTagFromLocalList(char idTag[])
  611. {
  612. int rc = 0;
  613. // const char* data = "Callback function called";
  614. char sql[100];
  615. char zErrMsg[100];
  616. memset(sql, 0, 100);
  617. memset(zErrMsg, 0, 100);
  618. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  619. memset(&idTagQuery, 0, sizeof(idTagQuery));
  620. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  621. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  622. /* Execute SQL statement */
  623. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  624. if( rc != SQLITE_OK )
  625. {
  626. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  627. }
  628. //return ver;
  629. }
  630. void OCPP_deleteIdTagFromLocalList(char idTag[])
  631. {
  632. //int ver = 0;
  633. //int isSuccess = FALSE;
  634. int rc = 0;
  635. char sql[100];
  636. char zErrMsg[100];
  637. memset(sql, 0, 100);
  638. memset(zErrMsg, 0, 100);
  639. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  640. //* Execute SQL statement */
  641. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  642. if( rc != SQLITE_OK )
  643. {
  644. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  645. }
  646. }
  647. int getCurrentYear()
  648. {
  649. int result = 0;
  650. time_t CurrentTime;
  651. struct tm *tm;
  652. CurrentTime = time(NULL);
  653. tm=localtime(&CurrentTime);
  654. result = (tm->tm_year + 1900);
  655. return result;
  656. }
  657. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  658. {
  659. int result = PASS;
  660. char* errMsg = NULL;
  661. char sqlStr[8192];
  662. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  663. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  664. {
  665. result = FAIL;
  666. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  667. }
  668. 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));
  669. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  670. {
  671. result = FAIL;
  672. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  673. }
  674. return result;
  675. }
  676. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  677. {
  678. int result = PASS;
  679. char* errMsg = NULL;
  680. char sqlStr[8192];
  681. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  682. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  683. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  684. {
  685. result = FAIL;
  686. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  687. }
  688. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  689. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  690. {
  691. result = FAIL;
  692. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  693. }
  694. return result;
  695. }
  696. int OCPP_update_deduct_info(int txId, char *creditNo)
  697. {
  698. int result = PASS;
  699. char* errMsg = NULL;
  700. char sqlStr[8192];
  701. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  702. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  703. {
  704. result = FAIL;
  705. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  706. }
  707. return result;
  708. }
  709. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  710. {
  711. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  712. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  713. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  714. atoi(columnValue[1]),
  715. columnValue[2],
  716. atoi(columnValue[3])==1?"true":"false",
  717. atoi(columnValue[4])==1?"true":"false",
  718. columnValue[5],
  719. columnValue[9]);
  720. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  721. return 0;
  722. }
  723. void OCPP_query_deduct_info()
  724. {
  725. int rc = 0;
  726. char sql[100];
  727. char zErrMsg[100];
  728. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  729. /* Execute SQL statement */
  730. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  731. if( rc != SQLITE_OK )
  732. {
  733. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  734. }
  735. }
  736. void reportReaderStatus(int gun_index)
  737. {
  738. struct timeval tmnow;
  739. struct tm *tm;
  740. char buf[28];//, usec_buf[6];
  741. gettimeofday(&tmnow, NULL);
  742. time_t t;
  743. t = time(NULL);
  744. /*UTC time and date*/
  745. tm = gmtime(&t);
  746. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  747. #if 0 // remove temporally
  748. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  749. strcat(buf,".");
  750. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  751. strcat(buf,usec_buf);
  752. #endif
  753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  754. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  755. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  756. (gun_index+1),
  757. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  758. buf,
  759. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  760. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  761. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  762. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  763. }
  764. //==========================================
  765. // Check time passed since today
  766. //==========================================
  767. long long DiffTimebWithNow(struct timeb ST)
  768. {
  769. //return milli-second
  770. struct timeb ET;
  771. long long StartTime,StopTime;
  772. ftime(&ET);
  773. StartTime=(long long)ST.time;
  774. StopTime=(long long)ET.time;
  775. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  776. }
  777. int getTimePassSinceToday(uint8_t gun_index)
  778. {
  779. int result = -1;
  780. static time_t lastTime[4];
  781. time_t t;
  782. struct tm *tmStartToday;
  783. struct timeb tbStartToday;
  784. t=time(NULL);
  785. if(difftime(t, lastTime[gun_index])>0)
  786. {
  787. tmStartToday=localtime(&t);
  788. tmStartToday->tm_hour = 0;
  789. tmStartToday->tm_min = 0;
  790. tmStartToday->tm_sec = 0;
  791. tbStartToday.time = mktime(tmStartToday);
  792. tbStartToday.millitm = 0;
  793. result = DiffTimebWithNow(tbStartToday)/1000;
  794. lastTime[gun_index] = t;
  795. }
  796. return result;
  797. }
  798. void getNowDatetime(uint8_t *data)
  799. {
  800. time_t t = time(NULL);
  801. struct tm tm = *localtime(&t);
  802. 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);
  803. }
  804. int syncDateTimeRTC(uint8_t *data)
  805. {
  806. struct ParsingResult
  807. {
  808. int result;
  809. int scanedElement;
  810. int year;
  811. int month;
  812. int mday;
  813. int hour;
  814. int min;
  815. int sec;
  816. int tz_hour;
  817. int tz_min;
  818. float minSec;
  819. }result;
  820. struct tm tmOrg;
  821. struct tm *tmTarget;
  822. struct timeb tbTarget;
  823. char buf[128];
  824. memset(&result, 0x00, sizeof(struct ParsingResult));
  825. result.result = PASS;
  826. if(strstr((char*)data, ".") != NULL)
  827. {
  828. // Original data with mini second
  829. if(strstr((char*)data, "Z") != NULL)
  830. {
  831. // Original data with Z
  832. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  833. &result.year,
  834. &result.month,
  835. &result.mday,
  836. &result.hour,
  837. &result.min,
  838. &result.sec,
  839. &result.minSec);
  840. }
  841. else
  842. {
  843. // Original data without Z
  844. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  845. &result.year,
  846. &result.month,
  847. &result.mday,
  848. &result.hour,
  849. &result.min,
  850. &result.sec,
  851. &result.minSec,
  852. &result.tz_hour,
  853. &result.tz_min);
  854. }
  855. }
  856. else
  857. {
  858. // Original data without mini second
  859. if(strstr((char*)data, "Z") != NULL)
  860. {
  861. // Original data with Z
  862. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  863. &result.year,
  864. &result.month,
  865. &result.mday,
  866. &result.hour,
  867. &result.min,
  868. &result.sec);
  869. }
  870. else
  871. {
  872. // Original data without Z
  873. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  874. &result.year,
  875. &result.month,
  876. &result.mday,
  877. &result.hour,
  878. &result.min,
  879. &result.sec,
  880. &result.tz_hour,
  881. &result.tz_min);
  882. }
  883. }
  884. tmOrg.tm_year = result.year - 1900;
  885. tmOrg.tm_mon = result.month - 1;
  886. tmOrg.tm_mday = result.mday;
  887. tmOrg.tm_hour = result.hour;
  888. tmOrg.tm_min = result.min;
  889. tmOrg.tm_sec = result.sec;
  890. tmOrg.tm_gmtoff = 0;
  891. tbTarget.time = mktime(&tmOrg);
  892. tbTarget.timezone = 0;
  893. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  894. tmTarget = gmtime(&tbTarget.time);
  895. 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);
  896. //DEBUG_INFO(" org date time: %s\n", data);
  897. //DEBUG_INFO("parse date time: %s\n", buf);
  898. system(buf);
  899. system("/sbin/hwclock -w --systohc");
  900. if(result.scanedElement < 6)
  901. result.result = FAIL;
  902. return result.result;
  903. }
  904. //==========================================
  905. // GetCompositeSchedule logic related function
  906. //==========================================
  907. int DiffTimebSec(struct timeb ST, struct timeb ET)
  908. {
  909. //return milli-second
  910. unsigned int StartTime,StopTime;
  911. StartTime=(unsigned int)ST.time;
  912. StopTime=(unsigned int)ET.time;
  913. return (StopTime-StartTime);
  914. }
  915. int DiffTimebWithNowSec(struct timeb ST)
  916. {
  917. //return milli-second
  918. struct timeb ET;
  919. unsigned int StartTime,StopTime;
  920. ftime(&ET);
  921. StartTime=(unsigned int)ST.time;
  922. StopTime=(unsigned int)ET.time;
  923. return (StopTime-StartTime);
  924. }
  925. int getStartStop(uint8_t *start, uint8_t *stop)
  926. {
  927. struct ParsingResult
  928. {
  929. int result;
  930. int scanedElement;
  931. int year;
  932. int month;
  933. int mday;
  934. int hour;
  935. int min;
  936. int sec;
  937. int tz_hour;
  938. int tz_min;
  939. float minSec;
  940. };
  941. struct ParsingResult parseStart;
  942. struct ParsingResult parseStop;
  943. int result = -1;
  944. struct tm tmStart;
  945. struct timeb tbStart;
  946. struct tm tmStop;
  947. struct timeb tbStop;
  948. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  949. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  950. // Scan start & stop date time
  951. if(strstr((char*)start, ".") != NULL)
  952. {
  953. // Original data with mini second
  954. if(strstr((char*)start, "Z") != NULL)
  955. {
  956. // Original data with Z
  957. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  958. &parseStart.year,
  959. &parseStart.month,
  960. &parseStart.mday,
  961. &parseStart.hour,
  962. &parseStart.min,
  963. &parseStart.sec,
  964. &parseStart.minSec);
  965. }
  966. else
  967. {
  968. // Original data without Z
  969. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  970. &parseStart.year,
  971. &parseStart.month,
  972. &parseStart.mday,
  973. &parseStart.hour,
  974. &parseStart.min,
  975. &parseStart.sec,
  976. &parseStart.minSec,
  977. &parseStart.tz_hour,
  978. &parseStart.tz_min);
  979. }
  980. }
  981. else
  982. {
  983. // Original data without mini second
  984. if(strstr((char*)start, "Z") != NULL)
  985. {
  986. // Original data with Z
  987. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  988. &parseStart.year,
  989. &parseStart.month,
  990. &parseStart.mday,
  991. &parseStart.hour,
  992. &parseStart.min,
  993. &parseStart.sec);
  994. }
  995. else
  996. {
  997. // Original data without Z
  998. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  999. &parseStart.year,
  1000. &parseStart.month,
  1001. &parseStart.mday,
  1002. &parseStart.hour,
  1003. &parseStart.min,
  1004. &parseStart.sec,
  1005. &parseStart.tz_hour,
  1006. &parseStart.tz_min);
  1007. }
  1008. }
  1009. if(strstr((char*)stop, ".") != NULL)
  1010. {
  1011. // Original data with mini second
  1012. if(strstr((char*)stop, "Z") != NULL)
  1013. {
  1014. // Original data with Z
  1015. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1016. &parseStop.year,
  1017. &parseStop.month,
  1018. &parseStop.mday,
  1019. &parseStop.hour,
  1020. &parseStop.min,
  1021. &parseStop.sec,
  1022. &parseStop.minSec);
  1023. }
  1024. else
  1025. {
  1026. // Original data without Z
  1027. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1028. &parseStop.year,
  1029. &parseStop.month,
  1030. &parseStop.mday,
  1031. &parseStop.hour,
  1032. &parseStop.min,
  1033. &parseStop.sec,
  1034. &parseStop.minSec,
  1035. &parseStop.tz_hour,
  1036. &parseStop.tz_min);
  1037. }
  1038. }
  1039. else
  1040. {
  1041. // Original data without mini second
  1042. if(strstr((char*)stop, "Z") != NULL)
  1043. {
  1044. // Original data with Z
  1045. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1046. &parseStop.year,
  1047. &parseStop.month,
  1048. &parseStop.mday,
  1049. &parseStop.hour,
  1050. &parseStop.min,
  1051. &parseStop.sec);
  1052. }
  1053. else
  1054. {
  1055. // Original data without Z
  1056. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1057. &parseStop.year,
  1058. &parseStop.month,
  1059. &parseStop.mday,
  1060. &parseStop.hour,
  1061. &parseStop.min,
  1062. &parseStop.sec,
  1063. &parseStop.tz_hour,
  1064. &parseStop.tz_min);
  1065. }
  1066. }
  1067. // Calculate date time difference
  1068. if((parseStart.scanedElement >=6) &&
  1069. (parseStop.scanedElement >=6))
  1070. {
  1071. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1072. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1073. tmStart.tm_year = parseStart.year - 1900;
  1074. tmStart.tm_mon = parseStart.month - 1;
  1075. tmStart.tm_mday = parseStart.mday;
  1076. tmStart.tm_hour = parseStart.hour;
  1077. tmStart.tm_min = parseStart.min;
  1078. tmStart.tm_sec = parseStart.sec;
  1079. tmStart.tm_gmtoff = 0;
  1080. tbStart.time = mktime(&tmStart);
  1081. tbStart.timezone = 0;
  1082. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1083. tmStop.tm_year = parseStop.year - 1900;
  1084. tmStop.tm_mon = parseStop.month - 1;
  1085. tmStop.tm_mday = parseStop.mday;
  1086. tmStop.tm_hour = parseStop.hour;
  1087. tmStop.tm_min = parseStop.min;
  1088. tmStop.tm_sec = parseStop.sec;
  1089. tmStop.tm_gmtoff = 0;
  1090. tbStop.time = mktime(&tmStop);
  1091. tbStop.timezone = 0;
  1092. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1093. result = DiffTimebSec(tbStart, tbStop);
  1094. //DEBUG_INFO("getStartStop(): %d\n", result);
  1095. }
  1096. else
  1097. {
  1098. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1099. }
  1100. return result;
  1101. }
  1102. int isOvertNow(uint8_t *start)
  1103. {
  1104. int result = NO;
  1105. struct ParsingResult
  1106. {
  1107. int result;
  1108. int scanedElement;
  1109. int year;
  1110. int month;
  1111. int mday;
  1112. int hour;
  1113. int min;
  1114. int sec;
  1115. int tz_hour;
  1116. int tz_min;
  1117. float minSec;
  1118. }parsingResult;
  1119. struct tm tmStart;
  1120. struct timeb tbStart;
  1121. if(strstr((char*)start, ".") != NULL)
  1122. {
  1123. // Original data with mini second
  1124. if(strstr((char*)start, "Z") != NULL)
  1125. {
  1126. // Original data with Z
  1127. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1128. &parsingResult.year,
  1129. &parsingResult.month,
  1130. &parsingResult.mday,
  1131. &parsingResult.hour,
  1132. &parsingResult.min,
  1133. &parsingResult.sec,
  1134. &parsingResult.minSec);
  1135. }
  1136. else
  1137. {
  1138. // Original data without Z
  1139. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1140. &parsingResult.year,
  1141. &parsingResult.month,
  1142. &parsingResult.mday,
  1143. &parsingResult.hour,
  1144. &parsingResult.min,
  1145. &parsingResult.sec,
  1146. &parsingResult.minSec,
  1147. &parsingResult.tz_hour,
  1148. &parsingResult.tz_min);
  1149. }
  1150. }
  1151. else
  1152. {
  1153. // Original data without mini second
  1154. if(strstr((char*)start, "Z") != NULL)
  1155. {
  1156. // Original data with Z
  1157. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1158. &parsingResult.year,
  1159. &parsingResult.month,
  1160. &parsingResult.mday,
  1161. &parsingResult.hour,
  1162. &parsingResult.min,
  1163. &parsingResult.sec);
  1164. }
  1165. else
  1166. {
  1167. // Original data without Z
  1168. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1169. &parsingResult.year,
  1170. &parsingResult.month,
  1171. &parsingResult.mday,
  1172. &parsingResult.hour,
  1173. &parsingResult.min,
  1174. &parsingResult.sec,
  1175. &parsingResult.tz_hour,
  1176. &parsingResult.tz_min);
  1177. }
  1178. }
  1179. if(parsingResult.scanedElement >= 6)
  1180. {
  1181. tmStart.tm_year = parsingResult.year - 1900;
  1182. tmStart.tm_mon = parsingResult.month - 1;
  1183. tmStart.tm_mday = parsingResult.mday;
  1184. tmStart.tm_hour = parsingResult.hour;
  1185. tmStart.tm_min = parsingResult.min;
  1186. tmStart.tm_sec = parsingResult.sec;
  1187. tmStart.tm_gmtoff = 0;
  1188. tbStart.time = mktime(&tmStart);
  1189. tbStart.timezone = 0;
  1190. tbStart.millitm = 0;
  1191. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1192. if(DiffTimebWithNowSec(tbStart) <= 0)
  1193. result = NO;
  1194. else
  1195. result = YES;
  1196. }
  1197. else
  1198. {
  1199. DEBUG_WARN("Start date parsing error.\n");
  1200. }
  1201. return result;
  1202. }
  1203. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1204. {
  1205. struct ParsingResult
  1206. {
  1207. int result;
  1208. int scanedElement;
  1209. int year;
  1210. int month;
  1211. int mday;
  1212. int hour;
  1213. int min;
  1214. int sec;
  1215. int tz_hour;
  1216. int tz_min;
  1217. float minSec;
  1218. };
  1219. struct ParsingResult parseStart;
  1220. struct ParsingResult parseStop;
  1221. int result = -1;
  1222. struct tm tmStart;
  1223. struct timeb tbStart;
  1224. struct tm tmStop;
  1225. struct timeb tbStop;
  1226. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1227. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1228. // Scan start & stop date time
  1229. if(strstr((char*)start, ".") != NULL)
  1230. {
  1231. // Original data with mini second
  1232. if(strstr((char*)start, "Z") != NULL)
  1233. {
  1234. // Original data with Z
  1235. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1236. &parseStart.year,
  1237. &parseStart.month,
  1238. &parseStart.mday,
  1239. &parseStart.hour,
  1240. &parseStart.min,
  1241. &parseStart.sec,
  1242. &parseStart.minSec);
  1243. }
  1244. else
  1245. {
  1246. // Original data without Z
  1247. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1248. &parseStart.year,
  1249. &parseStart.month,
  1250. &parseStart.mday,
  1251. &parseStart.hour,
  1252. &parseStart.min,
  1253. &parseStart.sec,
  1254. &parseStart.minSec,
  1255. &parseStart.tz_hour,
  1256. &parseStart.tz_min);
  1257. }
  1258. }
  1259. else
  1260. {
  1261. // Original data without mini second
  1262. if(strstr((char*)start, "Z") != NULL)
  1263. {
  1264. // Original data with Z
  1265. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1266. &parseStart.year,
  1267. &parseStart.month,
  1268. &parseStart.mday,
  1269. &parseStart.hour,
  1270. &parseStart.min,
  1271. &parseStart.sec);
  1272. }
  1273. else
  1274. {
  1275. // Original data without Z
  1276. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1277. &parseStart.year,
  1278. &parseStart.month,
  1279. &parseStart.mday,
  1280. &parseStart.hour,
  1281. &parseStart.min,
  1282. &parseStart.sec,
  1283. &parseStart.tz_hour,
  1284. &parseStart.tz_min);
  1285. }
  1286. }
  1287. if(strstr((char*)stop, ".") != NULL)
  1288. {
  1289. // Original data with mini second
  1290. if(strstr((char*)stop, "Z") != NULL)
  1291. {
  1292. // Original data with Z
  1293. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1294. &parseStop.year,
  1295. &parseStop.month,
  1296. &parseStop.mday,
  1297. &parseStop.hour,
  1298. &parseStop.min,
  1299. &parseStop.sec,
  1300. &parseStop.minSec);
  1301. }
  1302. else
  1303. {
  1304. // Original data without Z
  1305. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1306. &parseStop.year,
  1307. &parseStop.month,
  1308. &parseStop.mday,
  1309. &parseStop.hour,
  1310. &parseStop.min,
  1311. &parseStop.sec,
  1312. &parseStop.minSec,
  1313. &parseStop.tz_hour,
  1314. &parseStop.tz_min);
  1315. }
  1316. }
  1317. else
  1318. {
  1319. // Original data without mini second
  1320. if(strstr((char*)stop, "Z") != NULL)
  1321. {
  1322. // Original data with Z
  1323. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1324. &parseStop.year,
  1325. &parseStop.month,
  1326. &parseStop.mday,
  1327. &parseStop.hour,
  1328. &parseStop.min,
  1329. &parseStop.sec);
  1330. }
  1331. else
  1332. {
  1333. // Original data without Z
  1334. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1335. &parseStop.year,
  1336. &parseStop.month,
  1337. &parseStop.mday,
  1338. &parseStop.hour,
  1339. &parseStop.min,
  1340. &parseStop.sec,
  1341. &parseStop.tz_hour,
  1342. &parseStop.tz_min);
  1343. }
  1344. }
  1345. // Calculate date time difference
  1346. if((parseStart.scanedElement >=6) &&
  1347. (parseStop.scanedElement >=6))
  1348. {
  1349. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1350. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1351. tmStart.tm_year = parseStart.year - 1900;
  1352. tmStart.tm_mon = parseStart.month - 1;
  1353. tmStart.tm_mday = parseStart.mday;
  1354. tmStart.tm_hour = parseStart.hour;
  1355. tmStart.tm_min = parseStart.min;
  1356. tmStart.tm_sec = parseStart.sec;
  1357. tmStart.tm_gmtoff = 0;
  1358. tbStart.time = mktime(&tmStart);
  1359. tbStart.timezone = 0;
  1360. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1361. tmStop.tm_year = parseStop.year - 1900;
  1362. tmStop.tm_mon = parseStop.month - 1;
  1363. tmStop.tm_mday = parseStop.mday;
  1364. tmStop.tm_hour = parseStop.hour;
  1365. tmStop.tm_min = parseStop.min;
  1366. tmStop.tm_sec = parseStop.sec;
  1367. tmStop.tm_gmtoff = 0;
  1368. tbStop.time = mktime(&tmStop);
  1369. tbStop.timezone = 0;
  1370. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1371. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1372. //DEBUG_INFO("getStartStop(): %d\n", result);
  1373. }
  1374. else
  1375. {
  1376. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1377. }
  1378. return result;
  1379. }
  1380. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1381. {
  1382. FILE *fp;
  1383. char profileFileName[128];
  1384. char *line = NULL;
  1385. size_t len = 0;
  1386. time_t CurrentTime;
  1387. struct tm *tmComposite;
  1388. struct StructChargingProfile maxProfile;
  1389. struct StructChargingProfile compositeProfile;
  1390. uint8_t limitMax=0;
  1391. int compositePeriodIdx = 0;
  1392. CurrentTime = time(NULL);
  1393. tmComposite=localtime(&CurrentTime);
  1394. 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);
  1395. if(isUnitA)
  1396. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1397. else
  1398. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1399. compositeProfile.ChargingSchedule.Duration = durationReq;
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1403. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1404. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1405. }
  1406. compositeProfile.ChargingProfileId = 0;
  1407. compositeProfile.StackLevel = 99 ;
  1408. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1409. maxProfile.ChargingProfileId = -1;
  1410. maxProfile.ChargingSchedule.Duration = -1;
  1411. system("rm -f /tmp/*.json");
  1412. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1413. // Search max profile
  1414. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1415. if((access(profileFileName, F_OK))!=-1)
  1416. {
  1417. fp = fopen(profileFileName, "r");
  1418. while(getline(&line, &len, fp) != -1)
  1419. {
  1420. json_object *obj = NULL;
  1421. obj = json_tokener_parse(line);
  1422. if(is_error(obj))
  1423. {
  1424. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1425. }
  1426. else
  1427. {
  1428. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1429. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1430. )
  1431. {
  1432. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1433. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1434. )
  1435. {
  1436. struct tm tmFrom, tmTo;
  1437. struct timeb tbFrom, tbTo;
  1438. 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) &&
  1439. (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))
  1440. {
  1441. tmFrom.tm_year -= 1900;
  1442. tmFrom.tm_mon -= 1;
  1443. tbFrom.time = mktime(&tmFrom);
  1444. tmTo.tm_year -= 1900;
  1445. tmTo.tm_mon -= 1;
  1446. tbTo.time = mktime(&tmTo);
  1447. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1448. {
  1449. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1450. {
  1451. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1452. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1453. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1454. }
  1455. if(maxProfile.ChargingProfileId == -1)
  1456. DEBUG_INFO("MaxProfile found.\n");
  1457. else
  1458. DEBUG_INFO("MaxProfile updated.\n");
  1459. // Required item
  1460. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1461. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1462. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1463. if(isUnitA)
  1464. {
  1465. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1466. 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++)
  1467. {
  1468. 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"));
  1469. 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?
  1470. 3:
  1471. 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")));
  1472. 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")));
  1473. }
  1474. }
  1475. else
  1476. {
  1477. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1478. 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++)
  1479. {
  1480. 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"));
  1481. 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?
  1482. 3:
  1483. 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")));
  1484. 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));
  1485. }
  1486. }
  1487. // Optional item
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1489. {
  1490. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)maxProfile.ValidFrom, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1497. {
  1498. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1499. }
  1500. else
  1501. {
  1502. sprintf((char*)maxProfile.ValidTo, " ");
  1503. }
  1504. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1505. {
  1506. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1507. }
  1508. else
  1509. {
  1510. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1511. }
  1512. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1513. {
  1514. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1515. }
  1516. else
  1517. {
  1518. maxProfile.TransactionId = -1;
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1521. {
  1522. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1523. }
  1524. else
  1525. {
  1526. maxProfile.ChargingSchedule.Duration = 86400;
  1527. }
  1528. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1529. {
  1530. 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")));
  1531. }
  1532. else
  1533. {
  1534. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1535. }
  1536. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1537. {
  1538. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1539. }
  1540. else
  1541. {
  1542. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1543. }
  1544. }
  1545. }
  1546. }
  1547. else
  1548. {
  1549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1552. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1553. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1554. }
  1555. if(maxProfile.ChargingProfileId == -1)
  1556. DEBUG_INFO("MaxProfile found.\n");
  1557. else
  1558. DEBUG_INFO("MaxProfile updated.\n");
  1559. // Required item
  1560. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1561. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1562. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1563. if(isUnitA)
  1564. {
  1565. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1566. 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++)
  1567. {
  1568. 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"));
  1569. 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?
  1570. 3:
  1571. 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")));
  1572. 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")));
  1573. }
  1574. }
  1575. else
  1576. {
  1577. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1578. 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++)
  1579. {
  1580. 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"));
  1581. 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?
  1582. 3:
  1583. 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")));
  1584. 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));
  1585. }
  1586. }
  1587. // Optional item
  1588. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1589. {
  1590. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1591. }
  1592. else
  1593. {
  1594. sprintf((char*)maxProfile.ValidFrom, " ");
  1595. }
  1596. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1597. {
  1598. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1599. }
  1600. else
  1601. {
  1602. sprintf((char*)maxProfile.ValidTo, " ");
  1603. }
  1604. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1605. {
  1606. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1607. }
  1608. else
  1609. {
  1610. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1611. }
  1612. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1613. {
  1614. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1615. }
  1616. else
  1617. {
  1618. maxProfile.TransactionId = -1;
  1619. }
  1620. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1621. {
  1622. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1623. }
  1624. else
  1625. {
  1626. maxProfile.ChargingSchedule.Duration = 86400;
  1627. }
  1628. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1629. {
  1630. 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")));
  1631. }
  1632. else
  1633. {
  1634. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1635. }
  1636. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1637. {
  1638. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1639. }
  1640. else
  1641. {
  1642. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1643. }
  1644. }
  1645. }
  1646. }
  1647. json_object_put(obj);
  1648. }
  1649. fclose(fp);
  1650. /*
  1651. if(maxProfile.ChargingProfileId !=-1)
  1652. {
  1653. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1654. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1655. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1656. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1657. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1658. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1659. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1660. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1661. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1662. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1663. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1664. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1665. {
  1666. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1667. {
  1668. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1669. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1670. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1671. }
  1672. }
  1673. }
  1674. else
  1675. DEBUG_INFO("MaxProfile not found.\n");
  1676. DEBUG_INFO("------------------------------------\n");*/
  1677. }
  1678. if(maxProfile.ChargingProfileId != -1)
  1679. {
  1680. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1681. {
  1682. if(maxProfile.ChargingSchedule.Duration != -1)
  1683. {
  1684. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1685. 0:
  1686. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1687. }
  1688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1689. {
  1690. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1691. {
  1692. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1693. 0:
  1694. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1695. if(idxPeriod > 0)
  1696. {
  1697. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1698. {
  1699. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1700. }
  1701. }
  1702. }
  1703. }
  1704. }
  1705. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1706. {
  1707. if(maxProfile.ChargingSchedule.Duration != -1)
  1708. {
  1709. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1710. }
  1711. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1712. {
  1713. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1714. {
  1715. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1716. if(idxPeriod > 0)
  1717. {
  1718. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1719. {
  1720. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1721. }
  1722. }
  1723. }
  1724. }
  1725. }
  1726. else
  1727. {
  1728. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1729. {
  1730. if(maxProfile.ChargingSchedule.Duration != -1)
  1731. {
  1732. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1733. 0:
  1734. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1735. }
  1736. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1737. {
  1738. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1739. {
  1740. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1741. 0:
  1742. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1743. if(idxPeriod > 0)
  1744. {
  1745. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1746. {
  1747. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1748. }
  1749. }
  1750. }
  1751. }
  1752. }
  1753. else
  1754. {
  1755. if(maxProfile.ChargingSchedule.Duration != -1)
  1756. {
  1757. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1758. 0:
  1759. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1760. }
  1761. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1762. {
  1763. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1764. {
  1765. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1766. 0:
  1767. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1768. if(idxPeriod > 0)
  1769. {
  1770. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1771. {
  1772. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1773. }
  1774. }
  1775. }
  1776. }
  1777. }
  1778. }
  1779. /*
  1780. DEBUG_INFO("MaxProfile after align.\n");
  1781. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1782. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1783. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1784. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1785. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1786. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1787. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1788. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1789. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1790. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1791. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1792. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1793. {
  1794. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1795. {
  1796. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1797. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1798. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1799. }
  1800. }
  1801. DEBUG_INFO("------------------------------------\n");*/
  1802. }
  1803. // Find each profile period quantity
  1804. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1805. {
  1806. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1807. limitMax = idx+1;
  1808. }
  1809. if(maxProfile.ChargingProfileId != -1)
  1810. {
  1811. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1812. {
  1813. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1814. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1815. (maxProfile.ChargingSchedule.Duration > 0))
  1816. {
  1817. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1818. {
  1819. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1820. compositePeriodIdx++;
  1821. }
  1822. else
  1823. {
  1824. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1825. }
  1826. }
  1827. }
  1828. }
  1829. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1830. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1831. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1832. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1834. {
  1835. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1836. {
  1837. compositeProfile.ChargingProfileId = 1;
  1838. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1839. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1840. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1841. }
  1842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1843. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1844. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1845. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1846. }
  1847. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1848. if(line)
  1849. free(line);
  1850. }
  1851. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1852. {
  1853. FILE *fp;
  1854. char profileFileName[128];
  1855. char *line = NULL;
  1856. size_t len = 0;
  1857. time_t CurrentTime;
  1858. struct tm *tmComposite;
  1859. struct StructChargingProfile maxProfile;
  1860. struct StructChargingProfile defaultTxProfile;
  1861. struct StructChargingProfile txProfile;
  1862. struct StructChargingProfile compositeProfile;
  1863. struct StructChargingSchedulePeriod tmpPeriod;
  1864. uint8_t limitMax=0;
  1865. uint8_t limitDef=0;
  1866. uint8_t limitTx=0;
  1867. int compositePeriodIdx = 0;
  1868. CurrentTime = time(NULL);
  1869. tmComposite=localtime(&CurrentTime);
  1870. 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);
  1871. if(isUnitA)
  1872. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1873. else
  1874. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1875. compositeProfile.ChargingSchedule.Duration = durationReq;
  1876. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1877. {
  1878. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1879. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1880. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1881. }
  1882. compositeProfile.ChargingProfileId = 0;
  1883. compositeProfile.StackLevel = 99 ;
  1884. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1885. maxProfile.ChargingProfileId = -1;
  1886. defaultTxProfile.ChargingProfileId = -1;
  1887. txProfile.ChargingProfileId = -1;
  1888. maxProfile.ChargingSchedule.Duration = -1;
  1889. defaultTxProfile.ChargingSchedule.Duration = -1;
  1890. txProfile.ChargingSchedule.Duration = -1;
  1891. system("rm -f /tmp/*.json");
  1892. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1893. /*
  1894. * Search valid charging profile
  1895. */
  1896. //DEBUG_INFO("====================================\n");
  1897. // Search tx profile
  1898. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1899. if((access(profileFileName, F_OK))!=-1)
  1900. {
  1901. fp = fopen(profileFileName, "r");
  1902. while(getline(&line, &len, fp) != -1)
  1903. {
  1904. json_object *obj = NULL;
  1905. obj = json_tokener_parse(line);
  1906. if(is_error(obj))
  1907. {
  1908. DEBUG_ERROR("Parse txProfile from file error.\n");
  1909. }
  1910. else
  1911. {
  1912. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1913. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1914. )
  1915. {
  1916. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1917. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1918. )
  1919. {
  1920. struct tm tmFrom, tmTo;
  1921. struct timeb tbFrom, tbTo;
  1922. 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) &&
  1923. (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))
  1924. {
  1925. tmFrom.tm_year -= 1900;
  1926. tmFrom.tm_mon -= 1;
  1927. tbFrom.time = mktime(&tmFrom);
  1928. tmTo.tm_year -= 1900;
  1929. tmTo.tm_mon -= 1;
  1930. tbTo.time = mktime(&tmTo);
  1931. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1932. {
  1933. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1934. {
  1935. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1936. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1937. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1938. }
  1939. if(txProfile.ChargingProfileId == -1)
  1940. DEBUG_INFO("TxProfile found.\n");
  1941. else
  1942. DEBUG_INFO("TxProfile updated.\n");
  1943. // Required item
  1944. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1945. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1946. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1947. if(isUnitA)
  1948. {
  1949. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1950. 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++)
  1951. {
  1952. 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"));
  1953. 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?
  1954. 3:
  1955. 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")));
  1956. 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")));
  1957. }
  1958. }
  1959. else
  1960. {
  1961. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1962. 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++)
  1963. {
  1964. 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"));
  1965. 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?
  1966. 3:
  1967. 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")));
  1968. 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));
  1969. }
  1970. }
  1971. // Optional item
  1972. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1973. {
  1974. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1975. }
  1976. else
  1977. {
  1978. sprintf((char*)txProfile.ValidFrom, " ");
  1979. }
  1980. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1981. {
  1982. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1983. }
  1984. else
  1985. {
  1986. sprintf((char*)txProfile.ValidTo, " ");
  1987. }
  1988. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1989. {
  1990. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1991. }
  1992. else
  1993. {
  1994. sprintf((char*)txProfile.RecurrencyKind, " ");
  1995. }
  1996. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1997. {
  1998. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1999. }
  2000. else
  2001. {
  2002. txProfile.TransactionId = -1;
  2003. }
  2004. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2005. {
  2006. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2007. }
  2008. else
  2009. {
  2010. txProfile.ChargingSchedule.Duration = 86400;
  2011. }
  2012. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2013. {
  2014. 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")));
  2015. }
  2016. else
  2017. {
  2018. 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));
  2019. }
  2020. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2021. {
  2022. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2023. }
  2024. else
  2025. {
  2026. txProfile.ChargingSchedule.MinChargingRate = -1;
  2027. }
  2028. }
  2029. }
  2030. }
  2031. else
  2032. {
  2033. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2034. {
  2035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2036. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2037. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2038. }
  2039. if(txProfile.ChargingProfileId == -1)
  2040. DEBUG_INFO("TxProfile found.\n");
  2041. else
  2042. DEBUG_INFO("TxProfile updated.\n");
  2043. // Required item
  2044. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2045. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2046. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2047. if(isUnitA)
  2048. {
  2049. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2050. 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++)
  2051. {
  2052. 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"));
  2053. 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?
  2054. 3:
  2055. 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")));
  2056. 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")));
  2057. }
  2058. }
  2059. else
  2060. {
  2061. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2062. 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++)
  2063. {
  2064. 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"));
  2065. 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?
  2066. 3:
  2067. 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")));
  2068. 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));
  2069. }
  2070. }
  2071. // Optional item
  2072. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2073. {
  2074. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2075. }
  2076. else
  2077. {
  2078. sprintf((char*)txProfile.ValidFrom, " ");
  2079. }
  2080. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2081. {
  2082. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2083. }
  2084. else
  2085. {
  2086. sprintf((char*)txProfile.ValidTo, " ");
  2087. }
  2088. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2089. {
  2090. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2091. }
  2092. else
  2093. {
  2094. sprintf((char*)txProfile.RecurrencyKind, " ");
  2095. }
  2096. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2097. {
  2098. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2099. }
  2100. else
  2101. {
  2102. txProfile.TransactionId = -1;
  2103. }
  2104. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2105. {
  2106. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2107. }
  2108. else
  2109. {
  2110. txProfile.ChargingSchedule.Duration = 86400;
  2111. }
  2112. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2113. {
  2114. 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")));
  2115. }
  2116. else
  2117. {
  2118. 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));
  2119. }
  2120. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2121. {
  2122. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2123. }
  2124. else
  2125. {
  2126. txProfile.ChargingSchedule.MinChargingRate = -1;
  2127. }
  2128. }
  2129. }
  2130. }
  2131. json_object_put(obj);
  2132. }
  2133. fclose(fp);
  2134. /*
  2135. if(txProfile.ChargingProfileId != -1)
  2136. {
  2137. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2138. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2139. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2140. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2141. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2142. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2143. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2144. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2145. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2146. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2147. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2148. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2149. {
  2150. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2151. {
  2152. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2153. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2154. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2155. }
  2156. }
  2157. }
  2158. else
  2159. DEBUG_INFO("TxProfile not found.\n");*/
  2160. }
  2161. // Search default tx profile
  2162. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2163. if((access(profileFileName, F_OK))==-1)
  2164. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2165. if((access(profileFileName, F_OK))!=-1)
  2166. {
  2167. fp = fopen(profileFileName, "r");
  2168. while(getline(&line, &len, fp) != -1)
  2169. {
  2170. json_object *obj = NULL;
  2171. obj = json_tokener_parse(line);
  2172. if(is_error(obj))
  2173. {
  2174. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2175. }
  2176. else
  2177. {
  2178. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2179. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2180. )
  2181. {
  2182. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2183. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2184. )
  2185. {
  2186. struct tm tmFrom, tmTo;
  2187. struct timeb tbFrom, tbTo;
  2188. 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) &&
  2189. (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))
  2190. {
  2191. tmFrom.tm_year -= 1900;
  2192. tmFrom.tm_mon -= 1;
  2193. tbFrom.time = mktime(&tmFrom);
  2194. tmTo.tm_year -= 1900;
  2195. tmTo.tm_mon -= 1;
  2196. tbTo.time = mktime(&tmTo);
  2197. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2198. {
  2199. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2200. {
  2201. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2202. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2203. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2204. }
  2205. if(defaultTxProfile.ChargingProfileId == -1)
  2206. DEBUG_INFO("TxDefaultProfile found.\n");
  2207. else
  2208. DEBUG_INFO("TxDefaultProfile updated.\n");
  2209. // Required item
  2210. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2211. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2212. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2213. if(isUnitA)
  2214. {
  2215. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2216. 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++)
  2217. {
  2218. 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"));
  2219. 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?
  2220. 3:
  2221. 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")));
  2222. 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")));
  2223. }
  2224. }
  2225. else
  2226. {
  2227. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2228. 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++)
  2229. {
  2230. 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"));
  2231. 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?
  2232. 3:
  2233. 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")));
  2234. 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));
  2235. }
  2236. }
  2237. // Optional item
  2238. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2239. {
  2240. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2241. }
  2242. else
  2243. {
  2244. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2245. }
  2246. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2247. {
  2248. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2249. }
  2250. else
  2251. {
  2252. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2253. }
  2254. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2255. {
  2256. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2257. }
  2258. else
  2259. {
  2260. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2261. }
  2262. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2263. {
  2264. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2265. }
  2266. else
  2267. {
  2268. defaultTxProfile.TransactionId = -1;
  2269. }
  2270. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2271. {
  2272. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2273. }
  2274. else
  2275. {
  2276. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2277. }
  2278. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2279. {
  2280. 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")));
  2281. }
  2282. else
  2283. {
  2284. 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));
  2285. }
  2286. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2287. {
  2288. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2289. }
  2290. else
  2291. {
  2292. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2293. }
  2294. }
  2295. }
  2296. }
  2297. else
  2298. {
  2299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2300. {
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2302. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2303. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2304. }
  2305. if(defaultTxProfile.ChargingProfileId == -1)
  2306. DEBUG_INFO("TxDefaultProfile found.\n");
  2307. else
  2308. DEBUG_INFO("TxDefaultProfile updated.\n");
  2309. // Required item
  2310. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2311. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2312. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2313. if(isUnitA)
  2314. {
  2315. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2316. 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++)
  2317. {
  2318. 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"));
  2319. 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?
  2320. 3:
  2321. 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")));
  2322. 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")));
  2323. }
  2324. }
  2325. else
  2326. {
  2327. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2328. 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++)
  2329. {
  2330. 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"));
  2331. 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?
  2332. 3:
  2333. 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")));
  2334. 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));
  2335. }
  2336. }
  2337. // Optional item
  2338. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2339. {
  2340. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2341. }
  2342. else
  2343. {
  2344. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2345. }
  2346. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2347. {
  2348. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2349. }
  2350. else
  2351. {
  2352. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2353. }
  2354. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2355. {
  2356. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2357. }
  2358. else
  2359. {
  2360. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2361. }
  2362. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2363. {
  2364. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2365. }
  2366. else
  2367. {
  2368. defaultTxProfile.TransactionId = -1;
  2369. }
  2370. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2371. {
  2372. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2373. }
  2374. else
  2375. {
  2376. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2377. }
  2378. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2379. {
  2380. 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")));
  2381. }
  2382. else
  2383. {
  2384. 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));
  2385. }
  2386. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2387. {
  2388. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2389. }
  2390. else
  2391. {
  2392. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2393. }
  2394. }
  2395. }
  2396. }
  2397. json_object_put(obj);
  2398. }
  2399. fclose(fp);
  2400. /*
  2401. if(defaultTxProfile.ChargingProfileId != -1)
  2402. {
  2403. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2404. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2405. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2406. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2407. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2408. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2409. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2410. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2411. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2412. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2413. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2414. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2415. {
  2416. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2417. {
  2418. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2419. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2420. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2421. }
  2422. }
  2423. }
  2424. else
  2425. DEBUG_INFO("TxDefaultProfile not found.\n");
  2426. DEBUG_INFO("------------------------------------\n");*/
  2427. }
  2428. // Search max profile
  2429. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2430. if((access(profileFileName, F_OK))!=-1)
  2431. {
  2432. fp = fopen(profileFileName, "r");
  2433. while(getline(&line, &len, fp) != -1)
  2434. {
  2435. json_object *obj = NULL;
  2436. obj = json_tokener_parse(line);
  2437. if(is_error(obj))
  2438. {
  2439. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2440. }
  2441. else
  2442. {
  2443. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2444. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2445. )
  2446. {
  2447. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2448. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2449. )
  2450. {
  2451. struct tm tmFrom, tmTo;
  2452. struct timeb tbFrom, tbTo;
  2453. 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) &&
  2454. (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))
  2455. {
  2456. tmFrom.tm_year -= 1900;
  2457. tmFrom.tm_mon -= 1;
  2458. tbFrom.time = mktime(&tmFrom);
  2459. tmTo.tm_year -= 1900;
  2460. tmTo.tm_mon -= 1;
  2461. tbTo.time = mktime(&tmTo);
  2462. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2463. {
  2464. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2465. {
  2466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2467. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2468. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2469. }
  2470. if(maxProfile.ChargingProfileId == -1)
  2471. DEBUG_INFO("MaxProfile found.\n");
  2472. else
  2473. DEBUG_INFO("MaxProfile updated.\n");
  2474. // Required item
  2475. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2476. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2477. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2478. if(isUnitA)
  2479. {
  2480. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2481. 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++)
  2482. {
  2483. 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"));
  2484. 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?
  2485. 3:
  2486. 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")));
  2487. 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")));
  2488. }
  2489. }
  2490. else
  2491. {
  2492. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2493. 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++)
  2494. {
  2495. 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"));
  2496. 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?
  2497. 3:
  2498. 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")));
  2499. 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));
  2500. }
  2501. }
  2502. // Optional item
  2503. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2504. {
  2505. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2506. }
  2507. else
  2508. {
  2509. sprintf((char*)maxProfile.ValidFrom, " ");
  2510. }
  2511. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2512. {
  2513. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2514. }
  2515. else
  2516. {
  2517. sprintf((char*)maxProfile.ValidTo, " ");
  2518. }
  2519. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2520. {
  2521. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2522. }
  2523. else
  2524. {
  2525. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2526. }
  2527. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2528. {
  2529. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2530. }
  2531. else
  2532. {
  2533. maxProfile.TransactionId = -1;
  2534. }
  2535. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2536. {
  2537. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2538. }
  2539. else
  2540. {
  2541. maxProfile.ChargingSchedule.Duration = 86400;
  2542. }
  2543. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2544. {
  2545. 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")));
  2546. }
  2547. else
  2548. {
  2549. 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));
  2550. }
  2551. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2552. {
  2553. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2554. }
  2555. else
  2556. {
  2557. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2558. }
  2559. }
  2560. }
  2561. }
  2562. else
  2563. {
  2564. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2565. {
  2566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2567. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2568. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2569. }
  2570. if(maxProfile.ChargingProfileId == -1)
  2571. DEBUG_INFO("MaxProfile found.\n");
  2572. else
  2573. DEBUG_INFO("MaxProfile updated.\n");
  2574. // Required item
  2575. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2576. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2577. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2578. if(isUnitA)
  2579. {
  2580. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2581. 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++)
  2582. {
  2583. 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"));
  2584. 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?
  2585. 3:
  2586. 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")));
  2587. 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")));
  2588. }
  2589. }
  2590. else
  2591. {
  2592. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2593. 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++)
  2594. {
  2595. 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"));
  2596. 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?
  2597. 3:
  2598. 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")));
  2599. 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));
  2600. }
  2601. }
  2602. // Optional item
  2603. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2604. {
  2605. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2606. }
  2607. else
  2608. {
  2609. sprintf((char*)maxProfile.ValidFrom, " ");
  2610. }
  2611. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2612. {
  2613. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2614. }
  2615. else
  2616. {
  2617. sprintf((char*)maxProfile.ValidTo, " ");
  2618. }
  2619. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2620. {
  2621. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2622. }
  2623. else
  2624. {
  2625. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2626. }
  2627. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2628. {
  2629. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2630. }
  2631. else
  2632. {
  2633. maxProfile.TransactionId = -1;
  2634. }
  2635. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2636. {
  2637. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2638. }
  2639. else
  2640. {
  2641. maxProfile.ChargingSchedule.Duration = 86400;
  2642. }
  2643. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2644. {
  2645. 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")));
  2646. }
  2647. else
  2648. {
  2649. 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));
  2650. }
  2651. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2652. {
  2653. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2654. }
  2655. else
  2656. {
  2657. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2658. }
  2659. }
  2660. }
  2661. }
  2662. json_object_put(obj);
  2663. }
  2664. fclose(fp);
  2665. /*
  2666. if(maxProfile.ChargingProfileId !=-1)
  2667. {
  2668. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2669. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2670. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2671. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2672. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2673. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2674. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2675. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2676. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2677. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2678. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2679. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2680. {
  2681. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2682. {
  2683. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2684. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2685. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2686. }
  2687. }
  2688. }
  2689. else
  2690. DEBUG_INFO("MaxProfile not found.\n");
  2691. DEBUG_INFO("------------------------------------\n");*/
  2692. }
  2693. /*
  2694. * Align found profile start schedule & periods
  2695. */
  2696. //DEBUG_INFO("====================================\n");
  2697. /*
  2698. // For local test usage, force modify found profile start schedule info
  2699. 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);
  2700. 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);
  2701. 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);
  2702. */
  2703. if(txProfile.ChargingProfileId != -1)
  2704. {
  2705. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2706. {
  2707. if(txProfile.ChargingSchedule.Duration != -1)
  2708. {
  2709. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2710. 0:
  2711. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2712. }
  2713. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2714. {
  2715. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2716. {
  2717. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2718. 0:
  2719. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2720. if(idxPeriod > 0)
  2721. {
  2722. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2723. {
  2724. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2725. }
  2726. }
  2727. }
  2728. }
  2729. }
  2730. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2731. {
  2732. if(txProfile.ChargingSchedule.Duration != -1)
  2733. {
  2734. 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?
  2735. 0:
  2736. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2737. }
  2738. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2739. {
  2740. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2741. {
  2742. 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?
  2743. 0:
  2744. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2745. if(idxPeriod > 0)
  2746. {
  2747. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2748. {
  2749. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2750. }
  2751. }
  2752. }
  2753. }
  2754. }
  2755. else
  2756. {
  2757. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2758. {
  2759. if(txProfile.ChargingSchedule.Duration != -1)
  2760. {
  2761. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2762. 0:
  2763. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2764. }
  2765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2766. {
  2767. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2768. {
  2769. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2770. 0:
  2771. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2772. if(idxPeriod > 0)
  2773. {
  2774. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2775. {
  2776. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2777. }
  2778. }
  2779. }
  2780. }
  2781. }
  2782. else
  2783. {
  2784. if(txProfile.ChargingSchedule.Duration != -1)
  2785. {
  2786. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2787. 0:
  2788. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2789. }
  2790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2791. {
  2792. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2793. {
  2794. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2795. 0:
  2796. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2797. if(idxPeriod > 0)
  2798. {
  2799. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2800. {
  2801. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2802. }
  2803. }
  2804. }
  2805. }
  2806. }
  2807. }
  2808. /*
  2809. DEBUG_INFO("txProfile after align.\n");
  2810. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2811. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2812. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2813. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2814. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2815. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2816. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2817. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2818. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2819. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2820. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2821. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2822. {
  2823. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2824. {
  2825. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2826. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2827. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2828. }
  2829. }*/
  2830. }
  2831. if(defaultTxProfile.ChargingProfileId != -1)
  2832. {
  2833. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2834. {
  2835. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2836. {
  2837. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2838. 0:
  2839. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2840. }
  2841. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2842. {
  2843. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2844. {
  2845. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2846. 0:
  2847. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2848. if(idxPeriod > 0)
  2849. {
  2850. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2851. {
  2852. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2853. }
  2854. }
  2855. }
  2856. }
  2857. }
  2858. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2859. {
  2860. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2861. {
  2862. 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?
  2863. 0:
  2864. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2865. }
  2866. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2867. {
  2868. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2869. {
  2870. 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?
  2871. 0:
  2872. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2873. if(idxPeriod > 0)
  2874. {
  2875. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2876. {
  2877. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2878. }
  2879. }
  2880. }
  2881. }
  2882. }
  2883. else
  2884. {
  2885. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2886. {
  2887. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2888. {
  2889. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2890. 0:
  2891. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2892. }
  2893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2894. {
  2895. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2896. {
  2897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2898. 0:
  2899. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2900. if(idxPeriod > 0)
  2901. {
  2902. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2903. {
  2904. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2905. }
  2906. }
  2907. }
  2908. }
  2909. }
  2910. else
  2911. {
  2912. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2913. {
  2914. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2915. 0:
  2916. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2917. }
  2918. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2919. {
  2920. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2921. {
  2922. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2923. 0:
  2924. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2925. if(idxPeriod > 0)
  2926. {
  2927. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2928. {
  2929. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2930. }
  2931. }
  2932. }
  2933. }
  2934. }
  2935. }
  2936. /*
  2937. DEBUG_INFO("defaultTxProfile after align.\n");
  2938. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2939. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2940. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2941. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2942. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2943. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2944. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2945. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2946. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2947. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2948. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2950. {
  2951. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2952. {
  2953. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2954. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2955. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2956. }
  2957. }
  2958. DEBUG_INFO("------------------------------------\n");*/
  2959. }
  2960. if(maxProfile.ChargingProfileId != -1)
  2961. {
  2962. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2963. {
  2964. if(maxProfile.ChargingSchedule.Duration != -1)
  2965. {
  2966. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2967. 0:
  2968. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2969. }
  2970. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2971. {
  2972. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2973. {
  2974. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2975. 0:
  2976. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2977. if(idxPeriod > 0)
  2978. {
  2979. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2980. {
  2981. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2982. }
  2983. }
  2984. }
  2985. }
  2986. }
  2987. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2988. {
  2989. if(maxProfile.ChargingSchedule.Duration != -1)
  2990. {
  2991. 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?
  2992. 0:
  2993. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2994. }
  2995. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2996. {
  2997. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2998. {
  2999. 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?
  3000. 0:
  3001. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3002. if(idxPeriod > 0)
  3003. {
  3004. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3005. {
  3006. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3007. }
  3008. }
  3009. }
  3010. }
  3011. }
  3012. else
  3013. {
  3014. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3015. {
  3016. if(maxProfile.ChargingSchedule.Duration != -1)
  3017. {
  3018. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3019. 0:
  3020. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3021. }
  3022. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3023. {
  3024. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3025. {
  3026. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3027. 0:
  3028. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3029. if(idxPeriod > 0)
  3030. {
  3031. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3032. {
  3033. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3034. }
  3035. }
  3036. }
  3037. }
  3038. }
  3039. else
  3040. {
  3041. if(maxProfile.ChargingSchedule.Duration != -1)
  3042. {
  3043. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3044. 0:
  3045. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3046. }
  3047. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3048. {
  3049. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3050. {
  3051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3052. 0:
  3053. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3054. if(idxPeriod > 0)
  3055. {
  3056. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3057. {
  3058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3059. }
  3060. }
  3061. }
  3062. }
  3063. }
  3064. }
  3065. /*
  3066. DEBUG_INFO("MaxProfile after align.\n");
  3067. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3068. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3069. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3070. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3071. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3072. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3073. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3074. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3075. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3076. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3077. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3078. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3079. {
  3080. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3081. {
  3082. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3083. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3084. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3085. }
  3086. }
  3087. DEBUG_INFO("------------------------------------\n");*/
  3088. }
  3089. /*
  3090. * Merge to conposite schedule
  3091. */
  3092. //DEBUG_INFO("====================================\n");
  3093. // Find each profile period quantity
  3094. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3095. {
  3096. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3097. limitMax = idx+1;
  3098. }
  3099. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3100. {
  3101. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3102. limitDef = idx+1;
  3103. }
  3104. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3105. {
  3106. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3107. limitTx = idx+1;
  3108. }
  3109. // TxProfile found, composite schedule based on it
  3110. if(txProfile.ChargingProfileId != -1)
  3111. {
  3112. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3113. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3114. {
  3115. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3116. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3117. (txProfile.ChargingSchedule.Duration > 0))
  3118. {
  3119. if(maxProfile.ChargingProfileId != -1)
  3120. {
  3121. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3122. {
  3123. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3124. {
  3125. if((maxProfile.ChargingSchedule.Duration > 0))
  3126. {
  3127. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3128. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3129. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3130. }
  3131. else
  3132. {
  3133. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3134. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3135. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3136. }
  3137. }
  3138. if(idxMaxPeriod == (limitMax-1))
  3139. {
  3140. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3141. {
  3142. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3143. {
  3144. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3145. compositePeriodIdx++;
  3146. }
  3147. else
  3148. {
  3149. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3150. }
  3151. }
  3152. }
  3153. }
  3154. }
  3155. else
  3156. {
  3157. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3158. {
  3159. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3160. compositePeriodIdx++;
  3161. }
  3162. else
  3163. {
  3164. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3165. }
  3166. }
  3167. }
  3168. if(idxTxPeriod == (limitTx-1))
  3169. {
  3170. if(defaultTxProfile.ChargingProfileId != -1)
  3171. {
  3172. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3173. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3174. {
  3175. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3176. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3177. (defaultTxProfile.ChargingSchedule.Duration>0))
  3178. {
  3179. if(maxProfile.ChargingProfileId != -1)
  3180. {
  3181. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3182. {
  3183. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3184. {
  3185. if((maxProfile.ChargingSchedule.Duration > 0))
  3186. {
  3187. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3188. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3189. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3190. }
  3191. else
  3192. {
  3193. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3194. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3195. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3196. }
  3197. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3198. {
  3199. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3200. {
  3201. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3202. compositePeriodIdx++;
  3203. }
  3204. else
  3205. {
  3206. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3207. }
  3208. }
  3209. // Delete duplicate period
  3210. if(compositePeriodIdx > 1)
  3211. {
  3212. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3213. {
  3214. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3215. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3216. compositePeriodIdx -= 1;
  3217. }
  3218. }
  3219. }
  3220. else
  3221. {
  3222. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3223. {
  3224. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3225. compositePeriodIdx++;
  3226. }
  3227. else
  3228. {
  3229. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3230. }
  3231. break;
  3232. }
  3233. }
  3234. }
  3235. else
  3236. {
  3237. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3238. {
  3239. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3240. compositePeriodIdx++;
  3241. }
  3242. else
  3243. {
  3244. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3245. }
  3246. }
  3247. }
  3248. }
  3249. }
  3250. }
  3251. }
  3252. }
  3253. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3254. else if(defaultTxProfile.ChargingProfileId != -1)
  3255. {
  3256. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3257. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3258. {
  3259. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3260. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3261. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3262. {
  3263. if(maxProfile.ChargingProfileId != -1)
  3264. {
  3265. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3266. {
  3267. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3268. {
  3269. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3270. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3271. if((maxProfile.ChargingSchedule.Duration > 0))
  3272. {
  3273. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3274. }
  3275. else
  3276. {
  3277. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3278. }
  3279. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3280. {
  3281. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3282. {
  3283. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3284. compositePeriodIdx++;
  3285. }
  3286. else
  3287. {
  3288. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3289. }
  3290. }
  3291. // Delete duplicate period
  3292. if(compositePeriodIdx > 1)
  3293. {
  3294. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3295. {
  3296. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3297. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3298. compositePeriodIdx -= 1;
  3299. }
  3300. }
  3301. }
  3302. else
  3303. {
  3304. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3305. {
  3306. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3307. compositePeriodIdx++;
  3308. }
  3309. else
  3310. {
  3311. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3312. }
  3313. break;
  3314. }
  3315. }
  3316. }
  3317. else
  3318. {
  3319. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3320. {
  3321. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3322. compositePeriodIdx++;
  3323. }
  3324. else
  3325. {
  3326. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3327. }
  3328. }
  3329. }
  3330. }
  3331. }
  3332. // Fill other period by MaxProfile
  3333. if(maxProfile.ChargingProfileId != -1)
  3334. {
  3335. if(compositePeriodIdx==0)
  3336. {
  3337. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3338. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3339. {
  3340. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3341. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3342. (maxProfile.ChargingSchedule.Duration > 0))
  3343. {
  3344. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3345. {
  3346. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3347. compositePeriodIdx++;
  3348. }
  3349. else
  3350. {
  3351. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3352. }
  3353. }
  3354. }
  3355. }
  3356. else
  3357. {
  3358. int lastCompositePeriodIdx = compositePeriodIdx;
  3359. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3360. {
  3361. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3362. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3363. (maxProfile.ChargingSchedule.Duration > 0))
  3364. {
  3365. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3366. {
  3367. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3368. {
  3369. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3370. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3371. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3372. }
  3373. else
  3374. {
  3375. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3376. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3377. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3378. }
  3379. }
  3380. if(tmpPeriod.Limit != -1)
  3381. {
  3382. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3383. {
  3384. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3385. {
  3386. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3387. compositePeriodIdx++;
  3388. }
  3389. else
  3390. {
  3391. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3392. }
  3393. }
  3394. // Delete duplicate period
  3395. if(compositePeriodIdx > 1)
  3396. {
  3397. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3398. {
  3399. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3400. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3401. compositePeriodIdx -= 1;
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. }
  3409. compositeProfile.ChargingSchedule.Duration = durationReq;
  3410. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3411. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3412. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3413. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3414. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3415. {
  3416. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3417. {
  3418. compositeProfile.ChargingProfileId = 1;
  3419. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3420. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3421. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3422. }
  3423. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3424. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3425. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3426. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3427. }
  3428. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3429. if(line)
  3430. free(line);
  3431. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3432. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3433. }
  3434. //==========================================
  3435. // Init all share memory
  3436. //==========================================
  3437. int InitShareMemory()
  3438. {
  3439. int result = PASS;
  3440. int MeterSMId;
  3441. //creat ShmSysConfigAndInfo
  3442. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3443. {
  3444. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3445. result = FAIL;
  3446. }
  3447. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3448. {
  3449. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3450. result = FAIL;
  3451. }
  3452. else
  3453. {}
  3454. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3455. {
  3456. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3457. result = FAIL;
  3458. }
  3459. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3460. {
  3461. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3462. result = FAIL;
  3463. }
  3464. else
  3465. {}
  3466. //creat ShmPsuData
  3467. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3468. {
  3469. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3470. result = FAIL;
  3471. }
  3472. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3473. {
  3474. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3475. result = FAIL;
  3476. }
  3477. else
  3478. {}
  3479. //link ShmOCPP16Data
  3480. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3481. {
  3482. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3483. result = FAIL;
  3484. }
  3485. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3486. {
  3487. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3488. result = FAIL;
  3489. }
  3490. else
  3491. {}
  3492. //creat ShmOCPP16DataPH
  3493. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3494. {
  3495. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3496. result = FAIL;
  3497. }
  3498. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3499. {
  3500. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3501. result = FAIL;
  3502. }
  3503. else
  3504. {}
  3505. /****************************** For Initial Settings************************************************/
  3506. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3507. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3508. // allocate Configuration memory address
  3509. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3510. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3511. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3512. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3513. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3514. //offline MeterValue Interval
  3515. TempMeterValueInterval = 0;
  3516. return result;
  3517. }
  3518. int ProcessShareMemory()
  3519. {
  3520. int result = PASS;
  3521. if(InitShareMemory() == FAIL)
  3522. {
  3523. DEBUG_ERROR("InitShareMemory NG\n");
  3524. if(ShmStatusCodeData!=NULL)
  3525. {
  3526. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3527. }
  3528. result = FAIL;
  3529. }
  3530. // Model name parsing
  3531. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3532. {
  3533. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3534. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3535. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3536. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3537. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3538. ) // 'D' means DC
  3539. {
  3540. // DO series
  3541. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3542. {
  3543. gunTotalNumber += 1;
  3544. gunType[gun_index] = GUN_TYPE_DO;
  3545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3546. {
  3547. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3548. {
  3549. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3550. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3551. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3552. }
  3553. }
  3554. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3555. {
  3556. case Gun_Type_Chademo:
  3557. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3558. break;
  3559. case Gun_Type_CCS_2:
  3560. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3561. break;
  3562. case Gun_Type_GB:
  3563. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3564. break;
  3565. case Gun_Type_AC:
  3566. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3567. break;
  3568. default:
  3569. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3570. break;
  3571. }
  3572. }
  3573. }
  3574. else
  3575. {
  3576. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3577. {
  3578. gunTotalNumber += 1;
  3579. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3580. {
  3581. case Gun_Type_Chademo:
  3582. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3583. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3584. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3585. {
  3586. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3587. {
  3588. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3589. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3590. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  3591. }
  3592. }
  3593. break;
  3594. case Gun_Type_CCS_2:
  3595. gunType[gun_index] = GUN_TYPE_CCS;
  3596. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3597. for (int index = 0; index < CCS_QUANTITY; index++)
  3598. {
  3599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3600. {
  3601. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3602. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3603. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  3604. }
  3605. }
  3606. break;
  3607. case Gun_Type_GB:
  3608. gunType[gun_index] = GUN_TYPE_GBT;
  3609. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3610. for (int index = 0; index < GB_QUANTITY; index++)
  3611. {
  3612. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3613. {
  3614. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3615. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3616. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  3617. }
  3618. }
  3619. break;
  3620. case Gun_Type_AC:
  3621. gunType[gun_index] = GUN_TYPE_AC;
  3622. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3623. for (int index = 0; index < AC_QUANTITY; index++)
  3624. {
  3625. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  3626. {
  3627. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3628. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3629. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  3630. }
  3631. }
  3632. break;
  3633. default:
  3634. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3635. break;
  3636. }
  3637. }
  3638. }
  3639. }
  3640. else
  3641. {
  3642. DEBUG_ERROR("Model name parsing fail.\n");
  3643. result = FAIL;
  3644. }
  3645. if(result != PASS)sleep(5);
  3646. return result;
  3647. }
  3648. void checkRemoteStart(uint8_t connectorIdInt)
  3649. {
  3650. uint8_t tempIndex;
  3651. int result = PASS;
  3652. char cmdBuf[512];
  3653. //check Transaction active
  3654. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3655. {
  3656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3657. {
  3658. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3659. }
  3660. else
  3661. {
  3662. tempIndex = connectorIdInt -1;
  3663. }
  3664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3665. {
  3666. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3667. {
  3668. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3669. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3670. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3671. {
  3672. //Reserved
  3673. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3674. }
  3675. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3677. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3678. {
  3679. //Reserved
  3680. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3681. result = FAIL;
  3682. goto end;
  3683. }
  3684. else
  3685. {
  3686. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3687. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3688. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3689. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3690. {
  3691. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3692. result = FAIL;
  3693. goto end;
  3694. }
  3695. }//END FOR ELSE
  3696. }
  3697. }// END FOR CHAdeMO_QUANTITY
  3698. }
  3699. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3700. {
  3701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3702. {
  3703. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3704. }
  3705. else
  3706. {
  3707. tempIndex = connectorIdInt -1;
  3708. }
  3709. for (int index = 0; index < CCS_QUANTITY; index++)
  3710. {
  3711. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3712. {
  3713. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3714. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3715. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3716. {
  3717. //Reserved
  3718. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3719. }
  3720. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3721. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3722. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3723. {
  3724. //Reserved
  3725. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3726. result = FAIL;
  3727. goto end;
  3728. }
  3729. else
  3730. {
  3731. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3732. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3733. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3734. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3735. {
  3736. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3737. result = FAIL;
  3738. goto end;
  3739. }
  3740. }// END FOR ELSE
  3741. }
  3742. }// END FOR CCS_QUANTITY
  3743. }
  3744. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3745. {
  3746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3747. {
  3748. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3749. }
  3750. else
  3751. {
  3752. tempIndex = connectorIdInt -1;
  3753. }
  3754. for (int index = 0; index < GB_QUANTITY; index++)
  3755. {
  3756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3757. {
  3758. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3759. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3760. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3761. {
  3762. //Reserved
  3763. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3764. }
  3765. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3766. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3767. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3768. {
  3769. //Reserved
  3770. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3771. result = FAIL;
  3772. goto end;
  3773. }
  3774. else
  3775. {
  3776. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3777. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3778. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3779. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3780. {
  3781. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3782. result = FAIL;
  3783. goto end;
  3784. }
  3785. }// END FOR ELSE
  3786. }
  3787. } // END FOR GB_QUANTITY
  3788. }
  3789. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3790. {
  3791. tempIndex = connectorIdInt -1;
  3792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3793. {
  3794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3795. {
  3796. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3797. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3798. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3799. {
  3800. //Reserved
  3801. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3802. }
  3803. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3804. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3805. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3806. {
  3807. //Reserved
  3808. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3809. result = FAIL;
  3810. goto end;
  3811. }
  3812. else
  3813. {
  3814. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3815. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3816. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3817. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3818. {
  3819. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3820. result = FAIL;
  3821. goto end;
  3822. }
  3823. }// END FOR ELSE
  3824. }
  3825. } // END FOR GB_QUANTITY
  3826. }
  3827. else
  3828. {
  3829. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3830. {
  3831. tempIndex = 2;
  3832. }
  3833. else
  3834. {
  3835. tempIndex = connectorIdInt -1;
  3836. }
  3837. for (int index = 0; index < AC_QUANTITY; index++)
  3838. {
  3839. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3840. {
  3841. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3842. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3843. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3844. {
  3845. //Reserved
  3846. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3847. }
  3848. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3849. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3850. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3851. {
  3852. //Reserved
  3853. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3854. result = FAIL;
  3855. goto end;
  3856. }
  3857. else
  3858. {
  3859. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3860. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3861. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3862. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3863. {
  3864. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3865. result = FAIL;
  3866. goto end;
  3867. }
  3868. }//END FOR ELSE
  3869. }
  3870. }// END FOR AC_QUANTITY
  3871. }
  3872. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3873. {
  3874. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3875. {
  3876. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3877. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3878. {
  3879. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3880. system(cmdBuf);
  3881. }
  3882. }
  3883. else
  3884. {
  3885. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3886. result = FAIL;
  3887. }
  3888. }
  3889. end:
  3890. if(result == PASS)
  3891. {
  3892. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3893. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3894. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3895. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3896. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3897. }
  3898. }
  3899. void CheckSystemValue(void)
  3900. {
  3901. char filenmae[100]={0};
  3902. char str[100]={0};
  3903. int tempIndex = 0;
  3904. //===============================
  3905. // send Heartbeat
  3906. //===============================
  3907. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3908. {
  3909. //parameter for test
  3910. sendHeartbeatRequest(0);
  3911. //==============================================
  3912. // Reset Waiting Time
  3913. //==============================================
  3914. HeartBeatWithNOResponse += 2;
  3915. }
  3916. //===============================
  3917. // Credit deduct report
  3918. //===============================
  3919. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3920. {
  3921. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3922. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3923. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3924. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3925. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3926. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3927. }
  3928. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3929. {
  3930. OCPP_query_deduct_info();
  3931. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3932. }
  3933. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3934. {
  3935. // ClockAlign MeterValue
  3936. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3937. {
  3938. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3939. {
  3940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3941. {
  3942. tempIndex = ((gun_index==2) ? 1: 0);
  3943. }
  3944. else
  3945. {
  3946. tempIndex = gun_index;
  3947. }
  3948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3949. {
  3950. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3951. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3952. {
  3953. reqClockAlignMeter[gun_index] = 1;
  3954. }
  3955. }// End for CHAdeMO
  3956. }
  3957. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3958. {
  3959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3960. {
  3961. tempIndex = ((gun_index==2) ? 1: 0);
  3962. }
  3963. else
  3964. {
  3965. tempIndex = gun_index;
  3966. }
  3967. for (int index = 0; index < CCS_QUANTITY; index++)
  3968. {
  3969. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3970. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3971. {
  3972. reqClockAlignMeter[gun_index] = 1;
  3973. }
  3974. } // End for CCS
  3975. }
  3976. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3977. {
  3978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3979. {
  3980. tempIndex = ((gun_index==2) ? 1: 0);
  3981. }
  3982. else
  3983. {
  3984. tempIndex = gun_index;
  3985. }
  3986. for (int index = 0; index < GB_QUANTITY; index++)
  3987. {
  3988. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3989. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3990. {
  3991. reqClockAlignMeter[gun_index] = 1;
  3992. }
  3993. }// End for GB
  3994. }
  3995. else if(gunType[gun_index] == GUN_TYPE_DO)
  3996. {
  3997. tempIndex = gun_index;
  3998. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3999. {
  4000. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4001. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4002. {
  4003. reqClockAlignMeter[gun_index] = 1;
  4004. }
  4005. }
  4006. }
  4007. else
  4008. {
  4009. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4010. {
  4011. tempIndex = 2;
  4012. }
  4013. else
  4014. {
  4015. tempIndex = gun_index;
  4016. }
  4017. for (int index = 0; index < AC_QUANTITY; index++)
  4018. {
  4019. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4020. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4021. {
  4022. reqClockAlignMeter[gun_index] = 1;
  4023. }
  4024. }//End for AC
  4025. }
  4026. }
  4027. }
  4028. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4029. {
  4030. //==========================================
  4031. // Check remote start without connector id
  4032. //==========================================
  4033. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  4034. {
  4035. int connectorIdInt = -1;
  4036. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4037. {
  4038. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4039. {
  4040. connectorIdInt = (gun_index+1);
  4041. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4042. checkRemoteStart(connectorIdInt);
  4043. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4044. break;
  4045. }
  4046. }
  4047. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4048. {
  4049. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4050. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4051. }
  4052. }
  4053. //==========================================
  4054. // csu trigger DataTransferReq
  4055. //==========================================
  4056. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4057. {
  4058. sendDataTransferRequest(gun_index);
  4059. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4060. }
  4061. //===============================
  4062. // CSU Trigger Authorize Request
  4063. //===============================
  4064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4065. {
  4066. sendAuthorizeRequest(0);
  4067. authorizeRetryTimes = authorizeRetryTimes + 1;
  4068. if(authorizeRetryTimes < 3)
  4069. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4070. }
  4071. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4072. {
  4073. authorizeRetryTimes = 0;
  4074. SetOcppConnStatus(FALSE);
  4075. server_sign = FALSE;
  4076. }
  4077. 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))
  4078. {
  4079. sendAuthorizeRequest(0);
  4080. }
  4081. //==============================================
  4082. // Charger start transaction
  4083. //==============================================
  4084. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4085. {
  4086. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4087. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4088. sendStartTransactionRequest(gun_index);
  4089. refreshStartTimer(&clientTime.StartTransaction);
  4090. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4091. //storeTempStopTransaction(gun_index);
  4092. }
  4093. //==============================================
  4094. // Charger stop transaction
  4095. //==============================================
  4096. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4097. {
  4098. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4099. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4100. sendStopTransactionRequest(gun_index);
  4101. refreshStartTimer(&clientTime.StopTransaction);
  4102. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4103. }
  4104. //==============================================
  4105. // Charger status report
  4106. //==============================================
  4107. //--- Check Mode Change ---//
  4108. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4110. {
  4111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4112. {
  4113. tempIndex = ((gun_index==2) ? 1: 0);
  4114. }
  4115. else
  4116. {
  4117. tempIndex = gun_index;
  4118. }
  4119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4120. {
  4121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4122. {
  4123. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4124. {
  4125. // Sent unplug message for California pricing logic
  4126. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4127. {
  4128. uint8_t ts[36];
  4129. getNowDatetime(ts);
  4130. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4131. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4132. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4133. sendUnplugByDataTransferRequest(gun_index);
  4134. interLock.isSentUnplug[gun_index] = 1;
  4135. }
  4136. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4137. {
  4138. interLock.isSentUnplug[gun_index] = 0;
  4139. }
  4140. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4141. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4142. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4143. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4144. {
  4145. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4146. if((access(filenmae,F_OK))!=-1)
  4147. {
  4148. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4149. sprintf(str,"rm -f %s",filenmae);
  4150. system(str);
  4151. }
  4152. }
  4153. }
  4154. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4155. #if 1 // for TempStopTransaction
  4156. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4157. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4158. {
  4159. checkTempStopTransaction(gun_index);
  4160. }
  4161. #endif
  4162. }
  4163. }
  4164. }
  4165. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4166. {
  4167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4168. {
  4169. tempIndex = ((gun_index==2) ? 1: 0);
  4170. }
  4171. else
  4172. {
  4173. tempIndex = gun_index;
  4174. }
  4175. for (int index = 0; index < CCS_QUANTITY; index++)
  4176. {
  4177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4178. {
  4179. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  4180. {
  4181. // Sent unplug message for California pricing logic
  4182. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4183. {
  4184. uint8_t ts[36];
  4185. getNowDatetime(ts);
  4186. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4187. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4188. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4189. sendUnplugByDataTransferRequest(gun_index);
  4190. interLock.isSentUnplug[gun_index] = 1;
  4191. }
  4192. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4193. {
  4194. interLock.isSentUnplug[gun_index] = 0;
  4195. }
  4196. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4197. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4198. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4199. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4200. {
  4201. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4202. if((access(filenmae,F_OK))!=-1)
  4203. {
  4204. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4205. sprintf(str,"rm -f %s",filenmae);
  4206. system(str);
  4207. }
  4208. }
  4209. }
  4210. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4211. #if 1 // for TempStopTransaction
  4212. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4213. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4214. {
  4215. checkTempStopTransaction(gun_index);
  4216. }
  4217. #endif
  4218. }
  4219. }
  4220. }
  4221. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4222. {
  4223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4224. {
  4225. tempIndex = ((gun_index==2) ? 1: 0);
  4226. }
  4227. else
  4228. {
  4229. tempIndex = gun_index;
  4230. }
  4231. for (int index = 0; index < GB_QUANTITY; index++)
  4232. {
  4233. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4234. {
  4235. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4236. {
  4237. // Sent unplug message for California pricing logic
  4238. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4239. {
  4240. uint8_t ts[36];
  4241. getNowDatetime(ts);
  4242. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4243. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4244. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4245. sendUnplugByDataTransferRequest(gun_index);
  4246. interLock.isSentUnplug[gun_index] = 1;
  4247. }
  4248. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4249. {
  4250. interLock.isSentUnplug[gun_index] = 0;
  4251. }
  4252. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4253. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4254. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4255. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4256. {
  4257. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4258. if((access(filenmae,F_OK))!=-1)
  4259. {
  4260. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4261. sprintf(str,"rm -f %s",filenmae);
  4262. system(str);
  4263. }
  4264. }
  4265. }
  4266. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4267. #if 1 // for TempStopTransaction
  4268. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4269. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4270. {
  4271. checkTempStopTransaction(gun_index);
  4272. }
  4273. #endif
  4274. }
  4275. }
  4276. }
  4277. else if(gunType[gun_index] == GUN_TYPE_DO)
  4278. {
  4279. tempIndex = gun_index;
  4280. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4281. {
  4282. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4283. {
  4284. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4285. {
  4286. // Sent unplug message for California pricing logic
  4287. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4288. {
  4289. uint8_t ts[36];
  4290. getNowDatetime(ts);
  4291. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4292. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4293. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4294. sendUnplugByDataTransferRequest(gun_index);
  4295. interLock.isSentUnplug[gun_index] = 1;
  4296. }
  4297. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4298. {
  4299. interLock.isSentUnplug[gun_index] = 0;
  4300. }
  4301. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4302. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4303. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4304. 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
  4305. {
  4306. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4307. if((access(filenmae,F_OK))!=-1)
  4308. {
  4309. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4310. sprintf(str,"rm -f %s",filenmae);
  4311. system(str);
  4312. }
  4313. }
  4314. }
  4315. 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);
  4316. #if 1 // for TempStopTransaction
  4317. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4318. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4319. {
  4320. checkTempStopTransaction(gun_index);
  4321. }
  4322. #endif
  4323. }
  4324. }
  4325. }
  4326. else
  4327. {
  4328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4329. {
  4330. tempIndex = 2;
  4331. }
  4332. else
  4333. {
  4334. tempIndex = gun_index;
  4335. }
  4336. for (int index = 0; index < AC_QUANTITY; index++)
  4337. {
  4338. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4339. {
  4340. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4341. {
  4342. // Sent unplug message for California pricing logic
  4343. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4344. {
  4345. uint8_t ts[36];
  4346. getNowDatetime(ts);
  4347. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4348. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4349. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4350. sendUnplugByDataTransferRequest(gun_index);
  4351. interLock.isSentUnplug[gun_index] = 1;
  4352. }
  4353. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4354. {
  4355. interLock.isSentUnplug[gun_index] = 0;
  4356. }
  4357. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4358. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4359. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4360. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4361. {
  4362. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4363. if((access(filenmae,F_OK))!=-1)
  4364. {
  4365. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4366. sprintf(str,"rm -f %s",filenmae);
  4367. system(str);
  4368. }
  4369. }
  4370. }
  4371. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4372. #if 1 // for TempStopTransaction
  4373. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4374. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4375. {
  4376. checkTempStopTransaction(gun_index);
  4377. }
  4378. #endif
  4379. }
  4380. }// END
  4381. }
  4382. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4383. (
  4384. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4385. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4386. )
  4387. )
  4388. {
  4389. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4390. sendStatusNotificationRequest(gun_index);
  4391. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4392. }
  4393. //==============================================
  4394. // TCCI reader status report
  4395. //==============================================
  4396. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4397. {
  4398. reportReaderStatus(gun_index);
  4399. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4400. }
  4401. //==============================================
  4402. // CSU Trigger Smart Charging Profile
  4403. //==============================================
  4404. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4405. {
  4406. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4407. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4408. }
  4409. //==============================================
  4410. // Meter report
  4411. //==============================================
  4412. // Trigger MeterValue
  4413. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4414. {
  4415. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4416. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4417. }
  4418. // Clock-aligned Meter value
  4419. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4420. {
  4421. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4422. reqClockAlignMeter[gun_index] = 0;
  4423. }
  4424. // Sample period MeterValue
  4425. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4426. {
  4427. //check Transaction active
  4428. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4429. {
  4430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4431. {
  4432. tempIndex = ((gun_index==2) ? 1: 0);
  4433. }
  4434. else
  4435. {
  4436. tempIndex = gun_index;
  4437. }
  4438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4439. {
  4440. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4441. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4442. {
  4443. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4444. {
  4445. reqSampleMeter[gun_index] = 1;
  4446. }
  4447. }
  4448. }// End for CHAdeMO
  4449. }
  4450. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4451. {
  4452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4453. {
  4454. tempIndex = ((gun_index==2) ? 1: 0);
  4455. }
  4456. else
  4457. {
  4458. tempIndex = gun_index;
  4459. }
  4460. for (int index = 0; index < CCS_QUANTITY; index++)
  4461. {
  4462. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4463. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4464. {
  4465. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4466. {
  4467. reqSampleMeter[gun_index] = 1;
  4468. }
  4469. }
  4470. } // End for CCS
  4471. }
  4472. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4473. {
  4474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4475. {
  4476. tempIndex = ((gun_index==2) ? 1: 0);
  4477. }
  4478. else
  4479. {
  4480. tempIndex = gun_index;
  4481. }
  4482. for (int index = 0; index < GB_QUANTITY; index++)
  4483. {
  4484. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4485. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4486. {
  4487. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4488. {
  4489. reqSampleMeter[gun_index] = 1;
  4490. }
  4491. }
  4492. }// End for GB
  4493. }
  4494. else if(gunType[gun_index] == GUN_TYPE_DO)
  4495. {
  4496. tempIndex = gun_index;
  4497. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4498. {
  4499. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4500. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4501. {
  4502. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4503. {
  4504. reqSampleMeter[gun_index] = 1;
  4505. }
  4506. }
  4507. }
  4508. }
  4509. else
  4510. {
  4511. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4512. {
  4513. tempIndex = 2;
  4514. }
  4515. else
  4516. {
  4517. tempIndex = gun_index;
  4518. }
  4519. for (int index = 0; index < AC_QUANTITY; index++)
  4520. {
  4521. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4522. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4523. {
  4524. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4525. {
  4526. reqSampleMeter[gun_index] = 1;
  4527. }
  4528. }
  4529. }//End for AC
  4530. }
  4531. if(reqSampleMeter[gun_index] == 1)
  4532. {
  4533. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4534. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4535. //storeTempStopTransaction(gun_index);
  4536. reqSampleMeter[gun_index] = 0;
  4537. }
  4538. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4539. }
  4540. //==============================================
  4541. // Check Connector reserved
  4542. //==============================================
  4543. //===============================
  4544. // Check if Reserve is expired
  4545. //===============================
  4546. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4547. {
  4548. double diff_t;
  4549. struct tm tp;
  4550. // current time
  4551. time_t t = time(NULL);
  4552. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4553. tp.tm_isdst = -1;
  4554. time_t utc = mktime(&tp);
  4555. diff_t = difftime(utc, t);
  4556. if(diff_t <= 0)
  4557. {
  4558. DEBUG_INFO("reserve expired.\n");
  4559. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4560. }
  4561. }//END OF Check if Reserve is expired
  4562. //==========================================
  4563. // csu trigger FirmwareStatusNotificationReq
  4564. //==========================================
  4565. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4566. {
  4567. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4568. }
  4569. //==========================================
  4570. // csu trigger DiagnosticsStatusNotificationReq
  4571. //==========================================
  4572. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4573. {
  4574. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4575. }
  4576. //==========================================
  4577. // csu trigger CancelReservationConf
  4578. //==========================================
  4579. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4580. {
  4581. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4582. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4583. }
  4584. //==========================================
  4585. // csu trigger ChangeAvailabilityConf
  4586. //==========================================
  4587. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4588. {
  4589. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4590. }
  4591. //==========================================
  4592. // csu trigger UnlockConnectorConf
  4593. //==========================================
  4594. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4595. {
  4596. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4597. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4598. }
  4599. //==========================================
  4600. // csu trigger ReserveNowConf
  4601. //==========================================
  4602. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4603. {
  4604. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4605. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4606. }
  4607. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4608. {
  4609. sendSignCertificateRequest();
  4610. }
  4611. }
  4612. }
  4613. //==========================================
  4614. // send request routine
  4615. //==========================================
  4616. int sendAuthorizeRequest(int gun_index)
  4617. {
  4618. mtrace();
  4619. int result = FAIL;
  4620. char message[100]={0};
  4621. char guid[37];
  4622. char tempdata[65]={0};
  4623. DEBUG_INFO("sendAuthorizeRequest...\n");
  4624. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4625. //Local Authorize
  4626. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4627. {
  4628. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4629. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4630. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4631. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4632. result = PASS;
  4633. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4634. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4635. authorizeRetryTimes = 0;
  4636. return result;
  4637. }
  4638. 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))||
  4639. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4640. {
  4641. // Query from cache
  4642. DEBUG_INFO("Authorize from cache.\n");
  4643. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4644. // Query from list
  4645. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4646. {
  4647. DEBUG_INFO("Authorize from list.\n");
  4648. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4649. }
  4650. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4651. {
  4652. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4653. {
  4654. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4655. }
  4656. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4657. {
  4658. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4659. }
  4660. if(!GetOcppConnStatus())
  4661. {
  4662. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4663. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4664. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4665. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4666. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4667. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4668. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4669. authorizeRetryTimes = 0;
  4670. return result;
  4671. }
  4672. }
  4673. else
  4674. {
  4675. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4676. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4677. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4678. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4679. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4680. else
  4681. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4682. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4683. result = PASS;
  4684. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4685. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4686. authorizeRetryTimes = 0;
  4687. return result;
  4688. }
  4689. }
  4690. //initialize struct Authorize
  4691. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4692. //get data from shared memory
  4693. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4694. random_uuid(guid);
  4695. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4696. LWS_Send(message);
  4697. sprintf(tempdata, "Authorize,%d", gun_index);
  4698. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4699. {
  4700. result = PASS;
  4701. DEBUG_INFO("Authorize mapItem pass\n");
  4702. }
  4703. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4704. return result;
  4705. }
  4706. int sendBootNotificationRequest(void)
  4707. {
  4708. mtrace();
  4709. int result = FAIL;
  4710. char message[500]={0}, payload[700]={0};
  4711. char guid[37]={0};
  4712. char tempdata[65]={0};
  4713. // Fill BootNotification fields
  4714. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4715. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4716. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4717. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4718. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4719. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4720. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4721. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4722. ShmOCPP16DataPH->ChargeBoxId
  4723. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4724. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4725. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4726. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4727. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4728. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4729. random_uuid(guid);
  4730. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4731. LWS_Send(message);
  4732. sprintf(tempdata, "BootNotification,0");
  4733. 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*/)
  4734. {
  4735. result = PASS;
  4736. }
  4737. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4738. strcpy(queuedata,message);
  4739. return result;
  4740. }
  4741. int sendDataTransferRequest(int gun_index)
  4742. {
  4743. mtrace();
  4744. char message[1000]={0};
  4745. char guid[37]={0};
  4746. char tempdata[65]={0};
  4747. int result = FAIL;
  4748. random_uuid(guid);
  4749. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4750. MESSAGE_TYPE_CALL,
  4751. guid,
  4752. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4753. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4754. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4755. LWS_Send(message);
  4756. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4757. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4758. {
  4759. result = PASS;
  4760. DEBUG_INFO("DataTransfer mapItem pass\n");
  4761. }
  4762. return result;
  4763. }
  4764. int sendUnplugByDataTransferRequest(int gun_index)
  4765. {
  4766. mtrace();
  4767. char message[1000]={0};
  4768. char guid[37]={0};
  4769. char tempdata[65]={0};
  4770. int result = FAIL;
  4771. random_uuid(guid);
  4772. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4773. (gun_index+1),
  4774. MESSAGE_TYPE_CALL,
  4775. guid,
  4776. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4777. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4778. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4779. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4780. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4781. {
  4782. result = PASS;
  4783. DEBUG_INFO("DataTransfer mapItem pass\n");
  4784. }
  4785. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4786. return result;
  4787. }
  4788. int sendDiagnosticsStatusNotificationRequest(char *status)
  4789. {
  4790. mtrace();
  4791. int result = FAIL;
  4792. char message[110]={0};
  4793. char guid[37]={0};
  4794. char tempdata[65]={0};
  4795. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4796. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4797. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4798. random_uuid(guid);
  4799. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4800. LWS_SendNow(message);
  4801. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4802. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4803. {
  4804. result = PASS;
  4805. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4806. }
  4807. //#ifdef SystemLogMessage
  4808. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4809. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4810. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4811. //#endif
  4812. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4813. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4814. //record status
  4815. if(strcmp(status,"Idle")==0)
  4816. {
  4817. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4818. }
  4819. else if(strcmp(status,"Uploaded")==0)
  4820. {
  4821. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4822. }
  4823. else if(strcmp(status,"UploadFailed")==0)
  4824. {
  4825. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4826. }
  4827. else if(strcmp(status,"Uploading")==0)
  4828. {
  4829. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4830. }
  4831. return result;
  4832. }
  4833. int sendFirmwareStatusNotificationRequest(char *status)
  4834. {
  4835. mtrace();
  4836. int result = FAIL;
  4837. char message[110]={0};
  4838. char guid[37]={0};
  4839. char tempdata[65]={0};
  4840. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4841. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4842. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4843. random_uuid(guid);
  4844. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4845. LWS_SendNow(message);
  4846. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4847. 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*/)
  4848. {
  4849. result = PASS;
  4850. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4851. }
  4852. //#ifdef SystemLogMessage
  4853. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4854. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4855. //#endif
  4856. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4857. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4858. //record status
  4859. if(strcmp(status,"Downloaded")==0)
  4860. {
  4861. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4862. }
  4863. else if(strcmp(status,"DownloadFailed")==0)
  4864. {
  4865. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4866. }
  4867. else if(strcmp(status,"Downloading")==0)
  4868. {
  4869. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4870. }
  4871. else if(strcmp(status,"Idle")==0)
  4872. {
  4873. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4874. }
  4875. else if(strcmp(status,"InstallationFailed")==0)
  4876. {
  4877. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4878. }
  4879. else if(strcmp(status,"Installing")==0)
  4880. {
  4881. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4882. }
  4883. else if(strcmp(status,"Installed")==0)
  4884. {
  4885. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4886. }
  4887. return result;
  4888. }
  4889. int sendHeartbeatRequest(int gun_index)
  4890. {
  4891. mtrace();
  4892. int result = FAIL;
  4893. char message[80]={0};
  4894. char guid[37]={0};
  4895. char tempdata[65]={0};
  4896. random_uuid(guid);
  4897. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4898. , MESSAGE_TYPE_CALL
  4899. , guid );
  4900. LWS_Send(message);
  4901. sprintf(tempdata, "Heartbeat,%d", 0);
  4902. 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*/)
  4903. {
  4904. result = PASS;
  4905. }
  4906. return result;
  4907. }
  4908. int sendStartTransactionRequest(int gun_index)
  4909. {
  4910. mtrace();
  4911. int result = FAIL;
  4912. char message[250]={0};
  4913. char guid[37]={0};
  4914. struct timeval tmnow;
  4915. struct tm *tm;
  4916. char buf[28];//, usec_buf[6];
  4917. char tempdata[65]={0};
  4918. int tempIndex = 0;
  4919. DEBUG_INFO("sendStartTransactionRequest...\n");
  4920. gettimeofday(&tmnow, NULL);
  4921. time_t t;
  4922. t = time(NULL);
  4923. /*UTC time and date*/
  4924. tm = gmtime(&t);
  4925. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4926. #if 0 // remove temporally
  4927. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4928. strcat(buf,".");
  4929. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4930. strcat(buf,usec_buf);
  4931. #endif
  4932. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4933. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4934. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4935. // clear StartTransaction Response
  4936. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4937. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4938. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4939. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4940. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4941. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4942. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4943. {
  4944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4945. {
  4946. tempIndex = ((gun_index==2) ? 1: 0);
  4947. }
  4948. else
  4949. {
  4950. tempIndex = gun_index;
  4951. }
  4952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4953. {
  4954. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4955. {
  4956. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4957. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4958. }
  4959. }
  4960. }
  4961. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4962. {
  4963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4964. {
  4965. tempIndex = ((gun_index==2) ? 1: 0);
  4966. }
  4967. else
  4968. {
  4969. tempIndex = gun_index;
  4970. }
  4971. for (int index = 0; index < CCS_QUANTITY; index++)
  4972. {
  4973. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4974. {
  4975. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4976. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4977. }
  4978. }
  4979. }
  4980. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4981. {
  4982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4983. {
  4984. tempIndex = ((gun_index==2) ? 1: 0);
  4985. }
  4986. else
  4987. {
  4988. tempIndex = gun_index;
  4989. }
  4990. for (int index = 0; index < GB_QUANTITY; index++)
  4991. {
  4992. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4993. {
  4994. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4995. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4996. }
  4997. }
  4998. }
  4999. else if(gunType[gun_index] == GUN_TYPE_DO)
  5000. {
  5001. tempIndex = gun_index;
  5002. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5003. {
  5004. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5005. {
  5006. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5007. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5008. }
  5009. }
  5010. }
  5011. else
  5012. {
  5013. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5014. {
  5015. tempIndex = 2;
  5016. }
  5017. else
  5018. {
  5019. tempIndex = gun_index;
  5020. }
  5021. for (int index = 0; index < AC_QUANTITY; index++)
  5022. {
  5023. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5024. {
  5025. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5026. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5027. }
  5028. }
  5029. }
  5030. random_uuid(guid);
  5031. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5032. {
  5033. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5034. , gun_index +1
  5035. , MESSAGE_TYPE_CALL
  5036. , guid
  5037. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5038. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5039. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5040. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5041. }
  5042. else
  5043. {
  5044. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5045. , gun_index +1
  5046. , MESSAGE_TYPE_CALL
  5047. , guid
  5048. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5049. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5050. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5051. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5052. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5053. }
  5054. #if 1
  5055. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5056. 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*/)
  5057. {
  5058. result = PASS;
  5059. }
  5060. #endif
  5061. strcpy(queuedata, message);
  5062. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5063. OCPP_insert_transaction_msg(YES, queuedata);
  5064. return result;
  5065. }
  5066. int sendStatusNotificationRequest(int gun_index)
  5067. {
  5068. mtrace();
  5069. int result = FAIL;
  5070. char message[600]={0};
  5071. char guid[37];
  5072. int currentStatus = 0;
  5073. struct timeval tmnow;
  5074. struct tm *tm;
  5075. char buf[28];//, usec_buf[6];
  5076. char tempdata[65]={0};
  5077. int tempIndex = 0;
  5078. uint8_t isStateChanged = TRUE;
  5079. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5080. gettimeofday(&tmnow, NULL);
  5081. time_t t;
  5082. t = time(NULL);
  5083. /*UTC time and date*/
  5084. tm = gmtime(&t);
  5085. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5086. #if 0 // remove temporally
  5087. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5088. strcat(buf,".");
  5089. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5090. strcat(buf,usec_buf);
  5091. #endif
  5092. //printf("%s",buf);
  5093. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5094. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5095. // it's option
  5096. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5097. /*
  5098. enum _SYSTEM_STATUS
  5099. {
  5100. S_BOOTING = 0,
  5101. S_IDLE, = 1
  5102. S_AUTHORIZING, =2
  5103. S_REASSIGN_CHECK, =3
  5104. S_REASSIGN, =4
  5105. S_PRECHARGE, =5
  5106. S_PREPARING_FOR_EV, =6
  5107. S_PREPARING_FOR_EVSE, =7
  5108. S_CHARGING, =8
  5109. S_TERMINATING, =9
  5110. S_COMPLETE, =10
  5111. S_ALARM, =11
  5112. S_FAULT =12
  5113. }
  5114. */
  5115. //check Transaction active
  5116. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5117. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5118. {
  5119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5120. {
  5121. tempIndex = ((gun_index==2) ? 1: 0);
  5122. }
  5123. else
  5124. {
  5125. tempIndex = gun_index;
  5126. }
  5127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5128. {
  5129. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5130. {
  5131. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5132. {
  5133. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5134. {
  5135. currentStatus = Preparing; //OCPP Status: Preparing
  5136. }
  5137. else
  5138. {
  5139. currentStatus = Available; //OCPP Status: Available
  5140. }
  5141. }
  5142. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5143. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5144. ) //S_PRECHARGE
  5145. {
  5146. currentStatus = Preparing; //OCPP Status: Preparing
  5147. }
  5148. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5149. {
  5150. currentStatus = Charging; //OCPP Status: Charging
  5151. }
  5152. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5153. {
  5154. currentStatus = Finishing; //OCPP Status: Finishing
  5155. }
  5156. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5157. {
  5158. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5159. }
  5160. 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
  5161. {
  5162. currentStatus = Unavailable; //OCPP Status: Unavailable
  5163. }
  5164. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5165. {
  5166. currentStatus = Faulted; //OCPP Status: Faulted
  5167. }
  5168. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5169. {
  5170. currentStatus = Reserved; //OCPP Status: Reserved
  5171. }
  5172. } //end of the same index
  5173. }//end of for CHAdeMO_QUANTITY
  5174. }
  5175. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5176. {
  5177. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5178. {
  5179. tempIndex = ((gun_index==2) ? 1: 0);
  5180. }
  5181. else
  5182. {
  5183. tempIndex = gun_index;
  5184. }
  5185. for (int index = 0; index < CCS_QUANTITY; index++)
  5186. {
  5187. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5190. {
  5191. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5192. {
  5193. currentStatus = Preparing; //OCPP Status: Preparing
  5194. }
  5195. else
  5196. {
  5197. currentStatus = Available; //OCPP Status: Available
  5198. }
  5199. }
  5200. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5201. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5202. ) //S_PRECHARGE
  5203. {
  5204. currentStatus = Preparing; //OCPP Status: Preparing
  5205. }
  5206. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5207. {
  5208. currentStatus = Charging; //OCPP Status: Charging
  5209. }
  5210. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5211. {
  5212. currentStatus = Finishing; //OCPP Status: Finishing
  5213. }
  5214. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5215. {
  5216. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5217. }
  5218. 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
  5219. {
  5220. currentStatus = Unavailable; //OCPP Status : Unavailable
  5221. }
  5222. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5223. {
  5224. currentStatus = Faulted; //OCPP Status: Faulted
  5225. }
  5226. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5227. {
  5228. currentStatus = Reserved; //OCPP Status: Reserved
  5229. }
  5230. } //end of the same index
  5231. } // end of for CCS_QUANTITY
  5232. }
  5233. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5234. {
  5235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5236. {
  5237. tempIndex = ((gun_index==2) ? 1: 0);
  5238. }
  5239. else
  5240. {
  5241. tempIndex = gun_index;
  5242. }
  5243. for (int index = 0; index < GB_QUANTITY; index++)
  5244. {
  5245. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5246. {
  5247. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5248. {
  5249. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5250. {
  5251. currentStatus = Preparing; //OCPP Status: Preparing
  5252. }
  5253. else
  5254. {
  5255. currentStatus = Available; //OCPP Status: Available
  5256. }
  5257. }
  5258. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5259. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5260. ) //S_PRECHARGE
  5261. {
  5262. currentStatus = Preparing; //OCPP Status: Preparing
  5263. }
  5264. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5265. {
  5266. currentStatus = Charging; //OCPP Status: Charging
  5267. }
  5268. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5269. {
  5270. currentStatus = Finishing; //OCPP Status: Finishing
  5271. }
  5272. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5273. {
  5274. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5275. }
  5276. 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
  5277. {
  5278. currentStatus = Unavailable; //OCPP Status: Unavailable
  5279. }
  5280. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5281. {
  5282. currentStatus = Faulted; //OCPP Status: Faulted
  5283. }
  5284. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5285. {
  5286. currentStatus = Reserved; //OCPP Status: Reserved
  5287. }
  5288. } //end of the same index
  5289. } // end of for GB_QUANTITY
  5290. }
  5291. else if(gunType[gun_index] == GUN_TYPE_DO)
  5292. {
  5293. tempIndex = gun_index;
  5294. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5295. {
  5296. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5297. {
  5298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5299. {
  5300. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5301. {
  5302. currentStatus = Preparing; //OCPP Status: Preparing
  5303. }
  5304. else
  5305. {
  5306. currentStatus = Available; //OCPP Status: Available
  5307. }
  5308. }
  5309. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5310. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5311. ) //S_PRECHARGE
  5312. {
  5313. currentStatus = Preparing; //OCPP Status: Preparing
  5314. }
  5315. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5316. {
  5317. currentStatus = Charging; //OCPP Status: Charging
  5318. }
  5319. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5320. {
  5321. currentStatus = Finishing; //OCPP Status: Finishing
  5322. }
  5323. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5324. {
  5325. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5326. }
  5327. 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
  5328. {
  5329. currentStatus = Unavailable; //OCPP Status: Unavailable
  5330. }
  5331. 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
  5332. {
  5333. currentStatus = Faulted; //OCPP Status: Faulted
  5334. }
  5335. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5336. {
  5337. currentStatus = Reserved; //OCPP Status: Reserved
  5338. }
  5339. } //end of the same index
  5340. }
  5341. }
  5342. else
  5343. {
  5344. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5345. {
  5346. tempIndex = 2;
  5347. }
  5348. else
  5349. {
  5350. tempIndex = gun_index;
  5351. }
  5352. for (int index = 0; index < AC_QUANTITY; index++)
  5353. {
  5354. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5355. {
  5356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5357. {
  5358. 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))
  5359. {
  5360. currentStatus = Preparing; //OCPP Status: Preparing
  5361. }
  5362. else
  5363. {
  5364. currentStatus = Available; //OCPP Status: Available
  5365. }
  5366. }
  5367. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5368. {
  5369. currentStatus = Preparing; //OCPP Status: Preparing
  5370. }
  5371. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5372. {
  5373. currentStatus = Charging; //OCPP Status: Charging
  5374. }
  5375. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5376. {
  5377. currentStatus = Finishing; //OCPP Status: Finishing
  5378. }
  5379. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5380. {
  5381. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5382. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5383. else
  5384. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5385. }
  5386. 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
  5387. {
  5388. currentStatus = Unavailable; //OCPP Status: Unavailable
  5389. }
  5390. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5391. {
  5392. currentStatus = Faulted; //OCPP Status: Faulted
  5393. }
  5394. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5395. {
  5396. currentStatus = Reserved; //OCPP Status: Reserved
  5397. }
  5398. }//end of the same index
  5399. }//end of for AC_QUANTITY
  5400. }
  5401. //it's option
  5402. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5403. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5404. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5405. {
  5406. isStateChanged = FALSE;
  5407. }
  5408. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5409. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5410. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5411. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5412. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5413. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5414. random_uuid(guid);
  5415. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5416. , MESSAGE_TYPE_CALL
  5417. , guid
  5418. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5419. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5420. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5421. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5422. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5423. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5424. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5425. if((server_sign == TRUE) && isStateChanged)
  5426. {
  5427. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5428. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5429. LWS_Send(message);
  5430. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5431. 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*/)
  5432. {
  5433. //DEBUG_ERROR("statusNotification mapitem pass");
  5434. result = PASS;
  5435. }
  5436. }
  5437. else
  5438. {
  5439. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5440. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5441. result = PASS;
  5442. }
  5443. return result;
  5444. }
  5445. int sendStopTransactionRequest(int gun_index)
  5446. {
  5447. mtrace();
  5448. int result = FAIL;
  5449. //char message[1500]={0};
  5450. char guid[37]={0};
  5451. char tempdata[65]={0};
  5452. int tempIndex = 0;
  5453. char TempStopTransaction[256];
  5454. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5455. //int idx_sample=0;
  5456. DEBUG_INFO("sendStopTransactionRequest \n");
  5457. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5458. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5459. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5460. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5461. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5462. {
  5463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5464. {
  5465. tempIndex = ((gun_index==2) ? 1: 0);
  5466. }
  5467. else
  5468. {
  5469. tempIndex = gun_index;
  5470. }
  5471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5472. {
  5473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5474. {
  5475. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5476. }
  5477. }// END OF CHAdeMO_QUANTITY
  5478. }
  5479. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5480. {
  5481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5482. {
  5483. tempIndex = ((gun_index==2) ? 1: 0);
  5484. }
  5485. else
  5486. {
  5487. tempIndex = gun_index;
  5488. }
  5489. for (int index = 0; index < CCS_QUANTITY; index++)
  5490. {
  5491. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5492. {
  5493. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5494. }
  5495. }// END OF CCS_QUANTITY
  5496. }
  5497. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5498. {
  5499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5500. {
  5501. tempIndex = ((gun_index==2) ? 1: 0);
  5502. }
  5503. else
  5504. {
  5505. tempIndex = gun_index;
  5506. }
  5507. for (int index = 0; index < GB_QUANTITY; index++)
  5508. {
  5509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5510. {
  5511. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5512. }
  5513. }// END OF GB_QUANTITY
  5514. }
  5515. else if(gunType[gun_index] == GUN_TYPE_DO)
  5516. {
  5517. tempIndex = gun_index;
  5518. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5519. {
  5520. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5521. {
  5522. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5523. }
  5524. }// END OF GB_QUANTITY
  5525. }
  5526. else
  5527. {
  5528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5529. {
  5530. tempIndex = 2;
  5531. }
  5532. else
  5533. {
  5534. tempIndex = gun_index;
  5535. }
  5536. for (int index = 0; index < AC_QUANTITY; index++)
  5537. {
  5538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5539. {
  5540. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5541. }
  5542. }// END OF AC_QUANTITY
  5543. }
  5544. //====================================== Stop Transaction Time =====================================================
  5545. struct timeval tmnow;
  5546. struct tm *tm;
  5547. char buf[28];//, usec_buf[6];
  5548. gettimeofday(&tmnow, NULL);
  5549. time_t t;
  5550. t = time(NULL);
  5551. /*UTC time and date*/
  5552. tm = gmtime(&t);
  5553. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5555. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5556. random_uuid(guid);
  5557. /***********************************transactionData******************************************************/
  5558. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5560. //=================================
  5561. // Transaction_Begin
  5562. //=================================
  5563. //=================================
  5564. // Transaction_End
  5565. //=================================
  5566. // ================================= Current.Import L1 ===============================================
  5567. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5568. {
  5569. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5570. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5571. {
  5572. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5573. {
  5574. tempIndex = ((gun_index==2) ? 1: 0);
  5575. }
  5576. else
  5577. {
  5578. tempIndex = gun_index;
  5579. }
  5580. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5581. {
  5582. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5583. {
  5584. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5585. }
  5586. }// End of for CHAdeMO_QUANTITY
  5587. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5588. }
  5589. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5590. {
  5591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5592. {
  5593. tempIndex = ((gun_index==2) ? 1: 0);
  5594. }
  5595. else
  5596. {
  5597. tempIndex = gun_index;
  5598. }
  5599. for (int index = 0; index < CCS_QUANTITY; index++)
  5600. {
  5601. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5602. {
  5603. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5604. }
  5605. }// End of for CCS_QUANTITY
  5606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5607. }
  5608. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5609. {
  5610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5611. {
  5612. tempIndex = ((gun_index==2) ? 1: 0);
  5613. }
  5614. else
  5615. {
  5616. tempIndex = gun_index;
  5617. }
  5618. for (int index = 0; index < GB_QUANTITY; index++)
  5619. {
  5620. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5621. {
  5622. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5623. }
  5624. }// End of for GB_QUANTITY
  5625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5626. }
  5627. else if(gunType[gun_index] == GUN_TYPE_DO)
  5628. {
  5629. tempIndex = gun_index;
  5630. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5631. {
  5632. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5633. {
  5634. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5635. }
  5636. }
  5637. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5638. }
  5639. else
  5640. {
  5641. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5642. {
  5643. tempIndex = 2;
  5644. }
  5645. else
  5646. {
  5647. tempIndex = gun_index;
  5648. }
  5649. for (int index = 0; index < AC_QUANTITY; index++)
  5650. {
  5651. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5652. {
  5653. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5654. }
  5655. }// End of for AC_QUANTITY
  5656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5657. }
  5658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5661. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5663. }
  5664. // ================================= Energy.Active.Import.Interval ==============================================
  5665. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5666. {
  5667. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5668. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5669. {
  5670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5671. {
  5672. tempIndex = ((gun_index==2) ? 1: 0);
  5673. }
  5674. else
  5675. {
  5676. tempIndex = gun_index;
  5677. }
  5678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5679. {
  5680. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5681. {
  5682. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5683. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5684. }
  5685. }// END OF CHAdeMO_QUANTITY
  5686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5687. }
  5688. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5689. {
  5690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5691. {
  5692. tempIndex = ((gun_index==2) ? 1: 0);
  5693. }
  5694. else
  5695. {
  5696. tempIndex = gun_index;
  5697. }
  5698. for (int index = 0; index < CCS_QUANTITY; index++)
  5699. {
  5700. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5701. {
  5702. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5703. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5704. }
  5705. }// END OF CCS_QUANTITY
  5706. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5707. }
  5708. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5709. {
  5710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5711. {
  5712. tempIndex = ((gun_index==2) ? 1: 0);
  5713. }
  5714. else
  5715. {
  5716. tempIndex = gun_index;
  5717. }
  5718. for (int index = 0; index < GB_QUANTITY; index++)
  5719. {
  5720. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5721. {
  5722. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5723. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5724. }
  5725. }// END OF GB_QUANTITY
  5726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5727. }
  5728. else if(gunType[gun_index] == GUN_TYPE_DO)
  5729. {
  5730. tempIndex = gun_index;
  5731. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5732. {
  5733. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5734. {
  5735. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5736. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5737. }
  5738. }
  5739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5740. }
  5741. else
  5742. {
  5743. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5744. {
  5745. tempIndex = 2;
  5746. }
  5747. else
  5748. {
  5749. tempIndex = gun_index;
  5750. }
  5751. for (int index = 0; index < AC_QUANTITY; index++)
  5752. {
  5753. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5754. {
  5755. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5756. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5757. }
  5758. }// END OF AC_QUANTITY
  5759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5760. }
  5761. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5762. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5763. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5764. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5765. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5766. }
  5767. //=================================== Power.Active.Import ==================================================
  5768. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5769. {
  5770. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5771. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5772. {
  5773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5774. {
  5775. tempIndex = ((gun_index==2) ? 1: 0);
  5776. }
  5777. else
  5778. {
  5779. tempIndex = gun_index;
  5780. }
  5781. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5782. {
  5783. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5784. {
  5785. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5786. }
  5787. } // End for CHAdeMO_QUANTITY
  5788. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5789. }
  5790. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5791. {
  5792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5793. {
  5794. tempIndex = ((gun_index==2) ? 1: 0);
  5795. }
  5796. else
  5797. {
  5798. tempIndex = gun_index;
  5799. }
  5800. for (int index = 0; index < CCS_QUANTITY; index++)
  5801. {
  5802. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5803. {
  5804. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5805. }
  5806. } // END for CCS_QUANTITY
  5807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5808. }
  5809. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5810. {
  5811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5812. {
  5813. tempIndex = ((gun_index==2) ? 1: 0);
  5814. }
  5815. else
  5816. {
  5817. tempIndex = gun_index;
  5818. }
  5819. for (int index = 0; index < GB_QUANTITY; index++)
  5820. {
  5821. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5822. {
  5823. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5824. }
  5825. }// END for GB_QUANTITY
  5826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5827. }
  5828. else if(gunType[gun_index] == GUN_TYPE_DO)
  5829. {
  5830. tempIndex = gun_index;
  5831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5832. {
  5833. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5834. {
  5835. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5836. }
  5837. }
  5838. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5839. }
  5840. else
  5841. {
  5842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5843. {
  5844. tempIndex = 2;
  5845. }
  5846. else
  5847. {
  5848. tempIndex = gun_index;
  5849. }
  5850. for (int index = 0; index < AC_QUANTITY; index++)
  5851. {
  5852. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5853. {
  5854. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5855. }
  5856. } // END for AC_QUANTITY
  5857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5858. }
  5859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5862. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5864. }
  5865. //============================ Voltage L1 ====================================
  5866. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5867. {
  5868. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5869. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5870. {
  5871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5872. {
  5873. tempIndex = ((gun_index==2) ? 1: 0);
  5874. }
  5875. else
  5876. {
  5877. tempIndex = gun_index;
  5878. }
  5879. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5880. {
  5881. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5882. {
  5883. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5884. }
  5885. } // END OF FOR CHAdeMO_QUANTITY
  5886. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5887. }
  5888. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5889. {
  5890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5891. {
  5892. tempIndex = ((gun_index==2) ? 1: 0);
  5893. }
  5894. else
  5895. {
  5896. tempIndex = gun_index;
  5897. }
  5898. for (int index = 0; index < CCS_QUANTITY; index++)
  5899. {
  5900. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5901. {
  5902. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5903. }
  5904. } // END OF FOR CCS_QUANTITY
  5905. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5906. }
  5907. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5908. {
  5909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5910. {
  5911. tempIndex = ((gun_index==2) ? 1: 0);
  5912. }
  5913. else
  5914. {
  5915. tempIndex = gun_index;
  5916. }
  5917. for (int index = 0; index < GB_QUANTITY; index++)
  5918. {
  5919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5920. {
  5921. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5922. }
  5923. } // END OF FOR GB_QUANTITY
  5924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5925. }
  5926. else if(gunType[gun_index] == GUN_TYPE_DO)
  5927. {
  5928. tempIndex = gun_index;
  5929. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5930. {
  5931. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5932. {
  5933. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5934. }
  5935. }
  5936. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5937. }
  5938. else
  5939. {
  5940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5941. {
  5942. tempIndex = 2;
  5943. }
  5944. else
  5945. {
  5946. tempIndex = gun_index;
  5947. }
  5948. for (int index = 0; index < AC_QUANTITY; index++)
  5949. {
  5950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5951. {
  5952. 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
  5953. }
  5954. } // END OF FOR AC_QUANTITY
  5955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5956. }
  5957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5958. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5960. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5961. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5962. }
  5963. //====================== End SoC ================================
  5964. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5965. {
  5966. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5967. 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))
  5968. {
  5969. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5970. {
  5971. tempIndex = ((gun_index==2) ? 1: 0);
  5972. }
  5973. else
  5974. {
  5975. tempIndex = gun_index;
  5976. }
  5977. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5978. {
  5979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5980. {
  5981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5982. {
  5983. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5984. }
  5985. }
  5986. }
  5987. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5988. {
  5989. for (int index = 0; index < CCS_QUANTITY; index++)
  5990. {
  5991. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5992. {
  5993. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5994. }
  5995. }
  5996. }
  5997. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5998. {
  5999. for (int index = 0; index < GB_QUANTITY; index++)
  6000. {
  6001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6002. {
  6003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6004. }
  6005. }
  6006. }
  6007. else if(gunType[gun_index] == GUN_TYPE_DO)
  6008. {
  6009. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6012. {
  6013. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6014. }
  6015. }
  6016. }
  6017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6020. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6021. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6022. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6023. } // END FOR DC CASE
  6024. }
  6025. // ================================= Current.Import L2 ===============================================
  6026. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6027. {
  6028. // AC 3 phse L2 current
  6029. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6030. {
  6031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6032. {
  6033. tempIndex = 2;
  6034. }
  6035. else
  6036. {
  6037. tempIndex = gun_index;
  6038. }
  6039. for (int index = 0; index < AC_QUANTITY; index++)
  6040. {
  6041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6042. {
  6043. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6044. }
  6045. }// End of for AC_QUANTITY
  6046. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6047. }
  6048. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6049. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6050. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6051. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6052. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6053. }
  6054. // ================================= Current.Import L3 ===============================================
  6055. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6056. {
  6057. // AC 3 phse L3 current
  6058. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6059. {
  6060. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6061. {
  6062. tempIndex = 2;
  6063. }
  6064. else
  6065. {
  6066. tempIndex = gun_index;
  6067. }
  6068. for (int index = 0; index < AC_QUANTITY; index++)
  6069. {
  6070. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6071. {
  6072. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6073. }
  6074. }// End of for AC_QUANTITY
  6075. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6076. }
  6077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6078. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6080. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6081. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6082. }
  6083. //============================ Voltage L2 ====================================
  6084. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6085. {
  6086. // AC 3 phse L2 voltage
  6087. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6088. {
  6089. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6090. {
  6091. tempIndex = 2;
  6092. }
  6093. else
  6094. {
  6095. tempIndex = gun_index;
  6096. }
  6097. for (int index = 0; index < AC_QUANTITY; index++)
  6098. {
  6099. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6100. {
  6101. 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
  6102. }
  6103. } // END OF FOR AC_QUANTITY
  6104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6105. }
  6106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6109. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6110. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6111. }
  6112. //============================ Voltage L3 ====================================
  6113. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6114. {
  6115. // AC 3 phse L3 voltage
  6116. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6117. {
  6118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6119. {
  6120. tempIndex = 2;
  6121. }
  6122. else
  6123. {
  6124. tempIndex = gun_index;
  6125. }
  6126. for (int index = 0; index < AC_QUANTITY; index++)
  6127. {
  6128. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6129. {
  6130. 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
  6131. }
  6132. } // END OF FOR AC_QUANTITY
  6133. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6134. }
  6135. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6136. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6137. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6138. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6139. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6140. }
  6141. //====================== Start SoC ================================
  6142. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6143. {
  6144. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6145. 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))
  6146. {
  6147. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6148. {
  6149. tempIndex = ((gun_index==2) ? 1: 0);
  6150. }
  6151. else
  6152. {
  6153. tempIndex = gun_index;
  6154. }
  6155. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6156. {
  6157. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6158. {
  6159. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6160. {
  6161. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6162. }
  6163. }
  6164. }
  6165. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6166. {
  6167. for (int index = 0; index < CCS_QUANTITY; index++)
  6168. {
  6169. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6170. {
  6171. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6172. }
  6173. }
  6174. }
  6175. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6176. {
  6177. for (int index = 0; index < GB_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6180. {
  6181. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6182. }
  6183. }
  6184. }
  6185. else if(gunType[gun_index] == GUN_TYPE_DO)
  6186. {
  6187. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6188. {
  6189. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6190. {
  6191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6192. }
  6193. }
  6194. }
  6195. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6196. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6197. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6198. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6201. } // END FOR DC CASE
  6202. }
  6203. //================================================ Message create ====================================================
  6204. json_object *StopTransaction = json_object_new_object();
  6205. json_object *transactionDatas = json_object_new_array();
  6206. json_object *sampledValues = json_object_new_array();
  6207. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6208. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6209. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6210. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6211. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6212. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6213. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6214. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6215. {
  6216. json_object *transactionData = json_object_new_object();
  6217. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6218. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6219. {
  6220. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6221. {
  6222. json_object *sampledValue = json_object_new_object();
  6223. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6224. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6225. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6226. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6227. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6228. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6229. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6230. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6231. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6232. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6233. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6234. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6235. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6236. json_object_array_add(sampledValues, sampledValue);
  6237. }
  6238. }
  6239. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6240. json_object_array_add(transactionDatas, transactionData);
  6241. }
  6242. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6243. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6244. ,MESSAGE_TYPE_CALL
  6245. ,guid
  6246. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6247. json_object_put(StopTransaction);
  6248. #if 1 // for TempStopTransaction
  6249. //Delete TempStopTransaction
  6250. if((access(TempStopTransaction,F_OK))!=-1)
  6251. {
  6252. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6253. }
  6254. #endif
  6255. #if 1
  6256. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6257. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6258. {
  6259. result = PASS;
  6260. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6261. }
  6262. #endif
  6263. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6264. OCPP_insert_transaction_msg(NO, queuedata);
  6265. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6266. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6267. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6268. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6269. {
  6270. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6271. }
  6272. //for test
  6273. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6274. return result;
  6275. }
  6276. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6277. {
  6278. mtrace();
  6279. int result = FAIL;
  6280. char guid[37]={0};
  6281. char tempdata[65]={0};
  6282. int tempIndex = 0;
  6283. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6284. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6285. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6286. //set value
  6287. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6288. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6289. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6290. -1);
  6291. random_uuid(guid);
  6292. //UTC Date time
  6293. struct timeval tmnow;
  6294. struct tm *tm;
  6295. char buf[28];//, usec_buf[6];
  6296. gettimeofday(&tmnow, NULL);
  6297. time_t t;
  6298. t = time(NULL);
  6299. /*UTC time and date*/
  6300. tm = gmtime(&t);
  6301. if(dataType == ReadingContext_Sample_Clock)
  6302. {
  6303. struct tm *tmTarget;
  6304. struct timeb tbTarget;
  6305. tbTarget.time = mktime(tm);
  6306. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6307. tmTarget = gmtime(&tbTarget.time);
  6308. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6309. }
  6310. else
  6311. {
  6312. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6313. }
  6314. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6315. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6316. //********************************(1)Current.Import L1************************************************/
  6317. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6318. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6319. (dataType == ReadingContext_Trigger))
  6320. {
  6321. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6322. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6323. {
  6324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6325. {
  6326. tempIndex = ((gun_index==2) ? 1: 0);
  6327. }
  6328. else
  6329. {
  6330. tempIndex = gun_index;
  6331. }
  6332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6333. {
  6334. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6335. {
  6336. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6337. }
  6338. }
  6339. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6340. }
  6341. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6342. {
  6343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6344. {
  6345. tempIndex = ((gun_index==2) ? 1: 0);
  6346. }
  6347. else
  6348. {
  6349. tempIndex = gun_index;
  6350. }
  6351. for (int index = 0; index < CCS_QUANTITY; index++)
  6352. {
  6353. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6354. {
  6355. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6356. }
  6357. }
  6358. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6359. }
  6360. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6361. {
  6362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6363. {
  6364. tempIndex = ((gun_index==2) ? 1: 0);
  6365. }
  6366. else
  6367. {
  6368. tempIndex = gun_index;
  6369. }
  6370. for (int index = 0; index < GB_QUANTITY; index++)
  6371. {
  6372. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6373. {
  6374. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6375. }
  6376. }
  6377. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6378. }
  6379. else if(gunType[gun_index] == GUN_TYPE_DO)
  6380. {
  6381. tempIndex = gun_index;
  6382. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6383. {
  6384. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6385. {
  6386. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6387. }
  6388. }
  6389. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6390. }
  6391. else
  6392. {
  6393. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6394. {
  6395. tempIndex = 2;
  6396. }
  6397. else
  6398. {
  6399. tempIndex = gun_index;
  6400. }
  6401. for (int index = 0; index < AC_QUANTITY; index++)
  6402. {
  6403. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6404. {
  6405. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6406. }
  6407. }
  6408. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6409. }
  6410. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6411. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6412. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6413. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6414. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6415. }
  6416. //********************************(2)Energy.Active.Import.Register ************************************************/
  6417. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6418. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6419. (dataType == ReadingContext_Trigger))
  6420. {
  6421. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6422. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6423. {
  6424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6425. {
  6426. tempIndex = ((gun_index==2) ? 1: 0);
  6427. }
  6428. else
  6429. {
  6430. tempIndex = gun_index;
  6431. }
  6432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6433. {
  6434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6435. {
  6436. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6437. }
  6438. }
  6439. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6440. }
  6441. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6442. {
  6443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6444. {
  6445. tempIndex = ((gun_index==2) ? 1: 0);
  6446. }
  6447. else
  6448. {
  6449. tempIndex = gun_index;
  6450. }
  6451. for (int index = 0; index < CCS_QUANTITY; index++)
  6452. {
  6453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6454. {
  6455. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6456. }
  6457. }
  6458. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6459. }
  6460. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6461. {
  6462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6463. {
  6464. tempIndex = ((gun_index==2) ? 1: 0);
  6465. }
  6466. else
  6467. {
  6468. tempIndex = gun_index;
  6469. }
  6470. for (int index = 0; index < GB_QUANTITY; index++)
  6471. {
  6472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6473. {
  6474. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6475. }
  6476. }
  6477. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6478. }
  6479. else if(gunType[gun_index] == GUN_TYPE_DO)
  6480. {
  6481. tempIndex = gun_index;
  6482. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6483. {
  6484. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6485. {
  6486. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6487. }
  6488. }
  6489. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6490. }
  6491. else
  6492. {
  6493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6494. {
  6495. tempIndex = 2;
  6496. }
  6497. else
  6498. {
  6499. tempIndex = gun_index;
  6500. }
  6501. for (int index = 0; index < AC_QUANTITY; index++)
  6502. {
  6503. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6504. {
  6505. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6506. }
  6507. }
  6508. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6509. }
  6510. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6513. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6514. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6515. }
  6516. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6517. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6518. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6519. (dataType == ReadingContext_Trigger))
  6520. {
  6521. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6522. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6523. {
  6524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6525. {
  6526. tempIndex = ((gun_index==2) ? 1: 0);
  6527. }
  6528. else
  6529. {
  6530. tempIndex = gun_index;
  6531. }
  6532. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6533. {
  6534. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6535. {
  6536. if(dataType == ReadingContext_Sample_Clock)
  6537. {
  6538. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6539. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6540. }
  6541. else if(dataType == ReadingContext_Sample_Periodic)
  6542. {
  6543. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6544. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6545. }
  6546. else
  6547. {
  6548. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6549. }
  6550. }
  6551. } // END OF FOR CHAdeMO_QUANTITY
  6552. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6553. }
  6554. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6555. {
  6556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6557. {
  6558. tempIndex = ((gun_index==2) ? 1: 0);
  6559. }
  6560. else
  6561. {
  6562. tempIndex = gun_index;
  6563. }
  6564. for (int index = 0; index < CCS_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6567. {
  6568. if(dataType == ReadingContext_Sample_Clock)
  6569. {
  6570. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6571. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6572. }
  6573. else if(dataType == ReadingContext_Sample_Periodic)
  6574. {
  6575. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6576. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6577. }
  6578. else
  6579. {
  6580. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6581. }
  6582. }
  6583. } // END OF CCS_QUANTITY
  6584. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6585. }
  6586. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6587. {
  6588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6589. {
  6590. tempIndex = ((gun_index==2) ? 1: 0);
  6591. }
  6592. else
  6593. {
  6594. tempIndex = gun_index;
  6595. }
  6596. for (int index = 0; index < GB_QUANTITY; index++)
  6597. {
  6598. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6599. {
  6600. if(dataType == ReadingContext_Sample_Clock)
  6601. {
  6602. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6603. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6604. }
  6605. else if(dataType == ReadingContext_Sample_Periodic)
  6606. {
  6607. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6608. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6609. }
  6610. else
  6611. {
  6612. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6613. }
  6614. }
  6615. } // END OF GB_QUANTITY
  6616. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6617. }
  6618. else if(gunType[gun_index] == GUN_TYPE_DO)
  6619. {
  6620. tempIndex = gun_index;
  6621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6622. {
  6623. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6624. {
  6625. if(dataType == ReadingContext_Sample_Clock)
  6626. {
  6627. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6628. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6629. }
  6630. else if(dataType == ReadingContext_Sample_Periodic)
  6631. {
  6632. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6633. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6634. }
  6635. else
  6636. {
  6637. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6638. }
  6639. }
  6640. }
  6641. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6642. }
  6643. else
  6644. {
  6645. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6646. {
  6647. tempIndex = 2;
  6648. }
  6649. else
  6650. {
  6651. tempIndex = gun_index;
  6652. }
  6653. for (int index = 0; index < AC_QUANTITY; index++)
  6654. {
  6655. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6656. {
  6657. if(dataType == ReadingContext_Sample_Clock)
  6658. {
  6659. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6660. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6661. }
  6662. else if(dataType == ReadingContext_Sample_Periodic)
  6663. {
  6664. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6665. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6666. }
  6667. else
  6668. {
  6669. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6670. }
  6671. }
  6672. }
  6673. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6674. }
  6675. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6676. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6677. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6678. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6679. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6680. }
  6681. //********************************(4)Power.Active.Import************************************************/
  6682. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6683. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6684. (dataType == ReadingContext_Trigger))
  6685. {
  6686. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6687. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6688. {
  6689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6690. {
  6691. tempIndex = ((gun_index==2) ? 1: 0);
  6692. }
  6693. else
  6694. {
  6695. tempIndex = gun_index;
  6696. }
  6697. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6698. {
  6699. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6700. {
  6701. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6702. }
  6703. } // END OF FOR
  6704. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6705. }
  6706. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6707. {
  6708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6709. {
  6710. tempIndex = ((gun_index==2) ? 1: 0);
  6711. }
  6712. else
  6713. {
  6714. tempIndex = gun_index;
  6715. }
  6716. for (int index = 0; index < CCS_QUANTITY; index++)
  6717. {
  6718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6719. {
  6720. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6721. }
  6722. }
  6723. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6724. }
  6725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6726. {
  6727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6728. {
  6729. tempIndex = ((gun_index==2) ? 1: 0);
  6730. }
  6731. else
  6732. {
  6733. tempIndex = gun_index;
  6734. }
  6735. for (int index = 0; index < GB_QUANTITY; index++)
  6736. {
  6737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6738. {
  6739. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6740. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6741. }
  6742. }
  6743. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6744. }
  6745. else if(gunType[gun_index] == GUN_TYPE_DO)
  6746. {
  6747. tempIndex = gun_index;
  6748. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6749. {
  6750. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6751. {
  6752. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6753. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6754. }
  6755. }
  6756. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6757. }
  6758. else
  6759. {
  6760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6761. {
  6762. tempIndex = 2;
  6763. }
  6764. else
  6765. {
  6766. tempIndex = gun_index;
  6767. }
  6768. for (int index = 0; index < AC_QUANTITY; index++)
  6769. {
  6770. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6771. {
  6772. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6773. }
  6774. }
  6775. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6776. }
  6777. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6778. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6779. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6780. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6781. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6782. }
  6783. //***********************************************(5)VOLTAGE L1******************************************************/
  6784. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6785. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6786. (dataType == ReadingContext_Trigger))
  6787. {
  6788. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6789. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6790. {
  6791. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6792. {
  6793. tempIndex = ((gun_index==2) ? 1: 0);
  6794. }
  6795. else
  6796. {
  6797. tempIndex = gun_index;
  6798. }
  6799. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6800. {
  6801. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6802. {
  6803. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6804. }
  6805. }
  6806. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6807. }
  6808. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6809. {
  6810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6811. {
  6812. tempIndex = ((gun_index==2) ? 1: 0);
  6813. }
  6814. else
  6815. {
  6816. tempIndex = gun_index;
  6817. }
  6818. for (int index = 0; index < CCS_QUANTITY; index++)
  6819. {
  6820. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6821. {
  6822. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6823. }
  6824. }
  6825. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6826. }
  6827. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6828. {
  6829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6830. {
  6831. tempIndex = ((gun_index==2) ? 1: 0);
  6832. }
  6833. else
  6834. {
  6835. tempIndex = gun_index;
  6836. }
  6837. for (int index = 0; index < GB_QUANTITY; index++)
  6838. {
  6839. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6840. {
  6841. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6842. }
  6843. }
  6844. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6845. }
  6846. else if(gunType[gun_index] == GUN_TYPE_DO)
  6847. {
  6848. tempIndex = gun_index;
  6849. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6850. {
  6851. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6852. {
  6853. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6854. }
  6855. }
  6856. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6857. }
  6858. else
  6859. {
  6860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6861. {
  6862. tempIndex = 2;
  6863. }
  6864. else
  6865. {
  6866. tempIndex = gun_index;
  6867. }
  6868. for (int index = 0; index < AC_QUANTITY; index++)
  6869. {
  6870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6871. {
  6872. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6873. }
  6874. }
  6875. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6876. }
  6877. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6878. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6879. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6880. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6881. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6882. }
  6883. //***********************************************(6)SOC******************************************************/
  6884. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6885. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6886. (dataType == ReadingContext_Trigger))
  6887. {
  6888. 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))
  6889. {
  6890. //idx_sample=5;
  6891. //sampledValue = NULL;
  6892. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6893. {
  6894. tempIndex = ((gun_index==2) ? 1: 0);
  6895. }
  6896. else
  6897. {
  6898. tempIndex = gun_index;
  6899. }
  6900. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6901. {
  6902. //tempIndex = ((gun_index==2) ? 1: 0);
  6903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6904. {
  6905. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6906. {
  6907. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6908. }
  6909. }
  6910. }
  6911. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6912. {
  6913. //tempIndex = ((gun_index==2) ? 1: 0);
  6914. for (int index = 0; index < CCS_QUANTITY; index++)
  6915. {
  6916. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6917. {
  6918. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6919. }
  6920. }
  6921. }
  6922. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6923. {
  6924. //tempIndex = ((gun_index==2) ? 1: 0);
  6925. for (int index = 0; index < GB_QUANTITY; index++)
  6926. {
  6927. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6928. {
  6929. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6930. }
  6931. }
  6932. }
  6933. else if(gunType[gun_index] == GUN_TYPE_DO)
  6934. {
  6935. //tempIndex = ((gun_index==2) ? 1: 0);
  6936. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6937. {
  6938. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6939. {
  6940. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6941. }
  6942. }
  6943. }
  6944. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6945. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6946. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6947. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6948. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6949. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6950. }
  6951. }
  6952. //********************************(7)Current.Import L2************************************************/
  6953. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6954. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6955. (dataType == ReadingContext_Trigger))
  6956. {
  6957. // Only for AC 3 phase
  6958. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6959. {
  6960. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6961. {
  6962. tempIndex = 2;
  6963. }
  6964. else
  6965. {
  6966. tempIndex = gun_index;
  6967. }
  6968. for (int index = 0; index < AC_QUANTITY; index++)
  6969. {
  6970. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6971. {
  6972. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6973. }
  6974. }
  6975. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6976. }
  6977. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6978. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6979. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6980. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6981. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6982. }
  6983. //********************************(8)Current.Import L3************************************************/
  6984. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6985. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6986. (dataType == ReadingContext_Trigger))
  6987. {
  6988. // Only for AC 3 phase
  6989. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6990. {
  6991. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6992. {
  6993. tempIndex = 2;
  6994. }
  6995. else
  6996. {
  6997. tempIndex = gun_index;
  6998. }
  6999. for (int index = 0; index < AC_QUANTITY; index++)
  7000. {
  7001. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7002. {
  7003. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7004. }
  7005. }
  7006. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7007. }
  7008. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7009. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7010. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7011. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7012. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7013. }
  7014. //***********************************************(9)VOLTAGE L2******************************************************/
  7015. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7016. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7017. (dataType == ReadingContext_Trigger))
  7018. {
  7019. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7020. {
  7021. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7022. {
  7023. tempIndex = 2;
  7024. }
  7025. else
  7026. {
  7027. tempIndex = gun_index;
  7028. }
  7029. for (int index = 0; index < AC_QUANTITY; index++)
  7030. {
  7031. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7032. {
  7033. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7034. }
  7035. }
  7036. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7037. }
  7038. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7039. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7040. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7041. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7042. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7043. }
  7044. //***********************************************(10)VOLTAGE L3******************************************************/
  7045. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7046. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7047. (dataType == ReadingContext_Trigger))
  7048. {
  7049. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7050. {
  7051. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7052. {
  7053. tempIndex = 2;
  7054. }
  7055. else
  7056. {
  7057. tempIndex = gun_index;
  7058. }
  7059. for (int index = 0; index < AC_QUANTITY; index++)
  7060. {
  7061. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7062. {
  7063. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7064. }
  7065. }
  7066. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7067. }
  7068. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7069. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7070. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7071. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7072. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7073. }
  7074. //***********************************************(11)Current.Offered******************************************************/
  7075. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7076. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7077. (dataType == ReadingContext_Trigger))
  7078. {
  7079. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7080. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7081. {
  7082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7083. {
  7084. tempIndex = ((gun_index==2) ? 1: 0);
  7085. }
  7086. else
  7087. {
  7088. tempIndex = gun_index;
  7089. }
  7090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7091. {
  7092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7093. {
  7094. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7095. }
  7096. } // END OF FOR CHAdeMO_QUANTITY
  7097. }
  7098. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7099. {
  7100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7101. {
  7102. tempIndex = ((gun_index==2) ? 1: 0);
  7103. }
  7104. else
  7105. {
  7106. tempIndex = gun_index;
  7107. }
  7108. for (int index = 0; index < CCS_QUANTITY; index++)
  7109. {
  7110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7111. {
  7112. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7113. }
  7114. } // END OF CCS_QUANTITY
  7115. }
  7116. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7117. {
  7118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7119. {
  7120. tempIndex = ((gun_index==2) ? 1: 0);
  7121. }
  7122. else
  7123. {
  7124. tempIndex = gun_index;
  7125. }
  7126. for (int index = 0; index < GB_QUANTITY; index++)
  7127. {
  7128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7129. {
  7130. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7131. }
  7132. } // END OF GB_QUANTITY
  7133. }
  7134. else if(gunType[gun_index] == GUN_TYPE_DO)
  7135. {
  7136. tempIndex = gun_index;
  7137. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7138. {
  7139. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7140. {
  7141. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7142. }
  7143. }
  7144. }
  7145. else
  7146. {
  7147. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7148. {
  7149. tempIndex = 2;
  7150. }
  7151. else
  7152. {
  7153. tempIndex = gun_index;
  7154. }
  7155. for (int index = 0; index < AC_QUANTITY; index++)
  7156. {
  7157. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7158. {
  7159. uint16_t currentOffer;
  7160. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7161. {
  7162. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7163. }
  7164. else
  7165. {
  7166. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7167. }
  7168. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7169. }
  7170. }
  7171. }
  7172. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7173. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7174. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7175. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7176. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7177. }
  7178. //***********************************************(12)Power.Offered******************************************************/
  7179. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7180. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7181. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7182. {
  7183. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7184. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7185. {
  7186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7187. {
  7188. tempIndex = ((gun_index==2) ? 1: 0);
  7189. }
  7190. else
  7191. {
  7192. tempIndex = gun_index;
  7193. }
  7194. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7195. {
  7196. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7197. {
  7198. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7199. }
  7200. } // END OF FOR CHAdeMO_QUANTITY
  7201. }
  7202. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7203. {
  7204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7205. {
  7206. tempIndex = ((gun_index==2) ? 1: 0);
  7207. }
  7208. else
  7209. {
  7210. tempIndex = gun_index;
  7211. }
  7212. for (int index = 0; index < CCS_QUANTITY; index++)
  7213. {
  7214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7215. {
  7216. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7217. }
  7218. } // END OF CCS_QUANTITY
  7219. }
  7220. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7221. {
  7222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7223. {
  7224. tempIndex = ((gun_index==2) ? 1: 0);
  7225. }
  7226. else
  7227. {
  7228. tempIndex = gun_index;
  7229. }
  7230. for (int index = 0; index < GB_QUANTITY; index++)
  7231. {
  7232. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7233. {
  7234. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7235. }
  7236. } // END OF GB_QUANTITY
  7237. }
  7238. else if(gunType[gun_index] == GUN_TYPE_DO)
  7239. {
  7240. tempIndex = gun_index;
  7241. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7242. {
  7243. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7244. {
  7245. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7246. }
  7247. }
  7248. }
  7249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7250. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7251. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7252. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7253. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7254. }
  7255. // Message create ====================================================================================================
  7256. if(TRUE)
  7257. {
  7258. json_object *MeterValueReq = json_object_new_object();
  7259. json_object *MeterValues = json_object_new_array();
  7260. json_object *sampledValues = json_object_new_array();
  7261. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7262. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7263. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7264. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7265. {
  7266. json_object *MeterValue = json_object_new_object();
  7267. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7268. {
  7269. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7270. {
  7271. json_object *sampledValue = json_object_new_object();
  7272. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7273. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7274. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7275. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7276. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7277. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7278. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7279. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7280. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7281. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7282. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7283. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7284. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7285. json_object_array_add(sampledValues, sampledValue);
  7286. }
  7287. }
  7288. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7289. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7290. json_object_array_add(MeterValues, MeterValue);
  7291. }
  7292. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7293. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7294. ,gun_index + 1
  7295. ,MESSAGE_TYPE_CALL
  7296. ,guid
  7297. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7298. json_object_put(MeterValueReq);
  7299. }
  7300. // Put request guid to hash map
  7301. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7302. 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*/)
  7303. {
  7304. result = PASS;
  7305. //DEBUG_INFO("MeterValues mapitem pass\n");
  7306. }
  7307. if((dataType != ReadingContext_Trigger) &&
  7308. (dataType != ReadingContext_Sample_Clock) &&
  7309. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7310. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7311. else
  7312. {
  7313. if(FirstHeartBeat)
  7314. LWS_Send(queuedata +2);
  7315. }
  7316. return result;
  7317. }
  7318. int sendLogStatusNotificationRequest(char *status)
  7319. {
  7320. mtrace();
  7321. int result = PASS;
  7322. char message[4096]={0};
  7323. char guid[37]={0};
  7324. char tempdata[128]={0};
  7325. json_object *LogStatusNotification = json_object_new_object();
  7326. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7327. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7328. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7329. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7330. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7331. random_uuid(guid);
  7332. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7333. json_object_put(LogStatusNotification);
  7334. LWS_Send(message);
  7335. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7336. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7337. {
  7338. result = PASS;
  7339. }
  7340. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7341. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7342. return result;
  7343. }
  7344. int sendSecurityEventNotificationRequest()
  7345. {
  7346. mtrace();
  7347. int result = PASS;
  7348. char message[4096]={0};
  7349. char guid[37]={0};
  7350. char tempdata[128]={0};
  7351. json_object *SecurityEventNotification = json_object_new_object();
  7352. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7353. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7354. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7355. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7356. random_uuid(guid);
  7357. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7358. json_object_put(SecurityEventNotification);
  7359. LWS_Send(message);
  7360. sprintf(tempdata, "SecurityEventNotification,0");
  7361. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7362. {
  7363. result = PASS;
  7364. }
  7365. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7366. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7367. return result;
  7368. }
  7369. int sendSignCertificateRequest()
  7370. {
  7371. mtrace();
  7372. int result = PASS;
  7373. char message[4096]={0};
  7374. char guid[37]={0};
  7375. char tempdata[128]={0};
  7376. json_object *SignCertificate = json_object_new_object();
  7377. DEBUG_INFO("sendSignCertificateRequest...\n");
  7378. // Read csr file content
  7379. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7380. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7381. char *line = NULL;
  7382. size_t len = 0;
  7383. while(getline(&line, &len, fp) != -1)
  7384. {
  7385. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7386. {
  7387. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7388. }
  7389. }
  7390. fclose(fp);
  7391. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7392. random_uuid(guid);
  7393. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7394. json_object_put(SignCertificate);
  7395. LWS_Send(message);
  7396. sprintf(tempdata, "SignCertificate,0");
  7397. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7398. {
  7399. result = PASS;
  7400. }
  7401. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7402. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7403. return result;
  7404. }
  7405. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7406. {
  7407. mtrace();
  7408. int result = PASS;
  7409. char message[110]={0};
  7410. char guid[37]={0};
  7411. char tempdata[65]={0};
  7412. json_object *FirmwareStatusNotification = json_object_new_object();
  7413. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7414. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7415. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7416. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7417. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7418. random_uuid(guid);
  7419. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7420. json_object_put(FirmwareStatusNotification);
  7421. LWS_Send(message);
  7422. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7423. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7424. {
  7425. result = PASS;
  7426. }
  7427. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7428. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7429. return result;
  7430. }
  7431. //==========================================
  7432. // send confirm routine
  7433. //==========================================
  7434. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7435. {
  7436. mtrace();
  7437. int result = FAIL;
  7438. char message[100]={0};
  7439. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7440. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7441. LWS_Send(message);
  7442. result = TRUE;
  7443. return result;
  7444. }
  7445. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7446. {
  7447. mtrace();
  7448. int result = FAIL;
  7449. char message[100]={0};
  7450. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7451. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7452. LWS_Send(message);
  7453. result = TRUE;
  7454. return result;
  7455. }
  7456. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7457. {
  7458. mtrace();
  7459. int result = FAIL;
  7460. char message[100]={0};
  7461. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7462. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7463. LWS_Send(message);
  7464. result = TRUE;
  7465. return result;
  7466. }
  7467. int sendClearCacheConfirmation(char *uuid,char *payload)
  7468. {
  7469. mtrace();
  7470. int result = FAIL;
  7471. char message[500]={0};
  7472. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7473. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7474. LWS_Send(message);
  7475. return result;
  7476. }
  7477. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7478. {
  7479. mtrace();
  7480. int result = FAIL;
  7481. char message[500]={0};
  7482. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7483. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7484. LWS_Send(message);
  7485. return result;
  7486. }
  7487. int sendDataTransferConfirmation(char *uuid,char *payload)
  7488. {
  7489. mtrace();
  7490. char statusStr[20]={0};
  7491. char dataStr[10]={0};
  7492. char sstr[20]={0};
  7493. int c = 0;
  7494. char *loc;
  7495. int result = FAIL;
  7496. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7497. /**********************status**************************/
  7498. loc = strstr(payload, "status");
  7499. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7500. c = 0;
  7501. while (loc[3+strlen("status")+c] != '\"')
  7502. {
  7503. sstr[c] = loc[3+strlen("status")+c];
  7504. c++;
  7505. }
  7506. sstr[c] = '\0';
  7507. strcpy(statusStr, sstr);
  7508. /**********************data**************************/
  7509. loc = strstr(payload, "data");
  7510. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7511. c = 0;
  7512. while (loc[3+strlen("data")+c] != '\"')
  7513. {
  7514. sstr[c] = loc[3+strlen("data")+c];
  7515. c++;
  7516. }
  7517. sstr[c] = '\0';
  7518. strcpy(dataStr, sstr);
  7519. return result;
  7520. }
  7521. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7522. {
  7523. mtrace();
  7524. int result = FAIL;
  7525. char message[1000]={0};
  7526. int CompositeScheduleIndex = 0;
  7527. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7528. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7529. if(nPeriod == 0)
  7530. {
  7531. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7532. {
  7533. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7534. ,MESSAGE_TYPE_CALLRESULT
  7535. ,uuid
  7536. ,payload
  7537. ,connectorIdInt);
  7538. }
  7539. else
  7540. {
  7541. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7542. ,MESSAGE_TYPE_CALLRESULT
  7543. ,uuid
  7544. ,payload
  7545. ,connectorIdInt
  7546. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7547. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7548. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7549. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7550. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7551. }
  7552. }
  7553. else
  7554. {
  7555. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7556. ,MESSAGE_TYPE_CALLRESULT
  7557. ,uuid
  7558. ,payload
  7559. ,connectorIdInt
  7560. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7561. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7562. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7563. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7564. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7565. {
  7566. if (idx_sample == 0)
  7567. {
  7568. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7569. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7570. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7571. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7572. }
  7573. else
  7574. {
  7575. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7576. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7577. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7578. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7579. }
  7580. }
  7581. sprintf(message + strlen(message), "]}}]");
  7582. }
  7583. LWS_Send(message);
  7584. result = TRUE;
  7585. return result;
  7586. }
  7587. int sendGetConfigurationConfirmation(char *uuid)
  7588. {
  7589. mtrace();
  7590. int result = FAIL;
  7591. int MaxKeySupported = 0;
  7592. int sentConfigurationNumber= 0;
  7593. int sentunConfigurationNumber= 0;
  7594. char message[1024*10]={0};
  7595. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7596. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7597. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7598. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7599. ,MESSAGE_TYPE_CALLRESULT
  7600. ,uuid );
  7601. //configuration key
  7602. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7603. {
  7604. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7605. {
  7606. if (sentConfigurationNumber == 0)
  7607. {
  7608. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7609. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7610. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7611. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7612. }
  7613. else
  7614. {
  7615. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7616. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7617. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7618. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7619. }
  7620. sentConfigurationNumber = sentConfigurationNumber + 1;
  7621. }
  7622. }
  7623. sprintf(message + strlen(message), "]");
  7624. if(UnknownKeynum != 0)
  7625. {
  7626. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7627. //unkown key
  7628. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7629. {
  7630. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7631. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7632. if(sentunConfigurationNumber == 0)
  7633. {
  7634. sprintf(message + strlen(message), "\"%s\""
  7635. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7636. }
  7637. else
  7638. {
  7639. sprintf(message + strlen(message), ",\"%s\""
  7640. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7641. }
  7642. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7643. }
  7644. sprintf(message + strlen(message), "]");
  7645. }
  7646. sprintf(message + strlen(message), "}]");
  7647. LWS_Send(message);
  7648. return result;
  7649. }
  7650. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7651. {
  7652. mtrace();
  7653. int result = FAIL;
  7654. char message[400]={0};
  7655. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7656. if(strcmp(payload,"")==0)
  7657. {
  7658. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7659. }
  7660. else
  7661. {
  7662. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7663. }
  7664. LWS_Send(message);
  7665. result = TRUE;
  7666. return result;
  7667. }
  7668. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7669. {
  7670. mtrace();
  7671. int result = FAIL;
  7672. char message[80]={0};
  7673. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7674. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7675. LWS_Send(message);
  7676. result = TRUE;
  7677. return result;
  7678. }
  7679. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7680. {
  7681. mtrace();
  7682. int result = FAIL;
  7683. char message[80]={0};
  7684. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7685. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7686. LWS_Send(message);
  7687. result = TRUE;
  7688. return result;
  7689. }
  7690. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7691. {
  7692. mtrace();
  7693. int result = FAIL;
  7694. char message[80]={0};
  7695. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7696. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7697. LWS_Send(message);
  7698. result = TRUE;
  7699. return result;
  7700. }
  7701. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7702. {
  7703. mtrace();
  7704. int result = FAIL;
  7705. char message[80]={0};
  7706. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7707. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7708. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7709. LWS_Send(message);
  7710. result = TRUE;
  7711. return result;
  7712. }
  7713. int sendResetConfirmation(char *uuid,char *payload)
  7714. {
  7715. mtrace();
  7716. int result = FAIL;
  7717. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7718. char message[80]={0};
  7719. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7720. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7721. LWS_Send(message);
  7722. result = TRUE;
  7723. return result;
  7724. }
  7725. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7726. {
  7727. mtrace();
  7728. int result = FAIL;
  7729. char message[500]={0};
  7730. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7731. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7732. LWS_Send(message);
  7733. result = TRUE;
  7734. return result;
  7735. }
  7736. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7737. {
  7738. mtrace();
  7739. int result = FAIL;
  7740. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7741. char message[80]={0};
  7742. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7743. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7744. LWS_Send(message);
  7745. result = TRUE;
  7746. return result;
  7747. }
  7748. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7749. {
  7750. mtrace();
  7751. int result = FAIL;
  7752. char message[80]={0};
  7753. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7754. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7755. LWS_Send(message);
  7756. result = TRUE;
  7757. return result;
  7758. }
  7759. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7760. {
  7761. mtrace();
  7762. int result = FAIL;
  7763. char message[80]={0};
  7764. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7765. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7766. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7767. LWS_Send(message);
  7768. result = TRUE;
  7769. return result;
  7770. }
  7771. int sendUpdateFirmwareConfirmation(char *uuid)
  7772. {
  7773. mtrace();
  7774. int result = FAIL;
  7775. char message[60]={0};
  7776. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7777. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7778. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7779. LWS_Send(message);
  7780. result = TRUE;
  7781. return result;
  7782. }
  7783. int sendCertificateSignedConfirmation(char *uuid)
  7784. {
  7785. mtrace();
  7786. int result = PASS;
  7787. char message[4096]={0};
  7788. json_object *CertificateSigned = json_object_new_object();
  7789. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7790. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7791. sprintf(message,"[%d,\"%s\",%s]"
  7792. ,MESSAGE_TYPE_CALLRESULT
  7793. ,uuid
  7794. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7795. json_object_put(CertificateSigned);
  7796. LWS_Send(message);
  7797. return result;
  7798. }
  7799. int sendDeleteCertificateConfirmation(char *uuid)
  7800. {
  7801. mtrace();
  7802. int result = PASS;
  7803. char message[4096]={0};
  7804. json_object *DeleteCertificate = json_object_new_object();
  7805. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7806. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7807. sprintf(message,"[%d,\"%s\",%s]"
  7808. ,MESSAGE_TYPE_CALLRESULT
  7809. ,uuid
  7810. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7811. json_object_put(DeleteCertificate);
  7812. LWS_Send(message);
  7813. return result;
  7814. }
  7815. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7816. {
  7817. mtrace();
  7818. int result = PASS;
  7819. char message[4096]={0};
  7820. json_object *ExtendedTriggerMessage = json_object_new_object();
  7821. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7822. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7823. sprintf(message,"[%d,\"%s\",%s]"
  7824. ,MESSAGE_TYPE_CALLRESULT
  7825. ,uuid
  7826. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7827. json_object_put(ExtendedTriggerMessage);
  7828. LWS_Send(message);
  7829. return result;
  7830. }
  7831. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7832. {
  7833. mtrace();
  7834. int result = PASS;
  7835. char message[4096]={0};
  7836. json_object *GetInstalledCertificateIds = json_object_new_object();
  7837. json_object *certificateHashDataDatas = json_object_new_array();
  7838. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7839. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7840. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7841. {
  7842. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7843. {
  7844. json_object *certificateHashData = json_object_new_object();
  7845. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7846. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7847. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7848. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7849. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7850. }
  7851. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7852. }
  7853. else
  7854. {
  7855. json_object_put(certificateHashDataDatas);
  7856. }
  7857. sprintf(message,"[%d,\"%s\",%s]"
  7858. ,MESSAGE_TYPE_CALLRESULT
  7859. ,uuid
  7860. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7861. json_object_put(GetInstalledCertificateIds);
  7862. LWS_Send(message);
  7863. return result;
  7864. }
  7865. int sendGetLogConfirmation(char *uuid)
  7866. {
  7867. mtrace();
  7868. int result = PASS;
  7869. char message[4096]={0};
  7870. json_object *GetLog = json_object_new_object();
  7871. DEBUG_INFO("sendGetLogConfirmation...\n");
  7872. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7873. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7874. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7875. sprintf(message,"[%d,\"%s\",%s]"
  7876. ,MESSAGE_TYPE_CALLRESULT
  7877. ,uuid
  7878. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7879. json_object_put(GetLog);
  7880. LWS_Send(message);
  7881. return result;
  7882. }
  7883. int sendInstallCertificateConfirmation(char *uuid)
  7884. {
  7885. mtrace();
  7886. int result = PASS;
  7887. char message[4096]={0};
  7888. json_object *InstallCertificate = json_object_new_object();
  7889. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7890. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7891. sprintf(message,"[%d,\"%s\",%s]"
  7892. ,MESSAGE_TYPE_CALLRESULT
  7893. ,uuid
  7894. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7895. json_object_put(InstallCertificate);
  7896. LWS_Send(message);
  7897. return result;
  7898. }
  7899. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7900. {
  7901. mtrace();
  7902. int result = PASS;
  7903. char message[4096]={0};
  7904. json_object *SignedUpdateFirmware = json_object_new_object();
  7905. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7906. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7907. sprintf(message,"[%d,\"%s\",%s]"
  7908. ,MESSAGE_TYPE_CALLRESULT
  7909. ,uuid
  7910. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7911. json_object_put(SignedUpdateFirmware);
  7912. LWS_Send(message);
  7913. return result;
  7914. }
  7915. int sendUnknownConfirmation(char *uuid)
  7916. {
  7917. mtrace();
  7918. int result = PASS;
  7919. char message[256]={0};
  7920. DEBUG_INFO("sendUnknownConfirmation...\n");
  7921. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7922. LWS_Send(message);
  7923. return result;
  7924. }
  7925. //==========================================
  7926. // Handle server request routine Start
  7927. //==========================================
  7928. int handleCancelReservationRequest(char *uuid, char *payload)
  7929. {
  7930. mtrace();
  7931. int result = FAIL;
  7932. int gunNO = 0;
  7933. int reservationIdInt = -1;
  7934. char comfirmstr[20];
  7935. DEBUG_INFO("handleCancelReservationRequest...\n");
  7936. json_object *CancelReservation;
  7937. CancelReservation = json_tokener_parse(payload);
  7938. if(!is_error(CancelReservation))
  7939. {
  7940. // Required data
  7941. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7942. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7943. }
  7944. json_object_put(CancelReservation);
  7945. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7946. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7947. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7948. if(reservationIdInt != -1)
  7949. {
  7950. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7951. //check Transaction active
  7952. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7953. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7954. {
  7955. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7956. {
  7957. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7958. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7959. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7960. {
  7961. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7962. }
  7963. else
  7964. {
  7965. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7966. }
  7967. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7968. goto end;
  7969. }
  7970. }
  7971. for (int index = 0; index < CCS_QUANTITY; index++)
  7972. {
  7973. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7974. {
  7975. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7976. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7977. if(gunType[2] == GUN_TYPE_CCS)
  7978. {
  7979. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7980. }
  7981. else
  7982. {
  7983. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7984. }
  7985. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7986. goto end;
  7987. }
  7988. }
  7989. for (int index = 0; index < GB_QUANTITY; index++)
  7990. {
  7991. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7992. {
  7993. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7994. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7995. if(gunType[2] == GUN_TYPE_GBT)
  7996. {
  7997. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7998. }
  7999. else
  8000. {
  8001. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8002. }
  8003. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8004. goto end;
  8005. }
  8006. }
  8007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8008. {
  8009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8010. {
  8011. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8012. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8013. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8014. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8015. goto end;
  8016. }
  8017. }
  8018. for (int index = 0; index < AC_QUANTITY; index++)
  8019. {
  8020. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8021. {
  8022. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8023. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8025. {
  8026. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8027. }
  8028. else
  8029. {
  8030. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8031. }
  8032. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8033. goto end;
  8034. }
  8035. }
  8036. }
  8037. //The reservationId does NOT match the reservationId
  8038. sendCancelReservationConfirmation(uuid, comfirmstr);
  8039. end:
  8040. // Fill in ocpp packet uuid
  8041. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8042. return result;
  8043. }
  8044. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8045. {
  8046. mtrace();
  8047. int result = FAIL;
  8048. int gunIndex = -1;
  8049. char typeStr[16]={0};
  8050. char comfirmstr[20];
  8051. int specificId = FALSE;
  8052. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8053. json_object *ChangeAvailability;
  8054. ChangeAvailability = json_tokener_parse(payload);
  8055. if(!is_error(ChangeAvailability))
  8056. {
  8057. // Required data
  8058. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8059. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8060. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8061. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8062. }
  8063. json_object_put(ChangeAvailability);
  8064. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8065. {
  8066. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8067. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8068. }
  8069. else if(gunIndex == 0)
  8070. {
  8071. for(int i=0; i < gunTotalNumber; i++)
  8072. {
  8073. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8074. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8075. }
  8076. }
  8077. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8078. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8079. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8080. {
  8081. specificId = TRUE;
  8082. }
  8083. if(specificId == FALSE)
  8084. goto end;
  8085. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8086. {
  8087. //----------------------gunIndex is 0 ------------------------------------------------//
  8088. if(gunIndex == 0)
  8089. {
  8090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8091. {
  8092. for(int i=0; i < gunTotalNumber; i++)
  8093. {
  8094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8095. {
  8096. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8097. {
  8098. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8099. {
  8100. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8101. goto end;
  8102. }
  8103. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8104. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8105. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8106. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8107. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8108. {
  8109. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8110. goto end;
  8111. }
  8112. }
  8113. }//END FOR CHAdeMO_QUANTITY
  8114. for (int index = 0; index < CCS_QUANTITY; index++)
  8115. {
  8116. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8117. {
  8118. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8119. {
  8120. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8121. goto end;
  8122. }
  8123. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8124. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8125. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8126. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8127. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8128. {
  8129. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8130. goto end;
  8131. }
  8132. }
  8133. }//END FOR CCS_QUANTITY
  8134. for (int index = 0; index < GB_QUANTITY; index++)
  8135. {
  8136. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8137. {
  8138. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8139. {
  8140. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8141. goto end;
  8142. }
  8143. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8144. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8145. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8146. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8147. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8148. {
  8149. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8150. goto end;
  8151. }
  8152. }
  8153. }// END FOR GB_QUANTITY
  8154. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8155. {
  8156. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8157. {
  8158. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8159. {
  8160. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8161. goto end;
  8162. }
  8163. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8164. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8165. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8168. {
  8169. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8170. goto end;
  8171. }
  8172. }
  8173. }// END FOR GENERAL_GUN_QUANTITY
  8174. for (int index = 0; index < AC_QUANTITY; index++)
  8175. {
  8176. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8177. {
  8178. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8179. {
  8180. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8181. goto end;
  8182. }
  8183. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8184. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8185. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8188. {
  8189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8190. goto end;
  8191. }
  8192. }
  8193. }//END FOR AC_QUANTITY
  8194. }// END FOR gunTotalNumber
  8195. }
  8196. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8197. {
  8198. for(int i=0; i < gunTotalNumber; i++)
  8199. {
  8200. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8201. {
  8202. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8203. goto end;
  8204. }
  8205. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8206. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8207. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8208. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8209. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8210. {
  8211. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8212. goto end;
  8213. }
  8214. }
  8215. }
  8216. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8217. goto end;
  8218. }
  8219. //----------------------gunIndex is not 0 ------------------------------------------------//
  8220. //check Transaction active
  8221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8222. {
  8223. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8224. {
  8225. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8226. {
  8227. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8228. goto end;
  8229. }
  8230. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8231. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8232. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8233. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8234. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8235. {
  8236. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8237. goto end;
  8238. }
  8239. else
  8240. {
  8241. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8242. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8243. goto end;
  8244. }
  8245. }
  8246. }//END FOR CHAdeMO_QUANTITY
  8247. for (int index = 0; index < CCS_QUANTITY; index++)
  8248. {
  8249. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8250. {
  8251. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8252. {
  8253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8254. goto end;
  8255. }
  8256. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8257. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8258. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8259. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8260. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8261. {
  8262. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8263. goto end;
  8264. }
  8265. else
  8266. {
  8267. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8268. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8269. goto end;
  8270. }
  8271. }
  8272. }//END FOR CCS_QUANTITY
  8273. for (int index = 0; index < GB_QUANTITY; index++)
  8274. {
  8275. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8276. {
  8277. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8278. {
  8279. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8280. goto end;
  8281. }
  8282. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8283. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8284. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8285. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8286. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8287. {
  8288. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8289. goto end;
  8290. }
  8291. else
  8292. {
  8293. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8294. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8295. goto end;
  8296. }
  8297. }
  8298. }// END FOR GB_QUANTITY
  8299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8300. {
  8301. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8302. {
  8303. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8304. {
  8305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8306. goto end;
  8307. }
  8308. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8309. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8310. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8311. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8312. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8313. {
  8314. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8315. goto end;
  8316. }
  8317. else
  8318. {
  8319. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8320. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8321. goto end;
  8322. }
  8323. }
  8324. }// END FOR GENERAL_GUN_QUANTITY
  8325. for (int index = 0; index < AC_QUANTITY; index++)
  8326. {
  8327. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8328. {
  8329. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8330. {
  8331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8332. goto end;
  8333. }
  8334. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8335. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8336. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8337. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8338. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8339. {
  8340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8341. goto end;
  8342. }
  8343. else
  8344. {
  8345. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8347. goto end;
  8348. }
  8349. }
  8350. }//END FOR AC_QUANTITY
  8351. }//END FOR AvailabilityTypeStr[Inoperative]
  8352. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8353. {
  8354. //----------------------gunIndex is 0 ------------------------------------------------//
  8355. if(gunIndex == 0)
  8356. {
  8357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8358. {
  8359. for(int i=0; i < gunTotalNumber; i++)
  8360. {
  8361. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8362. {
  8363. 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
  8364. {
  8365. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8366. goto end;
  8367. }
  8368. }//END FOR CHAdeMO_QUANTITY
  8369. for (int index = 0; index < CCS_QUANTITY; index++)
  8370. {
  8371. 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
  8372. {
  8373. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8374. goto end;
  8375. }
  8376. }//END FOR CCS_QUANTITY
  8377. for (int index = 0; index < GB_QUANTITY; index++)
  8378. {
  8379. 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
  8380. {
  8381. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8382. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8383. goto end;
  8384. }
  8385. }// END FOR GB_QUANTITY
  8386. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8387. {
  8388. 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
  8389. {
  8390. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8392. goto end;
  8393. }
  8394. }// END FOR GENERAL_GUN_QUANTITY
  8395. for (int index = 0; index < AC_QUANTITY; index++)
  8396. {
  8397. 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
  8398. {
  8399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8400. goto end;
  8401. }
  8402. }//END FOR CHAdeMO_QUANTITY
  8403. }// END FOR gunTotalNumber
  8404. }
  8405. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8406. {
  8407. for(int i=0; i < gunTotalNumber; i++)
  8408. {
  8409. for (int index = 0; index < AC_QUANTITY; index++)
  8410. {
  8411. 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
  8412. {
  8413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8414. goto end;
  8415. }
  8416. }//END FOR CHAdeMO_QUANTITY
  8417. } // END FOR gunTotalNumber
  8418. }
  8419. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8420. goto end;
  8421. }
  8422. //----------------------gunIndex is not 0 ------------------------------------------------//
  8423. //check Transaction active
  8424. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8425. {
  8426. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8427. {
  8428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8429. goto end;
  8430. }
  8431. }//END FOR CHAdeMO_QUANTITY
  8432. for (int index = 0; index < CCS_QUANTITY; index++)
  8433. {
  8434. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8435. {
  8436. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8437. goto end;
  8438. }
  8439. }//END FOR CCS_QUANTITY
  8440. for (int index = 0; index < GB_QUANTITY; index++)
  8441. {
  8442. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8443. {
  8444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8445. goto end;
  8446. }
  8447. }// END FOR GB_QUANTITY
  8448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8449. {
  8450. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8451. {
  8452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8453. goto end;
  8454. }
  8455. }// END FOR GENERAL_GUN_QUANTITY
  8456. for (int index = 0; index < AC_QUANTITY; index++)
  8457. {
  8458. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8459. {
  8460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8461. goto end;
  8462. }
  8463. }//END FOR AC_QUANTITY
  8464. }//END FOR AvailabilityTypeStr[Operative]
  8465. end:
  8466. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8467. {
  8468. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8469. }
  8470. else
  8471. {
  8472. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8473. }
  8474. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8475. {
  8476. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8477. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8478. }
  8479. else if(gunIndex == 0)
  8480. {
  8481. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8482. {
  8483. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8484. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8485. }
  8486. }
  8487. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8488. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8489. return result;
  8490. }
  8491. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8492. {
  8493. mtrace();
  8494. int valueInvalid = NO;
  8495. int result = FAIL;
  8496. char keystr[40]={0};
  8497. char valuestr[501]={0}; //value should be limited in 500 bytes
  8498. char comfirmstr[20]={0};
  8499. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8500. json_object *ChangeConfiguration;
  8501. ChangeConfiguration = json_tokener_parse(payload);
  8502. if(!is_error(ChangeConfiguration))
  8503. {
  8504. // Required data
  8505. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8506. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8507. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8508. {
  8509. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8510. }
  8511. else
  8512. {
  8513. valueInvalid = YES;
  8514. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8515. }
  8516. }
  8517. json_object_put(ChangeConfiguration);
  8518. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8519. {
  8520. DEBUG_ERROR("Payload is null or not accepted.\n");
  8521. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8522. }
  8523. else
  8524. {
  8525. int status = setKeyValue(keystr, valuestr);
  8526. switch(status)
  8527. {
  8528. case ConfigurationStatus_Accepted:
  8529. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8530. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8531. StoreConfigurationTable();
  8532. break;
  8533. case RebootRequired:
  8534. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8535. StoreConfigurationTable();
  8536. break;
  8537. case NotSupported:
  8538. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8539. break;
  8540. case ConfigurationStatus_Rejected:
  8541. default:
  8542. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8543. break;
  8544. }
  8545. }
  8546. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8547. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8548. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8549. {
  8550. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8551. SetOcppConnStatus(FALSE);
  8552. }
  8553. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8554. {
  8555. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8556. }
  8557. return result;
  8558. }
  8559. int handleClearCacheRequest(char *uuid, char *payload)
  8560. {
  8561. mtrace();
  8562. int result = FAIL;
  8563. char comfirmstr[20];
  8564. char rmFileCmd[100]={0};
  8565. struct stat stats;
  8566. DEBUG_INFO("handleClearCacheRequest...\n");
  8567. stat("/Storage/OCPP_PH", &stats);
  8568. // Check for directory existence
  8569. if (S_ISDIR(stats.st_mode) == 1)
  8570. {}
  8571. else
  8572. {
  8573. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8574. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8575. system(rmFileCmd);
  8576. }
  8577. if(OCPP_cleanLocalCache())
  8578. {
  8579. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8580. }
  8581. else
  8582. {
  8583. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8584. }
  8585. sendClearCacheConfirmation(uuid, comfirmstr);
  8586. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8587. return result;
  8588. }
  8589. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8590. {
  8591. mtrace();
  8592. int result = FAIL;
  8593. int resultRename;
  8594. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8595. char chargingProfilePurposeStr[26]={0};
  8596. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8597. char tempchargingProfilePurposeStr[26]={0};
  8598. char str[100]={0};
  8599. char fname[200]={0};
  8600. char comfirmstr[20]={0};
  8601. char word[1600]={0};
  8602. int clearflag = FALSE;
  8603. int chargingProfileIdIsNULL = FALSE;
  8604. int connectorIsNULL = FALSE;
  8605. int chargingProfilePurposeIsNULL = FALSE;
  8606. int stackLevelIsNULL = FALSE;
  8607. //int GotoEnd = FALSE;
  8608. FILE *fptr1, *fptr2;
  8609. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8610. int n_chargingProfile=0;
  8611. int isEmptyFile = FALSE;
  8612. char sLineWord[1600]={0};
  8613. char chargingProfiles[10][100]={0};
  8614. int ChargeProfileCount = 0;
  8615. int ch;
  8616. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8617. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8618. json_object *ClearChargingProfile;
  8619. ClearChargingProfile = json_tokener_parse(payload);
  8620. if(!is_error(ClearChargingProfile))
  8621. {
  8622. // Optional data
  8623. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8624. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8625. else
  8626. chargingProfileIdIsNULL = TRUE;
  8627. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8628. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8629. else
  8630. connectorIsNULL = TRUE;
  8631. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8632. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8633. else
  8634. chargingProfilePurposeIsNULL = TRUE;
  8635. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8636. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8637. else
  8638. stackLevelIsNULL = TRUE;
  8639. }
  8640. json_object_put(ClearChargingProfile);
  8641. if(connectorIsNULL == FALSE)
  8642. {
  8643. switch(connectorIdInt)
  8644. {
  8645. case 0:
  8646. if(chargingProfilePurposeIsNULL == TRUE)
  8647. {
  8648. int l = 0;
  8649. strcpy(fname, ChargePointMaxProfile_JSON);
  8650. if((access(fname,F_OK))!=-1)
  8651. {
  8652. strcpy(chargingProfiles[l], fname);
  8653. l = l + 1;
  8654. }
  8655. strcpy(fname, TxDefaultProfile_0_JSON);
  8656. if((access(fname,F_OK))!=-1)
  8657. {
  8658. strcpy(chargingProfiles[l], fname);
  8659. l = l + 1;
  8660. }
  8661. ChargeProfileCount = l;
  8662. }
  8663. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8664. {
  8665. strcpy(fname, ChargePointMaxProfile_JSON);
  8666. if((access(fname,F_OK))!=-1)
  8667. {
  8668. strcpy(chargingProfiles[0], fname);
  8669. ChargeProfileCount = 1;
  8670. }
  8671. }
  8672. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8673. {
  8674. strcpy(fname, TxDefaultProfile_0_JSON);
  8675. if((access(fname,F_OK))!=-1)
  8676. {
  8677. strcpy(chargingProfiles[0], fname);
  8678. ChargeProfileCount = 1;
  8679. }
  8680. }
  8681. break;
  8682. default:
  8683. if(chargingProfilePurposeIsNULL == TRUE)
  8684. {
  8685. int m = 0;
  8686. memset(fname, 0, ARRAY_SIZE(fname));
  8687. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8688. if((access(fname,F_OK))!=-1)
  8689. {
  8690. strcpy(chargingProfiles[m], fname);
  8691. m = m + 1;
  8692. }
  8693. memset(fname, 0, ARRAY_SIZE(fname));
  8694. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8695. if((access(fname,F_OK))!=-1)
  8696. {
  8697. strcpy(chargingProfiles[m], fname);
  8698. m = m + 1;
  8699. }
  8700. ChargeProfileCount = m;
  8701. }
  8702. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8703. {
  8704. //strcpy(fname, TxDefaultProfile_1_JSON);
  8705. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8706. if((access(fname,F_OK))!=-1)
  8707. {
  8708. strcpy(chargingProfiles[0], fname);
  8709. ChargeProfileCount = 1;
  8710. }
  8711. }
  8712. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8713. {
  8714. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8715. if((access(fname,F_OK))!=-1)
  8716. {
  8717. strcpy(chargingProfiles[0], fname);
  8718. ChargeProfileCount = 1;
  8719. }
  8720. //strcpy(fname, TxProfile_1_JSON);
  8721. }
  8722. //strcpy(fname, ChargePointMaxProfile_JSON );
  8723. break;
  8724. }
  8725. }
  8726. else // Check all Charging Profiles
  8727. {
  8728. int i = 0;
  8729. char fnametemp[200]={0};
  8730. ChargeProfileCount = 0;
  8731. //Check ChargePointMaxProfile.json exit
  8732. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8733. {
  8734. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8735. i = i + 1;
  8736. }
  8737. //Check TxDefaultProfile_0.json exit
  8738. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8739. {
  8740. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8741. i = i + 1;
  8742. }
  8743. //Check TxDefaultProfile_%d.json
  8744. for(int j=1; j <= gunTotalNumber; j++)
  8745. {
  8746. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8747. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8748. if((access(fnametemp,F_OK))!=-1)
  8749. {
  8750. strcpy(chargingProfiles[i], fnametemp);
  8751. i = i + 1;
  8752. }
  8753. }
  8754. //Check TxProfile_%d.json
  8755. for(int j=1; j <= gunTotalNumber; j++)
  8756. {
  8757. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8758. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8759. if((access(fnametemp,F_OK))!=-1)
  8760. {
  8761. strcpy(chargingProfiles[i], fnametemp);
  8762. i = i + 1;
  8763. }
  8764. }
  8765. ChargeProfileCount = i;
  8766. }// End connectorIsNULL is TRUE
  8767. if(ChargeProfileCount == 0)
  8768. {
  8769. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8770. goto end;
  8771. }
  8772. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8773. {
  8774. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8775. goto end;
  8776. }
  8777. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8778. {
  8779. memset(str, 0, ARRAY_SIZE(str));
  8780. // clear temp file
  8781. sprintf(str,"rm -f %s",temp);
  8782. system(str);
  8783. for(int k=0; k < ChargeProfileCount; k++)
  8784. {
  8785. memset(str, 0, ARRAY_SIZE(str));
  8786. //clear file in C
  8787. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8788. system(str);
  8789. }
  8790. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8791. goto end;
  8792. }
  8793. else if(connectorIsNULL == TRUE)
  8794. {
  8795. for(int k=0; k < ChargeProfileCount; k++)
  8796. {
  8797. fptr1 = fopen(chargingProfiles[k], "r");
  8798. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8799. //Check Charging Profile Count
  8800. while(fscanf(fptr1, "%s", word) != EOF)
  8801. {
  8802. //DEBUG_INFO("word=%s\n",word);
  8803. if(strstr(word, "chargingProfileId")!= NULL)
  8804. {
  8805. //DEBUG_INFO("test chargingProfileId \n");
  8806. n_chargingProfile = n_chargingProfile + 1;
  8807. //DEBUG_INFO("chargingProfileId Found\n");
  8808. }
  8809. }
  8810. rewind(fptr1);
  8811. //search Charging Profile Element
  8812. //int i= 0;
  8813. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8814. {
  8815. json_object *tmpProfilee;
  8816. tmpProfilee = json_tokener_parse(sLineWord);
  8817. if(!is_error(tmpProfilee))
  8818. {
  8819. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8820. {
  8821. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8822. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8823. }
  8824. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8825. {
  8826. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8827. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8828. }
  8829. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8830. {
  8831. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8832. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8833. }
  8834. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8835. {
  8836. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8837. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8838. }
  8839. }
  8840. json_object_put(tmpProfilee);
  8841. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8842. {
  8843. //------- not write to fptr2-------//
  8844. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8845. //clearflag = TRUE;
  8846. }
  8847. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8848. {
  8849. //------- not write to fptr2-------//
  8850. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8851. }
  8852. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8853. {
  8854. //------- not write to fptr2-------//
  8855. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8856. }
  8857. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8858. {
  8859. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8860. }
  8861. else
  8862. {
  8863. fprintf(fptr2, sLineWord);//writing data into file
  8864. }
  8865. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8866. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8867. if(clearflag == TRUE)
  8868. {
  8869. fclose(fptr1);
  8870. fclose(fptr2);
  8871. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8872. system(str);
  8873. // clear temp file
  8874. sprintf(str,"rm -f %s",temp);
  8875. system(str);
  8876. }
  8877. else
  8878. {
  8879. fclose(fptr1);
  8880. fclose(fptr2);
  8881. memset(str, 0, ARRAY_SIZE(str));
  8882. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8883. system(str);
  8884. resultRename = rename(temp, chargingProfiles[k]);
  8885. if(resultRename == 0)
  8886. {
  8887. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8888. }
  8889. else
  8890. {
  8891. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8892. }
  8893. if(comfirmstr[0]== 0)
  8894. {
  8895. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8896. }
  8897. //Check chargingProfile is empty file
  8898. /*------ Read the file ----------------*/
  8899. fptr1=fopen(chargingProfiles[k],"r");
  8900. ch=fgetc(fptr1);
  8901. rewind(fptr1);
  8902. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8903. if(ch!=EOF)
  8904. {
  8905. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8906. {
  8907. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8908. if(sLineWord[0]=='\0')
  8909. {
  8910. isEmptyFile = TRUE;
  8911. break;
  8912. }
  8913. else
  8914. {
  8915. isEmptyFile = FALSE;
  8916. break;
  8917. }
  8918. }
  8919. }
  8920. else
  8921. isEmptyFile = TRUE;
  8922. fclose(fptr1);
  8923. if(isEmptyFile == TRUE)
  8924. {
  8925. memset(str, 0, ARRAY_SIZE(str));
  8926. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8927. system(str);
  8928. }
  8929. }
  8930. }// End of while(int k=0; k < ChargePointCount; k++)
  8931. }
  8932. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8933. {
  8934. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8935. for(int k=0; k < ChargeProfileCount; k++)
  8936. {
  8937. fptr1 = fopen(chargingProfiles[k], "r");
  8938. fptr2 = fopen(temp, "w+");
  8939. //Check Charging Profile Count
  8940. while(fscanf(fptr1, "%s", word) != EOF)
  8941. {
  8942. //DEBUG_INFO("word=%s\n",word);
  8943. if(strstr(word, "chargingProfileId")!= NULL)
  8944. {
  8945. n_chargingProfile = n_chargingProfile + 1;
  8946. }
  8947. }
  8948. rewind(fptr1);
  8949. //search Charging Profile Element
  8950. //int i= 0;
  8951. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8952. {
  8953. json_object *tmpProfilee;
  8954. tmpProfilee = json_tokener_parse(sLineWord);
  8955. if(!is_error(tmpProfilee))
  8956. {
  8957. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8958. {
  8959. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8960. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8961. }
  8962. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8963. {
  8964. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8965. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8966. }
  8967. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8968. {
  8969. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8970. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8971. }
  8972. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8973. {
  8974. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8975. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8976. }
  8977. }
  8978. json_object_put(tmpProfilee);
  8979. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8980. {
  8981. //------- not write to fptr2-------//
  8982. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8983. //clearflag = TRUE;
  8984. }
  8985. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8986. {
  8987. //------- not write to fptr2-------//
  8988. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8989. }
  8990. else if(stackLevelIsNULL == TRUE)
  8991. {
  8992. //Clear Whole File
  8993. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8994. clearflag = TRUE;
  8995. break;
  8996. }
  8997. else
  8998. {
  8999. fprintf(fptr2, sLineWord);//writing data into file
  9000. }
  9001. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9002. }
  9003. if(clearflag == TRUE)
  9004. {
  9005. fclose(fptr1);
  9006. fclose(fptr2);
  9007. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9008. system(str);
  9009. // clear temp file
  9010. sprintf(str,"rm -f %s",temp);
  9011. system(str);
  9012. }
  9013. else
  9014. {
  9015. fclose(fptr1);
  9016. fclose(fptr2);
  9017. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9018. system(str);
  9019. resultRename = rename(temp, chargingProfiles[k]);
  9020. if(resultRename == 0)
  9021. {
  9022. DEBUG_INFO("File ChargingProfile renamed successfully");
  9023. }
  9024. else
  9025. {
  9026. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9027. }
  9028. if(comfirmstr[0]== 0)
  9029. {
  9030. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9031. }
  9032. //Check chargingProfile is empty file
  9033. /*------ Read the file ----------------*/
  9034. fptr1=fopen(chargingProfiles[k],"r");
  9035. ch=fgetc(fptr1);
  9036. rewind(fptr1);
  9037. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9038. if(ch!=EOF)
  9039. {
  9040. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9041. {
  9042. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9043. if(sLineWord[0]=='\0')
  9044. {
  9045. isEmptyFile = TRUE;
  9046. break;
  9047. }
  9048. else
  9049. {
  9050. isEmptyFile = FALSE;
  9051. break;
  9052. }
  9053. }
  9054. }
  9055. else
  9056. isEmptyFile = TRUE;
  9057. fclose(fptr1);
  9058. if(isEmptyFile == TRUE)
  9059. {
  9060. memset(str, 0, ARRAY_SIZE(str));
  9061. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9062. system(str);
  9063. }
  9064. /*------- End of reading ---------------*/
  9065. }
  9066. } // while(int k=0; k < ChargeProfileCount; k++)
  9067. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9068. end:
  9069. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9070. {
  9071. if(connectorIdInt == 0)
  9072. {
  9073. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9074. {
  9075. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9076. }
  9077. }
  9078. else
  9079. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9080. }
  9081. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9082. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9083. return result;
  9084. }
  9085. void createFirmwareVersionByDataTransfer(void)
  9086. {
  9087. json_object *FirmwareDataTransfer = json_object_new_object();
  9088. // AC & DC model
  9089. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9090. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9091. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9092. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9093. // DC model
  9094. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9095. {
  9096. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9097. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9098. (gunType[3] != GUN_TYPE_UNKNOWN))
  9099. {
  9100. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9101. }
  9102. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9103. {
  9104. // DS DM DW
  9105. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9106. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9107. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9108. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9109. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9110. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9111. }
  9112. else
  9113. {
  9114. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9115. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9116. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9117. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9118. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9119. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9120. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9121. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9122. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9123. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9124. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9125. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9126. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9127. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9128. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9129. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9130. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9131. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9132. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9133. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9134. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9135. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9136. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9137. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9138. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9139. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9140. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9141. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9142. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9143. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9144. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9145. }
  9146. }
  9147. // 4G model
  9148. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9149. {
  9150. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9151. }
  9152. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9153. json_object_put(FirmwareDataTransfer);
  9154. }
  9155. int handleDataTransferRequest(char *uuid, char *payload)
  9156. {
  9157. mtrace();
  9158. json_object *response = json_object_new_object();
  9159. int result = FAIL;
  9160. char tempvendorId[255]={0};
  9161. char tempmessageId[50]={0};
  9162. char tempdata[1024]={0};
  9163. char message[2048]={0};
  9164. DEBUG_INFO("handleDataTransferRequest...\n");
  9165. if((uuid != NULL) && (payload != NULL))
  9166. {
  9167. json_object *DataTransfer;
  9168. DataTransfer = json_tokener_parse(payload);
  9169. if(!is_error(DataTransfer))
  9170. {
  9171. // Required data
  9172. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9173. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9174. // Optional data
  9175. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9176. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9177. if(json_object_object_get(DataTransfer, "data") != NULL)
  9178. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9179. result = PASS;
  9180. }
  9181. json_object_put(DataTransfer);
  9182. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9183. {
  9184. // Send all moudle firmware version on EVSE
  9185. createFirmwareVersionByDataTransfer();
  9186. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9187. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9188. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9189. json_object_put(response);
  9190. }
  9191. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9192. {
  9193. system("/usr/bin/run_tmate_restart.sh &");
  9194. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9195. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9196. json_object_put(response);
  9197. }
  9198. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9199. {
  9200. json_object *data;
  9201. data = json_tokener_parse(tempdata);
  9202. if(!is_error(data))
  9203. {
  9204. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9205. {
  9206. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9207. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9208. if(json_object_object_get(data, "SOC") != NULL)
  9209. {
  9210. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9211. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9212. }
  9213. if(json_object_object_get(data, "Energy") != NULL)
  9214. {
  9215. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9216. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9217. }
  9218. if(json_object_object_get(data, "Duration") != NULL)
  9219. {
  9220. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9221. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9222. }
  9223. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9224. }
  9225. else
  9226. {
  9227. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9228. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9229. }
  9230. }
  9231. else
  9232. {
  9233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9235. }
  9236. json_object_put(data);
  9237. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9238. json_object_put(response);
  9239. }
  9240. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9241. {
  9242. json_object *data;
  9243. data = json_tokener_parse(tempdata);
  9244. if(!is_error(data))
  9245. {
  9246. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9247. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9248. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9249. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9250. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9251. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9252. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9253. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9254. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9255. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9256. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9257. }
  9258. else
  9259. {
  9260. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9261. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9262. }
  9263. json_object_put(data);
  9264. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9265. json_object_put(response);
  9266. }
  9267. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9268. {
  9269. json_object *data;
  9270. data = json_tokener_parse(tempdata);
  9271. if(!is_error(data))
  9272. {
  9273. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9274. if(json_object_object_get(data, "idToken") != NULL)
  9275. {
  9276. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9277. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9278. }
  9279. if(json_object_object_get(data, "price") != NULL)
  9280. {
  9281. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9282. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9283. }
  9284. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9285. }
  9286. else
  9287. {
  9288. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9289. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9290. }
  9291. json_object_put(data);
  9292. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9293. json_object_put(response);
  9294. }
  9295. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9296. {
  9297. json_object *data;
  9298. data = json_tokener_parse(tempdata);
  9299. if(!is_error(data))
  9300. {
  9301. if(json_object_object_get(data, "txId") != NULL)
  9302. {
  9303. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9304. for(int idx = 0;idx<gunTotalNumber;idx++)
  9305. {
  9306. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9307. {
  9308. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9309. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9310. if(json_object_object_get(data, "description") != NULL)
  9311. {
  9312. // California pricing V1.0
  9313. DEBUG_INFO("California pricing V1.0\n");
  9314. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9315. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9316. }
  9317. else
  9318. {
  9319. // California pricing V1.1
  9320. DEBUG_INFO("California pricing V1.1\n");
  9321. if(json_object_object_get(data, "timestamp") != NULL)
  9322. {
  9323. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9324. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9325. }
  9326. if(json_object_object_get(data, "meterValue") != NULL)
  9327. {
  9328. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9329. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9330. }
  9331. if(json_object_object_get(data, "cost") != NULL)
  9332. {
  9333. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9334. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9335. }
  9336. if(json_object_object_get(data, "state") != NULL)
  9337. {
  9338. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9339. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9340. }
  9341. if(json_object_object_get(data, "chargingPrice") != NULL)
  9342. {
  9343. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9344. {
  9345. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9346. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9347. }
  9348. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9349. {
  9350. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9351. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9352. }
  9353. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9354. {
  9355. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9356. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9357. }
  9358. }
  9359. if(json_object_object_get(data, "idlePrice") != NULL)
  9360. {
  9361. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9362. {
  9363. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9364. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9365. }
  9366. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9367. {
  9368. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9369. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9370. }
  9371. }
  9372. if(json_object_object_get(data, "nextPeriod") != NULL)
  9373. {
  9374. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9375. {
  9376. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9377. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9378. }
  9379. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9380. {
  9381. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9382. {
  9383. 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")));
  9384. 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"));
  9385. }
  9386. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9387. {
  9388. 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")));
  9389. 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"));
  9390. }
  9391. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9392. {
  9393. 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")));
  9394. 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"));
  9395. }
  9396. }
  9397. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9398. {
  9399. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9400. {
  9401. 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")));
  9402. 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"));
  9403. }
  9404. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9405. {
  9406. 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")));
  9407. 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"));
  9408. }
  9409. }
  9410. }
  9411. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9412. {
  9413. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9414. {
  9415. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9416. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9417. }
  9418. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9419. {
  9420. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9421. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9422. }
  9423. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9424. {
  9425. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9426. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9427. }
  9428. }
  9429. }
  9430. }
  9431. }
  9432. }
  9433. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9434. }
  9435. else
  9436. {
  9437. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9438. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9439. }
  9440. json_object_put(data);
  9441. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9442. json_object_put(response);
  9443. }
  9444. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9445. {
  9446. json_object *data;
  9447. data = json_tokener_parse(tempdata);
  9448. if(!is_error(data))
  9449. {
  9450. if(json_object_object_get(data, "txId") != NULL)
  9451. {
  9452. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9453. for(int idx = 0;idx<gunTotalNumber;idx++)
  9454. {
  9455. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9456. {
  9457. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9458. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9459. if(json_object_object_get(data, "description") != NULL)
  9460. {
  9461. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9462. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9463. }
  9464. }
  9465. }
  9466. }
  9467. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9468. }
  9469. else
  9470. {
  9471. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9472. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9473. }
  9474. json_object_put(data);
  9475. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9476. json_object_put(response);
  9477. }
  9478. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9479. {
  9480. json_object *data;
  9481. data = json_tokener_parse(tempdata);
  9482. if(!is_error(data))
  9483. {
  9484. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9485. if(json_object_object_get(data, "Content_Type") != NULL)
  9486. {
  9487. 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))
  9488. {
  9489. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9490. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9491. {
  9492. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9493. }
  9494. }
  9495. else
  9496. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9497. }
  9498. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9499. }
  9500. else
  9501. {
  9502. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9503. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9504. }
  9505. json_object_put(data);
  9506. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9507. json_object_put(response);
  9508. }
  9509. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9510. {
  9511. json_object *data;
  9512. data = json_tokener_parse(tempdata);
  9513. if(!is_error(data))
  9514. {
  9515. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9516. if(json_object_object_get(data, "ConnectorId") != NULL)
  9517. {
  9518. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9519. }
  9520. if(json_object_object_get(data, "SerialNo") != NULL)
  9521. {
  9522. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9523. }
  9524. if(json_object_object_get(data, "Page_Index") != NULL)
  9525. {
  9526. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9527. }
  9528. if(json_object_object_get(data, "Duration") != NULL)
  9529. {
  9530. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9531. }
  9532. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9533. }
  9534. else
  9535. {
  9536. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9537. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9538. }
  9539. json_object_put(data);
  9540. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9541. json_object_put(response);
  9542. }
  9543. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9544. {
  9545. json_object *data;
  9546. data = json_tokener_parse(tempdata);
  9547. if(!is_error(data))
  9548. {
  9549. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9550. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9551. {
  9552. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9553. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9554. else
  9555. {
  9556. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9557. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9558. }
  9559. }
  9560. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9561. {
  9562. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9563. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9564. else
  9565. {
  9566. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9567. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9568. }
  9569. }
  9570. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9571. {
  9572. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9573. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9574. else
  9575. {
  9576. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9577. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9578. }
  9579. }
  9580. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9581. {
  9582. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9583. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9584. else
  9585. {
  9586. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9587. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9588. }
  9589. }
  9590. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9591. {
  9592. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9593. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9594. else
  9595. {
  9596. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9597. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9598. }
  9599. }
  9600. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9601. {
  9602. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9603. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9604. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9605. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9606. else
  9607. {
  9608. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9609. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9610. }
  9611. }
  9612. if(json_object_object_get(data, "isAuthentication") != NULL)
  9613. {
  9614. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9615. {
  9616. case 0:
  9617. case 1:
  9618. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9619. break;
  9620. default:
  9621. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9622. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9623. break;
  9624. }
  9625. }
  9626. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9627. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9628. }
  9629. else
  9630. {
  9631. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9632. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9633. }
  9634. json_object_put(data);
  9635. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9636. json_object_put(response);
  9637. }
  9638. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9639. {
  9640. json_object *data;
  9641. data = json_tokener_parse(tempdata);
  9642. if(!is_error(data))
  9643. {
  9644. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9645. if(json_object_object_get(data, "stationName") != NULL)
  9646. {
  9647. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9648. }
  9649. else
  9650. {
  9651. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9652. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9653. }
  9654. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9655. {
  9656. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9657. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9658. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9659. }
  9660. }
  9661. else
  9662. {
  9663. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9664. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9665. }
  9666. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9667. json_object_put(response);
  9668. }
  9669. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9670. {
  9671. json_object *data;
  9672. data = json_tokener_parse(tempdata);
  9673. if(!is_error(data))
  9674. {
  9675. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9676. if(json_object_object_get(data, "weatherId") != NULL)
  9677. {
  9678. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9679. }
  9680. else
  9681. {
  9682. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9683. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9684. }
  9685. if(json_object_object_get(data, "Temperature") != NULL)
  9686. {
  9687. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9688. }
  9689. else
  9690. {
  9691. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9692. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9693. }
  9694. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9695. {
  9696. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9697. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9698. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9699. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9700. }
  9701. }
  9702. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9703. {
  9704. json_object *data;
  9705. data = json_tokener_parse(tempdata);
  9706. if(!is_error(data))
  9707. {
  9708. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9709. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9710. {
  9711. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9712. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9713. }
  9714. else
  9715. {
  9716. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9717. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9718. }
  9719. }
  9720. else
  9721. {
  9722. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9723. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9724. }
  9725. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9726. json_object_put(response);
  9727. }
  9728. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9729. {
  9730. json_object *data;
  9731. data = json_tokener_parse(tempdata);
  9732. if(!is_error(data))
  9733. {
  9734. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9735. {
  9736. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9737. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9738. if(gun_index < gunTotalNumber)
  9739. {
  9740. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9741. {
  9742. json_object *responsedata = json_object_new_object();
  9743. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9744. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9745. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9746. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9747. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9748. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9749. }
  9750. else
  9751. {
  9752. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9753. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9754. }
  9755. }
  9756. else
  9757. {
  9758. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9759. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9760. }
  9761. }
  9762. else
  9763. {
  9764. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9765. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9766. }
  9767. }
  9768. else
  9769. {
  9770. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9771. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9772. }
  9773. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9774. json_object_put(response);
  9775. }
  9776. else
  9777. {
  9778. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9779. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9780. }
  9781. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9782. json_object_put(response);
  9783. }
  9784. else
  9785. {
  9786. // Can not find valid message id
  9787. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9788. }
  9789. }
  9790. else
  9791. {
  9792. // Payload is null
  9793. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9794. }
  9795. LWS_Send(message);
  9796. return result;
  9797. }
  9798. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9799. {
  9800. mtrace();
  9801. int result = FAIL;
  9802. int connectorIdInt, durationInt;
  9803. char chargingRateUnitStr[4]={0};
  9804. char comfirmstr[20];
  9805. int confirmPeriods = 0;
  9806. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9807. json_object *GetCompositeSchedule;
  9808. GetCompositeSchedule = json_tokener_parse(payload);
  9809. if(!is_error(GetCompositeSchedule))
  9810. {
  9811. // Required data
  9812. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9813. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9814. else
  9815. connectorIdInt = -1;
  9816. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9817. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9818. else
  9819. durationInt = 86400;
  9820. // Optional data
  9821. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9822. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9823. }
  9824. json_object_put(GetCompositeSchedule);
  9825. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9826. if((connectorIdInt == 0) ||
  9827. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9828. {
  9829. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9830. struct StructChargingProfile tmpProfile[1];
  9831. if(strstr(chargingRateUnitStr, "W") != NULL)
  9832. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9833. else
  9834. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9835. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9836. {
  9837. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9838. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9839. }
  9840. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9841. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9842. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9843. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9844. {
  9845. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9846. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9847. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9848. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9849. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9850. {
  9851. confirmPeriods = idx;
  9852. break;
  9853. }
  9854. }
  9855. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9856. {
  9857. confirmPeriods += 1;
  9858. }
  9859. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9860. }
  9861. else
  9862. {
  9863. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9864. }
  9865. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9866. return result;
  9867. }
  9868. int handleGetConfigurationRequest(char *uuid, char *payload)
  9869. {
  9870. mtrace();
  9871. int result = FAIL;
  9872. int MaxKeySupported = 0;
  9873. int n_keys = 0;
  9874. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9875. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9876. json_object *GetConfiguration;
  9877. GetConfiguration = json_tokener_parse(payload);
  9878. if(!is_error(GetConfiguration))
  9879. {
  9880. // Optional data
  9881. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9882. {
  9883. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9884. {
  9885. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9886. n_keys = idx + 1;
  9887. }
  9888. }
  9889. }
  9890. json_object_put(GetConfiguration);
  9891. UnknownKeynum = 0;
  9892. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9893. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9894. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9895. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9896. if(n_keys != 0)
  9897. {
  9898. for(int i=0;i<n_keys;i++)
  9899. {
  9900. getKeyValue(requestKey[i]);
  9901. }
  9902. }
  9903. else
  9904. {
  9905. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9906. getKeyValue("");
  9907. }
  9908. processUnkownKey();
  9909. sendGetConfigurationConfirmation(uuid);
  9910. return result;
  9911. }
  9912. static char fnamePlusPath[100]={0};
  9913. static char fnamePWithNoPath[60]={0};
  9914. void checkUploadLog(void)
  9915. {
  9916. FILE *fp;
  9917. /* Open the command for reading. */
  9918. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9919. if (fp == NULL) {
  9920. DEBUG_WARN("Failed to run command\n" );
  9921. exit(1);
  9922. }
  9923. int ftppathlen = 0;
  9924. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9925. int i = 0;
  9926. /* Read the output a line at a time - output it. */
  9927. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9928. if(i==0)
  9929. {
  9930. ftppathlen = strlen(fnamePlusPath);
  9931. DEBUG_INFO("%s\n", fnamePlusPath);
  9932. fnamePlusPath[ftppathlen]='\0';
  9933. break;
  9934. }
  9935. i= i+1;
  9936. }
  9937. /* close */
  9938. pclose(fp);
  9939. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9940. {
  9941. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9942. {
  9943. fnamePlusPath[k]='\0';
  9944. }
  9945. }
  9946. i=1;
  9947. //char fname[60]={0};
  9948. while(i < ftppathlen)
  9949. {
  9950. int len=ftppathlen-i;
  9951. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9952. {
  9953. DEBUG_INFO("compare '/' all right\n");
  9954. break;
  9955. }
  9956. i=i+1;
  9957. }
  9958. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9959. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9960. fnamePWithNoPath[i+1] = '\0';
  9961. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9962. {
  9963. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9964. {
  9965. fnamePWithNoPath[j]='\0';
  9966. }
  9967. }
  9968. FILE* fp1 = fopen(fnamePlusPath, "r");
  9969. if (fp1)
  9970. {
  9971. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9972. // file exists
  9973. fclose(fp1);
  9974. }
  9975. else
  9976. {
  9977. // file doesn't exist
  9978. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9979. }
  9980. }
  9981. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9982. {
  9983. mtrace();
  9984. int result = FAIL;
  9985. time_t CurrentTime;
  9986. struct tm *tm;
  9987. pthread_t th_Status;
  9988. CurrentTime = time(NULL);
  9989. tm = localtime(&CurrentTime);
  9990. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9991. 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);
  9992. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9993. if(!interLock.isGetDiagnosticGoing)
  9994. {
  9995. interLock.isGetDiagnosticGoing = 1;
  9996. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9997. sleep(1);
  9998. }
  9999. else
  10000. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10001. return result;
  10002. }
  10003. void* GetDiagnosticsProcess(void* data)
  10004. {
  10005. pthread_detach(pthread_self());
  10006. mtrace();
  10007. int retriesInt=0, retryIntervalInt=0;
  10008. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10009. 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};
  10010. int port=0;
  10011. int isSuccess = FALSE;
  10012. char ftpbuf[200]={0};
  10013. char cmdBuf[2048];
  10014. struct tm *tmNow;
  10015. time_t CurrentTime;
  10016. struct tm tmStart;
  10017. struct tm tmStop;
  10018. CurrentTime = time(NULL);
  10019. tmNow=localtime(&CurrentTime);
  10020. uint16_t targetYear, targetMonth;
  10021. json_object *GetDiagnostics;
  10022. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10023. GetDiagnostics = json_tokener_parse(data);
  10024. if(!is_error(GetDiagnostics))
  10025. {
  10026. // Required data
  10027. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10028. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10029. // Optional data
  10030. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10031. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10032. else
  10033. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10034. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10035. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10036. else
  10037. retryIntervalInt = 30;
  10038. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10039. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10040. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10041. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10042. }
  10043. json_object_put(GetDiagnostics);
  10044. // Pack log to compress file
  10045. 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) &&
  10046. (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))
  10047. {
  10048. // Pack system log
  10049. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10050. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10051. targetYear = tmStart.tm_year;
  10052. targetMonth = tmStart.tm_mon;
  10053. do
  10054. {
  10055. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10056. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10057. if(targetMonth+1>=13)
  10058. {
  10059. targetYear += 1;
  10060. targetMonth = 1;
  10061. }
  10062. else
  10063. {
  10064. targetMonth += 1;
  10065. }
  10066. }while((targetYear < (tmNow->tm_year+1900)) ||
  10067. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10068. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10069. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10070. system(cmdBuf);
  10071. // Pack charging & event log
  10072. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10073. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10074. targetYear = tmStart.tm_year;
  10075. targetMonth = tmStart.tm_mon;
  10076. do
  10077. {
  10078. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10079. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10080. if(targetMonth+1>=13)
  10081. {
  10082. targetYear += 1;
  10083. targetMonth = 1;
  10084. }
  10085. else
  10086. {
  10087. targetMonth += 1;
  10088. }
  10089. }while((targetYear < (tmNow->tm_year+1900)) ||
  10090. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10091. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10092. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10093. system(cmdBuf);
  10094. // Combine log file
  10095. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10096. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10097. }
  10098. else
  10099. {
  10100. system("exec /root/logPackTools 'log' 6");
  10101. }
  10102. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10103. system(cmdBuf);
  10104. checkUploadLog();
  10105. //****************location*******************/
  10106. if(strcmp(locationstr,"")==0)
  10107. {
  10108. DEBUG_INFO("location is <Empty>!\n");
  10109. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10110. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10111. goto end;
  10112. }
  10113. memset(protocol, 0, ARRAY_SIZE(protocol));
  10114. memset(user, 0, ARRAY_SIZE(user) );
  10115. memset(password, 0, ARRAY_SIZE(password));
  10116. memset(host, 0, ARRAY_SIZE(host));
  10117. memset(path, 0, ARRAY_SIZE(path));
  10118. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10119. memset(host1, 0, ARRAY_SIZE(host1));
  10120. memset(path1, 0, ARRAY_SIZE(path1));
  10121. /*location: ftp://user:password@host:port/path*/
  10122. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10123. if((access(fnamePlusPath,F_OK))!=-1)
  10124. {
  10125. DEBUG_INFO("fnamePlusPath exist.\n");
  10126. }
  10127. else
  10128. {
  10129. DEBUG_INFO("fnamePlusPath not exist!\n");
  10130. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10131. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10132. goto end;
  10133. }
  10134. if(strchr(locationstr,'@')==NULL)
  10135. {
  10136. sscanf(locationstr,
  10137. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10138. protocol, host, &port, path);
  10139. strcpy(user,"anonymous");
  10140. strcpy(password,"");
  10141. }
  10142. else
  10143. {
  10144. //DEBUG_INFO("pch=%s\n", pch);
  10145. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10146. protocol, user, password, host, &port, path);
  10147. }
  10148. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10149. {
  10150. DEBUG_INFO("protocol is not ftp/http ! \n");
  10151. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10152. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10153. goto end;
  10154. }
  10155. if(strncmp(locationstr,"http", 4) == 0)
  10156. {
  10157. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10158. sprintf(ftppath,"/%s", path);
  10159. do
  10160. {
  10161. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10162. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10163. sleep(3);
  10164. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10165. if(!isSuccess)
  10166. {
  10167. DEBUG_INFO("Diagnostics fail.\n");
  10168. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10169. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10170. sleep(retryIntervalInt);
  10171. }
  10172. else
  10173. {
  10174. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10175. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10176. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10177. }
  10178. retriesInt--;
  10179. }while((isSuccess == 0)&&(retriesInt >= 0));
  10180. }
  10181. else
  10182. {
  10183. sscanf(host,"%[^/]%s",host1, path1);
  10184. if(strlen(path) > 0)
  10185. sprintf(ftppath,"/%s", path);
  10186. else
  10187. sprintf(ftppath,"/%s", path1);
  10188. int ftppathlen=strlen(ftppath);
  10189. int i=1;
  10190. char filenametemp[50];
  10191. while(i < ftppathlen)
  10192. {
  10193. int len=ftppathlen-i;
  10194. if(ftppath[len]== 47) // '/' ascll code: 47
  10195. {
  10196. DEBUG_INFO("find '/' all right\n");
  10197. break;
  10198. }
  10199. i=i+1;
  10200. }
  10201. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10202. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10203. filenametemp[i+1] = 0;
  10204. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10205. if(port == 0)
  10206. port = 21;
  10207. do
  10208. {
  10209. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10210. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10211. sleep(3);
  10212. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10213. if(!isSuccess)
  10214. {
  10215. DEBUG_INFO("Diagnostics fail.\n");
  10216. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10217. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10218. sleep(retryIntervalInt);
  10219. }
  10220. else
  10221. {
  10222. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10223. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10224. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10225. }
  10226. retriesInt--;
  10227. }while((!isSuccess)&&(retriesInt >= 0));
  10228. }
  10229. end:
  10230. system("rm -f /mnt/*");
  10231. sleep(5);
  10232. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10233. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10234. interLock.isGetDiagnosticGoing = 0;
  10235. pthread_exit(NULL);
  10236. }
  10237. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10238. {
  10239. mtrace();
  10240. int result = FAIL;
  10241. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10242. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10243. {
  10244. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10245. locallistVersion = -1;
  10246. }
  10247. else
  10248. {
  10249. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10250. locallistVersion = 0;
  10251. OCPP_getListVerion();
  10252. }
  10253. //from db.OCPP_getListVerion
  10254. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10255. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10256. sendGetLocalListVersionConfirmation(uuid,"");
  10257. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10258. return result;
  10259. }
  10260. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10261. {
  10262. mtrace();
  10263. int result = FAIL;
  10264. int connectorIdInt=-1;
  10265. int tempIndex = 0;
  10266. int connectorIdIsNULL, chargingProfileIsNULL;
  10267. char comfirmstr[20]={0};
  10268. char cmdBuf[512];
  10269. json_object *RemoteStartTransaction;
  10270. FILE *fp;
  10271. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10272. if(server_pending == TRUE)
  10273. {
  10274. return 0;
  10275. }
  10276. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10277. RemoteStartTransaction = json_tokener_parse(payload);
  10278. if(!is_error(RemoteStartTransaction))
  10279. {
  10280. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10281. {
  10282. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10283. }
  10284. else
  10285. {
  10286. connectorIdIsNULL = TRUE;
  10287. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10288. {
  10289. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10290. {
  10291. connectorIdIsNULL = FALSE;
  10292. connectorIdInt = (gun_index+1);
  10293. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10294. break;
  10295. }
  10296. }
  10297. }
  10298. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10299. {
  10300. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10301. // Required data
  10302. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10303. // Optional data
  10304. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10305. {
  10306. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10307. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10308. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10309. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10310. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10311. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10312. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10313. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10314. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10315. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10316. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10317. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10318. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10319. {
  10320. 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")));
  10321. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10322. 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"));
  10323. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10324. 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"));
  10325. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10326. 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")));
  10327. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10328. {
  10329. 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++)
  10330. {
  10331. 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"));
  10332. 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"));
  10333. 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)
  10334. 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"));
  10335. }
  10336. }
  10337. }
  10338. }
  10339. else
  10340. {
  10341. chargingProfileIsNULL = TRUE;
  10342. }
  10343. }
  10344. }
  10345. else
  10346. {
  10347. connectorIdIsNULL = TRUE;
  10348. }
  10349. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10350. {
  10351. DEBUG_WARN("Connector id is NULL\n.");
  10352. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10353. goto end;
  10354. }
  10355. /*
  10356. enum _SYSTEM_STATUS
  10357. {
  10358. S_BOOTING = 0,
  10359. S_IDLE, = 1
  10360. S_AUTHORIZING, = 2
  10361. S_REASSIGN_CHECK, = 3
  10362. S_REASSIGN, = 4
  10363. S_PRECHARGE, = 5
  10364. S_PREPARING_FOR_EV, = 6
  10365. S_PREPARING_FOR_EVSE, = 7
  10366. S_CHARGING, = 8
  10367. S_TERMINATING, = 9
  10368. S_COMPLETE, = 10
  10369. S_ALARM, = 11
  10370. S_FAULT = 12
  10371. }
  10372. */
  10373. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10374. {
  10375. //check Transaction active
  10376. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10377. {
  10378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10379. {
  10380. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10381. }
  10382. else
  10383. {
  10384. tempIndex = connectorIdInt -1;
  10385. }
  10386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10387. {
  10388. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10389. {
  10390. 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))
  10391. {
  10392. //Reserved
  10393. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10394. }
  10395. 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))
  10396. {
  10397. //Reserved
  10398. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10399. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10400. goto end;
  10401. }
  10402. else
  10403. {
  10404. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10405. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10406. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10407. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10408. {
  10409. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10410. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10411. goto end;
  10412. }
  10413. }//END FOR ELSE
  10414. }
  10415. }// END FOR CHAdeMO_QUANTITY
  10416. }
  10417. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10418. {
  10419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10420. {
  10421. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10422. }
  10423. else
  10424. {
  10425. tempIndex = connectorIdInt -1;
  10426. }
  10427. for (int index = 0; index < CCS_QUANTITY; index++)
  10428. {
  10429. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10430. {
  10431. 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))
  10432. {
  10433. //Reserved
  10434. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10435. }
  10436. 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))
  10437. {
  10438. //Reserved
  10439. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10440. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10441. goto end;
  10442. }
  10443. else
  10444. {
  10445. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10446. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10447. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10448. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10449. {
  10450. DEBUG_WARN("CCS connector not allow start\n.");
  10451. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10452. goto end;
  10453. }
  10454. }// END FOR ELSE
  10455. }
  10456. }// END FOR CCS_QUANTITY
  10457. }
  10458. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10459. {
  10460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10461. {
  10462. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10463. }
  10464. else
  10465. {
  10466. tempIndex = connectorIdInt -1;
  10467. }
  10468. for (int index = 0; index < GB_QUANTITY; index++)
  10469. {
  10470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10471. {
  10472. 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))
  10473. {
  10474. //Reserved
  10475. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10476. }
  10477. 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))
  10478. {
  10479. //Reserved
  10480. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10481. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10482. goto end;
  10483. }
  10484. else
  10485. {
  10486. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10487. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10488. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10489. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10490. {
  10491. DEBUG_WARN("GB connector not allow start\n.");
  10492. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10493. goto end;
  10494. }
  10495. }// END FOR ELSE
  10496. }
  10497. } // END FOR GB_QUANTITY
  10498. }
  10499. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10500. {
  10501. tempIndex = connectorIdInt -1;
  10502. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10503. {
  10504. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10505. {
  10506. 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))
  10507. {
  10508. //Reserved
  10509. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10510. }
  10511. 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))
  10512. {
  10513. //Reserved
  10514. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10515. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10516. goto end;
  10517. }
  10518. else
  10519. {
  10520. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10521. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10522. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10523. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10524. {
  10525. DEBUG_WARN("GB connector not allow start\n.");
  10526. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10527. goto end;
  10528. }
  10529. }// END FOR ELSE
  10530. }
  10531. } // END FOR GB_QUANTITY
  10532. }
  10533. else
  10534. {
  10535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10536. {
  10537. tempIndex = 2;
  10538. }
  10539. else
  10540. {
  10541. tempIndex = connectorIdInt -1;
  10542. }
  10543. for (int index = 0; index < AC_QUANTITY; index++)
  10544. {
  10545. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10546. {
  10547. 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))
  10548. {
  10549. //Reserved
  10550. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10551. }
  10552. 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))
  10553. {
  10554. //Reserved
  10555. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10556. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10557. goto end;
  10558. }
  10559. else
  10560. {
  10561. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10562. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10563. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10564. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10565. {
  10566. DEBUG_WARN("AC connector not allow start\n.");
  10567. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10568. goto end;
  10569. }
  10570. }//END FOR ELSE
  10571. }
  10572. }// END FOR AC_QUANTITY
  10573. }
  10574. if(chargingProfileIsNULL == FALSE)
  10575. {
  10576. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10577. {
  10578. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10579. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10580. //memset idTag
  10581. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10582. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10583. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10585. // Save profile to file
  10586. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10587. system(cmdBuf);
  10588. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10589. fp = fopen(cmdBuf, "w");
  10590. 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));
  10591. fclose(fp);
  10592. }
  10593. else
  10594. {
  10595. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10596. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10597. }
  10598. }
  10599. else
  10600. {
  10601. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10602. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10603. //memset idTag
  10604. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10605. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10606. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10608. }
  10609. }
  10610. else
  10611. {
  10612. DEBUG_WARN("Connector id over\n.");
  10613. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10614. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10615. }
  10616. end:
  10617. json_object_put(RemoteStartTransaction);
  10618. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10619. {
  10620. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10621. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10622. }
  10623. //OCPP send RemoteStartConfirmation by first.
  10624. sendRemoteStartConfirmation(uuid, comfirmstr);
  10625. return result;
  10626. }
  10627. int handleRemoteStartRequest(char *uuid, char *payload)
  10628. {
  10629. mtrace();
  10630. int result = PASS;
  10631. int connectorIdInt=-1;
  10632. int tempIndex = 0;
  10633. char comfirmstr[20]={0};
  10634. char cmdBuf[512];
  10635. json_object *RemoteStartTransaction;
  10636. FILE *fp;
  10637. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10638. if(server_pending == TRUE)
  10639. {
  10640. result = FAIL;
  10641. }
  10642. RemoteStartTransaction = json_tokener_parse(payload);
  10643. if(!is_error(RemoteStartTransaction))
  10644. {
  10645. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10646. {
  10647. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10648. }
  10649. else
  10650. {
  10651. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10652. {
  10653. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10654. {
  10655. connectorIdInt = (gun_index+1);
  10656. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10657. break;
  10658. }
  10659. }
  10660. }
  10661. if(connectorIdInt == 0)
  10662. {
  10663. DEBUG_WARN("Connector id shall not equal 0.\n");
  10664. result = FAIL;
  10665. }
  10666. else if(connectorIdInt == -1)
  10667. {
  10668. DEBUG_INFO("Connector id does not specific.\n");
  10669. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10670. {
  10671. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10672. // Required data
  10673. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10674. // Optional data
  10675. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10676. {
  10677. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10678. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10679. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10680. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10681. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10682. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10683. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10684. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10685. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10686. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10687. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10688. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10689. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10690. {
  10691. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10692. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10693. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10694. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10695. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10696. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10697. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10698. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10699. {
  10700. 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++)
  10701. {
  10702. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10703. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10704. 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)
  10705. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10706. }
  10707. }
  10708. }
  10709. }
  10710. else
  10711. {
  10712. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10713. }
  10714. }
  10715. }
  10716. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10717. {
  10718. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10719. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10720. // Required data
  10721. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10722. // Optional data
  10723. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10724. {
  10725. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10726. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10727. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10728. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10729. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10730. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10731. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10732. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10733. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10734. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10735. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10736. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10737. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10738. {
  10739. 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")));
  10740. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10741. 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"));
  10742. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10743. 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"));
  10744. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10745. 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")));
  10746. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10747. {
  10748. 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++)
  10749. {
  10750. 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"));
  10751. 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"));
  10752. 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)
  10753. 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"));
  10754. }
  10755. }
  10756. }
  10757. }
  10758. else
  10759. {
  10760. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10761. }
  10762. }
  10763. else
  10764. {
  10765. DEBUG_WARN("Connector id is over maximun value.\n");
  10766. result = FAIL;
  10767. }
  10768. }
  10769. if(result == PASS)
  10770. {
  10771. if(connectorIdInt > 0)
  10772. {
  10773. //check Transaction active
  10774. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10775. {
  10776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10777. {
  10778. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10779. }
  10780. else
  10781. {
  10782. tempIndex = connectorIdInt -1;
  10783. }
  10784. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10785. {
  10786. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10787. {
  10788. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10789. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10790. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10791. {
  10792. //Reserved
  10793. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10794. }
  10795. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10796. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10797. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10798. {
  10799. //Reserved
  10800. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10801. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10802. goto end;
  10803. }
  10804. else
  10805. {
  10806. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10807. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10808. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10809. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10810. {
  10811. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10812. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10813. goto end;
  10814. }
  10815. }//END FOR ELSE
  10816. }
  10817. }// END FOR CHAdeMO_QUANTITY
  10818. }
  10819. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10820. {
  10821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10822. {
  10823. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10824. }
  10825. else
  10826. {
  10827. tempIndex = connectorIdInt -1;
  10828. }
  10829. for (int index = 0; index < CCS_QUANTITY; index++)
  10830. {
  10831. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10832. {
  10833. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10834. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10835. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10836. {
  10837. //Reserved
  10838. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10839. }
  10840. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10841. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10842. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10843. {
  10844. //Reserved
  10845. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10846. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10847. goto end;
  10848. }
  10849. else
  10850. {
  10851. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10852. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10853. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10854. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10855. {
  10856. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10857. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10858. goto end;
  10859. }
  10860. }// END FOR ELSE
  10861. }
  10862. }// END FOR CCS_QUANTITY
  10863. }
  10864. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10865. {
  10866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10867. {
  10868. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10869. }
  10870. else
  10871. {
  10872. tempIndex = connectorIdInt -1;
  10873. }
  10874. for (int index = 0; index < GB_QUANTITY; index++)
  10875. {
  10876. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10877. {
  10878. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10879. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10880. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10881. {
  10882. //Reserved
  10883. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10884. }
  10885. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10886. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10887. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10888. {
  10889. //Reserved
  10890. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10891. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10892. goto end;
  10893. }
  10894. else
  10895. {
  10896. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10897. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10898. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10899. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10900. {
  10901. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10902. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10903. goto end;
  10904. }
  10905. }// END FOR ELSE
  10906. }
  10907. } // END FOR GB_QUANTITY
  10908. }
  10909. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10910. {
  10911. tempIndex = connectorIdInt -1;
  10912. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10913. {
  10914. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10915. {
  10916. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10917. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10918. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10919. {
  10920. //Reserved
  10921. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10922. }
  10923. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10924. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10925. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10926. {
  10927. //Reserved
  10928. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10929. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10930. goto end;
  10931. }
  10932. else
  10933. {
  10934. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10935. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10936. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10937. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10938. {
  10939. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10940. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10941. goto end;
  10942. }
  10943. }// END FOR ELSE
  10944. }
  10945. } // END FOR GB_QUANTITY
  10946. }
  10947. else
  10948. {
  10949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10950. {
  10951. tempIndex = 2;
  10952. }
  10953. else
  10954. {
  10955. tempIndex = connectorIdInt -1;
  10956. }
  10957. for (int index = 0; index < AC_QUANTITY; index++)
  10958. {
  10959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10960. {
  10961. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10962. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10963. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10964. {
  10965. //Reserved
  10966. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10967. }
  10968. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10969. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10970. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10971. {
  10972. //Reserved
  10973. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10974. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10975. goto end;
  10976. }
  10977. else
  10978. {
  10979. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10980. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10981. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10982. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10983. {
  10984. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10985. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10986. goto end;
  10987. }
  10988. }//END FOR ELSE
  10989. }
  10990. }// END FOR AC_QUANTITY
  10991. }
  10992. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10993. {
  10994. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10995. {
  10996. // Save profile to file
  10997. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10998. system(cmdBuf);
  10999. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11000. fp = fopen(cmdBuf, "w");
  11001. 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));
  11002. fclose(fp);
  11003. }
  11004. else
  11005. {
  11006. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11007. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11008. goto end;
  11009. }
  11010. }
  11011. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11012. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11013. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11014. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11015. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11017. }
  11018. else
  11019. {
  11020. uint8_t isHasIdleConnector = FALSE;
  11021. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11022. {
  11023. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11024. {
  11025. isHasIdleConnector = TRUE;
  11026. break;
  11027. }
  11028. }
  11029. if(isHasIdleConnector == TRUE)
  11030. {
  11031. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11032. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11033. {
  11034. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11035. {
  11036. // Save profile to file
  11037. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  11038. system(cmdBuf);
  11039. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  11040. fp = fopen(cmdBuf, "w");
  11041. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11042. fclose(fp);
  11043. refreshStartTimer(&clientTime.RemoteStartWait);
  11044. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11045. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11046. }
  11047. else
  11048. {
  11049. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11050. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11051. }
  11052. }
  11053. else
  11054. {
  11055. refreshStartTimer(&clientTime.RemoteStartWait);
  11056. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11057. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11058. }
  11059. }
  11060. else
  11061. {
  11062. DEBUG_INFO("There is not any connector is idle.\n");
  11063. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11064. }
  11065. }
  11066. }
  11067. else
  11068. {
  11069. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11070. }
  11071. end:
  11072. json_object_put(RemoteStartTransaction);
  11073. sendRemoteStartConfirmation(uuid, comfirmstr);
  11074. return result;
  11075. }
  11076. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11077. {
  11078. mtrace();
  11079. int result = FAIL;
  11080. int match = FALSE;
  11081. int GunNO = 0;
  11082. int tempIndex = 0;
  11083. int transactionIdInt=0;
  11084. int transactionIdIsNULL= TRUE;
  11085. char comfirmstr[20];
  11086. json_object *RemoteStopTransaction;
  11087. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11088. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11089. if(server_pending == TRUE)
  11090. {
  11091. return 0;
  11092. }
  11093. RemoteStopTransaction = json_tokener_parse(payload);
  11094. if(!is_error(RemoteStopTransaction))
  11095. {
  11096. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11097. {
  11098. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11099. transactionIdIsNULL = FALSE;
  11100. }
  11101. }
  11102. json_object_put(RemoteStopTransaction);
  11103. if(transactionIdIsNULL == FALSE)
  11104. {
  11105. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11106. {
  11107. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11108. {
  11109. //check Transaction active
  11110. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11111. {
  11112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11113. {
  11114. tempIndex = ((gun_index==2) ? 1: 0);
  11115. }
  11116. else
  11117. {
  11118. tempIndex = gun_index;
  11119. }
  11120. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11121. {
  11122. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11123. {
  11124. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11125. {
  11126. match = TRUE;
  11127. GunNO = gun_index;
  11128. }
  11129. }
  11130. }// END FOR CHAdeMO_QUANTITY
  11131. }
  11132. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11133. {
  11134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11135. {
  11136. tempIndex = ((gun_index==2) ? 1: 0);
  11137. }
  11138. else
  11139. {
  11140. tempIndex = gun_index;
  11141. }
  11142. for (int index = 0; index < CCS_QUANTITY; index++)
  11143. {
  11144. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11145. {
  11146. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11147. {
  11148. match = TRUE;
  11149. GunNO = gun_index;
  11150. }
  11151. }
  11152. }// END FOR CCS_QUANTITY
  11153. }
  11154. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11155. {
  11156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11157. {
  11158. tempIndex = ((gun_index==2) ? 1: 0);
  11159. }
  11160. else
  11161. {
  11162. tempIndex = gun_index;
  11163. }
  11164. for (int index = 0; index < GB_QUANTITY; index++)
  11165. {
  11166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11167. {
  11168. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11169. {
  11170. match = TRUE;
  11171. GunNO = gun_index;
  11172. }
  11173. }
  11174. }// END FOR GB_QUANTITY
  11175. }
  11176. else if(gunType[gun_index] == GUN_TYPE_DO)
  11177. {
  11178. tempIndex = gun_index;
  11179. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11180. {
  11181. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11182. {
  11183. 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
  11184. {
  11185. match = TRUE;
  11186. GunNO = gun_index;
  11187. }
  11188. }
  11189. }// END FOR GB_QUANTITY
  11190. }
  11191. else
  11192. {
  11193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11194. {
  11195. tempIndex = 2;
  11196. }
  11197. else
  11198. {
  11199. tempIndex = gun_index;
  11200. }
  11201. for (int index = 0; index < AC_QUANTITY; index++)
  11202. {
  11203. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11204. {
  11205. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11206. {
  11207. match = TRUE;
  11208. GunNO = gun_index;
  11209. }
  11210. }
  11211. }// END FOR CHAdeMO_QUANTITY
  11212. } // END FOR AC ELSE
  11213. }// CHECK IF ResponseTransactionId == transactionIdInt
  11214. }//END FOR
  11215. if( match == TRUE)
  11216. {
  11217. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11218. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11219. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11220. }
  11221. else
  11222. {
  11223. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11224. }
  11225. }
  11226. else
  11227. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11228. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11229. return result;
  11230. }
  11231. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11232. {
  11233. mtrace();
  11234. int result = FAIL;
  11235. int connectorIdInt=0, reservationIdInt=0;
  11236. int tempIndex = 0;
  11237. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11238. char comfirmstr[20]={0};
  11239. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11240. int c = 0;
  11241. char *loc;
  11242. //char *ptr;
  11243. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11244. strcpy(sstrtemp, stringtrimspace(payload));
  11245. //***(1)connectorId ****/
  11246. c=0;
  11247. loc = strstr(sstrtemp, "connectorId");
  11248. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11249. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11250. {
  11251. sstr[c] = loc[strlen("connectorId")+2+c];
  11252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11253. c++;
  11254. }
  11255. sstr[c] = '\0';
  11256. connectorIdInt = atoi(sstr);
  11257. //***(2)expiryDate ****/
  11258. loc = strstr(sstrtemp, "expiryDate");
  11259. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11260. c = 0;
  11261. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11262. {
  11263. sstr[c] = loc[3+strlen("expiryDate")+c];
  11264. c++;
  11265. }
  11266. sstr[c] = '\0';
  11267. strcpy(expiryDatestr, sstr);
  11268. //***(3)idTag ****/
  11269. loc = strstr(sstrtemp, "idTag");
  11270. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11271. c = 0;
  11272. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11273. {
  11274. sstr[c] = loc[3+strlen("idTag")+c];
  11275. c++;
  11276. }
  11277. sstr[c] = '\0';
  11278. strcpy(idTagstr, sstr);
  11279. //***(4)parentIdTag ****/
  11280. loc = strstr(sstrtemp, "parentIdTag");
  11281. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11282. c = 0;
  11283. if(loc == NULL)
  11284. {
  11285. strcpy(parentIdTagstr, "");
  11286. }
  11287. else
  11288. {
  11289. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11290. {
  11291. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11292. c++;
  11293. }
  11294. sstr[c] = '\0';
  11295. strcpy(parentIdTagstr, sstr);
  11296. }
  11297. //***(5)reservationId ****/
  11298. c=0;
  11299. loc = strstr(sstrtemp, "reservationId");
  11300. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11301. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11302. {
  11303. sstr[c] = loc[strlen("reservationId")+2+c];
  11304. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11305. c++;
  11306. }
  11307. sstr[c] = '\0';
  11308. reservationIdInt = atoi(sstr);
  11309. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11310. /*
  11311. enum SYSTEM_STATUS
  11312. {
  11313. SYS_MODE_BOOTING = 0,
  11314. SYS_MODE_IDLE = 1,
  11315. SYS_MODE_AUTHORIZING = 2,
  11316. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11317. SYS_MODE_REASSIGN = 4,
  11318. SYS_MODE_PREPARING = 5,
  11319. SYS_MODE_PREPARE_FOR_EV = 6,
  11320. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11321. SYS_MODE_CHARGING = 8,
  11322. SYS_MODE_TERMINATING = 9,
  11323. SYS_MODE_COMPLETE = 10,
  11324. SYS_MODE_ALARM = 11,
  11325. SYS_MODE_FAULT = 12,
  11326. SYS_MODE_RESERVATION = 13,
  11327. SYS_MODE_BOOKING = 14,
  11328. SYS_MODE_MAINTAIN = 15,
  11329. SYS_MODE_DEBUG = 16,
  11330. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11331. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11332. SYS_MODE_UPDATE = 19
  11333. };
  11334. */
  11335. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11336. {
  11337. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11338. goto end;
  11339. }
  11340. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11341. {
  11342. //check Transaction active
  11343. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11344. {
  11345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11346. {
  11347. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11348. }
  11349. else
  11350. {
  11351. tempIndex = connectorIdInt -1;
  11352. }
  11353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11354. {
  11355. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11356. {
  11357. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11358. {
  11359. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11360. {
  11361. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11362. {
  11363. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11364. {
  11365. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11366. }
  11367. else
  11368. {
  11369. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11371. }
  11372. }
  11373. 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'))
  11374. {
  11375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11376. }
  11377. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11378. {
  11379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11380. }
  11381. else
  11382. {
  11383. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11384. }
  11385. }
  11386. 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
  11387. {
  11388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11389. }
  11390. }
  11391. else
  11392. {
  11393. //replace reservation
  11394. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11395. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11396. }
  11397. }
  11398. } // END FOR CHAdeMO_QUANTITY
  11399. }
  11400. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11401. {
  11402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11403. {
  11404. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11405. }
  11406. else
  11407. {
  11408. tempIndex = connectorIdInt -1;
  11409. }
  11410. for (int index = 0; index < CCS_QUANTITY; index++)
  11411. {
  11412. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11413. {
  11414. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11415. {
  11416. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11417. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11418. {
  11419. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11420. {
  11421. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11422. {
  11423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11424. }
  11425. else
  11426. {
  11427. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11429. }
  11430. }
  11431. 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'))
  11432. {
  11433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11434. }
  11435. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11436. {
  11437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11438. }
  11439. else
  11440. {
  11441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11442. }
  11443. }
  11444. 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
  11445. {
  11446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11447. }
  11448. }
  11449. else
  11450. {
  11451. //replace reservation
  11452. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11454. }
  11455. }
  11456. } // END FOR CCS_QUANTITY
  11457. }
  11458. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11459. {
  11460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11461. {
  11462. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11463. }
  11464. else
  11465. {
  11466. tempIndex = connectorIdInt -1;
  11467. }
  11468. for (int index = 0; index < GB_QUANTITY; index++)
  11469. {
  11470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11471. {
  11472. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11473. {
  11474. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11475. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11476. {
  11477. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11478. {
  11479. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11480. {
  11481. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11482. }
  11483. else
  11484. {
  11485. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11487. }
  11488. }
  11489. 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'))
  11490. {
  11491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11492. }
  11493. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11494. {
  11495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11496. }
  11497. else
  11498. {
  11499. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11500. }
  11501. }
  11502. 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
  11503. {
  11504. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11505. }
  11506. }
  11507. else
  11508. {
  11509. //replace reservation
  11510. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11511. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11512. }
  11513. }
  11514. }// END FOR GB_QUANTITY
  11515. }
  11516. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11517. {
  11518. tempIndex = connectorIdInt -1;
  11519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11520. {
  11521. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11522. {
  11523. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11524. {
  11525. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11526. 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
  11527. {
  11528. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11529. {
  11530. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11531. {
  11532. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11533. }
  11534. else
  11535. {
  11536. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11538. }
  11539. }
  11540. 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'))
  11541. {
  11542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11543. }
  11544. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11545. {
  11546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11547. }
  11548. else
  11549. {
  11550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11551. }
  11552. }
  11553. 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
  11554. {
  11555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11556. }
  11557. }
  11558. else
  11559. {
  11560. //replace reservation
  11561. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11562. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11563. }
  11564. }
  11565. }// END FOR GB_QUANTITY
  11566. }
  11567. else
  11568. {
  11569. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11570. {
  11571. tempIndex = 2;
  11572. }
  11573. else
  11574. {
  11575. tempIndex = (connectorIdInt -1);
  11576. }
  11577. for (int index = 0; index < AC_QUANTITY; index++)
  11578. {
  11579. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11580. {
  11581. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11582. {
  11583. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11584. {
  11585. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11586. {
  11587. 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))
  11588. {
  11589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11590. }
  11591. else
  11592. {
  11593. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11595. }
  11596. }
  11597. 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'))
  11598. {
  11599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11600. }
  11601. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11602. {
  11603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11604. }
  11605. else
  11606. {
  11607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11608. }
  11609. }
  11610. 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
  11611. {
  11612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11613. }
  11614. }
  11615. else
  11616. {
  11617. //replace reservation
  11618. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11620. }
  11621. }
  11622. } // END FOR AC_QUANTITY
  11623. }
  11624. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11625. }
  11626. else if(connectorIdInt == 0)
  11627. {
  11628. //check Transaction active
  11629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11630. {
  11631. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11632. {
  11633. 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'))
  11634. {
  11635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11636. goto end;
  11637. }
  11638. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11639. {
  11640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11641. goto end;
  11642. }
  11643. 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
  11644. {
  11645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11646. goto end;
  11647. }
  11648. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11649. {
  11650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11651. goto end;
  11652. }
  11653. }
  11654. }// END FOR CHAdeMO_QUANTITY
  11655. for (int index = 0; index < CCS_QUANTITY; index++)
  11656. {
  11657. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11658. {
  11659. 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'))
  11660. {
  11661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11662. goto end;
  11663. }
  11664. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11665. {
  11666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11667. goto end;
  11668. }
  11669. 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
  11670. {
  11671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11672. goto end;
  11673. }
  11674. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11675. {
  11676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11677. goto end;
  11678. }
  11679. }
  11680. } // END FOR CCS_QUANTITY
  11681. for (int index = 0; index < GB_QUANTITY; index++)
  11682. {
  11683. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11684. {
  11685. 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'))
  11686. {
  11687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11688. goto end;
  11689. }
  11690. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11691. {
  11692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11693. goto end;
  11694. }
  11695. 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
  11696. {
  11697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11698. goto end;
  11699. }
  11700. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11701. {
  11702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11703. goto end;
  11704. }
  11705. }
  11706. } // END FOR GB_QUANTITY
  11707. for (int index = 0; index < AC_QUANTITY; index++)
  11708. {
  11709. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11710. {
  11711. 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'))
  11712. {
  11713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11714. goto end;
  11715. }
  11716. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11717. {
  11718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11719. goto end;
  11720. }
  11721. 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
  11722. {
  11723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11724. goto end;
  11725. }
  11726. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11727. {
  11728. 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))
  11729. {
  11730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11731. goto end;
  11732. }
  11733. }
  11734. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11735. {
  11736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11737. goto end;
  11738. }
  11739. }
  11740. }// END FOR AC_QUANTITY
  11741. //The connectorId is 0
  11742. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11744. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11745. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11746. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11747. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11748. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11749. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11750. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11751. result = TRUE;
  11752. return result;
  11753. }
  11754. else
  11755. {
  11756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11757. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11758. }
  11759. if(strcmp(comfirmstr,"Accepted") == 0)
  11760. {
  11761. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11762. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11763. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11764. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11765. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11766. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11767. result = TRUE;
  11768. return result;
  11769. }
  11770. end:
  11771. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11772. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11773. return result;
  11774. }
  11775. int handleResetRequest(char *uuid, char *payload)
  11776. {
  11777. mtrace();
  11778. int result = FAIL;
  11779. char sstr[10]={0},sstrtemp[30]={ 0 };
  11780. char typestr[10]={0};
  11781. char comfirmstr[20]={0};
  11782. int c = 0;
  11783. char *loc;
  11784. DEBUG_INFO("handleResetRequest...\n");
  11785. strcpy(sstrtemp, stringtrimspace(payload));
  11786. loc = strstr(sstrtemp, "type");
  11787. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11788. c = 0;
  11789. while (loc[3+strlen("type")+c] != '\"')
  11790. {
  11791. sstr[c] = loc[3+strlen("type")+c];
  11792. c++;
  11793. }
  11794. sstr[c] = '\0';
  11795. strcpy(typestr,sstr);
  11796. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11797. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11798. {
  11799. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11800. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11801. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11802. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11803. }
  11804. else
  11805. {
  11806. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11807. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11808. result = PASS;
  11809. }
  11810. sendResetConfirmation(uuid, comfirmstr);
  11811. return result;
  11812. }
  11813. int handleSendLocalListRequest(char *uuid, char *payload)
  11814. {
  11815. mtrace();
  11816. int result = FAIL;
  11817. char comfirmstr[20];
  11818. int checkState_Faulted = FALSE;
  11819. json_object *SendLocalList;
  11820. DEBUG_INFO("handleSendLocalListRequest...\n");
  11821. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11822. {
  11823. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11824. goto end;
  11825. }
  11826. //check Charge Point state
  11827. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11828. {
  11829. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11830. {
  11831. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11832. }
  11833. }
  11834. for (int index = 0; index < CCS_QUANTITY; index++)
  11835. {
  11836. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11837. {
  11838. checkState_Faulted = TRUE; //OCPP Status
  11839. }
  11840. }
  11841. for (int index = 0; index < GB_QUANTITY; index++)
  11842. {
  11843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11844. {
  11845. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11846. }
  11847. }
  11848. //check Charge Point state
  11849. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11850. {
  11851. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11852. {
  11853. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11854. }
  11855. }
  11856. //check Charge Point state
  11857. for (int index = 0; index < AC_QUANTITY; index++)
  11858. {
  11859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11860. {
  11861. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11862. }
  11863. }
  11864. if(checkState_Faulted == TRUE)
  11865. {
  11866. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11867. goto end;
  11868. }
  11869. // Parsing payload
  11870. SendLocalList = json_tokener_parse(payload);
  11871. if(!is_error(SendLocalList))
  11872. {
  11873. // Required data
  11874. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11875. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11876. // Optional data
  11877. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11878. {
  11879. //Check UpdateType
  11880. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11881. {
  11882. //Local list full update
  11883. DEBUG_INFO("Local list full update.\n");
  11884. locallistVersion = 0;
  11885. OCPP_getListVerion();
  11886. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11887. {
  11888. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11889. goto end;
  11890. }*/
  11891. OCPP_cleanLocalList();
  11892. }
  11893. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11894. {
  11895. //Local list different update
  11896. DEBUG_INFO("Local list different update.\n");
  11897. locallistVersion = 0;
  11898. OCPP_getListVerion();
  11899. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11900. {
  11901. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11902. goto end;
  11903. }
  11904. }
  11905. else
  11906. {
  11907. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11908. goto end;
  11909. }
  11910. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11911. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11912. {
  11913. 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")));
  11914. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11915. {
  11916. 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")));
  11917. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11918. 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")));
  11919. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11920. 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")));
  11921. }
  11922. // Add to db
  11923. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11924. {
  11925. //Local list full update
  11926. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11927. idx,
  11928. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11929. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11930. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11931. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11932. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11933. // update list
  11934. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11935. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11936. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11937. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11938. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11939. }
  11940. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11941. {
  11942. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11943. idx,
  11944. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11945. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11946. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11947. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11948. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11949. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11950. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11951. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11952. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11953. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11954. }
  11955. }
  11956. }
  11957. else
  11958. {
  11959. //Check UpdateType
  11960. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11961. {
  11962. //Local list full update
  11963. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11964. OCPP_cleanLocalList();
  11965. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11966. goto end;
  11967. }
  11968. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11969. {
  11970. //Local list different update
  11971. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11972. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11973. goto end;
  11974. }
  11975. }
  11976. result = PASS;
  11977. }
  11978. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11979. end:
  11980. json_object_put(SendLocalList);
  11981. sendSendLocalListConfirmation(uuid, comfirmstr);
  11982. return result;
  11983. }
  11984. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11985. {
  11986. mtrace();
  11987. int result = FAIL;
  11988. struct StructSetChargingProfile SetProfileReq = {0};
  11989. int tempchargingProfileIdInt;
  11990. int tempstackLevelInt;
  11991. int chargingSchedulePeriodCount = 0;
  11992. char comfirmstr[20]={0};
  11993. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11994. char rmFileCmd[128]={0};
  11995. int profileQuantity = 0;
  11996. int replaceableProfileCnt = 0;
  11997. json_object *SetChargingProfile;
  11998. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11999. SetChargingProfile = json_tokener_parse(payload);
  12000. if(!is_error(SetChargingProfile))
  12001. {
  12002. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12003. {
  12004. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12005. }
  12006. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12007. {
  12008. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12009. {
  12010. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12011. }
  12012. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12013. {
  12014. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12015. }
  12016. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12017. {
  12018. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12019. }
  12020. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12021. {
  12022. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12023. }
  12024. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12025. {
  12026. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12027. }
  12028. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12029. {
  12030. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12031. }
  12032. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12033. {
  12034. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12035. }
  12036. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12037. {
  12038. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12039. }
  12040. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12041. {
  12042. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12043. {
  12044. 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")));
  12045. }
  12046. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12047. {
  12048. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12049. }
  12050. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12051. {
  12052. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12053. }
  12054. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12055. {
  12056. 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")));
  12057. }
  12058. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12059. {
  12060. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12061. if(chargingSchedulePeriodCount <= 10)
  12062. {
  12063. 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++)
  12064. {
  12065. 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)
  12066. {
  12067. 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"));
  12068. }
  12069. 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)
  12070. {
  12071. 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"));
  12072. }
  12073. 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)
  12074. {
  12075. 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"));
  12076. }
  12077. }
  12078. }
  12079. }
  12080. }
  12081. }
  12082. }
  12083. // Profile periods quantity check
  12084. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12085. {
  12086. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12087. goto end;
  12088. }
  12089. // Check invalid limit
  12090. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12091. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12092. {
  12093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12094. {
  12095. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12096. {
  12097. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12098. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12099. {
  12100. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12101. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12102. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12103. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12104. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12105. goto end;
  12106. }
  12107. }
  12108. }
  12109. else
  12110. {
  12111. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12112. {
  12113. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  12114. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12115. {
  12116. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12117. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12118. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12119. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12120. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12121. goto end;
  12122. }
  12123. }
  12124. }
  12125. }
  12126. // Profile purpose info check
  12127. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12128. {
  12129. FILE *fp;
  12130. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12131. if(SetProfileReq.ConnectorId != 0)
  12132. {
  12133. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12134. goto end;
  12135. }
  12136. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12137. if (!fp)
  12138. {
  12139. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12140. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12141. }
  12142. else
  12143. {
  12144. char *line = NULL;
  12145. size_t len = 0;
  12146. while(getline(&line, &len, fp) != -1)
  12147. {
  12148. json_object *obj = NULL;
  12149. obj = json_tokener_parse(line);
  12150. if(is_error(obj))
  12151. {
  12152. DEBUG_ERROR("Parse txProfile from file error.\n");
  12153. }
  12154. else
  12155. {
  12156. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12157. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12158. {
  12159. profileQuantity += 1;
  12160. }
  12161. else
  12162. replaceableProfileCnt += 1;
  12163. }
  12164. }
  12165. }
  12166. fclose(fp);
  12167. }
  12168. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12169. {
  12170. FILE *fp;
  12171. char filename[128]={0};
  12172. int tmpProfileQuantity;
  12173. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12174. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12175. {
  12176. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12177. goto end;
  12178. }
  12179. if(SetProfileReq.ConnectorId == 0)
  12180. {
  12181. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12182. {
  12183. tmpProfileQuantity = 0;
  12184. memset(filename, 0, ARRAY_SIZE(filename));
  12185. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12186. fp = fopen(filename, "r");
  12187. if (!fp)
  12188. {
  12189. DEBUG_INFO("%s does not create.\n", filename);
  12190. fp = fopen(filename, "w+");
  12191. }
  12192. else
  12193. {
  12194. char *line = NULL;
  12195. size_t len = 0;
  12196. while(getline(&line, &len, fp) != -1)
  12197. {
  12198. json_object *obj = NULL;
  12199. obj = json_tokener_parse(line);
  12200. if(is_error(obj))
  12201. {
  12202. DEBUG_ERROR("Parse txProfile from file error.\n");
  12203. }
  12204. else
  12205. {
  12206. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12207. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12208. {
  12209. tmpProfileQuantity += 1;
  12210. }
  12211. else
  12212. replaceableProfileCnt += 1;
  12213. }
  12214. }
  12215. }
  12216. fclose(fp);
  12217. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12218. }
  12219. }
  12220. else
  12221. {
  12222. memset(filename, 0, ARRAY_SIZE(filename));
  12223. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12224. fp = fopen(filename, "r");
  12225. if (!fp)
  12226. {
  12227. DEBUG_INFO("%s does not create.\n", filename);
  12228. fp = fopen(filename, "w+");
  12229. }
  12230. else
  12231. {
  12232. char *line = NULL;
  12233. size_t len = 0;
  12234. while(getline(&line, &len, fp) != -1)
  12235. {
  12236. json_object *obj = NULL;
  12237. obj = json_tokener_parse(line);
  12238. if(is_error(obj))
  12239. {
  12240. DEBUG_ERROR("Parse txProfile from file error.\n");
  12241. }
  12242. else
  12243. {
  12244. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12245. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12246. {
  12247. profileQuantity += 1;
  12248. }
  12249. else
  12250. replaceableProfileCnt += 1;
  12251. }
  12252. }
  12253. }
  12254. fclose(fp);
  12255. }
  12256. }
  12257. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12258. {
  12259. int isMatchTransactiodId= FALSE;
  12260. FILE *fp;
  12261. char filename[128]={0};
  12262. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12263. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12264. if(SetProfileReq.ConnectorId == 0)
  12265. {
  12266. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12267. goto end;
  12268. }
  12269. int tempIndex = 0;
  12270. //check Transaction active
  12271. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12272. {
  12273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12274. {
  12275. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12276. }
  12277. else
  12278. {
  12279. tempIndex = SetProfileReq.ConnectorId -1;
  12280. }
  12281. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12282. {
  12283. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12284. {
  12285. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12286. {
  12287. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12288. {
  12289. isMatchTransactiodId = TRUE;
  12290. break;
  12291. }
  12292. }
  12293. }
  12294. }
  12295. }
  12296. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12297. {
  12298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12299. {
  12300. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12301. }
  12302. else
  12303. {
  12304. tempIndex = SetProfileReq.ConnectorId -1;
  12305. }
  12306. for (int index = 0; index < CCS_QUANTITY; index++)
  12307. {
  12308. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12309. {
  12310. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12311. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12312. {
  12313. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12314. {
  12315. isMatchTransactiodId = TRUE;
  12316. break;
  12317. }
  12318. }
  12319. }
  12320. }
  12321. }
  12322. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12323. {
  12324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12325. {
  12326. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12327. }
  12328. else
  12329. {
  12330. tempIndex = SetProfileReq.ConnectorId -1;
  12331. }
  12332. for (int index = 0; index < GB_QUANTITY; index++)
  12333. {
  12334. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12335. {
  12336. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12337. {
  12338. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12339. {
  12340. isMatchTransactiodId = TRUE;
  12341. break;
  12342. }
  12343. }
  12344. }
  12345. }
  12346. }
  12347. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12348. {
  12349. tempIndex = SetProfileReq.ConnectorId -1;
  12350. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12351. {
  12352. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12353. {
  12354. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12355. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12356. {
  12357. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12358. {
  12359. isMatchTransactiodId = TRUE;
  12360. break;
  12361. }
  12362. }
  12363. }
  12364. }
  12365. }
  12366. else
  12367. {
  12368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12369. {
  12370. tempIndex = 2;
  12371. }
  12372. else
  12373. {
  12374. tempIndex = (SetProfileReq.ConnectorId -1);
  12375. }
  12376. for (int index = 0; index < AC_QUANTITY; index++)
  12377. {
  12378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12379. {
  12380. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12381. {
  12382. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12383. {
  12384. isMatchTransactiodId = TRUE;
  12385. break;
  12386. }
  12387. }
  12388. }
  12389. }
  12390. }
  12391. //check Transaction active
  12392. if(isMatchTransactiodId == FALSE)
  12393. {
  12394. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12395. goto end;
  12396. }
  12397. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12398. {
  12399. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12400. goto end;
  12401. }
  12402. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12403. fp = fopen(filename, "r");
  12404. if (!fp)
  12405. {
  12406. DEBUG_INFO("%s does not create.\n", filename);
  12407. fp = fopen(filename, "w+");
  12408. }
  12409. else
  12410. {
  12411. char *line = NULL;
  12412. size_t len = 0;
  12413. while(getline(&line, &len, fp) != -1)
  12414. {
  12415. json_object *obj = NULL;
  12416. obj = json_tokener_parse(line);
  12417. if(is_error(obj))
  12418. {
  12419. DEBUG_ERROR("Parse txProfile from file error.\n");
  12420. }
  12421. else
  12422. {
  12423. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12424. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12425. {
  12426. profileQuantity += 1;
  12427. }
  12428. else
  12429. replaceableProfileCnt += 1;
  12430. }
  12431. }
  12432. }
  12433. fclose(fp);
  12434. }
  12435. // Check ChargeProfileMaxStackLevel
  12436. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12437. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12438. {
  12439. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12440. goto end;
  12441. }
  12442. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12443. {
  12444. FILE *fp;
  12445. char dataLine[4096]={0};
  12446. char fnametemp[128]={0};
  12447. int tmpProfileQuantity;
  12448. //Check ChargePointMaxProfile.json exit
  12449. profileQuantity = 0;
  12450. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12451. {
  12452. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12453. //Check Charging Profile Count
  12454. tmpProfileQuantity = 0;
  12455. while(fscanf(fp, "%s", dataLine) != EOF)
  12456. {
  12457. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12458. {
  12459. profileQuantity += 1;
  12460. tmpProfileQuantity += 1;
  12461. }
  12462. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12463. }
  12464. fclose(fp);
  12465. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12466. }
  12467. //Check TxDefaultProfile_%d.json
  12468. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12469. {
  12470. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12471. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12472. if((access(fnametemp,F_OK))!=-1)
  12473. {
  12474. fp = fopen(fnametemp, "r");
  12475. //Check Charging Profile Count
  12476. tmpProfileQuantity = 0;
  12477. while(fscanf(fp, "%s", dataLine) != EOF)
  12478. {
  12479. //DEBUG_INFO("word=%s\n",word);
  12480. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12481. {
  12482. profileQuantity += 1;
  12483. tmpProfileQuantity += 1;
  12484. }
  12485. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12486. }
  12487. fclose(fp);
  12488. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12489. }
  12490. }
  12491. //Check TxProfile_%d.json
  12492. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12493. {
  12494. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12495. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12496. if((access(fnametemp,F_OK))!=-1)
  12497. {
  12498. fp = fopen(fnametemp, "r");
  12499. //Check Charging Profile Count
  12500. tmpProfileQuantity = 0;
  12501. while(fscanf(fp, "%s", dataLine) != EOF)
  12502. {
  12503. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12504. {
  12505. profileQuantity += 1;
  12506. tmpProfileQuantity += 1;
  12507. }
  12508. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12509. }
  12510. fclose(fp);
  12511. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12512. }
  12513. }
  12514. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12515. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12516. // To check total Profile quantity
  12517. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12518. {
  12519. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12520. {
  12521. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12522. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12523. goto end;
  12524. }
  12525. }
  12526. else
  12527. {
  12528. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12529. {
  12530. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12531. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12532. goto end;
  12533. }
  12534. }
  12535. }
  12536. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12537. //**********************************Write to File********************************************************/
  12538. {
  12539. FILE *infile;
  12540. FILE *outfile;
  12541. char dataLine[4096]={0};
  12542. char filename[128]={0};
  12543. int chkChar=0;
  12544. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12545. {
  12546. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12547. {
  12548. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12549. }
  12550. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12551. {
  12552. if(SetProfileReq.ConnectorId==0)
  12553. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12554. else
  12555. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12556. }
  12557. else
  12558. {
  12559. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12560. }
  12561. infile = fopen (filename, "r");
  12562. outfile = fopen (tempfile, "w");
  12563. chkChar = fgetc(infile);
  12564. rewind(infile);
  12565. if(chkChar == EOF)
  12566. {
  12567. // Profile is empty
  12568. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12569. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12570. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12571. fclose(infile);
  12572. fclose(outfile);
  12573. sprintf(rmFileCmd,"rm -f %s",filename);
  12574. system(rmFileCmd);
  12575. rename(tempfile, filename);
  12576. }
  12577. else
  12578. {
  12579. // Profile is not empty
  12580. int ChargingProfileAdded = FALSE;
  12581. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12582. {
  12583. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12584. json_object *tmpChargingProfile;
  12585. tmpChargingProfile = json_tokener_parse(dataLine);
  12586. if(!is_error(SetChargingProfile))
  12587. {
  12588. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12589. {
  12590. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12591. {
  12592. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12593. }
  12594. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12595. {
  12596. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12597. }
  12598. }
  12599. }
  12600. json_object_put(tmpChargingProfile);
  12601. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12602. {
  12603. if(ChargingProfileAdded == FALSE)
  12604. {
  12605. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12606. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12607. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12608. ChargingProfileAdded = TRUE;
  12609. }
  12610. }
  12611. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12612. {
  12613. if(ChargingProfileAdded == FALSE)
  12614. {
  12615. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12616. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12617. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12618. ChargingProfileAdded = TRUE;
  12619. }
  12620. }
  12621. else
  12622. {
  12623. fprintf(outfile,"%s\n",dataLine);
  12624. if(ChargingProfileAdded == FALSE)
  12625. {
  12626. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12627. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12628. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12629. ChargingProfileAdded = TRUE;
  12630. }
  12631. }
  12632. } // end of while loop
  12633. fclose(infile);
  12634. fclose(outfile);
  12635. sprintf(rmFileCmd,"rm -f %s",filename);
  12636. system(rmFileCmd);
  12637. rename(tempfile, filename);
  12638. }
  12639. }
  12640. sleep(1);
  12641. result = TRUE;
  12642. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12643. }
  12644. end:
  12645. json_object_put(SetChargingProfile);
  12646. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12647. {
  12648. if(SetProfileReq.ConnectorId == 0)
  12649. {
  12650. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12651. {
  12652. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12653. }
  12654. }
  12655. else
  12656. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12657. }
  12658. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12659. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12660. return result;
  12661. }
  12662. int handleTriggerMessageRequest(char *uuid, char *payload)
  12663. {
  12664. mtrace();
  12665. int result = FAIL;
  12666. int connectorIdIsNULL = FALSE;
  12667. int connectorIdInt =0;
  12668. char sstr[40]={0},sstrtemp[100]={ 0 };
  12669. char requestedMessagestr[40]={0};
  12670. char comfirmstr[20]={0};
  12671. int c = 0;
  12672. char *loc;
  12673. DEBUG_INFO("handleTriggerMessageRequest\n");
  12674. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12675. strcpy(sstrtemp, stringtrimspace(payload));
  12676. c = 0;
  12677. loc = strstr(sstrtemp, "requestedMessage");
  12678. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12679. {
  12680. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12681. c++;
  12682. }
  12683. sstr[c] = '\0';
  12684. strcpy(requestedMessagestr, sstr);
  12685. c = 0;
  12686. loc = strstr(sstrtemp, "connectorId");
  12687. if(loc == NULL)
  12688. {
  12689. connectorIdIsNULL = TRUE;
  12690. }
  12691. else
  12692. {
  12693. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12694. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12695. {
  12696. sstr[c] = loc[strlen("connectorId")+2+c];
  12697. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12698. c++;
  12699. }
  12700. sstr[c] = '\0';
  12701. connectorIdInt = atoi(sstr);
  12702. }
  12703. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12704. {
  12705. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12706. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12707. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12708. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12709. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12710. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12711. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12712. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12713. {
  12714. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12715. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12716. return TRUE;
  12717. }
  12718. else
  12719. {
  12720. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12721. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12722. }
  12723. }
  12724. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12725. {
  12726. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12727. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12728. return TRUE;
  12729. }
  12730. //==========================
  12731. // Trigger message
  12732. //==========================
  12733. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12734. {
  12735. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12736. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12737. {
  12738. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12739. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12740. }
  12741. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12742. }
  12743. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12744. {
  12745. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12746. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12747. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12748. }
  12749. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12750. {
  12751. //sendBootNotificationRequest();
  12752. server_sign = FALSE;
  12753. }
  12754. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12755. {
  12756. refreshStartTimer(&clientTime.Heartbeat);
  12757. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12758. }
  12759. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12760. {
  12761. if(connectorIdIsNULL == FALSE)
  12762. {
  12763. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12764. {
  12765. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12766. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12767. }
  12768. }
  12769. else
  12770. {
  12771. for(int idx=0;idx< gunTotalNumber;idx++)
  12772. {
  12773. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12774. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12775. }
  12776. }
  12777. }
  12778. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12779. {
  12780. if(connectorIdIsNULL == FALSE)
  12781. {
  12782. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12783. {
  12784. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12785. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12786. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12787. }
  12788. }
  12789. else
  12790. {
  12791. for(int idx=0;idx< gunTotalNumber;idx++)
  12792. {
  12793. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12794. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12795. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12796. }
  12797. }
  12798. }
  12799. return result;
  12800. }
  12801. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12802. {
  12803. mtrace();
  12804. int result = FAIL;
  12805. int connectorIdInt =0;
  12806. char comfirmstr[20]={0};
  12807. int tempIndex = 0;
  12808. json_object *UnlockConnector;
  12809. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12810. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12811. UnlockConnector = json_tokener_parse(payload);
  12812. if(!is_error(UnlockConnector))
  12813. {
  12814. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12815. {
  12816. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12817. }
  12818. }
  12819. json_object_put(UnlockConnector);
  12820. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12821. if(gunTotalNumber == 0)
  12822. {
  12823. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12824. goto end;
  12825. }
  12826. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12827. {
  12828. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12829. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12830. goto end;
  12831. }
  12832. else
  12833. {
  12834. //check Transaction active
  12835. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12836. {
  12837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12838. {
  12839. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12840. }
  12841. else
  12842. {
  12843. tempIndex = connectorIdInt -1;
  12844. }
  12845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12846. {
  12847. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12848. {
  12849. //stop Transaction
  12850. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12851. }
  12852. }
  12853. }
  12854. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12855. {
  12856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12857. {
  12858. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12859. }
  12860. else
  12861. {
  12862. tempIndex = connectorIdInt -1;
  12863. }
  12864. for (int index = 0; index < CCS_QUANTITY; index++)
  12865. {
  12866. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12867. {
  12868. //stop Transaction
  12869. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12870. }
  12871. }
  12872. }
  12873. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12874. {
  12875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12876. {
  12877. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12878. }
  12879. else
  12880. {
  12881. tempIndex = connectorIdInt -1;
  12882. }
  12883. for (int index = 0; index < GB_QUANTITY; index++)
  12884. {
  12885. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12886. {
  12887. //stop Transaction
  12888. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12889. }
  12890. }
  12891. }
  12892. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12893. {
  12894. tempIndex = connectorIdInt -1;
  12895. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12896. {
  12897. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12898. {
  12899. //stop Transaction
  12900. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12901. }
  12902. }
  12903. }
  12904. else
  12905. {
  12906. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12907. {
  12908. tempIndex = 2;
  12909. }
  12910. else
  12911. {
  12912. tempIndex = connectorIdInt-1;
  12913. }
  12914. for (int index = 0; index < AC_QUANTITY; index++)
  12915. {
  12916. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12917. {
  12918. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12919. }
  12920. }
  12921. }
  12922. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12923. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12924. result = TRUE;
  12925. return result;
  12926. }
  12927. end:
  12928. //json_object_put(obj); --- remove temporally
  12929. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12930. return result;
  12931. }
  12932. static char UpdateFirmwarepayloadData[300]={0};
  12933. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12934. {
  12935. mtrace();
  12936. int result = FAIL;
  12937. pthread_t t;
  12938. sendUpdateFirmwareConfirmation(uuid);
  12939. memset(UpdateFirmwarepayloadData, 0, 300);
  12940. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12941. if(!interLock.isUpdateFirmwareGoing)
  12942. {
  12943. interLock.isUpdateFirmwareGoing = 1;
  12944. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12945. sleep(1);
  12946. }
  12947. else
  12948. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12949. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12950. return result;
  12951. }
  12952. void *UpdateFirmwareProcess(void *data)
  12953. {
  12954. pthread_detach(pthread_self());
  12955. mtrace();
  12956. int retriesInt =0, retryIntervalInt=0;
  12957. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12958. int port=0;
  12959. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12960. int isSuccess = 0;
  12961. char ftpbuf[512];
  12962. char temp[100];
  12963. char * pch;
  12964. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12965. json_object *UpdateFirmware;
  12966. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12967. if(!is_error(UpdateFirmware))
  12968. {
  12969. // Required data
  12970. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12971. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12972. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12973. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12974. // Optional data
  12975. if(json_object_object_get(UpdateFirmware, "retries"))
  12976. {
  12977. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12978. }
  12979. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12980. {
  12981. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12982. }
  12983. }
  12984. json_object_put(UpdateFirmware);
  12985. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12986. memset(path, 0, ARRAY_SIZE(path));
  12987. // Wait retrieveData
  12988. if(strlen(retrieveDatestr) > 10)
  12989. {
  12990. do
  12991. {
  12992. sleep(1);
  12993. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12994. }
  12995. // Ready to download
  12996. system("rm -f /mnt/*");
  12997. if(strncmp(locationstr,"http", 4) == 0)
  12998. {
  12999. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13000. sprintf(ftppath,"/%s", path);
  13001. DEBUG_INFO("locationstr: %s\n", locationstr);
  13002. DEBUG_INFO("protocol: %s\n",protocol);
  13003. DEBUG_INFO("host: %s\n",host);
  13004. DEBUG_INFO("path: %s\n",path);
  13005. DEBUG_INFO("ftppath: %s\n",ftppath);
  13006. int ftppathlen=strlen(ftppath);
  13007. int i=1;
  13008. char filenametemp[50];
  13009. while(i < ftppathlen)
  13010. {
  13011. int len=ftppathlen-i;
  13012. if(ftppath[len]== 47) // '/' ascll code: 47
  13013. {
  13014. DEBUG_INFO("compare '/' all right\n");
  13015. break;
  13016. }
  13017. i=i+1;
  13018. }
  13019. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13020. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13021. filenametemp[i+1] = 0;
  13022. do
  13023. {
  13024. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13025. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13026. sleep(1);
  13027. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13028. if(!isSuccess)
  13029. {
  13030. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13031. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13032. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13033. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13034. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13035. }
  13036. else
  13037. {
  13038. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13039. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13040. }
  13041. retriesInt--;
  13042. }while((isSuccess == 0)&&(retriesInt >= 0));
  13043. }
  13044. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13045. {
  13046. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13047. memset(temp, 0, ARRAY_SIZE(temp));
  13048. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13049. strcpy(ftpbuf, locationstr);
  13050. int ftppathlen=strlen(ftpbuf);
  13051. int i=1;
  13052. char filenametemp[50];
  13053. while(i < ftppathlen)
  13054. {
  13055. int len=ftppathlen-i;
  13056. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13057. {
  13058. DEBUG_INFO(" compare '/' all right\n");
  13059. break;
  13060. }
  13061. i=i+1;
  13062. }
  13063. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13064. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13065. filenametemp[i+1] = 0;
  13066. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13067. pch=strchr(temp,'@');
  13068. if(pch==NULL)
  13069. {
  13070. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13071. protocol, host, &port, path);
  13072. strcpy(user,"anonymous");
  13073. strcpy(password,"");
  13074. }
  13075. else
  13076. {
  13077. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13078. protocol, user, host, &port, path);
  13079. }
  13080. sscanf(host,"%[^/]%s",host1, path1);
  13081. sprintf(ftppath,"%s:/%s", host,path);
  13082. if(port == 0)
  13083. {
  13084. port = 21;
  13085. }
  13086. do
  13087. {
  13088. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13089. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13090. sleep(1);
  13091. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13092. if(!isSuccess)
  13093. {
  13094. //BulldogUtil.sleepMs(interval*1000);
  13095. DEBUG_INFO("Update firmware request and download file fail.\n");
  13096. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13097. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13098. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13099. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13100. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13101. }
  13102. else
  13103. {
  13104. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13105. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13106. }
  13107. retriesInt--;
  13108. }while((!isSuccess)&&(retriesInt >= 0));
  13109. }
  13110. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13111. {
  13112. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13113. memset(temp, 0, ARRAY_SIZE(temp));
  13114. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13115. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13116. int ftppathlen=strlen(ftpbuf);
  13117. int i=1;
  13118. char filenametemp[50];
  13119. while(i < ftppathlen)
  13120. {
  13121. int len=ftppathlen-i;
  13122. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13123. {
  13124. DEBUG_INFO(" compare '/' all right\n");
  13125. break;
  13126. }
  13127. i=i+1;
  13128. }
  13129. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13130. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13131. filenametemp[i+1] = 0;
  13132. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13133. pch=strchr(temp,'@');
  13134. if(pch==NULL)
  13135. {
  13136. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13137. protocol, host, &port, path);
  13138. strcpy(user,"anonymous");
  13139. strcpy(password,"");
  13140. }
  13141. else
  13142. {
  13143. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13144. protocol, user, password, host, &port, path);
  13145. }
  13146. sscanf(host,"%[^/]%s",host1, path1);
  13147. sprintf(ftppath,"%s", path1);
  13148. //DEBUG_INFO("protocol =%s\n",protocol);
  13149. //DEBUG_INFO("user =%s\n",user);
  13150. //DEBUG_INFO("password =%s\n",password);
  13151. //DEBUG_INFO("host1 =%s\n",host1);
  13152. //DEBUG_INFO("port =%d\n",port);
  13153. //DEBUG_INFO("path1 =%s\n",path1);
  13154. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13155. //ftpFile(host, user, password, port, ftppath, fname);
  13156. //download firmware pthred
  13157. if(port == 0)
  13158. {
  13159. port = 21;
  13160. }
  13161. do
  13162. {
  13163. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13164. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13165. sleep(1);
  13166. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13167. if(!isSuccess)
  13168. {
  13169. //BulldogUtil.sleepMs(interval*1000);
  13170. DEBUG_INFO("Update firmware request and download file fail.\n");
  13171. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13172. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13173. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13174. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13175. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13176. }
  13177. else
  13178. {
  13179. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13180. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13181. }
  13182. retriesInt--;
  13183. }while((!isSuccess)&&(retriesInt >= 0));
  13184. }
  13185. else
  13186. {
  13187. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13188. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13189. sleep(1);
  13190. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13191. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13192. }
  13193. // OCPPPH only, must announce CSU upgrade firmware
  13194. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13195. interLock.isUpdateFirmwareGoing = 0;
  13196. pthread_exit(NULL);
  13197. }
  13198. int handleCertificateSignedRequest(char *uuid, char *payload)
  13199. {
  13200. mtrace();
  13201. int result = PASS;
  13202. json_object *CertificateSigned;
  13203. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13204. CertificateSigned = json_tokener_parse(payload);
  13205. if(!is_error(CertificateSigned))
  13206. {
  13207. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13208. }
  13209. json_object_put(CertificateSigned);
  13210. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13211. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13212. fclose(fp);
  13213. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13214. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13215. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13216. sendCertificateSignedConfirmation(uuid);
  13217. return result;
  13218. }
  13219. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13220. {
  13221. mtrace();
  13222. int result = PASS;
  13223. json_object *DeleteCertificate;
  13224. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13225. DeleteCertificate = json_tokener_parse(payload);
  13226. if(!is_error(DeleteCertificate))
  13227. {
  13228. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13229. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13230. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13231. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13232. }
  13233. json_object_put(DeleteCertificate);
  13234. /*
  13235. * TODO: Delete certificateSigned process
  13236. */
  13237. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13238. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13239. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13240. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13241. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13242. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13243. sendDeleteCertificateConfirmation(uuid);
  13244. return result;
  13245. }
  13246. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13247. {
  13248. mtrace();
  13249. int result = PASS;
  13250. json_object *ExtendedTriggerMessage;
  13251. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13252. ExtendedTriggerMessage = json_tokener_parse(payload);
  13253. if(!is_error(ExtendedTriggerMessage))
  13254. {
  13255. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13256. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13257. {
  13258. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13259. }
  13260. else
  13261. {
  13262. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13263. }
  13264. }
  13265. json_object_put(ExtendedTriggerMessage);
  13266. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13267. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13268. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13269. {
  13270. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13271. }
  13272. else
  13273. {
  13274. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13275. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13276. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13277. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13278. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13279. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13280. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13281. {
  13282. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13283. }
  13284. else
  13285. {
  13286. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13287. }
  13288. }
  13289. sendExtendedTriggerMessageConfirmation(uuid);
  13290. //==========================
  13291. // Trigger message
  13292. //==========================
  13293. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13294. {
  13295. //sendBootNotificationRequest();
  13296. server_sign = FALSE;
  13297. }
  13298. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13299. {
  13300. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13301. }
  13302. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13303. {
  13304. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13305. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13306. {
  13307. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13308. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13309. }
  13310. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13311. }
  13312. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13313. {
  13314. refreshStartTimer(&clientTime.Heartbeat);
  13315. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13316. }
  13317. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13318. {
  13319. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13320. {
  13321. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13322. }
  13323. else
  13324. {
  13325. for(int idx=0;idx< gunTotalNumber;idx++)
  13326. {
  13327. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13328. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13329. }
  13330. }
  13331. }
  13332. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13333. {
  13334. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13335. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13336. {
  13337. 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\" &");
  13338. }
  13339. }
  13340. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13341. {
  13342. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13343. {
  13344. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13345. }
  13346. else
  13347. {
  13348. for(int idx=0;idx< gunTotalNumber;idx++)
  13349. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13350. }
  13351. }
  13352. return result;
  13353. }
  13354. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13355. {
  13356. mtrace();
  13357. int result = PASS;
  13358. json_object *GetInstalledCertificateIds;
  13359. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13360. GetInstalledCertificateIds = json_tokener_parse(payload);
  13361. if(!is_error(GetInstalledCertificateIds))
  13362. {
  13363. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13364. }
  13365. json_object_put(GetInstalledCertificateIds);
  13366. /*
  13367. * TODO: Return installed certificate process
  13368. */
  13369. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13370. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13371. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13372. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13373. sendGetInstalledCertificateIdsConfirmation(uuid);
  13374. return result;
  13375. }
  13376. int handleGetLogRequest(char *uuid, char *payload)
  13377. {
  13378. mtrace();
  13379. int result = PASS;
  13380. json_object *GetLog;
  13381. DEBUG_INFO("handleGetLogRequest...\n");
  13382. GetLog = json_tokener_parse(payload);
  13383. if(!is_error(GetLog))
  13384. {
  13385. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13386. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13387. if(json_object_object_get(GetLog, "retries") != NULL)
  13388. {
  13389. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13390. }
  13391. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13392. {
  13393. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13394. }
  13395. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13396. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13397. {
  13398. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13399. }
  13400. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13401. {
  13402. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13403. }
  13404. }
  13405. json_object_put(GetLog);
  13406. /*
  13407. * TODO: Upload log process
  13408. */
  13409. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13410. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13411. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13412. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13413. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13414. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13415. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13416. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13417. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13418. sendGetLogConfirmation(uuid);
  13419. return result;
  13420. }
  13421. int handleInstallCertificateRequest(char *uuid, char *payload)
  13422. {
  13423. mtrace();
  13424. int result = PASS;
  13425. json_object *InstallCertificate;
  13426. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13427. InstallCertificate = json_tokener_parse(payload);
  13428. if(!is_error(InstallCertificate))
  13429. {
  13430. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13431. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13432. /*
  13433. * TODO: Install certificate process
  13434. */
  13435. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13436. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13437. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13438. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13439. sendInstallCertificateConfirmation(uuid);
  13440. }
  13441. json_object_put(InstallCertificate);
  13442. return result;
  13443. }
  13444. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13445. {
  13446. mtrace();
  13447. int result = PASS;
  13448. json_object *SignedUpdateFirmware;
  13449. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13450. SignedUpdateFirmware = json_tokener_parse(payload);
  13451. if(!is_error(SignedUpdateFirmware))
  13452. {
  13453. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13454. {
  13455. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13456. }
  13457. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13458. {
  13459. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13460. }
  13461. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13462. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13463. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13464. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13465. {
  13466. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13467. }
  13468. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13469. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13470. }
  13471. json_object_put(SignedUpdateFirmware);
  13472. /*
  13473. * TODO: Upgrade firmware process
  13474. */
  13475. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13476. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13477. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13478. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13479. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13480. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13481. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13482. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13483. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13484. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13485. sendInstallCertificateConfirmation(uuid);
  13486. return result;
  13487. }
  13488. int handleUnknownRequest(char *uuid, char *payload)
  13489. {
  13490. mtrace();
  13491. int result = PASS;
  13492. DEBUG_INFO("handleUnknownRequest...\n");
  13493. sendUnknownConfirmation(uuid);
  13494. result = PASS;
  13495. return result;
  13496. }
  13497. //==========================================
  13498. // Handle server response routine
  13499. //==========================================
  13500. void handleAuthorizeResponse(char *payload, int gun_index)
  13501. {
  13502. mtrace();
  13503. char expiryDatestr[36]={0};
  13504. char parentIdTagstr[21]={0};
  13505. char statusstr[20]={0};
  13506. int expiryDateISNULL=FALSE;
  13507. int parentIdTagISNULL=FALSE;
  13508. DEBUG_INFO("handleAuthorizeResponse...\n");
  13509. json_object *Authorize;
  13510. Authorize = json_tokener_parse(payload);
  13511. if(!is_error(Authorize))
  13512. {
  13513. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13514. {
  13515. // Required data
  13516. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13517. // Optional data
  13518. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13519. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13520. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13521. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13522. }
  13523. }
  13524. json_object_put(Authorize);
  13525. if(expiryDateISNULL == FALSE)
  13526. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13527. if(parentIdTagISNULL == FALSE)
  13528. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13529. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13530. //Update idTag information to authorization cache if supproted
  13531. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13532. {
  13533. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13534. }
  13535. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13536. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13537. authorizeRetryTimes = 0;
  13538. }
  13539. void handleBootNotificationResponse(char *payload, int gun_index)
  13540. {
  13541. mtrace();
  13542. char statusStr[12]={0};
  13543. char currentTimeStr[30]={0};
  13544. int intervalInt = 0;
  13545. DEBUG_INFO("handleBootNotificationResponse...\n");
  13546. json_object *BootNotification;
  13547. BootNotification = json_tokener_parse(payload);
  13548. if(!is_error(BootNotification))
  13549. {
  13550. // Required data
  13551. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13552. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13553. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13554. }
  13555. json_object_put(BootNotification);
  13556. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13557. BootNotificationInterval = intervalInt;
  13558. //write back to ShmOCPP16DataPH->BootNotification
  13559. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13560. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13561. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13562. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13563. {
  13564. BootNotificationInterval = 0;
  13565. if((intervalInt == 0) || (intervalInt >= 10))
  13566. {
  13567. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13568. HeartBeatWaitTime = intervalInt;
  13569. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13570. }
  13571. server_sign = TRUE;
  13572. server_pending =FALSE;
  13573. }
  13574. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13575. {
  13576. server_pending = TRUE;
  13577. }
  13578. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13579. srand(time(NULL));
  13580. refreshStartTimer(&clientTime.Heartbeat);
  13581. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13582. SetOcppConnStatus(TRUE);
  13583. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13584. }
  13585. void handleDataTransferResponse(char *payload, int gun_index)
  13586. {
  13587. json_object *DataTransfer = json_tokener_parse(payload);
  13588. if(!is_error(DataTransfer))
  13589. {
  13590. // Required data
  13591. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13592. // Optional data
  13593. if(json_object_object_get(DataTransfer, "data") != NULL)
  13594. {
  13595. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13596. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13597. if(!is_error(Data))
  13598. {
  13599. if(json_object_object_get(Data, "msgId") != NULL)
  13600. {
  13601. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13602. {
  13603. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  13604. }
  13605. }
  13606. }
  13607. json_object_put(Data);
  13608. }
  13609. }
  13610. json_object_put(DataTransfer);
  13611. }
  13612. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13613. {
  13614. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13615. //struct json_object *obj;
  13616. // obj = json_tokener_parse(payload);
  13617. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13618. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13619. //No fields are defined.
  13620. }
  13621. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13622. {
  13623. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13624. //struct json_object *obj;
  13625. // obj = json_tokener_parse(payload);
  13626. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13627. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13628. //No fields are defined.
  13629. }
  13630. void handleHeartbeatResponse(char *payload, int gun_index)
  13631. {
  13632. mtrace();
  13633. DEBUG_INFO("handleHeartbeatResponse...\n");
  13634. json_object *Heartbeat;
  13635. Heartbeat = json_tokener_parse(payload);
  13636. if(!is_error(Heartbeat))
  13637. {
  13638. // Required data
  13639. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13640. }
  13641. json_object_put(Heartbeat);
  13642. if(FirstHeartBeat == 0)
  13643. {
  13644. FirstHeartBeat = 1;
  13645. DEBUG_INFO("FirstHeartBeat \n");
  13646. }
  13647. HeartBeatWithNOResponse = 0;
  13648. refreshStartTimer(&clientTime.Heartbeat);
  13649. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13650. }
  13651. void handleMeterValuesResponse(char *payload, int gun_index)
  13652. {
  13653. mtrace();
  13654. DEBUG_INFO("handleMeterValuesResponse...\n");
  13655. isQueueSendable = 1;
  13656. }
  13657. void handleStartTransactionResponse(char *payload, int gun_index)
  13658. {
  13659. mtrace();
  13660. //int transactionIdInt = 0;
  13661. FILE *outfile;
  13662. char data[100]={0};
  13663. DEBUG_INFO("handleStartTransactionResponse...\n");
  13664. json_object *StartTransaction;
  13665. StartTransaction = json_tokener_parse(payload);
  13666. if(!is_error(StartTransaction))
  13667. {
  13668. // Required data
  13669. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13670. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13671. // Optional data
  13672. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13673. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13674. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13675. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13676. }
  13677. json_object_put(StartTransaction);
  13678. isQueueSendable = 1;
  13679. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13680. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13681. //-----------Start : write to the Queue TransactionId file -----------------//
  13682. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13683. {}
  13684. else
  13685. {
  13686. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13687. if(log == NULL)
  13688. {
  13689. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13690. return ;
  13691. }
  13692. else
  13693. {
  13694. fclose(log);
  13695. }
  13696. }
  13697. // open file for writing
  13698. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13699. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13700. {
  13701. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13702. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13703. fputs(data, outfile);
  13704. fclose (outfile);
  13705. }
  13706. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13707. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13708. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13709. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13710. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13711. }
  13712. void handleStatusNotificationResponse(char *payload, int gun_index)
  13713. {
  13714. mtrace();
  13715. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13716. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13717. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13718. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13719. }
  13720. void handleStopTransactionnResponse(char *payload, int gun_index)
  13721. {
  13722. mtrace();
  13723. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13724. json_object *StopTransaction;
  13725. StopTransaction = json_tokener_parse(payload);
  13726. if(!is_error(StopTransaction))
  13727. {
  13728. // Optional data
  13729. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13730. {
  13731. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13732. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13733. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13734. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13735. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13736. }
  13737. }
  13738. json_object_put(StopTransaction);
  13739. isQueueSendable = 1;
  13740. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13741. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13742. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13743. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13744. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13745. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13746. }
  13747. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13748. {
  13749. mtrace();
  13750. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13751. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13752. }
  13753. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13754. {
  13755. mtrace();
  13756. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13757. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13758. }
  13759. void handleSignCertificateResponse(char *payload, int gun_index)
  13760. {
  13761. mtrace();
  13762. DEBUG_INFO("handleSignCertificateResponse...\n");
  13763. json_object *SignCertificate;
  13764. SignCertificate = json_tokener_parse(payload);
  13765. if(!is_error(SignCertificate))
  13766. {
  13767. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13768. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13769. }
  13770. json_object_put(SignCertificate);
  13771. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13772. }
  13773. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13774. {
  13775. mtrace();
  13776. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13777. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13778. }
  13779. //==========================================
  13780. // Handle Error routine
  13781. //==========================================
  13782. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13783. {
  13784. mtrace();
  13785. #ifdef SystemLogMessage
  13786. DEBUG_INFO("errorCode: %s\n", errorCode);
  13787. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13788. DEBUG_INFO("errorDetails: %s\n", payload);
  13789. #endif
  13790. }
  13791. //===============================================
  13792. // Common routine
  13793. //===============================================
  13794. int initialConfigurationTable(void)
  13795. {
  13796. //clock_t start_t, end_t, total_t;
  13797. FILE *fp;
  13798. FILE *outfile;
  13799. char str[512]={0};
  13800. char sstr[256]={0};
  13801. int c = 0;
  13802. char *loc;
  13803. int confVersion = 14;
  13804. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13805. //start_t = clock();
  13806. //printf("Starting of the program, start_t = %ld\n", start_t);
  13807. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13808. // Check configuration file size is correct
  13809. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13810. {
  13811. struct stat st;
  13812. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13813. if(st.st_size < 3100)
  13814. {
  13815. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13816. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13817. }
  13818. }
  13819. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13820. {
  13821. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13822. if(outfile == NULL)
  13823. {
  13824. DEBUG_INFO("Error opening file\n");
  13825. return FALSE;
  13826. }
  13827. /*Core Profile*/
  13828. //AllowOfflineTxForUnknownId
  13829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13833. //AuthorizationCacheEnabled
  13834. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13838. //AuthorizeRemoteTxRequests
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13843. //BlinkRepeat
  13844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13848. //ClockAlignedDataInterval
  13849. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13853. //ConnectionTimeOut
  13854. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13856. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13858. //GetConfigurationMaxKeys
  13859. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13861. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13863. // HeartbeatInterval
  13864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13868. // LightIntensity
  13869. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13873. // LocalAuthorizeOffline
  13874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13878. // LocalPreAuthorize
  13879. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13883. // MaxEnergyOnInvalidId
  13884. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13888. // MeterValuesAlignedData
  13889. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13891. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13892. 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" );
  13893. else
  13894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13896. // MeterValuesAlignedDataMaxLength
  13897. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13901. else
  13902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13904. // MeterValuesSampledData
  13905. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13908. 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" );
  13909. else
  13910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13912. // MeterValuesSampledDataMaxLength
  13913. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13917. else
  13918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13920. // MeterValueSampleInterval
  13921. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13923. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13925. // MinimumStatusDuration
  13926. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13929. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13931. // NumberOfConnectors
  13932. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13935. {
  13936. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13937. }
  13938. else
  13939. {
  13940. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13941. }
  13942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13943. // ResetRetries
  13944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13948. // ConnectorPhaseRotation
  13949. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13953. // ConnectorPhaseRotationMaxLength
  13954. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13955. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13958. // StopTransactionOnEVSideDisconnect
  13959. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13963. // StopTransactionOnInvalidId
  13964. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13968. // StopTxnAlignedData
  13969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13973. // StopTxnAlignedDataMaxLength
  13974. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13978. // StopTxnSampledData
  13979. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13983. else
  13984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13986. // StopTxnSampledDataMaxLength
  13987. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13989. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13990. {
  13991. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13992. }
  13993. else
  13994. {
  13995. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13996. }
  13997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13998. // SupportedFeatureProfiles
  13999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14003. // SupportedFeatureProfilesMaxLength
  14004. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14008. // TransactionMessageAttempts
  14009. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14010. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14012. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14014. // TransactionMessageRetryInterval
  14015. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14017. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14018. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14020. // UnlockConnectorOnEVSideDisconnect
  14021. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14025. // WebSocketPingInterval
  14026. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14030. // QueueOffLineMeterValues
  14031. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14032. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14035. // AuthorizationKey
  14036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  14039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14040. // SecurityProfile
  14041. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14043. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14045. // DefaultPrice
  14046. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14050. // CustomDisplayCostAndPrice
  14051. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14055. // CustomIdleFeeAfterStop
  14056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14060. // SystemUptimeSec
  14061. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14065. // FreeVend
  14066. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14070. // FreeVendIdtag
  14071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14075. // OcppServer
  14076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14078. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14080. // MaintainServer
  14081. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14083. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14085. // StatusNotificationPeriodically
  14086. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14090. // StatusNotificationInterval
  14091. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14095. // isEnableLocalPowerSharing
  14096. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14098. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14100. // PowerSharingServerIP
  14101. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14103. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14105. // EVCCID_PREFIX
  14106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14110. // Configuration Version
  14111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14113. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14115. //* Local Auth List Management Profile*/
  14116. #if 0
  14117. //For OCTT Test Case
  14118. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14121. #endif
  14122. #if 1
  14123. //LocalAuthListEnabled
  14124. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14128. #endif
  14129. //LocalAuthListMaxLength
  14130. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14134. //SendLocalListMaxLength
  14135. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  14138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14139. //ReserveConnectorZeroSupported
  14140. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14144. //* Smart Charging Profile */
  14145. //ChargeProfileMaxStackLevel
  14146. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14150. // ChargingScheduleAllowedChargingRateUnit
  14151. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14155. // ChargingScheduleMaxPeriods
  14156. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14160. // ConnectorSwitch3to1PhaseSupported
  14161. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14165. // MaxChargingProfilesInstalled
  14166. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14170. fclose(outfile);
  14171. }
  14172. else
  14173. {
  14174. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14175. char keystr[60]={0};
  14176. char readonlystr[10]={0};
  14177. char valuestr[256]={0};
  14178. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14179. if(fp == NULL) {
  14180. DEBUG_INFO("Error opening file");
  14181. return FALSE;
  14182. }
  14183. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14184. {
  14185. //DEBUG_INFO("Get Configuration \n");
  14186. if(strlen(str) > 0)
  14187. {
  14188. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14189. //*************************key*********************************/
  14190. if(strstr(str, "key") != NULL)
  14191. {
  14192. loc = strstr(str, "key");
  14193. c = 0;
  14194. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14195. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14196. {
  14197. sstr[c] = loc[strlen("key")+3+c];
  14198. c++;
  14199. }
  14200. sstr[c] = '\0';
  14201. strcpy(keystr,sstr);
  14202. }
  14203. //*************************readonly*********************************/
  14204. if(strstr(str, "readonly") != NULL)
  14205. {
  14206. loc = strstr(str, "readonly");
  14207. c = 0;
  14208. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14209. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14210. {
  14211. sstr[c] = loc[strlen("readonly")+2+c];
  14212. c++;
  14213. }
  14214. sstr[c] = '\0';
  14215. strcpy(readonlystr,sstr);
  14216. }
  14217. //*************************value*********************************/
  14218. if(strstr(str, "value") != NULL)
  14219. {
  14220. loc = strstr(str, "value");
  14221. c = 0;
  14222. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14223. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14224. {
  14225. sstr[c] = loc[strlen("value")+3+c];
  14226. c++;
  14227. }
  14228. sstr[c] = '\0';
  14229. strcpy(valuestr,sstr);
  14230. }
  14231. // DEBUG_INFO("keystr=%s\n",keystr);
  14232. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14233. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14234. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14235. {
  14236. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14237. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14238. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14239. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14240. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14241. }
  14242. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14243. {
  14244. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14245. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14246. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14247. }
  14248. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14249. {
  14250. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14251. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14252. }
  14253. if(strcmp(keystr, "BlinkRepeat") == 0)
  14254. {
  14255. //Charger.BlinkRepeat = Integer.parseInt(value);
  14256. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14257. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14258. }
  14259. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14260. {
  14261. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14262. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14263. }
  14264. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14265. {
  14266. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14267. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14268. }
  14269. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14270. {
  14271. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14273. }
  14274. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14275. {
  14276. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14278. HeartBeatWaitTime = atoi(valuestr);
  14279. }
  14280. if(strcmp(keystr, "LightIntensity") == 0)
  14281. {
  14282. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14283. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14284. }
  14285. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14286. {
  14287. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14289. }
  14290. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14291. {
  14292. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14294. }
  14295. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14296. {
  14297. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14298. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14299. }
  14300. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14301. {
  14302. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14303. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14304. }
  14305. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14306. {
  14307. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14308. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14309. }
  14310. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14311. {
  14312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14314. }
  14315. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14316. {
  14317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14318. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14319. }
  14320. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14321. {
  14322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14324. }
  14325. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14326. {
  14327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14329. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14330. }
  14331. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14332. {
  14333. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14334. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14335. }
  14336. if(strcmp(keystr, "ResetRetries") == 0)
  14337. {
  14338. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14340. }
  14341. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14342. {
  14343. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14344. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14345. }
  14346. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14347. {
  14348. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14350. }
  14351. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14352. {
  14353. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14354. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14355. }
  14356. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14357. {
  14358. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14359. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14360. }
  14361. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14362. {
  14363. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14364. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14365. }
  14366. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14367. {
  14368. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14369. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14370. }
  14371. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14372. {
  14373. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14374. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14375. }
  14376. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14377. {
  14378. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14379. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14380. }
  14381. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14382. {
  14383. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14384. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14385. }
  14386. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14387. {
  14388. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14389. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14390. }
  14391. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14392. {
  14393. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14394. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14395. TransactionMessageAttemptsValue = atoi(valuestr);
  14396. }
  14397. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14398. {
  14399. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14400. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14401. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14402. }
  14403. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14404. {
  14405. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14407. }
  14408. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14409. {
  14410. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14411. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14412. }
  14413. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14414. {
  14415. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14416. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14417. }
  14418. if(strcmp(keystr, "AuthorizationKey") == 0)
  14419. {
  14420. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14421. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14422. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14423. }
  14424. if(strcmp(keystr, "SecurityProfile") == 0)
  14425. {
  14426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14427. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14428. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14429. }
  14430. if(strcmp(keystr, "DefaultPrice") == 0)
  14431. {
  14432. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14433. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14434. }
  14435. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14436. {
  14437. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14438. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14439. }
  14440. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14441. {
  14442. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14443. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14444. }
  14445. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14446. {
  14447. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14449. }
  14450. if(strcmp(keystr, "FreeVend") == 0)
  14451. {
  14452. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14453. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14454. }
  14455. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14456. {
  14457. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14458. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14459. }
  14460. if(strcmp(keystr, "OcppServer") == 0)
  14461. {
  14462. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14463. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14464. }
  14465. if(strcmp(keystr, "MaintainServer") == 0)
  14466. {
  14467. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14468. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14469. }
  14470. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14471. {
  14472. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14473. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14474. }
  14475. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14476. {
  14477. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14479. }
  14480. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14481. {
  14482. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14484. }
  14485. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14486. {
  14487. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14488. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14489. }
  14490. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14491. {
  14492. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14493. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14494. }
  14495. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14496. {
  14497. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14498. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14499. }
  14500. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14501. {
  14502. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14503. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14504. }
  14505. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14506. {
  14507. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14508. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14509. }
  14510. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14511. {
  14512. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14513. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14514. }
  14515. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14516. {
  14517. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14518. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14519. }
  14520. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14521. {
  14522. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14523. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14524. }
  14525. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14526. {
  14527. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14528. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14529. }
  14530. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14531. {
  14532. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14533. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14534. }
  14535. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14536. {
  14537. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14538. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14539. }
  14540. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14541. {
  14542. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14543. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14544. }
  14545. }
  14546. }
  14547. fclose(fp);
  14548. }
  14549. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14550. {
  14551. return PASS;
  14552. }
  14553. else
  14554. {
  14555. return FAIL;
  14556. }
  14557. }
  14558. void StoreConfigurationTable(void)
  14559. {
  14560. FILE *outfile;
  14561. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14562. if(outfile == NULL)
  14563. {
  14564. DEBUG_INFO("Error opening file");
  14565. return ;
  14566. }
  14567. /*Core Profile*/
  14568. //AllowOfflineTxForUnknownId
  14569. /*
  14570. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14571. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14572. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14574. */
  14575. //DEBUG_INFO("data=%s\n",data);
  14576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14577. //AuthorizationCacheEnabled
  14578. /*
  14579. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14582. */
  14583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14584. //AuthorizeRemoteTxRequests
  14585. /*
  14586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14589. */
  14590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14591. //BlinkRepeat
  14592. /*
  14593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14594. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14595. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14596. */
  14597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14598. //ClockAlignedDataInterval
  14599. /*
  14600. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14603. */
  14604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14605. //ConnectionTimeOut
  14606. /*
  14607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14610. */
  14611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14612. //GetConfigurationMaxKeys
  14613. /*
  14614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14616. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14617. */
  14618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14619. // HeartbeatInterval
  14620. /*
  14621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14624. */
  14625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14626. // LightIntensity
  14627. /*
  14628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14631. */
  14632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14633. // LocalAuthorizeOffline
  14634. /*
  14635. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14638. */
  14639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14640. // LocalPreAuthorize
  14641. /*
  14642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14645. */
  14646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14647. // MaxEnergyOnInvalidId
  14648. /*
  14649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14650. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14652. */
  14653. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14655. // MeterValuesAlignedData
  14656. /*
  14657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14659. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14660. */
  14661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14662. // MeterValuesAlignedDataMaxLength
  14663. /*
  14664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14667. */
  14668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14669. // MeterValuesSampledData
  14670. /*
  14671. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14673. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14674. */
  14675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14676. // MeterValuesSampledDataMaxLength
  14677. /*
  14678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14681. */
  14682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14683. // MeterValueSampleInterval
  14684. /*
  14685. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14687. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14688. */
  14689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14690. // MinimumStatusDuration
  14691. /*
  14692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14695. */
  14696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14697. // NumberOfConnectors
  14698. /*
  14699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14701. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14702. {
  14703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14704. }
  14705. else
  14706. {
  14707. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14708. }
  14709. */
  14710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14711. // ResetRetries
  14712. /*
  14713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14716. */
  14717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14718. // ConnectorPhaseRotation
  14719. /*
  14720. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14721. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14723. */
  14724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14725. // ConnectorPhaseRotationMaxLength
  14726. /*
  14727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14729. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14730. */
  14731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14732. // StopTransactionOnEVSideDisconnect
  14733. /*
  14734. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14735. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14736. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14737. */
  14738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14739. // StopTransactionOnInvalidId
  14740. /*
  14741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14744. */
  14745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14746. // StopTxnAlignedData
  14747. /*
  14748. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14749. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14750. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14751. */
  14752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14753. // StopTxnAlignedDataMaxLength
  14754. /*
  14755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14756. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14758. */
  14759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14760. // StopTxnSampledData
  14761. /*
  14762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14765. */
  14766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14767. // StopTxnSampledDataMaxLength
  14768. /*
  14769. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14770. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14771. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14772. */
  14773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14774. // SupportedFeatureProfiles
  14775. /*
  14776. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14778. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14779. */
  14780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14781. // SupportedFeatureProfilesMaxLength
  14782. /*
  14783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14786. */
  14787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14788. // TransactionMessageAttempts
  14789. /*
  14790. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14792. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14793. */
  14794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14795. // TransactionMessageRetryInterval
  14796. /*
  14797. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14800. */
  14801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14802. // UnlockConnectorOnEVSideDisconnect
  14803. /*
  14804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14807. */
  14808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14809. // WebSocketPingInterval
  14810. /*
  14811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14814. */
  14815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14816. // QueueOffLineMeterValues
  14817. /*
  14818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14821. */
  14822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14823. // AuthorizationKey
  14824. /*
  14825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14828. */
  14829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14830. // SecurityProfile
  14831. /*
  14832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14835. */
  14836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14837. // DefaultPrice
  14838. /*
  14839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14842. */
  14843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14844. // CustomDisplayCostAndPrice
  14845. /*
  14846. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14849. */
  14850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14851. // CustomIdleFeeAfterStop
  14852. /*
  14853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14856. */
  14857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14858. // SystemUptimeSec
  14859. /*
  14860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14863. */
  14864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14865. // FreeVend
  14866. /*
  14867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14870. */
  14871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14872. // FreeVendIdtag
  14873. /*
  14874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14877. */
  14878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14879. // OcppServer
  14880. /*
  14881. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14884. */
  14885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14886. // MaintainServer
  14887. /*
  14888. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14891. */
  14892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14893. // StatusNotificationPeriodically
  14894. /*
  14895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14898. */
  14899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14900. // StatusNotificationInterval
  14901. /*
  14902. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14905. */
  14906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14907. // isEnableLocalPowerSharing
  14908. /*
  14909. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  14912. */
  14913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14914. // PowerSharingServerIP
  14915. /*
  14916. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  14919. */
  14920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14921. // EVCCID_PREFIX
  14922. /*
  14923. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14926. */
  14927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14928. // ConfigurationVersion
  14929. /*
  14930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14933. */
  14934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14935. //* Local Auth List Management Profile*/
  14936. //LocalAuthListEnabled
  14937. /*
  14938. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14941. */
  14942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14943. //LocalAuthListMaxLength
  14944. /*
  14945. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14948. */
  14949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14950. //SendLocalListMaxLength
  14951. /*
  14952. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14954. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14955. */
  14956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14957. //ReserveConnectorZeroSupported
  14958. /*
  14959. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14962. */
  14963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14964. //* Smart Charging Profile */
  14965. //ChargeProfileMaxStackLevel
  14966. /*
  14967. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14969. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14970. */
  14971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14972. // ChargingScheduleAllowedChargingRateUnit
  14973. /*
  14974. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14977. */
  14978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14979. // ChargingScheduleMaxPeriods
  14980. /*
  14981. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14984. */
  14985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14986. // ConnectorSwitch3to1PhaseSupported
  14987. /*
  14988. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14989. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14991. */
  14992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14993. // MaxChargingProfilesInstalled
  14994. /*
  14995. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14997. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14998. */
  14999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15000. fclose(outfile);
  15001. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15002. }
  15003. void getKeyValue(char *keyReq)
  15004. {
  15005. int isEmpty = FALSE;
  15006. int isKnowKey = FALSE;
  15007. DEBUG_INFO("keyReq = %s\n", keyReq);
  15008. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15009. isEmpty = TRUE;
  15010. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15011. {
  15012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15014. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15015. {
  15016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15017. }
  15018. else
  15019. {
  15020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15021. }
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15023. isKnowKey = TRUE;
  15024. }
  15025. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15026. {
  15027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15029. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15030. {
  15031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15032. }
  15033. else
  15034. {
  15035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15036. }
  15037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15038. isKnowKey = TRUE;
  15039. }
  15040. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15041. {
  15042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15044. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15045. {
  15046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15047. }
  15048. else
  15049. {
  15050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15051. }
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15053. isKnowKey = TRUE;
  15054. }
  15055. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15056. {
  15057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15059. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15060. {
  15061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15062. }
  15063. else
  15064. {
  15065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15066. }
  15067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15068. isKnowKey = TRUE;
  15069. }
  15070. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15071. {
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15074. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15075. {
  15076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15077. }
  15078. else
  15079. {
  15080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15081. }
  15082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15083. isKnowKey = TRUE;
  15084. }
  15085. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15086. {
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15089. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15090. {
  15091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15092. }
  15093. else
  15094. {
  15095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15096. }
  15097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15098. isKnowKey = TRUE;
  15099. }
  15100. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15101. {
  15102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15104. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15105. {
  15106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15107. }
  15108. else
  15109. {
  15110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15111. }
  15112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15113. isKnowKey = TRUE;
  15114. }
  15115. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15116. {
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15119. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15120. {
  15121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15122. }
  15123. else
  15124. {
  15125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15126. }
  15127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15128. isKnowKey = TRUE;
  15129. }
  15130. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15131. {
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15134. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15135. {
  15136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15137. }
  15138. else
  15139. {
  15140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15141. }
  15142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15143. isKnowKey = TRUE;
  15144. }
  15145. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15146. {
  15147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15149. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15150. {
  15151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15152. }
  15153. else
  15154. {
  15155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15156. }
  15157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15158. isKnowKey = TRUE;
  15159. }
  15160. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15161. {
  15162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15164. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15165. {
  15166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15167. }
  15168. else
  15169. {
  15170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15171. }
  15172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15173. isKnowKey = TRUE;
  15174. }
  15175. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15176. {
  15177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15179. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15180. {
  15181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15182. }
  15183. else
  15184. {
  15185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15186. }
  15187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15188. isKnowKey = TRUE;
  15189. }
  15190. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15191. {
  15192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15194. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15195. {
  15196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15197. }
  15198. else
  15199. {
  15200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15201. }
  15202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15203. isKnowKey = TRUE;
  15204. }
  15205. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15206. {
  15207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15209. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15210. {
  15211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15212. }
  15213. else
  15214. {
  15215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15216. }
  15217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15218. isKnowKey = TRUE;
  15219. }
  15220. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15221. {
  15222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15224. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15225. {
  15226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15227. }
  15228. else
  15229. {
  15230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15231. }
  15232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15233. isKnowKey = TRUE;
  15234. }
  15235. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15236. {
  15237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15239. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15240. {
  15241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15242. }
  15243. else
  15244. {
  15245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15246. }
  15247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15248. isKnowKey = TRUE;
  15249. }
  15250. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15251. {
  15252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15254. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15255. {
  15256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15257. }
  15258. else
  15259. {
  15260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15261. }
  15262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15263. isKnowKey = TRUE;
  15264. }
  15265. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15266. {
  15267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15269. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15270. {
  15271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15272. }
  15273. else
  15274. {
  15275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15276. }
  15277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15278. isKnowKey = TRUE;
  15279. }
  15280. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15281. {
  15282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15284. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15285. {
  15286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15287. }
  15288. else
  15289. {
  15290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15291. }
  15292. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15294. isKnowKey = TRUE;
  15295. }
  15296. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15297. {
  15298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15300. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15301. {
  15302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15303. }
  15304. else
  15305. {
  15306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15307. }
  15308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15309. isKnowKey = TRUE;
  15310. }
  15311. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15312. {
  15313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15315. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15316. {
  15317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15318. }
  15319. else
  15320. {
  15321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15322. }
  15323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15324. isKnowKey = TRUE;
  15325. }
  15326. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15327. {
  15328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15330. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15331. {
  15332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15333. }
  15334. else
  15335. {
  15336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15337. }
  15338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15339. isKnowKey = TRUE;
  15340. }
  15341. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15342. {
  15343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15345. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15346. {
  15347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15348. }
  15349. else
  15350. {
  15351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15352. }
  15353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15354. isKnowKey = TRUE;
  15355. }
  15356. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15357. {
  15358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15360. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15361. {
  15362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15363. }
  15364. else
  15365. {
  15366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15367. }
  15368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15369. isKnowKey = TRUE;
  15370. }
  15371. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15372. {
  15373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15375. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15376. {
  15377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15378. }
  15379. else
  15380. {
  15381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15382. }
  15383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15384. isKnowKey = TRUE;
  15385. }
  15386. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15387. {
  15388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15390. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15391. {
  15392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15393. }
  15394. else
  15395. {
  15396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15397. }
  15398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15399. isKnowKey = TRUE;
  15400. }
  15401. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15402. {
  15403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15405. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15406. {
  15407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15408. }
  15409. else
  15410. {
  15411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15412. }
  15413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15414. isKnowKey = TRUE;
  15415. }
  15416. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15417. {
  15418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15420. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15421. {
  15422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15423. }
  15424. else
  15425. {
  15426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15427. }
  15428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15429. isKnowKey = TRUE;
  15430. }
  15431. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15432. {
  15433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15435. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15436. {
  15437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15438. }
  15439. else
  15440. {
  15441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15442. }
  15443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15444. isKnowKey = TRUE;
  15445. }
  15446. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15447. {
  15448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15450. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15451. {
  15452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15453. }
  15454. else
  15455. {
  15456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15457. }
  15458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15459. isKnowKey = TRUE;
  15460. }
  15461. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15462. {
  15463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15465. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15466. {
  15467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15468. }
  15469. else
  15470. {
  15471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15472. }
  15473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15474. isKnowKey = TRUE;
  15475. }
  15476. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15477. {
  15478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15480. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15481. {
  15482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15483. }
  15484. else
  15485. {
  15486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15487. }
  15488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15489. isKnowKey = TRUE;
  15490. }
  15491. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15492. {
  15493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15495. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15496. {
  15497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15498. }
  15499. else
  15500. {
  15501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15502. }
  15503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15504. isKnowKey = TRUE;
  15505. }
  15506. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15507. {
  15508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15510. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15511. {
  15512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15513. }
  15514. else
  15515. {
  15516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15517. }
  15518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15519. isKnowKey = TRUE;
  15520. }
  15521. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15522. {
  15523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15525. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15526. {
  15527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15528. }
  15529. else
  15530. {
  15531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15532. }
  15533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15534. isKnowKey = TRUE;
  15535. }
  15536. /*
  15537. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15538. {
  15539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15541. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15542. {
  15543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15544. }
  15545. else
  15546. {
  15547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15548. }
  15549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15550. isKnowKey = TRUE;
  15551. }*/
  15552. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15553. {
  15554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15557. {
  15558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15559. }
  15560. else
  15561. {
  15562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15563. }
  15564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15565. isKnowKey = TRUE;
  15566. }
  15567. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15568. {
  15569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15571. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15572. {
  15573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15574. }
  15575. else
  15576. {
  15577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15578. }
  15579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15580. isKnowKey = TRUE;
  15581. }
  15582. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15583. {
  15584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15586. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15587. {
  15588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15589. }
  15590. else
  15591. {
  15592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15593. }
  15594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15595. isKnowKey = TRUE;
  15596. }
  15597. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15598. {
  15599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15601. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15602. {
  15603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15604. }
  15605. else
  15606. {
  15607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15608. }
  15609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15610. isKnowKey = TRUE;
  15611. }
  15612. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15613. {
  15614. struct sysinfo s_info;
  15615. int error = sysinfo(&s_info);
  15616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15618. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15619. {
  15620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15621. }
  15622. else
  15623. {
  15624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15625. }
  15626. if(error != 0)
  15627. {
  15628. DEBUG_WARN("System uptime get error: %d\n", error);
  15629. }
  15630. else
  15631. {
  15632. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15633. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15634. }
  15635. isKnowKey = TRUE;
  15636. }
  15637. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15638. {
  15639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15641. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15642. {
  15643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15644. }
  15645. else
  15646. {
  15647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15648. }
  15649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15650. isKnowKey = TRUE;
  15651. }
  15652. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15653. {
  15654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15656. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15657. {
  15658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15659. }
  15660. else
  15661. {
  15662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15663. }
  15664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15665. isKnowKey = TRUE;
  15666. }
  15667. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15668. {
  15669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15671. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15672. {
  15673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15674. }
  15675. else
  15676. {
  15677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15678. }
  15679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15680. isKnowKey = TRUE;
  15681. }
  15682. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15683. {
  15684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15686. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15687. {
  15688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15689. }
  15690. else
  15691. {
  15692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15693. }
  15694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15695. isKnowKey = TRUE;
  15696. }
  15697. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15698. {
  15699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15701. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15702. {
  15703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15704. }
  15705. else
  15706. {
  15707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15708. }
  15709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15710. isKnowKey = TRUE;
  15711. }
  15712. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15713. {
  15714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15716. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15717. {
  15718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15719. }
  15720. else
  15721. {
  15722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15723. }
  15724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15725. isKnowKey = TRUE;
  15726. }
  15727. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15728. {
  15729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15731. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15732. {
  15733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15734. }
  15735. else
  15736. {
  15737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15738. }
  15739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15740. isKnowKey = TRUE;
  15741. }
  15742. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15743. {
  15744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15746. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15747. {
  15748. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15749. }
  15750. else
  15751. {
  15752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15753. }
  15754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15755. isKnowKey = TRUE;
  15756. }
  15757. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15758. {
  15759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15761. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15762. {
  15763. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15764. }
  15765. else
  15766. {
  15767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15768. }
  15769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15770. isKnowKey = TRUE;
  15771. }
  15772. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15773. {
  15774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15776. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15777. {
  15778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15779. }
  15780. else
  15781. {
  15782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15783. }
  15784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15785. isKnowKey = TRUE;
  15786. }
  15787. #if 1
  15788. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15789. {
  15790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15792. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15793. {
  15794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15795. }
  15796. else
  15797. {
  15798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15799. }
  15800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15801. isKnowKey = TRUE;
  15802. }
  15803. #endif
  15804. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15805. {
  15806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15808. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15809. {
  15810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15811. }
  15812. else
  15813. {
  15814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15815. }
  15816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15817. isKnowKey = TRUE;
  15818. }
  15819. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15820. {
  15821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15823. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15824. {
  15825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15826. }
  15827. else
  15828. {
  15829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15830. }
  15831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15832. isKnowKey = TRUE;
  15833. }
  15834. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15835. {
  15836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15838. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15839. {
  15840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15841. }
  15842. else
  15843. {
  15844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15845. }
  15846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15847. isKnowKey = TRUE;
  15848. }
  15849. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15850. {
  15851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15853. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15854. {
  15855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15856. }
  15857. else
  15858. {
  15859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15860. }
  15861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15862. isKnowKey = TRUE;
  15863. }
  15864. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15865. {
  15866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15868. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15869. {
  15870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15871. }
  15872. else
  15873. {
  15874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15875. }
  15876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15877. isKnowKey = TRUE;
  15878. }
  15879. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15880. {
  15881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15883. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15884. {
  15885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15886. }
  15887. else
  15888. {
  15889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15890. }
  15891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15892. isKnowKey = TRUE;
  15893. }
  15894. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15895. {
  15896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15898. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15899. {
  15900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15901. }
  15902. else
  15903. {
  15904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15905. }
  15906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15907. isKnowKey = TRUE;
  15908. }
  15909. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15910. {
  15911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15913. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15914. {
  15915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15916. }
  15917. else
  15918. {
  15919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15920. }
  15921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15922. isKnowKey = TRUE;
  15923. }
  15924. //=========================================================
  15925. if(!isEmpty && !isKnowKey)
  15926. {
  15927. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15928. strcpy(unknownkey[UnknownKeynum], keyReq);
  15929. UnknownKeynum = UnknownKeynum + 1;
  15930. }
  15931. }
  15932. void processUnkownKey(void)
  15933. {
  15934. DEBUG_INFO("processUnkownKey...\n");
  15935. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15936. for(int index=0; index < UnknownKeynum; index++)
  15937. {
  15938. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15939. {
  15940. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15941. }
  15942. }
  15943. }
  15944. int setKeyValue(char *key, char *value)
  15945. {
  15946. int isSuccess = NotSupported;
  15947. int check_ascii=0;
  15948. char str[501]={0};
  15949. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15950. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15951. {
  15952. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15953. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15954. {
  15955. strcpy(str, (const char*)value);
  15956. for(int i = 0; str[i]; i++){
  15957. str[i] = tolower(str[i]);
  15958. }
  15959. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15960. isSuccess = ConfigurationStatus_Accepted;
  15961. }
  15962. else
  15963. {
  15964. isSuccess = ConfigurationStatus_Rejected;
  15965. }
  15966. }
  15967. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15968. {
  15969. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15970. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15971. {
  15972. strcpy(str, (const char*)value);
  15973. for(int i = 0; str[i]; i++){
  15974. str[i] = tolower(str[i]);
  15975. }
  15976. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15977. isSuccess = ConfigurationStatus_Accepted;
  15978. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15979. }
  15980. else
  15981. {
  15982. isSuccess = ConfigurationStatus_Rejected;
  15983. }
  15984. }
  15985. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15986. {
  15987. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15988. {
  15989. strcpy(str, (const char*)value);
  15990. for(int i = 0; str[i]; i++)
  15991. {
  15992. str[i] = tolower(str[i]);
  15993. }
  15994. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15995. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15996. isSuccess = ConfigurationStatus_Accepted;
  15997. }
  15998. else
  15999. {
  16000. isSuccess = ConfigurationStatus_Rejected;
  16001. }
  16002. }
  16003. if(strcmp(key, "BlinkRepeat") == 0)
  16004. {
  16005. //Charger.BlinkRepeat = Integer.parseInt(value);
  16006. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16007. {
  16008. check_ascii = value[0];
  16009. if( (check_ascii < 48) || (check_ascii > 57) )
  16010. {
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. else
  16014. {
  16015. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16016. isSuccess = ConfigurationStatus_Accepted;
  16017. }
  16018. }
  16019. else
  16020. {
  16021. isSuccess = ConfigurationStatus_Rejected;
  16022. }
  16023. }
  16024. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16025. {
  16026. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16027. {
  16028. check_ascii = value[0];
  16029. if( (check_ascii < 48) || (check_ascii > 57) )
  16030. {
  16031. isSuccess = ConfigurationStatus_Rejected;
  16032. }
  16033. else
  16034. {
  16035. if((atoi(value) == 0) || (atoi(value) >= 5))
  16036. {
  16037. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16038. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16039. isSuccess = ConfigurationStatus_Accepted;
  16040. }
  16041. else
  16042. isSuccess = ConfigurationStatus_Rejected;
  16043. }
  16044. }
  16045. else
  16046. {
  16047. isSuccess = ConfigurationStatus_Rejected;
  16048. }
  16049. }
  16050. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16051. {
  16052. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16053. {
  16054. check_ascii = value[0];
  16055. if( (check_ascii < 48) || (check_ascii > 57) )
  16056. {
  16057. isSuccess = ConfigurationStatus_Rejected;
  16058. }
  16059. else
  16060. {
  16061. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16062. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16063. isSuccess = ConfigurationStatus_Accepted;
  16064. }
  16065. }
  16066. else
  16067. {
  16068. isSuccess = ConfigurationStatus_Rejected;
  16069. }
  16070. }
  16071. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16072. {
  16073. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16074. {
  16075. check_ascii = value[0];
  16076. if( (check_ascii < 48) || (check_ascii > 57) )
  16077. {
  16078. isSuccess = ConfigurationStatus_Rejected;
  16079. }
  16080. else
  16081. {
  16082. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16083. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16084. isSuccess = ConfigurationStatus_Accepted;
  16085. }
  16086. }
  16087. else
  16088. {
  16089. isSuccess = ConfigurationStatus_Rejected;
  16090. }
  16091. }
  16092. if(strcmp(key, "HeartbeatInterval") == 0)
  16093. {
  16094. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16095. {
  16096. check_ascii = value[0];
  16097. if( (check_ascii < 48) || (check_ascii > 57) )
  16098. {
  16099. isSuccess = ConfigurationStatus_Rejected;
  16100. }
  16101. else
  16102. {
  16103. if((atoi(value) == 0) || (atoi(value) >= 10))
  16104. {
  16105. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16107. HeartBeatWaitTime = atoi(value);
  16108. isSuccess = ConfigurationStatus_Accepted;
  16109. }
  16110. else
  16111. {
  16112. isSuccess = ConfigurationStatus_Rejected;
  16113. }
  16114. }
  16115. }
  16116. else
  16117. {
  16118. isSuccess = ConfigurationStatus_Rejected;
  16119. }
  16120. }
  16121. if(strcmp(key, "LightIntensity") == 0)
  16122. {
  16123. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16124. {
  16125. check_ascii = value[0];
  16126. if( (check_ascii < 48) || (check_ascii > 57) )
  16127. {
  16128. isSuccess = ConfigurationStatus_Rejected;
  16129. }
  16130. else
  16131. {
  16132. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16133. isSuccess = ConfigurationStatus_Accepted;
  16134. }
  16135. }
  16136. else
  16137. {
  16138. isSuccess = ConfigurationStatus_Rejected;
  16139. }
  16140. }
  16141. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16142. {
  16143. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16144. {
  16145. strcpy(str, (const char*)value);
  16146. for(int i = 0; str[i]; i++)
  16147. {
  16148. str[i] = tolower(str[i]);
  16149. }
  16150. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16151. isSuccess = ConfigurationStatus_Accepted;
  16152. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16153. }
  16154. else
  16155. {
  16156. isSuccess = ConfigurationStatus_Rejected;
  16157. }
  16158. }
  16159. if(strcmp(key, "LocalPreAuthorize") == 0)
  16160. {
  16161. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16162. {
  16163. strcpy(str, (const char*)value);
  16164. for(int i = 0; str[i]; i++)
  16165. {
  16166. str[i] = tolower(str[i]);
  16167. }
  16168. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16169. isSuccess = ConfigurationStatus_Accepted;
  16170. }
  16171. else
  16172. {
  16173. isSuccess = ConfigurationStatus_Rejected;
  16174. }
  16175. }
  16176. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16177. {
  16178. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16179. {
  16180. check_ascii = value[0];
  16181. if( (check_ascii < 48) || (check_ascii > 57) )
  16182. {
  16183. isSuccess = ConfigurationStatus_Rejected;
  16184. }
  16185. else
  16186. {
  16187. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16188. isSuccess = ConfigurationStatus_Accepted;
  16189. }
  16190. }
  16191. else
  16192. {
  16193. isSuccess = ConfigurationStatus_Rejected;
  16194. }
  16195. }
  16196. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16197. {
  16198. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16199. {
  16200. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16201. isSuccess = ConfigurationStatus_Accepted;
  16202. }
  16203. else
  16204. {
  16205. isSuccess = ConfigurationStatus_Rejected;
  16206. }
  16207. }
  16208. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16209. {
  16210. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16211. {
  16212. check_ascii = value[0];
  16213. if( (check_ascii < 48) || (check_ascii > 57) )
  16214. {
  16215. isSuccess = ConfigurationStatus_Rejected;
  16216. }
  16217. else
  16218. {
  16219. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16220. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16221. isSuccess = ConfigurationStatus_Accepted;
  16222. }
  16223. }
  16224. else
  16225. {
  16226. isSuccess = ConfigurationStatus_Rejected;
  16227. }
  16228. }
  16229. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16230. {
  16231. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16232. {
  16233. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16234. isSuccess = ConfigurationStatus_Accepted;
  16235. }
  16236. else
  16237. {
  16238. isSuccess = ConfigurationStatus_Rejected;
  16239. }
  16240. }
  16241. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16242. {
  16243. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16244. {
  16245. check_ascii = value[0];
  16246. if( (check_ascii < 48) || (check_ascii > 57) )
  16247. {
  16248. isSuccess = ConfigurationStatus_Rejected;
  16249. }
  16250. else
  16251. {
  16252. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16253. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16254. isSuccess = ConfigurationStatus_Accepted;
  16255. }
  16256. }
  16257. else
  16258. {
  16259. isSuccess = ConfigurationStatus_Rejected;
  16260. }
  16261. }
  16262. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16263. {
  16264. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16265. {
  16266. check_ascii = value[0];
  16267. if( (check_ascii < 48) || (check_ascii > 57) )
  16268. {
  16269. isSuccess = ConfigurationStatus_Rejected;
  16270. }
  16271. else
  16272. {
  16273. if((atoi(value) == 0) || (atoi(value) >= 3))
  16274. {
  16275. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16277. isSuccess = ConfigurationStatus_Accepted;
  16278. }
  16279. else
  16280. {
  16281. isSuccess = ConfigurationStatus_Rejected;
  16282. }
  16283. }
  16284. }
  16285. else
  16286. {
  16287. isSuccess = ConfigurationStatus_Rejected;
  16288. }
  16289. }
  16290. if(strcmp(key, "MinimumStatusDuration") == 0)
  16291. {
  16292. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16293. {
  16294. check_ascii = value[0];
  16295. if( (check_ascii < 48) || (check_ascii > 57) )
  16296. {
  16297. isSuccess = ConfigurationStatus_Rejected;
  16298. }
  16299. else
  16300. {
  16301. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16302. {
  16303. isSuccess = ConfigurationStatus_Rejected;
  16304. }
  16305. else
  16306. {
  16307. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16308. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16309. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16310. isSuccess = ConfigurationStatus_Accepted;
  16311. }
  16312. }
  16313. }
  16314. else
  16315. {
  16316. isSuccess = ConfigurationStatus_Rejected;
  16317. }
  16318. }
  16319. if(strcmp(key, "NumberOfConnectors") == 0)
  16320. {
  16321. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16322. {
  16323. check_ascii = value[0];
  16324. if( (check_ascii < 48) || (check_ascii > 57) )
  16325. {
  16326. isSuccess = ConfigurationStatus_Rejected;
  16327. }
  16328. else
  16329. {
  16330. //Charger.ResetRetries = Integer.parseInt(value);
  16331. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16332. isSuccess = ConfigurationStatus_Accepted;
  16333. }
  16334. }
  16335. else
  16336. {
  16337. isSuccess = ConfigurationStatus_Rejected;
  16338. }
  16339. }
  16340. if(strcmp(key, "ResetRetries") == 0)
  16341. {
  16342. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16343. {
  16344. check_ascii = value[0];
  16345. if( (check_ascii < 48) || (check_ascii > 57) )
  16346. {
  16347. isSuccess = ConfigurationStatus_Rejected;
  16348. }
  16349. else
  16350. {
  16351. //Charger.ResetRetries = Integer.parseInt(value);
  16352. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16353. isSuccess = ConfigurationStatus_Accepted;
  16354. }
  16355. }
  16356. else
  16357. {
  16358. isSuccess = ConfigurationStatus_Rejected;
  16359. }
  16360. }
  16361. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16362. {
  16363. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16364. {
  16365. strcpy(str, (const char*)value);
  16366. for(int i = 0; str[i]; i++)
  16367. {
  16368. str[i] = tolower(str[i]);
  16369. }
  16370. if(strcmp(str, "notapplicable")== 0)
  16371. {
  16372. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16373. isSuccess = ConfigurationStatus_Accepted;
  16374. }
  16375. else if(strcmp(str, "unknown")== 0)
  16376. {
  16377. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16378. isSuccess = ConfigurationStatus_Accepted;
  16379. }
  16380. else if(strcmp(str, "rst")== 0)
  16381. {
  16382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16383. isSuccess = ConfigurationStatus_Accepted;
  16384. }
  16385. else if(strcmp(str, "rts")== 0)
  16386. {
  16387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16388. isSuccess = ConfigurationStatus_Accepted;
  16389. }
  16390. else if(strcmp(str, "srt")== 0)
  16391. {
  16392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16393. isSuccess = ConfigurationStatus_Accepted;
  16394. }
  16395. else if(strcmp(str, "str")== 0)
  16396. {
  16397. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16398. isSuccess = ConfigurationStatus_Accepted;
  16399. }
  16400. else if(strcmp(str, "trs")== 0)
  16401. {
  16402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16403. isSuccess = ConfigurationStatus_Accepted;
  16404. }
  16405. else if(strcmp(str, "tsr")== 0)
  16406. {
  16407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16408. isSuccess = ConfigurationStatus_Accepted;
  16409. }
  16410. else
  16411. {
  16412. isSuccess = ConfigurationStatus_Rejected;
  16413. }
  16414. }
  16415. else
  16416. {
  16417. isSuccess = ConfigurationStatus_Rejected;
  16418. }
  16419. }
  16420. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16421. {
  16422. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16423. {
  16424. check_ascii = value[0];
  16425. if( (check_ascii < 48) || (check_ascii > 57) )
  16426. {
  16427. isSuccess = ConfigurationStatus_Rejected;
  16428. }
  16429. else
  16430. {
  16431. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16432. isSuccess = ConfigurationStatus_Accepted;
  16433. }
  16434. }
  16435. else
  16436. {
  16437. isSuccess = ConfigurationStatus_Rejected;
  16438. }
  16439. }
  16440. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16441. {
  16442. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16443. {
  16444. strcpy(str, (const char*)value);
  16445. for(int i = 0; str[i]; i++)
  16446. {
  16447. str[i] = tolower(str[i]);
  16448. }
  16449. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16450. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16451. isSuccess = ConfigurationStatus_Accepted;
  16452. }
  16453. else
  16454. {
  16455. isSuccess = ConfigurationStatus_Rejected;
  16456. }
  16457. }
  16458. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16459. {
  16460. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16461. {
  16462. strcpy(str, (const char*)value);
  16463. for(int i = 0; str[i]; i++)
  16464. {
  16465. str[i] = tolower(str[i]);
  16466. }
  16467. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16468. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16469. isSuccess = ConfigurationStatus_Accepted;
  16470. }
  16471. else
  16472. {
  16473. isSuccess = ConfigurationStatus_Rejected;
  16474. }
  16475. }
  16476. if(strcmp(key, "StopTxnAlignedData") == 0)
  16477. {
  16478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16479. {
  16480. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16481. isSuccess = ConfigurationStatus_Accepted;
  16482. }
  16483. else
  16484. {
  16485. isSuccess = ConfigurationStatus_Rejected;
  16486. }
  16487. }
  16488. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16489. {
  16490. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16491. {
  16492. check_ascii = value[0];
  16493. if( (check_ascii < 48) || (check_ascii > 57) )
  16494. {
  16495. isSuccess = ConfigurationStatus_Rejected;
  16496. }
  16497. else
  16498. {
  16499. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16500. isSuccess = ConfigurationStatus_Accepted;
  16501. }
  16502. }
  16503. else
  16504. {
  16505. isSuccess = ConfigurationStatus_Rejected;
  16506. }
  16507. }
  16508. if(strcmp(key, "StopTxnSampledData") == 0)
  16509. {
  16510. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16511. {
  16512. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16513. isSuccess = ConfigurationStatus_Accepted;
  16514. }
  16515. else
  16516. {
  16517. isSuccess = ConfigurationStatus_Rejected;
  16518. }
  16519. }
  16520. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16521. {
  16522. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16523. {
  16524. check_ascii = value[0];
  16525. if( (check_ascii < 48) || (check_ascii > 57) )
  16526. {
  16527. isSuccess = ConfigurationStatus_Rejected;
  16528. }
  16529. else
  16530. {
  16531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16532. isSuccess = ConfigurationStatus_Accepted;
  16533. }
  16534. }
  16535. else
  16536. {
  16537. isSuccess = ConfigurationStatus_Rejected;
  16538. }
  16539. }
  16540. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16541. {
  16542. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16543. {
  16544. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16545. isSuccess = ConfigurationStatus_Accepted;
  16546. }
  16547. else
  16548. {
  16549. isSuccess = ConfigurationStatus_Rejected;
  16550. }
  16551. }
  16552. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16553. {
  16554. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16555. {
  16556. check_ascii = value[0];
  16557. if( (check_ascii < 48) || (check_ascii > 57) )
  16558. {
  16559. isSuccess = ConfigurationStatus_Rejected;
  16560. }
  16561. else
  16562. {
  16563. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16564. isSuccess = ConfigurationStatus_Accepted;
  16565. }
  16566. }
  16567. else
  16568. {
  16569. isSuccess = ConfigurationStatus_Rejected;
  16570. }
  16571. }
  16572. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16573. {
  16574. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16575. {
  16576. check_ascii = value[0];
  16577. if( (check_ascii < 48) || (check_ascii > 57) )
  16578. {
  16579. isSuccess = ConfigurationStatus_Rejected;
  16580. }
  16581. else
  16582. {
  16583. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16584. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16585. TransactionMessageAttemptsValue = atoi(value);
  16586. isSuccess = ConfigurationStatus_Accepted;
  16587. }
  16588. }
  16589. else
  16590. {
  16591. isSuccess = ConfigurationStatus_Rejected;
  16592. }
  16593. }
  16594. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16595. {
  16596. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16597. {
  16598. check_ascii = value[0];
  16599. if( (check_ascii < 48) || (check_ascii > 57) )
  16600. {
  16601. isSuccess = ConfigurationStatus_Rejected;
  16602. }
  16603. else
  16604. {
  16605. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16607. TransactionMessageRetryIntervalValue = atoi(value);
  16608. isSuccess = ConfigurationStatus_Accepted;
  16609. }
  16610. }
  16611. else
  16612. {
  16613. isSuccess = ConfigurationStatus_Rejected;
  16614. }
  16615. }
  16616. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16617. {
  16618. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16619. {
  16620. strcpy(str, (const char*)value);
  16621. for(int i = 0; str[i]; i++)
  16622. {
  16623. str[i] = tolower(str[i]);
  16624. }
  16625. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16626. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16627. isSuccess = ConfigurationStatus_Accepted;
  16628. }
  16629. else
  16630. {
  16631. isSuccess = ConfigurationStatus_Rejected;
  16632. }
  16633. }
  16634. if(strcmp(key, "WebSocketPingInterval") == 0)
  16635. {
  16636. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16637. {
  16638. check_ascii = value[0];
  16639. if( (check_ascii < 48) || (check_ascii > 57) )
  16640. {
  16641. isSuccess = ConfigurationStatus_Rejected;
  16642. }
  16643. else
  16644. {
  16645. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16646. isSuccess = ConfigurationStatus_Accepted;
  16647. if((atoi(value) == 0) || (atoi(value) >= 10))
  16648. {
  16649. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16650. isSuccess = ConfigurationStatus_Accepted;
  16651. }
  16652. else
  16653. isSuccess = ConfigurationStatus_Rejected;
  16654. }
  16655. }
  16656. else
  16657. {
  16658. isSuccess = ConfigurationStatus_Rejected;
  16659. }
  16660. }
  16661. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16662. {
  16663. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16664. {
  16665. strcpy(str, (const char*)value);
  16666. for(int i = 0; str[i]; i++)
  16667. {
  16668. str[i] = tolower(str[i]);
  16669. }
  16670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16671. isSuccess = ConfigurationStatus_Accepted;
  16672. }
  16673. else
  16674. {
  16675. isSuccess = ConfigurationStatus_Rejected;
  16676. }
  16677. }
  16678. if(strcmp(key, "AuthorizationKey") == 0)
  16679. {
  16680. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16681. {
  16682. strcpy(str, (const char*)value);
  16683. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16684. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16685. isSuccess = ConfigurationStatus_Accepted;
  16686. }
  16687. else
  16688. {
  16689. isSuccess = ConfigurationStatus_Rejected;
  16690. }
  16691. }
  16692. if(strcmp(key, "SecurityProfile") == 0)
  16693. {
  16694. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16695. {
  16696. check_ascii = value[0];
  16697. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16698. {
  16699. isSuccess = ConfigurationStatus_Rejected;
  16700. }
  16701. else if(check_ascii == 0x33)
  16702. {
  16703. isSuccess = NotSupported;
  16704. }
  16705. else
  16706. {
  16707. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16708. {
  16709. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16710. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16711. isSuccess = ConfigurationStatus_Accepted;
  16712. }
  16713. else
  16714. isSuccess = ConfigurationStatus_Rejected;
  16715. }
  16716. }
  16717. else
  16718. {
  16719. isSuccess = ConfigurationStatus_Rejected;
  16720. }
  16721. }
  16722. if(strcmp(key, "DefaultPrice") == 0)
  16723. {
  16724. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16725. {
  16726. strcpy(str, (const char*)value);
  16727. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16728. isSuccess = ConfigurationStatus_Accepted;
  16729. }
  16730. else
  16731. {
  16732. isSuccess = ConfigurationStatus_Rejected;
  16733. }
  16734. }
  16735. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16736. {
  16737. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16738. {
  16739. strcpy(str, (const char*)value);
  16740. for(int i = 0; str[i]; i++)
  16741. {
  16742. str[i] = tolower(str[i]);
  16743. }
  16744. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16745. isSuccess = ConfigurationStatus_Accepted;
  16746. }
  16747. else
  16748. {
  16749. isSuccess = ConfigurationStatus_Rejected;
  16750. }
  16751. }
  16752. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16753. {
  16754. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16755. {
  16756. strcpy(str, (const char*)value);
  16757. for(int i = 0; str[i]; i++)
  16758. {
  16759. str[i] = tolower(str[i]);
  16760. }
  16761. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16762. isSuccess = ConfigurationStatus_Accepted;
  16763. }
  16764. else
  16765. {
  16766. isSuccess = ConfigurationStatus_Rejected;
  16767. }
  16768. }
  16769. if(strcmp(key, "SystemUptimeSec") == 0)
  16770. {
  16771. isSuccess = NotSupported;
  16772. }
  16773. if(strcmp(key, "FreeVend") == 0)
  16774. {
  16775. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16776. {
  16777. strcpy(str, (const char*)value);
  16778. for(int i = 0; str[i]; i++)
  16779. {
  16780. str[i] = tolower(str[i]);
  16781. }
  16782. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16784. isSuccess = ConfigurationStatus_Accepted;
  16785. }
  16786. else
  16787. {
  16788. isSuccess = ConfigurationStatus_Rejected;
  16789. }
  16790. }
  16791. if(strcmp(key, "FreeVendIdtag") == 0)
  16792. {
  16793. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16794. {
  16795. strcpy(str, (const char*)value);
  16796. if(strlen(str) <= 20)
  16797. {
  16798. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16799. isSuccess = ConfigurationStatus_Accepted;
  16800. }
  16801. else
  16802. {
  16803. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16804. isSuccess = ConfigurationStatus_Rejected;
  16805. }
  16806. }
  16807. else
  16808. {
  16809. isSuccess = ConfigurationStatus_Rejected;
  16810. }
  16811. }
  16812. if(strcmp(key, "OcppServer") == 0)
  16813. {
  16814. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16815. {
  16816. strcpy(str, (const char*)value);
  16817. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16818. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16819. isSuccess = ConfigurationStatus_Accepted;
  16820. }
  16821. else
  16822. {
  16823. isSuccess = ConfigurationStatus_Rejected;
  16824. }
  16825. }
  16826. if(strcmp(key, "MaintainServer") == 0)
  16827. {
  16828. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16829. {
  16830. strcpy(str, (const char*)value);
  16831. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16832. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16833. isSuccess = ConfigurationStatus_Accepted;
  16834. }
  16835. else
  16836. {
  16837. isSuccess = ConfigurationStatus_Rejected;
  16838. }
  16839. }
  16840. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16841. {
  16842. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16843. {
  16844. strcpy(str, (const char*)value);
  16845. for(int i = 0; str[i]; i++)
  16846. {
  16847. str[i] = tolower(str[i]);
  16848. }
  16849. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16850. isSuccess = ConfigurationStatus_Accepted;
  16851. }
  16852. else
  16853. {
  16854. isSuccess = ConfigurationStatus_Rejected;
  16855. }
  16856. }
  16857. if(strcmp(key, "StatusNotificationInterval") == 0)
  16858. {
  16859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16860. {
  16861. check_ascii = value[0];
  16862. if( (check_ascii < 48) || (check_ascii > 57) )
  16863. {
  16864. isSuccess = ConfigurationStatus_Rejected;
  16865. }
  16866. else
  16867. {
  16868. if((atoi(value) == 0) || (atoi(value) >= 10))
  16869. {
  16870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16871. isSuccess = ConfigurationStatus_Accepted;
  16872. }
  16873. else
  16874. isSuccess = ConfigurationStatus_Rejected;
  16875. }
  16876. }
  16877. else
  16878. {
  16879. isSuccess = ConfigurationStatus_Rejected;
  16880. }
  16881. }
  16882. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  16883. {
  16884. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16885. {
  16886. check_ascii = value[0];
  16887. if( (check_ascii < 48) || (check_ascii > 57) )
  16888. {
  16889. isSuccess = ConfigurationStatus_Rejected;
  16890. }
  16891. else
  16892. {
  16893. if(atoi(value) >= 0)
  16894. {
  16895. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  16896. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  16897. isSuccess = ConfigurationStatus_Accepted;
  16898. }
  16899. else
  16900. isSuccess = ConfigurationStatus_Rejected;
  16901. }
  16902. }
  16903. else
  16904. {
  16905. isSuccess = ConfigurationStatus_Rejected;
  16906. }
  16907. }
  16908. if(strcmp(key, "PowerSharingServerIP") == 0)
  16909. {
  16910. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16911. {
  16912. strcpy(str, (const char*)value);
  16913. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  16914. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  16915. isSuccess = ConfigurationStatus_Accepted;
  16916. }
  16917. else
  16918. {
  16919. isSuccess = ConfigurationStatus_Rejected;
  16920. }
  16921. }
  16922. if(strcmp(key, "EVCCID_PREFIX") == 0)
  16923. {
  16924. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16925. {
  16926. strcpy(str, (const char*)value);
  16927. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  16928. isSuccess = ConfigurationStatus_Accepted;
  16929. }
  16930. else
  16931. {
  16932. isSuccess = ConfigurationStatus_Rejected;
  16933. }
  16934. }
  16935. #if 0
  16936. //For OCPP Test Case
  16937. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16938. {
  16939. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16940. {
  16941. strcpy(str, (const char*)value);
  16942. for(int i = 0; str[i]; i++)
  16943. {
  16944. str[i] = tolower(str[i]);
  16945. }
  16946. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16947. isSuccess = ConfigurationStatus_Accepted;
  16948. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16949. }
  16950. else
  16951. {
  16952. isSuccess = ConfigurationStatus_Rejected;
  16953. }
  16954. }
  16955. #endif
  16956. #if 1
  16957. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16958. {
  16959. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16960. {
  16961. strcpy(str, (const char*)value);
  16962. for(int i = 0; str[i]; i++)
  16963. {
  16964. str[i] = tolower(str[i]);
  16965. }
  16966. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16967. isSuccess = ConfigurationStatus_Accepted;
  16968. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16969. }
  16970. else
  16971. {
  16972. isSuccess = ConfigurationStatus_Rejected;
  16973. }
  16974. }
  16975. #endif
  16976. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16977. {
  16978. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16979. {
  16980. check_ascii = value[0];
  16981. if( (check_ascii < 48) || (check_ascii > 57) )
  16982. {
  16983. isSuccess = ConfigurationStatus_Rejected;
  16984. }
  16985. else
  16986. {
  16987. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16988. isSuccess = ConfigurationStatus_Accepted;
  16989. }
  16990. }
  16991. else
  16992. {
  16993. isSuccess = ConfigurationStatus_Rejected;
  16994. }
  16995. }
  16996. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16997. {
  16998. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16999. {
  17000. check_ascii = value[0];
  17001. if( (check_ascii < 48) || (check_ascii > 57) )
  17002. {
  17003. isSuccess = ConfigurationStatus_Rejected;
  17004. }
  17005. else
  17006. {
  17007. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17008. isSuccess = ConfigurationStatus_Accepted;
  17009. }
  17010. }
  17011. else
  17012. {
  17013. isSuccess = ConfigurationStatus_Rejected;
  17014. }
  17015. }
  17016. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17017. {
  17018. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17019. {
  17020. strcpy(str, (const char*)value);
  17021. for(int i = 0; str[i]; i++)
  17022. {
  17023. str[i] = tolower(str[i]);
  17024. }
  17025. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17026. isSuccess = ConfigurationStatus_Accepted;
  17027. }
  17028. else
  17029. {
  17030. isSuccess = ConfigurationStatus_Rejected;
  17031. }
  17032. }
  17033. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17034. {
  17035. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17036. {
  17037. check_ascii = value[0];
  17038. if( (check_ascii < 48) || (check_ascii > 57) )
  17039. {
  17040. isSuccess = ConfigurationStatus_Rejected;
  17041. }
  17042. else
  17043. {
  17044. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17045. isSuccess = ConfigurationStatus_Accepted;
  17046. }
  17047. }
  17048. else
  17049. {
  17050. isSuccess = ConfigurationStatus_Rejected;
  17051. }
  17052. }
  17053. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17054. {
  17055. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17056. {
  17057. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17058. isSuccess = ConfigurationStatus_Accepted;
  17059. }
  17060. else
  17061. {
  17062. isSuccess = ConfigurationStatus_Rejected;
  17063. }
  17064. }
  17065. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17066. {
  17067. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17068. {
  17069. check_ascii = value[0];
  17070. if( (check_ascii < 48) || (check_ascii > 57) )
  17071. {
  17072. isSuccess = ConfigurationStatus_Rejected;
  17073. }
  17074. else
  17075. {
  17076. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17077. isSuccess = ConfigurationStatus_Accepted;
  17078. }
  17079. }
  17080. else
  17081. {
  17082. isSuccess = ConfigurationStatus_Rejected;
  17083. }
  17084. }
  17085. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17086. {
  17087. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17088. {
  17089. strcpy(str, (const char*)value);
  17090. for(int i = 0; str[i]; i++)
  17091. {
  17092. str[i] = tolower(str[i]);
  17093. }
  17094. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17095. isSuccess = ConfigurationStatus_Accepted;
  17096. }
  17097. else
  17098. {
  17099. isSuccess = ConfigurationStatus_Rejected;
  17100. }
  17101. }
  17102. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17103. {
  17104. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17105. {
  17106. check_ascii = value[0];
  17107. if( (check_ascii < 48) || (check_ascii > 57) )
  17108. {
  17109. isSuccess = ConfigurationStatus_Rejected;
  17110. }
  17111. else
  17112. {
  17113. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17114. isSuccess = ConfigurationStatus_Accepted;
  17115. }
  17116. }
  17117. else
  17118. {
  17119. isSuccess = ConfigurationStatus_Rejected;
  17120. }
  17121. }
  17122. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17123. return isSuccess;
  17124. }
  17125. int TransactionMessageAttemptsGet(void)
  17126. {
  17127. return TransactionMessageAttemptsValue;
  17128. }
  17129. int FirstHeartBeatResponse(void)
  17130. {
  17131. return FirstHeartBeat;
  17132. }
  17133. int TransactionMessageRetryIntervalGet(void)
  17134. {
  17135. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17136. }
  17137. int ReadHttpStatus(int sock)
  17138. {
  17139. //char c;
  17140. char buff[1024]="",*ptr=buff+1;
  17141. int bytes_received, status;
  17142. DEBUG_INFO("Begin Response ..\n");
  17143. while((bytes_received = recv(sock, ptr, 1, 0))){
  17144. if(bytes_received==-1){
  17145. perror("ReadHttpStatus");
  17146. exit(1);
  17147. }
  17148. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17149. ptr++;
  17150. }
  17151. *ptr=0;
  17152. ptr=buff+1;
  17153. sscanf(ptr,"%*s %d ", &status);
  17154. DEBUG_INFO("%s\n",ptr);
  17155. DEBUG_INFO("status=%d\n",status);
  17156. DEBUG_INFO("End Response ..\n");
  17157. return (bytes_received>0)?status:0;
  17158. }
  17159. //the only filed that it parsed is 'Content-Length'
  17160. int ParseHeader(int sock)
  17161. {
  17162. //char c;
  17163. char buff[1024]="",*ptr=buff+4;
  17164. int bytes_received;
  17165. DEBUG_INFO("Begin HEADER ..\n");
  17166. while((bytes_received = recv(sock, ptr, 1, 0))){
  17167. if(bytes_received==-1){
  17168. perror("Parse Header");
  17169. exit(1);
  17170. }
  17171. if(
  17172. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17173. (ptr[-1]=='\r') && (*ptr=='\n' )
  17174. ) break;
  17175. ptr++;
  17176. }
  17177. *ptr=0;
  17178. ptr=buff+4;
  17179. //printf("%s",ptr);
  17180. if(bytes_received){
  17181. ptr=strstr(ptr,"Content-Length:");
  17182. if(ptr){
  17183. sscanf(ptr,"%*s %d",&bytes_received);
  17184. }else
  17185. bytes_received=-1; //unknown size
  17186. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17187. }
  17188. DEBUG_INFO("End HEADER ..\n");
  17189. return bytes_received ;
  17190. }
  17191. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17192. {
  17193. int result = TRUE;
  17194. char rmFileCmd[100]={0};
  17195. char FilePath[100]={0};
  17196. char ftpbuf[200];
  17197. int systemresult;
  17198. sprintf(FilePath,"/mnt/%s",filename);
  17199. system("ping 8.8.8.8 &");
  17200. if((access(FilePath,F_OK))!=-1)
  17201. {
  17202. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17203. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17204. system(rmFileCmd);
  17205. }
  17206. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17207. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17208. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17209. systemresult = system(ftpbuf);
  17210. if(systemresult != 0)
  17211. {
  17212. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17213. result = FALSE;
  17214. }
  17215. system("pkill ping");
  17216. return result;
  17217. }
  17218. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17219. {
  17220. int result = TRUE;
  17221. char rmFileCmd[100]={0};
  17222. char FilePath[100]={0};
  17223. char ftpbuf[200];
  17224. int systemresult;
  17225. sprintf(FilePath,"/mnt/%s",filename);
  17226. system("ping 8.8.8.8 &");
  17227. if((access(FilePath,F_OK))!=-1)
  17228. {
  17229. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17230. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17231. system(rmFileCmd);
  17232. }
  17233. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17234. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17235. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17236. systemresult = system(ftpbuf);
  17237. if(systemresult != 0)
  17238. {
  17239. DEBUG_WARN("scp error!\n");
  17240. result = FALSE;
  17241. }
  17242. system("pkill ping");
  17243. return result;
  17244. }
  17245. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17246. {
  17247. int result = TRUE;
  17248. char rmFileCmd[100]={0};
  17249. char FilePath[100]={0};
  17250. char ftpbuf[200];
  17251. int systemresult;
  17252. sprintf(FilePath,"/mnt/%s",filename);
  17253. system("ping 8.8.8.8 &");
  17254. if((access(FilePath,F_OK))!=-1)
  17255. {
  17256. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17257. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17258. system(rmFileCmd);
  17259. }
  17260. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17261. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17262. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17263. systemresult = system(ftpbuf);
  17264. if(systemresult != 0)
  17265. {
  17266. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17267. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17268. systemresult = system(ftpbuf);
  17269. if(systemresult != 0)
  17270. {
  17271. DEBUG_WARN("FTP download fail!\n");
  17272. result = FALSE;
  17273. }
  17274. }
  17275. system("pkill ping");
  17276. return result;
  17277. }
  17278. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17279. {
  17280. char rmFileCmd[100]={0};
  17281. char FilePath[100]={0};
  17282. char buf[512];
  17283. int systemresult = 0;
  17284. //DEBUG_INFO("filename=%s\n",filename);
  17285. //DEBUG_INFO("url=%s\n",url);
  17286. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17287. if((access(FilePath,F_OK))!=-1)
  17288. {
  17289. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17290. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17291. system(rmFileCmd);
  17292. }
  17293. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17294. if(fp == NULL)
  17295. {
  17296. DEBUG_INFO("log is NULL\n");
  17297. return FALSE;
  17298. }
  17299. else
  17300. {
  17301. fprintf(fp, "%s\n", url);
  17302. fprintf(fp, "%s\n", filename);
  17303. fclose(fp);
  17304. }
  17305. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17306. if(phpFP == NULL)
  17307. {
  17308. DEBUG_INFO("PHP upload fail.\n");
  17309. return FALSE;
  17310. }
  17311. else
  17312. {
  17313. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17314. {
  17315. if(strstr(buf, "result") != NULL)
  17316. {
  17317. sscanf(buf, "result: %d", &systemresult);
  17318. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17319. }
  17320. }
  17321. pclose(phpFP);
  17322. }
  17323. if(systemresult != 1)
  17324. {
  17325. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17326. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17327. if(phpFP == NULL)
  17328. {
  17329. DEBUG_WARN("PHP PUT upload fail.\n");
  17330. return FALSE;
  17331. }
  17332. else
  17333. {
  17334. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17335. {
  17336. if(strstr(buf, "result") != NULL)
  17337. {
  17338. sscanf(buf, "result: %d", &systemresult);
  17339. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17340. }
  17341. }
  17342. pclose(phpFP);
  17343. }
  17344. }
  17345. if(systemresult != 1)
  17346. {
  17347. DEBUG_WARN("PHP PUT upload fail.\n");
  17348. return FALSE;
  17349. }
  17350. return TRUE;
  17351. }
  17352. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17353. {
  17354. int result = FALSE;
  17355. char ftpbuf[200];
  17356. int systemresult;
  17357. /*
  17358. // Domaind name transfer to IP address
  17359. struct hostent* server;
  17360. char *IPbuffer;
  17361. server = gethostbyname(location);
  17362. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17363. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17364. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17365. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17366. systemresult = system(ftpbuf);
  17367. if(systemresult != 0)
  17368. {
  17369. DEBUG_INFO("ftpput error!\n");
  17370. }
  17371. else
  17372. {
  17373. result = TRUE;
  17374. DEBUG_INFO("ftpput OK!\n");
  17375. }
  17376. return result;
  17377. }
  17378. int GetOcppServerURL()
  17379. {
  17380. int result = FALSE;
  17381. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17382. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17383. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17384. struct yuarel url;
  17385. char urlStr[512];
  17386. // OCPPPH only
  17387. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17388. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17389. {
  17390. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17391. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17392. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17393. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17394. if(yuarel_parse(&url, urlStr) != -1)
  17395. {
  17396. sprintf(OcppProtocol, "%s", url.scheme);
  17397. sprintf(OcppHost, "%s", url.host);
  17398. if(url.path == NULL)
  17399. OcppTempPath[0] = '\0';
  17400. else
  17401. sprintf(OcppTempPath, "%s", url.path);
  17402. if(url.port == 0)
  17403. {
  17404. if(strcmp(OcppProtocol, "wss") == 0)
  17405. OcppPort = 443;
  17406. else
  17407. OcppPort = 80;
  17408. }
  17409. else
  17410. OcppPort = url.port;
  17411. result = TRUE;
  17412. }
  17413. }
  17414. else
  17415. {
  17416. strcpy(OcppHost,"");
  17417. }
  17418. return result;
  17419. }
  17420. int GetOcppPath()
  17421. {
  17422. int result = FALSE;
  17423. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17424. {
  17425. if(OcppTempPath == NULL)
  17426. {
  17427. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17428. }
  17429. else
  17430. {
  17431. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17432. }
  17433. result = TRUE;
  17434. goto End;
  17435. }
  17436. else
  17437. {
  17438. strcpy(OcppPath,"");
  17439. }
  17440. End:
  17441. return result;
  17442. }
  17443. int GetOcppPort()
  17444. {
  17445. return OcppPort;
  17446. }
  17447. int GetOcppConnStatus(void)
  17448. {
  17449. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17450. }
  17451. void SetOcppConnStatus(uint8_t status)
  17452. {
  17453. ShmOCPP16DataPH->OcppConnStatus = status;
  17454. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17455. }
  17456. int GetHeartBeatWithNOResponse(void)
  17457. {
  17458. return HeartBeatWithNOResponse;
  17459. }
  17460. void SetHeartBeatWithNOResponse(void)
  17461. {
  17462. HeartBeatWithNOResponse = 0;
  17463. }
  17464. void GetStartTransactionIdTag(int gun_index)
  17465. {
  17466. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17467. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17468. }
  17469. int GetStartTransactionId(int gun_index)
  17470. {
  17471. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17472. }
  17473. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17474. {
  17475. char ch;
  17476. FILE *fptr1;
  17477. int temptransactionId;
  17478. char str[100]={0};
  17479. temptransactionId = 0;
  17480. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17481. {
  17482. DEBUG_INFO("IdTag is empty.\n");
  17483. return temptransactionId;
  17484. }
  17485. /*------ Read the file ----------------*/
  17486. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17487. if (!fptr1)
  17488. {
  17489. DEBUG_INFO("QueueTransactionId file open error.\n");
  17490. //printf(" File not found or unable to open the input file!!\n");
  17491. return temptransactionId;
  17492. }
  17493. ch=fgetc(fptr1);
  17494. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17495. rewind(fptr1);
  17496. if(ch!=EOF)
  17497. {
  17498. // printf("%c",ch);
  17499. while (fgets(str, 100, fptr1) != NULL)
  17500. {
  17501. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17502. if(str[0]=='\0')
  17503. {
  17504. break;
  17505. }
  17506. char *revbuf[8] = {0}; // Variable store string split
  17507. int num = 0;// Quantity after string split
  17508. DEBUG_INFO("Transaction queue data= %s\n", str);
  17509. splitstring(str,",",revbuf,&num); // String split
  17510. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17511. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17512. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17513. DEBUG_INFO("------------------------------\n");
  17514. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17515. {
  17516. if(isStopTransaction)
  17517. {
  17518. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17519. {
  17520. temptransactionId = atoi(revbuf[2]);
  17521. //break;
  17522. }
  17523. }
  17524. else
  17525. {
  17526. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17527. {
  17528. temptransactionId = atoi(revbuf[2]);
  17529. //break;
  17530. }
  17531. }
  17532. }
  17533. }
  17534. }
  17535. else
  17536. DEBUG_INFO("EOF\n");
  17537. fclose(fptr1);
  17538. /*------- End of reading ---------------*/
  17539. return temptransactionId;
  17540. }
  17541. void SetTransactionIdZero(int transactionId)
  17542. {
  17543. char ch;
  17544. FILE *fptr1, *fptr2;
  17545. int temptransactionId = 0;
  17546. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17547. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17548. if (!fptr1)
  17549. {
  17550. //printf(" File not found or unable to open the input file!!\n");
  17551. return ;
  17552. }
  17553. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17554. if (!fptr2)
  17555. {
  17556. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17557. fclose(fptr1);
  17558. return ;
  17559. }
  17560. ch=fgetc(fptr1);
  17561. rewind(fptr1);
  17562. if(ch!=EOF)
  17563. {
  17564. // copy all contents to the temporary file except the specific line
  17565. while (fgets(str, 100, fptr1) != NULL)
  17566. {
  17567. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17568. if(str[0]=='\0')
  17569. {
  17570. break;
  17571. }
  17572. char *revbuf[8] = {0};
  17573. int num = 0;
  17574. strcpy(strtemp, str);
  17575. splitstring(str,",",revbuf,&num);
  17576. if(revbuf[2][0] != '\0')
  17577. {
  17578. temptransactionId = atoi(revbuf[2]);
  17579. if(transactionId != temptransactionId)
  17580. {
  17581. fprintf(fptr2, "%s\n", strtemp);
  17582. }
  17583. }
  17584. }
  17585. }
  17586. fclose(fptr1);
  17587. fclose(fptr2);
  17588. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17589. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17590. /*------ Read the file ----------------*/
  17591. }
  17592. int InternetDisconnect(void)
  17593. {
  17594. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17595. }
  17596. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17597. void storeTempStopTransaction(int gun_index)
  17598. {
  17599. char guid[37]={0};
  17600. int tempIndex = 0;
  17601. char TempStopTransaction[256];
  17602. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17603. DEBUG_INFO("storeTempStopTransaction...\n");
  17604. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17605. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17606. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17607. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17608. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17609. {
  17610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17611. {
  17612. tempIndex = ((gun_index==2) ? 1: 0);
  17613. }
  17614. else
  17615. {
  17616. tempIndex = gun_index;
  17617. }
  17618. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17619. {
  17620. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17621. {
  17622. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17623. }
  17624. }// END OF CHAdeMO_QUANTITY
  17625. }
  17626. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17627. {
  17628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17629. {
  17630. tempIndex = ((gun_index==2) ? 1: 0);
  17631. }
  17632. else
  17633. {
  17634. tempIndex = gun_index;
  17635. }
  17636. for (int index = 0; index < CCS_QUANTITY; index++)
  17637. {
  17638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17639. {
  17640. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17641. }
  17642. }// END OF CCS_QUANTITY
  17643. }
  17644. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17645. {
  17646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17647. {
  17648. tempIndex = ((gun_index==2) ? 1: 0);
  17649. }
  17650. else
  17651. {
  17652. tempIndex = gun_index;
  17653. }
  17654. for (int index = 0; index < GB_QUANTITY; index++)
  17655. {
  17656. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17657. {
  17658. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17659. }
  17660. }// END OF GB_QUANTITY
  17661. }
  17662. else if(gunType[gun_index] == GUN_TYPE_DO)
  17663. {
  17664. tempIndex = gun_index;
  17665. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17666. {
  17667. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17668. {
  17669. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17670. }
  17671. }
  17672. }
  17673. else
  17674. {
  17675. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17676. {
  17677. tempIndex = 2;
  17678. }
  17679. else
  17680. {
  17681. tempIndex = gun_index;
  17682. }
  17683. for (int index = 0; index < AC_QUANTITY; index++)
  17684. {
  17685. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17686. {
  17687. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17688. }
  17689. }// END OF AC_QUANTITY
  17690. }
  17691. //Stop Transaction Time
  17692. struct timeval tmnow;
  17693. struct tm *tm;
  17694. char buf[28];//, usec_buf[6];
  17695. gettimeofday(&tmnow, NULL);
  17696. time_t t;
  17697. t = time(NULL);
  17698. /*UTC time and date*/
  17699. tm = gmtime(&t);
  17700. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17701. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17702. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17704. random_uuid(guid);
  17705. /***********************************transactionData******************************************************/
  17706. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17708. //=================================
  17709. //1. Transaction_Begin
  17710. //=================================
  17711. //============================== Energy.Active.Import.Interval ===========================================
  17712. //=================================
  17713. //2. Transaction_End
  17714. //=================================
  17715. //2.1====================================== Current.Import L1 ==============================================
  17716. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17717. {
  17718. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17719. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17720. {
  17721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17722. {
  17723. tempIndex = ((gun_index==2) ? 1: 0);
  17724. }
  17725. else
  17726. {
  17727. tempIndex = gun_index;
  17728. }
  17729. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17730. {
  17731. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17732. {
  17733. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17734. }
  17735. }// End of for CHAdeMO_QUANTITY
  17736. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17737. }
  17738. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17739. {
  17740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17741. {
  17742. tempIndex = ((gun_index==2) ? 1: 0);
  17743. }
  17744. else
  17745. {
  17746. tempIndex = gun_index;
  17747. }
  17748. for (int index = 0; index < CCS_QUANTITY; index++)
  17749. {
  17750. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17751. {
  17752. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17753. }
  17754. }// End of for CCS_QUANTITY
  17755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17756. }
  17757. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17758. {
  17759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17760. {
  17761. tempIndex = ((gun_index==2) ? 1: 0);
  17762. }
  17763. else
  17764. {
  17765. tempIndex = gun_index;
  17766. }
  17767. for (int index = 0; index < GB_QUANTITY; index++)
  17768. {
  17769. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17770. {
  17771. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17772. }
  17773. }// End of for GB_QUANTITY
  17774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17775. }
  17776. else if(gunType[gun_index] == GUN_TYPE_DO)
  17777. {
  17778. tempIndex = gun_index;
  17779. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17780. {
  17781. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17782. {
  17783. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17784. }
  17785. }
  17786. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17787. }
  17788. else
  17789. {
  17790. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17791. {
  17792. tempIndex = 2;
  17793. }
  17794. else
  17795. {
  17796. tempIndex = gun_index;
  17797. }
  17798. for (int index = 0; index < AC_QUANTITY; index++)
  17799. {
  17800. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17801. {
  17802. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17803. }
  17804. }// End of for AC_QUANTITY
  17805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17806. }
  17807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17810. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17811. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17812. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17813. }
  17814. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17815. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17816. {
  17817. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17818. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17819. {
  17820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17821. {
  17822. tempIndex = ((gun_index==2) ? 1: 0);
  17823. }
  17824. else
  17825. {
  17826. tempIndex = gun_index;
  17827. }
  17828. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17829. {
  17830. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17831. {
  17832. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17833. }
  17834. }// END OF CHAdeMO_QUANTITY
  17835. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17836. }
  17837. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17838. {
  17839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17840. {
  17841. tempIndex = ((gun_index==2) ? 1: 0);
  17842. }
  17843. else
  17844. {
  17845. tempIndex = gun_index;
  17846. }
  17847. for (int index = 0; index < CCS_QUANTITY; index++)
  17848. {
  17849. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17850. {
  17851. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17852. }
  17853. }// END OF CCS_QUANTITY
  17854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17855. }
  17856. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17857. {
  17858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17859. {
  17860. tempIndex = ((gun_index==2) ? 1: 0);
  17861. }
  17862. else
  17863. {
  17864. tempIndex = gun_index;
  17865. }
  17866. for (int index = 0; index < GB_QUANTITY; index++)
  17867. {
  17868. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17869. {
  17870. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17871. }
  17872. }// END OF GB_QUANTITY
  17873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17874. }
  17875. else if(gunType[gun_index] == GUN_TYPE_DO)
  17876. {
  17877. tempIndex = gun_index;
  17878. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17879. {
  17880. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17881. {
  17882. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17883. }
  17884. }
  17885. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17886. }
  17887. else
  17888. {
  17889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17890. {
  17891. tempIndex = 2;
  17892. }
  17893. else
  17894. {
  17895. tempIndex = gun_index;
  17896. }
  17897. for (int index = 0; index < AC_QUANTITY; index++)
  17898. {
  17899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17900. {
  17901. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  17902. }
  17903. }// END OF AC_QUANTITY
  17904. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17905. }
  17906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17907. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17908. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17909. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17910. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17911. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17912. }
  17913. //2.3====================================== Power.Active.Import =========================================
  17914. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17915. {
  17916. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17917. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17918. {
  17919. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17920. {
  17921. tempIndex = ((gun_index==2) ? 1: 0);
  17922. }
  17923. else
  17924. {
  17925. tempIndex = gun_index;
  17926. }
  17927. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17928. {
  17929. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17930. {
  17931. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17932. }
  17933. } // End for CHAdeMO_QUANTITY
  17934. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17935. }
  17936. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17937. {
  17938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17939. {
  17940. tempIndex = ((gun_index==2) ? 1: 0);
  17941. }
  17942. else
  17943. {
  17944. tempIndex = gun_index;
  17945. }
  17946. for (int index = 0; index < CCS_QUANTITY; index++)
  17947. {
  17948. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17949. {
  17950. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17951. }
  17952. } // END for CCS_QUANTITY
  17953. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17954. }
  17955. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17956. {
  17957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17958. {
  17959. tempIndex = ((gun_index==2) ? 1: 0);
  17960. }
  17961. else
  17962. {
  17963. tempIndex = gun_index;
  17964. }
  17965. for (int index = 0; index < GB_QUANTITY; index++)
  17966. {
  17967. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17968. {
  17969. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17970. }
  17971. }// END for GB_QUANTITY
  17972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17973. }
  17974. else if(gunType[gun_index] == GUN_TYPE_DO)
  17975. {
  17976. tempIndex = gun_index;
  17977. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17978. {
  17979. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17980. {
  17981. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17982. }
  17983. }
  17984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17985. }
  17986. else
  17987. {
  17988. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17989. {
  17990. tempIndex = 2;
  17991. }
  17992. else
  17993. {
  17994. tempIndex = gun_index;
  17995. }
  17996. for (int index = 0; index < AC_QUANTITY; index++)
  17997. {
  17998. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17999. {
  18000. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18001. }
  18002. } // END for AC_QUANTITY
  18003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18004. }
  18005. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18007. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18008. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18009. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18010. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18011. }
  18012. //2.4====================================== Voltage L1 ====================================================
  18013. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18014. {
  18015. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18016. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18017. {
  18018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18019. {
  18020. tempIndex = ((gun_index==2) ? 1: 0);
  18021. }
  18022. else
  18023. {
  18024. tempIndex = gun_index;
  18025. }
  18026. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18027. {
  18028. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18029. {
  18030. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18031. }
  18032. } // END OF FOR CHAdeMO_QUANTITY
  18033. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18034. }
  18035. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18036. {
  18037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18038. {
  18039. tempIndex = ((gun_index==2) ? 1: 0);
  18040. }
  18041. else
  18042. {
  18043. tempIndex = gun_index;
  18044. }
  18045. for (int index = 0; index < CCS_QUANTITY; index++)
  18046. {
  18047. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18048. {
  18049. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18050. }
  18051. } // END OF FOR CCS_QUANTITY
  18052. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18053. }
  18054. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18055. {
  18056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18057. {
  18058. tempIndex = ((gun_index==2) ? 1: 0);
  18059. }
  18060. else
  18061. {
  18062. tempIndex = gun_index;
  18063. }
  18064. for (int index = 0; index < GB_QUANTITY; index++)
  18065. {
  18066. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18067. {
  18068. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18069. }
  18070. } // END OF FOR GB_QUANTITY
  18071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18072. }
  18073. else if(gunType[gun_index] == GUN_TYPE_DO)
  18074. {
  18075. tempIndex = gun_index;
  18076. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18077. {
  18078. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18079. {
  18080. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18081. }
  18082. }
  18083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18084. }
  18085. else
  18086. {
  18087. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18088. {
  18089. tempIndex = 2;
  18090. }
  18091. else
  18092. {
  18093. tempIndex = gun_index;
  18094. }
  18095. for (int index = 0; index < AC_QUANTITY; index++)
  18096. {
  18097. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18098. {
  18099. 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
  18100. }
  18101. } // END OF FOR AC_QUANTITY
  18102. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18103. }
  18104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18107. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18109. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18110. }
  18111. //2.5============================================== End SoC =========================================================
  18112. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18113. {
  18114. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18115. 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))
  18116. {
  18117. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18118. {
  18119. tempIndex = ((gun_index==2) ? 1: 0);
  18120. }
  18121. else
  18122. {
  18123. tempIndex = gun_index;
  18124. }
  18125. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18126. {
  18127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18128. {
  18129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18130. {
  18131. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18132. }
  18133. }
  18134. }
  18135. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18136. {
  18137. for (int index = 0; index < CCS_QUANTITY; index++)
  18138. {
  18139. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18140. {
  18141. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18142. }
  18143. }
  18144. }
  18145. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18146. {
  18147. for (int index = 0; index < GB_QUANTITY; index++)
  18148. {
  18149. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18150. {
  18151. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18152. }
  18153. }
  18154. }
  18155. else if(gunType[gun_index] == GUN_TYPE_DO)
  18156. {
  18157. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18158. {
  18159. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18160. {
  18161. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18162. }
  18163. }
  18164. }
  18165. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18171. } // END FOR DC CASE
  18172. }
  18173. //2.6====================================== Current.Import L2 ==============================================
  18174. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18175. {
  18176. // AC 3 phase L2 current
  18177. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18178. {
  18179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18180. {
  18181. tempIndex = 2;
  18182. }
  18183. else
  18184. {
  18185. tempIndex = gun_index;
  18186. }
  18187. for (int index = 0; index < AC_QUANTITY; index++)
  18188. {
  18189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18190. {
  18191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18192. }
  18193. }// End of for AC_QUANTITY
  18194. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18195. }
  18196. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18197. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18198. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18201. }
  18202. //2.7====================================== Current.Import L3 ==============================================
  18203. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18204. {
  18205. // AC 3 phase L3 current
  18206. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18207. {
  18208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18209. {
  18210. tempIndex = 2;
  18211. }
  18212. else
  18213. {
  18214. tempIndex = gun_index;
  18215. }
  18216. for (int index = 0; index < AC_QUANTITY; index++)
  18217. {
  18218. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18219. {
  18220. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18221. }
  18222. }// End of for AC_QUANTITY
  18223. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18224. }
  18225. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18226. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18227. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18228. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18229. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18230. }
  18231. //2.9====================================== Voltage L2 ====================================================
  18232. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18233. {
  18234. // AC 3 phase L2 volatge
  18235. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18236. {
  18237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18238. {
  18239. tempIndex = 2;
  18240. }
  18241. else
  18242. {
  18243. tempIndex = gun_index;
  18244. }
  18245. for (int index = 0; index < AC_QUANTITY; index++)
  18246. {
  18247. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18248. {
  18249. 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
  18250. }
  18251. } // END OF FOR AC_QUANTITY
  18252. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18253. }
  18254. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18255. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18256. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18259. }
  18260. //2.10====================================== Voltage L3 ====================================================
  18261. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18262. {
  18263. // AC 3 phase L3 volatge
  18264. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18265. {
  18266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18267. {
  18268. tempIndex = 2;
  18269. }
  18270. else
  18271. {
  18272. tempIndex = gun_index;
  18273. }
  18274. for (int index = 0; index < AC_QUANTITY; index++)
  18275. {
  18276. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18277. {
  18278. 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
  18279. }
  18280. } // END OF FOR AC_QUANTITY
  18281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18282. }
  18283. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18284. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18285. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18286. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18287. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18288. }
  18289. //====================== Start SoC ================================
  18290. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18291. {
  18292. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18293. 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))
  18294. {
  18295. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18296. {
  18297. tempIndex = ((gun_index==2) ? 1: 0);
  18298. }
  18299. else
  18300. {
  18301. tempIndex = gun_index;
  18302. }
  18303. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18304. {
  18305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18306. {
  18307. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18308. {
  18309. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18310. }
  18311. }
  18312. }
  18313. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18314. {
  18315. for (int index = 0; index < CCS_QUANTITY; index++)
  18316. {
  18317. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18318. {
  18319. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18320. }
  18321. }
  18322. }
  18323. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18324. {
  18325. for (int index = 0; index < GB_QUANTITY; index++)
  18326. {
  18327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18328. {
  18329. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18330. }
  18331. }
  18332. }
  18333. else if(gunType[gun_index] == GUN_TYPE_DO)
  18334. {
  18335. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18336. {
  18337. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18338. {
  18339. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18340. }
  18341. }
  18342. }
  18343. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18344. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18345. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18347. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18348. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18349. } // END FOR DC CASE
  18350. }
  18351. //======================================== Message create ==============================================
  18352. json_object *StopTransaction = json_object_new_object();
  18353. json_object *transactionDatas = json_object_new_array();
  18354. json_object *sampledValues = json_object_new_array();
  18355. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18356. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18357. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18358. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18359. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18360. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18361. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18362. {
  18363. json_object *transactionData = json_object_new_object();
  18364. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18365. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18366. {
  18367. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18368. {
  18369. json_object *sampledValue = json_object_new_object();
  18370. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18371. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18372. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18373. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18374. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18375. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18376. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18377. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18378. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18379. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18380. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18381. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18382. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18383. json_object_array_add(sampledValues, sampledValue);
  18384. }
  18385. }
  18386. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18387. json_object_array_add(transactionDatas, transactionData);
  18388. }
  18389. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18390. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18391. ,MESSAGE_TYPE_CALL
  18392. ,guid
  18393. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18394. json_object_put(StopTransaction);
  18395. // Check File "TempStopTransaction" Exist
  18396. if((access(TempStopTransaction,F_OK))!=-1)
  18397. {
  18398. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18399. fclose(fopen(TempStopTransaction, "w"));
  18400. }
  18401. else
  18402. {
  18403. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18404. FILE *log = fopen(TempStopTransaction, "w+");
  18405. if(log == NULL)
  18406. {
  18407. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18408. return ;
  18409. }
  18410. else
  18411. {
  18412. fclose(log);
  18413. }
  18414. }
  18415. //Add TempStopTransaction | Update TempStopTransaction
  18416. // open file for writing
  18417. FILE *outfile;
  18418. outfile = fopen (TempStopTransaction, "a");
  18419. //DEBUG_INFO("data = %s\n", queuedata);
  18420. fputs(queuedata, outfile);
  18421. fputs("\n", outfile);
  18422. fclose (outfile);
  18423. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18424. }
  18425. void checkTempStopTransaction(int gun_index)
  18426. {
  18427. FILE *fptr1;
  18428. char ch;
  18429. char str[QUEUE_MESSAGE_LENGTH]={0};
  18430. char guid[37]={0};
  18431. char tempdata[65]={0};
  18432. char connectorStr[2]={0};
  18433. char TempStopTransaction[256];
  18434. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18435. fptr1 = fopen(TempStopTransaction, "r");
  18436. //TempStopTransaction格式: 槍號,StopTransaction封包
  18437. if (!fptr1)
  18438. {
  18439. //printf(" File not found or unable to open the input file!!\n");
  18440. return ;
  18441. }
  18442. ch=fgetc(fptr1);
  18443. //printf(" Now the content of the file %s is : \n",fname);
  18444. rewind(fptr1);
  18445. if(ch!=EOF)
  18446. {
  18447. // copy all contents to the temporary file except the specific line
  18448. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18449. {
  18450. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18451. if(str[0]=='\0')
  18452. {
  18453. break;
  18454. }
  18455. //TempStopTransaction格式: 槍號,StopTransaction封包
  18456. strncpy(connectorStr, str, 1);
  18457. if(atoi(connectorStr) != (gun_index+1))
  18458. {
  18459. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18460. fclose(fptr1);
  18461. return ;
  18462. }
  18463. //random_uuid(guid);
  18464. strncpy(guid, str+6, 36); //copy guid
  18465. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18466. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18467. {
  18468. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18469. }
  18470. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18471. OCPP_insert_transaction_msg(NO, str);
  18472. memset(str,0,ARRAY_SIZE(str));
  18473. }
  18474. }
  18475. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18476. fclose(fptr1);
  18477. remove(TempStopTransaction); // remove the original file
  18478. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18479. }
  18480. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18481. {
  18482. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18483. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18484. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18485. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18486. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18487. }
  18488. int GetWebSocketPingInterval(void)
  18489. {
  18490. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18491. }
  18492. int GetServerSign(void)
  18493. {
  18494. return server_sign;
  18495. }
  18496. uint8_t GetOcppSecurityProfile()
  18497. {
  18498. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18499. }
  18500. void GetOcppChargerBoxId(uint8_t *data)
  18501. {
  18502. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18503. }
  18504. void GetOcppSecurityPassword(uint8_t *data)
  18505. {
  18506. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18507. }
  18508. void SetOcppVersion(uint8_t *version)
  18509. {
  18510. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18511. DEBUG_INFO("ocpp version: %s\n", version);
  18512. if(strstr((char*)version, "ocpp1.6") != NULL)
  18513. {
  18514. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18515. }
  18516. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18517. {
  18518. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18519. system("pkill OcppBackend");
  18520. }
  18521. }
  18522. void SetServerSign(int value)
  18523. {
  18524. server_sign = value;
  18525. }
  18526. int GetBootNotificationInterval(void)
  18527. {
  18528. return BootNotificationInterval;
  18529. }
  18530. int GetInternetConn(void)
  18531. {
  18532. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18533. }
  18534. int GetBackendConnectionTimeout(void)
  18535. {
  18536. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18537. }
  18538. int isConnectorInitMode(int gun_index)
  18539. {
  18540. int tempIndex = 0;
  18541. int result = TRUE;
  18542. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18543. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18544. {
  18545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18546. {
  18547. tempIndex = ((gun_index==2) ? 1: 0);
  18548. }
  18549. else
  18550. {
  18551. tempIndex = gun_index;
  18552. }
  18553. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18554. {
  18555. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18556. {
  18557. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18558. } //end of the same index
  18559. }//end of for CHAdeMO_QUANTITY
  18560. }
  18561. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18562. {
  18563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18564. {
  18565. tempIndex = ((gun_index==2) ? 1: 0);
  18566. }
  18567. else
  18568. {
  18569. tempIndex = gun_index;
  18570. }
  18571. for (int index = 0; index < CCS_QUANTITY; index++)
  18572. {
  18573. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18574. {
  18575. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18576. } //end of the same index
  18577. } // end of for CCS_QUANTITY
  18578. }
  18579. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18580. {
  18581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18582. {
  18583. tempIndex = ((gun_index==2) ? 1: 0);
  18584. }
  18585. else
  18586. {
  18587. tempIndex = gun_index;
  18588. }
  18589. for (int index = 0; index < GB_QUANTITY; index++)
  18590. {
  18591. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18592. {
  18593. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18594. } //end of the same index
  18595. } // end of for GB_QUANTITY
  18596. }
  18597. else if(gunType[gun_index] == GUN_TYPE_DO)
  18598. {
  18599. tempIndex = gun_index;
  18600. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18601. {
  18602. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18603. {
  18604. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18605. } //end of the same index
  18606. }
  18607. }
  18608. else
  18609. {
  18610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18611. {
  18612. tempIndex = 2;
  18613. }
  18614. else
  18615. {
  18616. tempIndex = gun_index;
  18617. }
  18618. for (int index = 0; index < AC_QUANTITY; index++)
  18619. {
  18620. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18621. {
  18622. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18623. }//end of the same index
  18624. }//end of for AC_QUANTITY
  18625. }
  18626. return result;
  18627. }
  18628. void refreshProcDogTimer()
  18629. {
  18630. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18631. }
  18632. void InitialSystemValue(void)
  18633. {
  18634. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18635. locallistVersion=0;
  18636. BootNotificationInterval = 0;
  18637. authorizeRetryTimes = 0;
  18638. GunStatusInterval = 10;
  18639. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18640. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18641. //Hear Beat
  18642. HeartBeatWithNOResponse = 0;
  18643. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18644. FirstHeartBeat = 0;
  18645. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18646. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18647. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18648. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18649. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18650. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18651. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18652. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18653. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18654. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18655. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18656. //Status && ConnectorPlugIn Setting
  18657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18658. {
  18659. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18660. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18661. }
  18662. for (int index = 0; index < CCS_QUANTITY; index++)
  18663. {
  18664. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18665. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18666. }
  18667. for (int index = 0; index < GB_QUANTITY; index++)
  18668. {
  18669. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18670. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18671. }
  18672. for (int index = 0; index < AC_QUANTITY; index++)
  18673. {
  18674. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18675. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18676. }
  18677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18678. {
  18679. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18680. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18681. }
  18682. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18683. {
  18684. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18685. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18686. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18687. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18688. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18689. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18690. }
  18691. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18692. refreshStartTimer(&clientTime.Heartbeat);
  18693. sleep(1);
  18694. }
  18695. void LWS_Send(char *str)
  18696. {
  18697. //=====================================================
  18698. // Check InternetConn 0: disconnected, 1: connected
  18699. //====================================================
  18700. if(GetOcppConnStatus() == 0)
  18701. {
  18702. DEBUG_INFO("offline now !!!\n");
  18703. return;
  18704. }
  18705. // Only disable isWebsocketSendable operation initiated by charger
  18706. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18707. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18708. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18709. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18710. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18711. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18712. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18713. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18714. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18715. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18716. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18717. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18718. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18719. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18720. {
  18721. isWebsocketSendable = 0;
  18722. }
  18723. pthread_mutex_lock(&lock_send);
  18724. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18725. sprintf((char *)SendBuffer, "%s", str);
  18726. SendBufLen = strlen(str);
  18727. pthread_mutex_unlock(&lock_send);
  18728. lws_callback_on_writable(wsi_client);
  18729. //lws_service(context, 0);
  18730. //sleep(1);
  18731. }
  18732. void LWS_SendNow(char *str)
  18733. {
  18734. //=====================================================
  18735. // Check InternetConn 0: disconnected, 1: connected
  18736. //====================================================
  18737. if(GetOcppConnStatus() == 0)
  18738. {
  18739. DEBUG_INFO("offline now !!!\n");
  18740. return;
  18741. }
  18742. // Only disable isWebsocketSendable operation initiated by charger
  18743. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18744. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18745. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18746. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18747. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18748. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18749. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18750. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18751. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18752. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18753. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18754. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18755. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18756. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18757. {
  18758. isWebsocketSendable = 0;
  18759. }
  18760. pthread_mutex_lock(&lock_send);
  18761. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18762. sprintf((char *)SendBuffer, "%s", str);
  18763. SendBufLen = strlen(str);
  18764. pthread_mutex_unlock(&lock_send);
  18765. lws_callback_on_writable(wsi_client);
  18766. lws_service(context, 0);
  18767. //sleep(1);
  18768. }