MessageHandler.c 881 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955
  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. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //=============================================
  81. // OCPP HeartBeat Response Not Receive Counts
  82. //============================================
  83. static int HeartBeatWithNOResponse = 0;
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct InterLock
  93. {
  94. unsigned char isGetDiagnosticGoing:1;
  95. unsigned char isUpdateFirmwareGoing:1;
  96. }interLock;
  97. struct ClientTime
  98. {
  99. struct timespec Heartbeat;
  100. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  101. struct timespec StartTransaction;
  102. struct timespec StopTransaction;
  103. struct timespec MeterValues[CONNECTOR_QUANTITY];
  104. struct timespec RemoteStartWait;
  105. }clientTime;
  106. typedef union
  107. {
  108. //Operations Initiated by Central System
  109. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  110. struct
  111. {
  112. //CsMsgValue[0]
  113. unsigned char StatusNotificationReq:1; //bit 0,
  114. unsigned char StatusNotificationConf:1; //bit 1,
  115. unsigned char TriggerMeterValue:1; //bit 2,
  116. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  117. unsigned char isOnCharging:1; //bit 4.
  118. unsigned char :3; //bit 5~7
  119. }bits[CONNECTOR_QUANTITY];
  120. }CpinitiateMsg;
  121. CpinitiateMsg cpinitateMsg;
  122. //GetConfiguration Array
  123. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  125. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  126. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  127. #if 0
  128. static char *ChargePointErrorCodeStr[] = {
  129. MACROSTR(ConnectorLockFailure),
  130. MACROSTR(EVCommunicationError),
  131. MACROSTR(GroundFailure),
  132. MACROSTR(HighTemperature),
  133. MACROSTR(InternalError),
  134. MACROSTR(LocalListConflict),
  135. MACROSTR(NoError),
  136. MACROSTR(OtherError),
  137. MACROSTR(OverCurrentFailure),
  138. MACROSTR(OverVoltage),
  139. MACROSTR(PowerMeterFailure),
  140. MACROSTR(PowerSwitchFailure),
  141. MACROSTR(ReaderFailure),
  142. MACROSTR(ResetFailure),
  143. MACROSTR(UnderVoltage),
  144. MACROSTR(WeakSignal)
  145. };
  146. #endif
  147. static char * ChargePointStatusStr[] = {
  148. MACROSTR(Available),
  149. MACROSTR(Preparing),
  150. MACROSTR(Charging),
  151. MACROSTR(SuspendedEVSE),
  152. MACROSTR(SuspendedEV),
  153. MACROSTR(Finishing),
  154. MACROSTR(Reserved),
  155. MACROSTR(Unavailable),
  156. MACROSTR(Faulted)
  157. };
  158. static char *RegistrationStatusStr[] = {
  159. MACROSTR(Accepted),
  160. MACROSTR(Pending),
  161. MACROSTR(Rejected)
  162. };
  163. static char *AvailabilityTypeStr[] = {
  164. MACROSTR(Inoperative),
  165. MACROSTR(Operative)
  166. };
  167. static char *AvailabilityStatusStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Rejected),
  170. MACROSTR(Scheduled)
  171. };
  172. static char *ConfigurationStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(RebootRequired),
  176. MACROSTR(NotSupported)
  177. };
  178. static char *ClearCacheStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected)
  181. };
  182. static char *ChargingProfilePurposeTypeStr[] = {
  183. MACROSTR(ChargePointMaxProfile),
  184. MACROSTR(TxDefaultProfile),
  185. MACROSTR(TxProfile)
  186. };
  187. static char *ChargingProfileStatusStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(NotSupported)
  191. };
  192. static char *ClearChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Unknown)
  195. };
  196. static char *GetCompositeScheduleStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Rejected)
  199. };
  200. static char *UpdateTypeStr[] = {
  201. MACROSTR(Differential),
  202. MACROSTR(Full)
  203. };
  204. static char *UpdateStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Failed),
  207. MACROSTR(NotSupported),
  208. MACROSTR(VersionMismatch)
  209. };
  210. static char *RemoteStartStopStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Rejected)
  213. };
  214. static char *ReservationStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Faulted),
  217. MACROSTR(Occupied),
  218. MACROSTR(Rejected),
  219. MACROSTR(Unavailable)
  220. };
  221. static char *ResetTypeStr[] = {
  222. MACROSTR(Hard),
  223. MACROSTR(Soft)
  224. };
  225. static char *ResetStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Rejected)
  228. };
  229. static char * DiagnosticsStatusStr[] = {
  230. MACROSTR(Idle),
  231. MACROSTR(Uploaded),
  232. MACROSTR(UploadFailed),
  233. MACROSTR(Uploading)
  234. };
  235. static char * FirmwareStatusStr[] = {
  236. MACROSTR(Downloaded),
  237. MACROSTR(DownloadFailed),
  238. MACROSTR(Downloading),
  239. MACROSTR(Idle),
  240. MACROSTR(InstallationFailed),
  241. MACROSTR(Installing),
  242. MACROSTR(Installed)
  243. };
  244. static char * MessageTriggerStr[] = {
  245. MACROSTR(BootNotification),
  246. MACROSTR(DiagnosticsStatusNotification),
  247. MACROSTR(FirmwareStatusNotification),
  248. MACROSTR(Heartbeat),
  249. MACROSTR(MeterValues),
  250. MACROSTR(StatusNotification)
  251. };
  252. static char * TriggerMessageStatusStr[] = {
  253. MACROSTR(Accepted),
  254. MACROSTR(Rejected),
  255. MACROSTR(NotImplemented)
  256. };
  257. static char * UnlockStatusStr[] = {
  258. MACROSTR(Unlocked),
  259. MACROSTR(UnlockFailed),
  260. MACROSTR(NotSupported)
  261. };
  262. #if 0
  263. static char * StopTransactionReasonStr[] = {
  264. MACROSTR(EmergencyStop),
  265. MACROSTR(EVDisconnected),
  266. MACROSTR(HardReset),
  267. MACROSTR(Local),
  268. MACROSTR(Other),
  269. MACROSTR(PowerLoss),
  270. MACROSTR(Reboot),
  271. MACROSTR(Remote),
  272. MACROSTR(SoftReset),
  273. MACROSTR(UnlockCommand),
  274. MACROSTR(DeAuthorized)
  275. };
  276. #endif
  277. static char * CancelReservationStatusStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(Rejected)
  280. };
  281. static char * ReadingContextStr[] = {
  282. MACROSTR(Interruption.Begin),
  283. MACROSTR(Interruption.End),
  284. MACROSTR(Other),
  285. MACROSTR(Sample.Clock),
  286. MACROSTR(Sample.Periodic),
  287. MACROSTR(Transaction.Begin),
  288. MACROSTR(Transaction.End),
  289. MACROSTR(Trigger)
  290. };
  291. static char * ValueFormatStr[] = {
  292. MACROSTR(Raw),
  293. MACROSTR(SignedData)
  294. };
  295. static char * MeasurandStr[] = {
  296. MACROSTR(Current.Export),
  297. MACROSTR(Current.Import),
  298. MACROSTR(Current.Offered),
  299. MACROSTR(Energy.Active.Export.Register),
  300. MACROSTR(Energy.Active.Import.Register),
  301. MACROSTR(Energy.Reactive.Export.Register),
  302. MACROSTR(Energy.Reactive.Import.Register),
  303. MACROSTR(Energy.Active.Export.Interval),
  304. MACROSTR(Energy.Active.Import.Interval),
  305. MACROSTR(Energy.Reactive.Export.Interval),
  306. MACROSTR(Energy.Reactive.Import.Interval),
  307. MACROSTR(Frequency),
  308. MACROSTR(Power.Active.Export),
  309. MACROSTR(Power.Active.Import),
  310. MACROSTR(Power.Factor),
  311. MACROSTR(Power.Offered),
  312. MACROSTR(Power.Reactive.ExportMACROSTR),
  313. MACROSTR(Power.Reactive.Import),
  314. MACROSTR(RPM),
  315. MACROSTR(SoC),
  316. MACROSTR(Temperature),
  317. MACROSTR(Voltage)
  318. };
  319. static char * LocationStr[] = {
  320. MACROSTR(Body),
  321. MACROSTR(Cable),
  322. MACROSTR(EV),
  323. MACROSTR(Inlet),
  324. MACROSTR(Outlet)
  325. };
  326. static char * PhaseStr[] = {
  327. MACROSTR(L1),
  328. MACROSTR(L2),
  329. MACROSTR(L3),
  330. MACROSTR(N),
  331. MACROSTR(L1-N),
  332. MACROSTR(L2-N),
  333. MACROSTR(L3-N),
  334. MACROSTR(L1-L2),
  335. MACROSTR(L2-L3),
  336. MACROSTR(L3-L1)
  337. };
  338. static char * UnitOfMeasureStr[] = {
  339. MACROSTR(Wh),
  340. MACROSTR(kWh),
  341. MACROSTR(varh),
  342. MACROSTR(kvarh),
  343. MACROSTR(W),
  344. MACROSTR(kW),
  345. MACROSTR(VA),
  346. MACROSTR(kVA),
  347. MACROSTR(var),
  348. MACROSTR(kvar),
  349. MACROSTR(A),
  350. MACROSTR(V),
  351. MACROSTR(Celsius),
  352. MACROSTR(Fahrenheit),
  353. MACROSTR(K),
  354. MACROSTR(Percent)
  355. };
  356. //=========================================
  357. // Save configuration
  358. //=========================================
  359. int runShellCmd(const char*cmd)
  360. {
  361. int result = FAIL;
  362. char buf[256];
  363. FILE *fp;
  364. fp = popen(cmd, "r");
  365. if(fp != NULL)
  366. {
  367. while(fgets(buf, sizeof(buf), fp) != NULL)
  368. {
  369. DEBUG_INFO("%s\n", buf);
  370. }
  371. result = PASS;
  372. }
  373. pclose(fp);
  374. return result;
  375. }
  376. int StoreUsrConfigData(struct SysConfigData *UsrData)
  377. {
  378. int result = PASS;
  379. int fd,wrd;
  380. unsigned int i,Chk;
  381. unsigned char *ptr, *BufTmp;
  382. int MtdBlockSize = 0x300000;
  383. Chk=0;
  384. ptr=(unsigned char *)UsrData;
  385. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  386. {
  387. memset(BufTmp,0,MtdBlockSize);
  388. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  389. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  390. Chk+=*(BufTmp+i);
  391. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  392. // Output configuration to file.
  393. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  394. if (fd < 0)
  395. {
  396. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  397. free(BufTmp);
  398. return 0;
  399. }
  400. wrd=write(fd, BufTmp, MtdBlockSize);
  401. close(fd);
  402. if(wrd<MtdBlockSize)
  403. {
  404. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  405. free(BufTmp);
  406. return 0;
  407. }
  408. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  409. DEBUG_INFO("Erase /dev/mtd10.\n");
  410. runShellCmd("flash_erase /dev/mtd10 0 0");
  411. DEBUG_INFO("Write /dev/mtd10.\n");
  412. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  413. DEBUG_INFO("Erase /dev/mtd11.\n");
  414. runShellCmd("flash_erase /dev/mtd11 0 0");
  415. DEBUG_INFO("Write /dev/mtd11.\n");
  416. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  417. system("rm -f /mnt/EvseConfig.bin");
  418. DEBUG_INFO("EvseConfig write to flash OK\n");
  419. }
  420. else
  421. {
  422. DEBUG_ERROR("alloc BlockSize NG\r\n");
  423. result = FAIL;
  424. }
  425. if(BufTmp!=NULL)
  426. free(BufTmp);
  427. return result;
  428. }
  429. //=========================================
  430. // Sqlite3 related function
  431. //=========================================
  432. static int selectSqlCount = 0;
  433. static int callback(void *data, int argc, char **argv, char **azColName){
  434. int i;
  435. //printf("%s: ", (const char*)data);
  436. selectSqlCount = argc;
  437. for(i = 0; i<argc; i++){
  438. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  439. }
  440. //printf("\n");
  441. return 0;
  442. }
  443. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  444. //int i;
  445. //printf("%s:\n", (const char*)data);
  446. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  447. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  448. return 0;
  449. }
  450. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  451. //printf("%s:\n", (const char*)data);
  452. //idTag
  453. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  455. //parentIdTag
  456. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  457. //expir_date
  458. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  459. //status
  460. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  461. //version
  462. if(columenCount > 5)
  463. idTagQuery.listVersionInt = atoi(columnValue[5]);
  464. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  465. return 0;
  466. }
  467. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  468. {
  469. // localversion = argv[5] ? atoi(argv[5]) : 0;
  470. // printf("localversion=%d\n", localversion);
  471. return 0;
  472. }
  473. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  474. {
  475. for (int i = 0; i < n_columns; i++)
  476. {
  477. DEBUG_INFO("%s\t", col_values[i]);
  478. }
  479. DEBUG_INFO("\n");
  480. return 0;
  481. }
  482. int OCPP_cleanLocalCache()
  483. {
  484. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  485. char *errMsg = 0;
  486. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  487. if (SQLITE_OK != rc)
  488. {
  489. DEBUG_INFO("SQL error: %s\n",errMsg);
  490. return FALSE;
  491. }
  492. return TRUE;
  493. }
  494. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  495. {
  496. int isSuccess = TRUE;
  497. int ret = 0;
  498. //const char* data = "Callback function called";
  499. char sql[300];
  500. char zErrMsg[200];
  501. memset(sql, 0, 300);
  502. memset(zErrMsg, 0, 200);
  503. 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);
  504. //* Execute SQL statement */
  505. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  506. if( ret != SQLITE_OK )
  507. {
  508. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  509. isSuccess = FALSE;
  510. }
  511. return isSuccess;
  512. }
  513. void OCPP_getIdTagFromLocalCache(char idTag[])
  514. {
  515. int rc = 0;
  516. char sql[100];
  517. char zErrMsg[100];
  518. memset(sql, 0, 100);
  519. memset(zErrMsg, 0, 100);
  520. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  521. memset(&idTagQuery, 0, sizeof(idTagQuery));
  522. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  523. /* Execute SQL statement */
  524. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  525. if( rc != SQLITE_OK )
  526. {
  527. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  528. }
  529. }
  530. void OCPP_getListVerion()
  531. {
  532. int rc = 0;
  533. // const char* data = "Callback function called";
  534. char sql[100];
  535. char zErrMsg[100];
  536. memset(sql, 0, 100);
  537. memset(zErrMsg, 0, 100);
  538. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  539. /* Execute SQL statement */
  540. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  541. if( rc != SQLITE_OK )
  542. {
  543. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  544. }
  545. }
  546. void OCPP_get_TableAuthlocalAllData(void)
  547. {
  548. int rc = 0;
  549. char sql[100];
  550. char zErrMsg[100];
  551. memset(sql, 0, 100);
  552. memset(zErrMsg, 0, 100);
  553. sprintf(sql,"select * from ocpp_auth_local ");
  554. /* Execute SQL statement */
  555. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  556. if( rc != SQLITE_OK )
  557. {
  558. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  559. }
  560. //return ver;
  561. }
  562. int OCPP_cleanLocalList()
  563. {
  564. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  565. char *errMsg = 0;
  566. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  567. if (SQLITE_OK != rc)
  568. {
  569. DEBUG_INFO("%s\n",errMsg);
  570. return FALSE;
  571. }
  572. return TRUE;
  573. }
  574. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  575. {
  576. int isSuccess = FALSE;
  577. int ret = 0;
  578. //const char* data = "Callback function called";
  579. char sql[300];
  580. char zErrMsg[200];
  581. memset(sql, 0, 300);
  582. memset(zErrMsg, 0, 200);
  583. 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);
  584. //* Execute SQL statement */
  585. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  586. if( ret != SQLITE_OK )
  587. {
  588. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  589. return isSuccess;
  590. }
  591. memset(sql, 0, 300);
  592. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  593. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  594. if( ret != SQLITE_OK )
  595. {
  596. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  597. return isSuccess;
  598. }
  599. isSuccess = TRUE;
  600. return isSuccess;
  601. }
  602. void OCPP_getIdTagFromLocalList(char idTag[])
  603. {
  604. int rc = 0;
  605. // const char* data = "Callback function called";
  606. char sql[100];
  607. char zErrMsg[100];
  608. memset(sql, 0, 100);
  609. memset(zErrMsg, 0, 100);
  610. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  611. memset(&idTagQuery, 0, sizeof(idTagQuery));
  612. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  613. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  614. /* Execute SQL statement */
  615. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  616. if( rc != SQLITE_OK )
  617. {
  618. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  619. }
  620. //return ver;
  621. }
  622. void OCPP_deleteIdTagFromLocalList(char idTag[])
  623. {
  624. //int ver = 0;
  625. //int isSuccess = FALSE;
  626. int rc = 0;
  627. char sql[100];
  628. char zErrMsg[100];
  629. memset(sql, 0, 100);
  630. memset(zErrMsg, 0, 100);
  631. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  632. //* Execute SQL statement */
  633. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  634. if( rc != SQLITE_OK )
  635. {
  636. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  637. }
  638. }
  639. int getCurrentYear()
  640. {
  641. int result = 0;
  642. time_t CurrentTime;
  643. struct tm *tm;
  644. CurrentTime = time(NULL);
  645. tm=localtime(&CurrentTime);
  646. result = (tm->tm_year + 1900);
  647. return result;
  648. }
  649. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  650. {
  651. int result = PASS;
  652. char* errMsg = NULL;
  653. char sqlStr[8192];
  654. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  655. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  656. {
  657. result = FAIL;
  658. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  659. }
  660. 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));
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  665. }
  666. return result;
  667. }
  668. //==========================================
  669. // Check time passed since today
  670. //==========================================
  671. long long DiffTimebWithNow(struct timeb ST)
  672. {
  673. //return milli-second
  674. struct timeb ET;
  675. long long StartTime,StopTime;
  676. ftime(&ET);
  677. StartTime=(long long)ST.time;
  678. StopTime=(long long)ET.time;
  679. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  680. }
  681. int getTimePassSinceToday(uint8_t gun_index)
  682. {
  683. int result = -1;
  684. static time_t lastTime[4];
  685. time_t t;
  686. struct tm *tmStartToday;
  687. struct timeb tbStartToday;
  688. t=time(NULL);
  689. if(difftime(t, lastTime[gun_index])>0)
  690. {
  691. tmStartToday=localtime(&t);
  692. tmStartToday->tm_hour = 0;
  693. tmStartToday->tm_min = 0;
  694. tmStartToday->tm_sec = 0;
  695. tbStartToday.time = mktime(tmStartToday);
  696. tbStartToday.millitm = 0;
  697. result = DiffTimebWithNow(tbStartToday)/1000;
  698. lastTime[gun_index] = t;
  699. }
  700. return result;
  701. }
  702. void getNowDatetime(uint8_t *data)
  703. {
  704. time_t t = time(NULL);
  705. struct tm tm = *localtime(&t);
  706. 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);
  707. }
  708. int syncDateTimeRTC(uint8_t *data)
  709. {
  710. struct ParsingResult
  711. {
  712. int result;
  713. int scanedElement;
  714. int year;
  715. int month;
  716. int mday;
  717. int hour;
  718. int min;
  719. int sec;
  720. int tz_hour;
  721. int tz_min;
  722. float minSec;
  723. }result;
  724. struct tm tmOrg;
  725. struct tm *tmTarget;
  726. struct timeb tbTarget;
  727. char buf[128];
  728. memset(&result, 0x00, sizeof(struct ParsingResult));
  729. result.result = PASS;
  730. if(strstr((char*)data, ".") != NULL)
  731. {
  732. // Original data with mini second
  733. if(strstr((char*)data, "Z") != NULL)
  734. {
  735. // Original data with Z
  736. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  737. &result.year,
  738. &result.month,
  739. &result.mday,
  740. &result.hour,
  741. &result.min,
  742. &result.sec,
  743. &result.minSec);
  744. }
  745. else
  746. {
  747. // Original data without Z
  748. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  749. &result.year,
  750. &result.month,
  751. &result.mday,
  752. &result.hour,
  753. &result.min,
  754. &result.sec,
  755. &result.minSec,
  756. &result.tz_hour,
  757. &result.tz_min);
  758. }
  759. }
  760. else
  761. {
  762. // Original data without mini second
  763. if(strstr((char*)data, "Z") != NULL)
  764. {
  765. // Original data with Z
  766. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  767. &result.year,
  768. &result.month,
  769. &result.mday,
  770. &result.hour,
  771. &result.min,
  772. &result.sec);
  773. }
  774. else
  775. {
  776. // Original data without Z
  777. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  778. &result.year,
  779. &result.month,
  780. &result.mday,
  781. &result.hour,
  782. &result.min,
  783. &result.sec,
  784. &result.tz_hour,
  785. &result.tz_min);
  786. }
  787. }
  788. tmOrg.tm_year = result.year - 1900;
  789. tmOrg.tm_mon = result.month - 1;
  790. tmOrg.tm_mday = result.mday;
  791. tmOrg.tm_hour = result.hour;
  792. tmOrg.tm_min = result.min;
  793. tmOrg.tm_sec = result.sec;
  794. tmOrg.tm_gmtoff = 0;
  795. tbTarget.time = mktime(&tmOrg);
  796. tbTarget.timezone = 0;
  797. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  798. tmTarget = gmtime(&tbTarget.time);
  799. 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);
  800. //DEBUG_INFO(" org date time: %s\n", data);
  801. //DEBUG_INFO("parse date time: %s\n", buf);
  802. system(buf);
  803. system("/sbin/hwclock -w --systohc");
  804. if(result.scanedElement < 6)
  805. result.result = FAIL;
  806. return result.result;
  807. }
  808. //==========================================
  809. // GetCompositeSchedule logic related function
  810. //==========================================
  811. int DiffTimebSec(struct timeb ST, struct timeb ET)
  812. {
  813. //return milli-second
  814. unsigned int StartTime,StopTime;
  815. StartTime=(unsigned int)ST.time;
  816. StopTime=(unsigned int)ET.time;
  817. return (StopTime-StartTime);
  818. }
  819. int DiffTimebWithNowSec(struct timeb ST)
  820. {
  821. //return milli-second
  822. struct timeb ET;
  823. unsigned int StartTime,StopTime;
  824. ftime(&ET);
  825. StartTime=(unsigned int)ST.time;
  826. StopTime=(unsigned int)ET.time;
  827. return (StopTime-StartTime);
  828. }
  829. int getStartStop(uint8_t *start, uint8_t *stop)
  830. {
  831. int result = -1;
  832. struct tm tmStart;
  833. struct timeb tbStart;
  834. struct tm tmStop;
  835. struct timeb tbStop;
  836. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  837. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  838. {
  839. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  840. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  841. tmStart.tm_year -= 1900;
  842. tmStart.tm_mon -= 1;
  843. tbStart.time = mktime(&tmStart);
  844. tbStart.millitm = 0;
  845. tmStop.tm_year -= 1900;
  846. tmStop.tm_mon -= 1;
  847. tbStop.time = mktime(&tmStop);
  848. tbStop.millitm = 0;
  849. result = DiffTimebSec(tbStart, tbStop);
  850. //DEBUG_INFO("getStartStop(): %d\n", result);
  851. }
  852. else
  853. {
  854. DEBUG_WARN("Start or stop date parsing error.\r\n");
  855. }
  856. return result;
  857. }
  858. int isOvertNow(uint8_t *start)
  859. {
  860. int result = NO;
  861. struct ParsingResult
  862. {
  863. int result;
  864. int scanedElement;
  865. int year;
  866. int month;
  867. int mday;
  868. int hour;
  869. int min;
  870. int sec;
  871. int tz_hour;
  872. int tz_min;
  873. float minSec;
  874. }parsingResult;
  875. struct tm tmStart;
  876. struct timeb tbStart;
  877. if(strstr((char*)start, ".") != NULL)
  878. {
  879. // Original data with mini second
  880. if(strstr((char*)start, "Z") != NULL)
  881. {
  882. // Original data with Z
  883. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  884. &parsingResult.year,
  885. &parsingResult.month,
  886. &parsingResult.mday,
  887. &parsingResult.hour,
  888. &parsingResult.min,
  889. &parsingResult.sec,
  890. &parsingResult.minSec);
  891. }
  892. else
  893. {
  894. // Original data without Z
  895. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  896. &parsingResult.year,
  897. &parsingResult.month,
  898. &parsingResult.mday,
  899. &parsingResult.hour,
  900. &parsingResult.min,
  901. &parsingResult.sec,
  902. &parsingResult.minSec,
  903. &parsingResult.tz_hour,
  904. &parsingResult.tz_min);
  905. }
  906. }
  907. else
  908. {
  909. // Original data without mini second
  910. if(strstr((char*)start, "Z") != NULL)
  911. {
  912. // Original data with Z
  913. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  914. &parsingResult.year,
  915. &parsingResult.month,
  916. &parsingResult.mday,
  917. &parsingResult.hour,
  918. &parsingResult.min,
  919. &parsingResult.sec);
  920. }
  921. else
  922. {
  923. // Original data without Z
  924. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  925. &parsingResult.year,
  926. &parsingResult.month,
  927. &parsingResult.mday,
  928. &parsingResult.hour,
  929. &parsingResult.min,
  930. &parsingResult.sec,
  931. &parsingResult.tz_hour,
  932. &parsingResult.tz_min);
  933. }
  934. }
  935. if(parsingResult.scanedElement >= 6)
  936. {
  937. tmStart.tm_year = parsingResult.year - 1900;
  938. tmStart.tm_mon = parsingResult.month - 1;
  939. tmStart.tm_mday = parsingResult.mday;
  940. tmStart.tm_hour = parsingResult.hour;
  941. tmStart.tm_min = parsingResult.min;
  942. tmStart.tm_sec = parsingResult.sec;
  943. tmStart.tm_gmtoff = 0;
  944. tbStart.time = mktime(&tmStart);
  945. tbStart.timezone = 0;
  946. tbStart.millitm = 0;
  947. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  948. if(DiffTimebWithNowSec(tbStart) <= 0)
  949. result = NO;
  950. else
  951. result = YES;
  952. }
  953. else
  954. {
  955. DEBUG_WARN("Start date parsing error.\n");
  956. }
  957. return result;
  958. }
  959. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  960. {
  961. int result = -1;
  962. struct tm tmStart;
  963. struct timeb tbStart;
  964. struct tm tmStop;
  965. struct timeb tbStop;
  966. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  967. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  968. {
  969. tmStart.tm_year -= 1900;
  970. tmStart.tm_mon -= 1;
  971. tbStart.time = mktime(&tmStart);
  972. tbStart.millitm = 0;
  973. tmStop.tm_year -= 1900;
  974. tmStop.tm_mon -= 1;
  975. tbStop.time = mktime(&tmStop);
  976. tbStop.millitm = 0;
  977. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  978. }
  979. return result;
  980. }
  981. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  982. {
  983. FILE *fp;
  984. char profileFileName[128];
  985. char *line = NULL;
  986. size_t len = 0;
  987. time_t CurrentTime;
  988. struct tm *tmComposite;
  989. struct StructChargingProfile maxProfile;
  990. uint8_t limitMax=0;
  991. int compositePeriodIdx = 0;
  992. CurrentTime = time(NULL);
  993. tmComposite=localtime(&CurrentTime);
  994. 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);
  995. if(isUnitA)
  996. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  997. else
  998. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  999. compositeProfile->ChargingSchedule.Duration = durationReq;
  1000. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1001. {
  1002. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1003. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1004. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1005. }
  1006. compositeProfile->ChargingProfileId = 0;
  1007. compositeProfile->StackLevel = 99 ;
  1008. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1009. maxProfile.ChargingProfileId = -1;
  1010. maxProfile.ChargingSchedule.Duration = -1;
  1011. system("rm -f /tmp/*.json");
  1012. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1013. // Search max profile
  1014. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1015. if((access(profileFileName, F_OK))!=-1)
  1016. {
  1017. fp = fopen(profileFileName, "r");
  1018. while(getline(&line, &len, fp) != -1)
  1019. {
  1020. json_object *obj = NULL;
  1021. obj = json_tokener_parse(line);
  1022. if(is_error(obj))
  1023. {
  1024. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1025. }
  1026. else
  1027. {
  1028. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1029. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1030. )
  1031. {
  1032. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1033. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1034. )
  1035. {
  1036. struct tm tmFrom, tmTo;
  1037. struct timeb tbFrom, tbTo;
  1038. 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) &&
  1039. (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))
  1040. {
  1041. tmFrom.tm_year -= 1900;
  1042. tmFrom.tm_mon -= 1;
  1043. tbFrom.time = mktime(&tmFrom);
  1044. tmTo.tm_year -= 1900;
  1045. tmTo.tm_mon -= 1;
  1046. tbTo.time = mktime(&tmTo);
  1047. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1048. {
  1049. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1050. {
  1051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1053. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1054. }
  1055. maxProfile.ChargingProfileId = -1;
  1056. maxProfile.StackLevel = -1;
  1057. if(maxProfile.ChargingProfileId == -1)
  1058. DEBUG_INFO("MaxProfile found.\n");
  1059. else
  1060. DEBUG_INFO("MaxProfile updated.\n");
  1061. // Required item
  1062. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1063. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1064. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1065. if(isUnitA)
  1066. {
  1067. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1068. 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++)
  1069. {
  1070. 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"));
  1071. 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?
  1072. 3:
  1073. 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")));
  1074. 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")));
  1075. }
  1076. }
  1077. else
  1078. {
  1079. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1080. 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++)
  1081. {
  1082. 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"));
  1083. 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?
  1084. 3:
  1085. 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")));
  1086. 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));
  1087. }
  1088. }
  1089. // Optional item
  1090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1091. {
  1092. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1093. }
  1094. else
  1095. {
  1096. sprintf((char*)maxProfile.ValidFrom, " ");
  1097. }
  1098. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1099. {
  1100. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1101. }
  1102. else
  1103. {
  1104. sprintf((char*)maxProfile.ValidTo, " ");
  1105. }
  1106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1107. {
  1108. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1109. }
  1110. else
  1111. {
  1112. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1113. }
  1114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1115. {
  1116. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1117. }
  1118. else
  1119. {
  1120. maxProfile.TransactionId = -1;
  1121. }
  1122. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1123. {
  1124. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1125. }
  1126. else
  1127. {
  1128. maxProfile.ChargingSchedule.Duration = 86400;
  1129. }
  1130. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1131. {
  1132. 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")));
  1133. }
  1134. else
  1135. {
  1136. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1137. }
  1138. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1139. {
  1140. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1141. }
  1142. else
  1143. {
  1144. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. else
  1150. {
  1151. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1152. {
  1153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1155. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1156. }
  1157. maxProfile.ChargingProfileId = -1;
  1158. maxProfile.StackLevel = -1;
  1159. if(maxProfile.ChargingProfileId == -1)
  1160. DEBUG_INFO("MaxProfile found.\n");
  1161. else
  1162. DEBUG_INFO("MaxProfile updated.\n");
  1163. // Required item
  1164. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1165. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1166. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1167. if(isUnitA)
  1168. {
  1169. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1170. 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++)
  1171. {
  1172. 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"));
  1173. 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?
  1174. 3:
  1175. 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")));
  1176. 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")));
  1177. }
  1178. }
  1179. else
  1180. {
  1181. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1182. 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++)
  1183. {
  1184. 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"));
  1185. 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?
  1186. 3:
  1187. 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")));
  1188. 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));
  1189. }
  1190. }
  1191. // Optional item
  1192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1193. {
  1194. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1195. }
  1196. else
  1197. {
  1198. sprintf((char*)maxProfile.ValidFrom, " ");
  1199. }
  1200. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1201. {
  1202. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1203. }
  1204. else
  1205. {
  1206. sprintf((char*)maxProfile.ValidTo, " ");
  1207. }
  1208. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1209. {
  1210. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1211. }
  1212. else
  1213. {
  1214. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1215. }
  1216. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1217. {
  1218. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1219. }
  1220. else
  1221. {
  1222. maxProfile.TransactionId = -1;
  1223. }
  1224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1225. {
  1226. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1227. }
  1228. else
  1229. {
  1230. maxProfile.ChargingSchedule.Duration = 86400;
  1231. }
  1232. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1233. {
  1234. 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")));
  1235. }
  1236. else
  1237. {
  1238. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1239. }
  1240. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1241. {
  1242. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1243. }
  1244. else
  1245. {
  1246. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1247. }
  1248. }
  1249. }
  1250. }
  1251. json_object_put(obj);
  1252. }
  1253. fclose(fp);
  1254. /*
  1255. if(maxProfile.ChargingProfileId !=-1)
  1256. {
  1257. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1258. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1259. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1260. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1261. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1262. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1263. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1264. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1265. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1266. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1267. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1268. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1269. {
  1270. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1271. {
  1272. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1273. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1274. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1275. }
  1276. }
  1277. }
  1278. else
  1279. DEBUG_INFO("MaxProfile not found.\n");
  1280. DEBUG_INFO("------------------------------------\n");*/
  1281. }
  1282. if(maxProfile.ChargingProfileId != -1)
  1283. {
  1284. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1285. {
  1286. if(maxProfile.ChargingSchedule.Duration != -1)
  1287. {
  1288. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1289. 0:
  1290. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1291. }
  1292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1293. {
  1294. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1295. {
  1296. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1297. 0:
  1298. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1299. if(idxPeriod > 0)
  1300. {
  1301. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1302. {
  1303. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1310. {
  1311. if(maxProfile.ChargingSchedule.Duration != -1)
  1312. {
  1313. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1314. }
  1315. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1316. {
  1317. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1318. {
  1319. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1320. if(idxPeriod > 0)
  1321. {
  1322. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1323. {
  1324. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1333. {
  1334. if(maxProfile.ChargingSchedule.Duration != -1)
  1335. {
  1336. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1337. 0:
  1338. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1339. }
  1340. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1341. {
  1342. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1343. {
  1344. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1345. 0:
  1346. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1347. if(idxPeriod > 0)
  1348. {
  1349. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1350. {
  1351. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1352. }
  1353. }
  1354. }
  1355. }
  1356. }
  1357. else
  1358. {
  1359. if(maxProfile.ChargingSchedule.Duration != -1)
  1360. {
  1361. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1362. 0:
  1363. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1364. }
  1365. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1366. {
  1367. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1368. {
  1369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1370. 0:
  1371. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1372. if(idxPeriod > 0)
  1373. {
  1374. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1375. {
  1376. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. }
  1383. /*
  1384. DEBUG_INFO("MaxProfile after align.\n");
  1385. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1386. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1387. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1388. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1389. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1390. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1391. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1392. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1393. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1394. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1395. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1396. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1397. {
  1398. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1399. {
  1400. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1401. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1402. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1403. }
  1404. }
  1405. DEBUG_INFO("------------------------------------\n");*/
  1406. }
  1407. // Find each profile period quantity
  1408. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1409. {
  1410. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1411. limitMax = idx+1;
  1412. }
  1413. if(maxProfile.ChargingProfileId != -1)
  1414. {
  1415. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1416. {
  1417. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1418. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1419. (maxProfile.ChargingSchedule.Duration > 0))
  1420. {
  1421. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1422. {
  1423. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1424. compositePeriodIdx++;
  1425. }
  1426. else
  1427. {
  1428. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1429. }
  1430. }
  1431. }
  1432. }
  1433. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1434. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1435. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1436. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1437. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1438. {
  1439. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1440. {
  1441. compositeProfile->ChargingProfileId = 1;
  1442. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1443. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1444. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1445. }
  1446. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1447. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1448. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1449. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1450. }
  1451. if(line)
  1452. free(line);
  1453. }
  1454. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1455. {
  1456. FILE *fp;
  1457. char profileFileName[128];
  1458. char *line = NULL;
  1459. size_t len = 0;
  1460. time_t CurrentTime;
  1461. struct tm *tmComposite;
  1462. struct StructChargingProfile maxProfile;
  1463. struct StructChargingProfile defaultTxProfile;
  1464. struct StructChargingProfile txProfile;
  1465. struct StructChargingSchedulePeriod tmpPeriod;
  1466. uint8_t limitMax=0;
  1467. uint8_t limitDef=0;
  1468. uint8_t limitTx=0;
  1469. int compositePeriodIdx = 0;
  1470. CurrentTime = time(NULL);
  1471. tmComposite=localtime(&CurrentTime);
  1472. 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);
  1473. if(isUnitA)
  1474. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1475. else
  1476. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1477. compositeProfile->ChargingSchedule.Duration = durationReq;
  1478. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1479. {
  1480. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1481. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1482. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1483. }
  1484. compositeProfile->ChargingProfileId = 0;
  1485. compositeProfile->StackLevel = 99 ;
  1486. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1487. maxProfile.ChargingProfileId = -1;
  1488. defaultTxProfile.ChargingProfileId = -1;
  1489. txProfile.ChargingProfileId = -1;
  1490. maxProfile.ChargingSchedule.Duration = -1;
  1491. defaultTxProfile.ChargingSchedule.Duration = -1;
  1492. txProfile.ChargingSchedule.Duration = -1;
  1493. system("rm -f /tmp/*.json");
  1494. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1495. /*
  1496. * Search valid charging profile
  1497. */
  1498. //DEBUG_INFO("====================================\n");
  1499. // Search tx profile
  1500. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1501. if((access(profileFileName, F_OK))!=-1)
  1502. {
  1503. fp = fopen(profileFileName, "r");
  1504. while(getline(&line, &len, fp) != -1)
  1505. {
  1506. json_object *obj = NULL;
  1507. obj = json_tokener_parse(line);
  1508. if(is_error(obj))
  1509. {
  1510. DEBUG_ERROR("Parse txProfile from file error.\n");
  1511. }
  1512. else
  1513. {
  1514. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1515. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1516. )
  1517. {
  1518. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1519. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1520. )
  1521. {
  1522. struct tm tmFrom, tmTo;
  1523. struct timeb tbFrom, tbTo;
  1524. 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) &&
  1525. (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))
  1526. {
  1527. tmFrom.tm_year -= 1900;
  1528. tmFrom.tm_mon -= 1;
  1529. tbFrom.time = mktime(&tmFrom);
  1530. tmTo.tm_year -= 1900;
  1531. tmTo.tm_mon -= 1;
  1532. tbTo.time = mktime(&tmTo);
  1533. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1534. {
  1535. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1536. {
  1537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1539. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1540. }
  1541. txProfile.ChargingProfileId = -1;
  1542. txProfile.StackLevel = -1;
  1543. if(txProfile.ChargingProfileId == -1)
  1544. DEBUG_INFO("TxProfile found.\n");
  1545. else
  1546. DEBUG_INFO("TxProfile updated.\n");
  1547. // Required item
  1548. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1549. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1550. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1551. if(isUnitA)
  1552. {
  1553. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1554. 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++)
  1555. {
  1556. 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"));
  1557. 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?
  1558. 3:
  1559. 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")));
  1560. 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")));
  1561. }
  1562. }
  1563. else
  1564. {
  1565. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  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. 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"));
  1569. 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?
  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. 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));
  1573. }
  1574. }
  1575. // Optional item
  1576. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1577. {
  1578. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1579. }
  1580. else
  1581. {
  1582. sprintf((char*)txProfile.ValidFrom, " ");
  1583. }
  1584. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1585. {
  1586. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1587. }
  1588. else
  1589. {
  1590. sprintf((char*)txProfile.ValidTo, " ");
  1591. }
  1592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1593. {
  1594. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1595. }
  1596. else
  1597. {
  1598. sprintf((char*)txProfile.RecurrencyKind, " ");
  1599. }
  1600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1601. {
  1602. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1603. }
  1604. else
  1605. {
  1606. txProfile.TransactionId = -1;
  1607. }
  1608. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1609. {
  1610. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1611. }
  1612. else
  1613. {
  1614. txProfile.ChargingSchedule.Duration = 86400;
  1615. }
  1616. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1617. {
  1618. 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")));
  1619. }
  1620. else
  1621. {
  1622. 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));
  1623. }
  1624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1625. {
  1626. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1627. }
  1628. else
  1629. {
  1630. txProfile.ChargingSchedule.MinChargingRate = -1;
  1631. }
  1632. }
  1633. }
  1634. }
  1635. else
  1636. {
  1637. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1638. {
  1639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1640. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1641. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1642. }
  1643. txProfile.ChargingProfileId = -1;
  1644. txProfile.StackLevel = -1;
  1645. if(txProfile.ChargingProfileId == -1)
  1646. DEBUG_INFO("TxProfile found.\n");
  1647. else
  1648. DEBUG_INFO("TxProfile updated.\n");
  1649. // Required item
  1650. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1651. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1652. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1653. if(isUnitA)
  1654. {
  1655. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1656. 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++)
  1657. {
  1658. 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"));
  1659. 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?
  1660. 3:
  1661. 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")));
  1662. 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")));
  1663. }
  1664. }
  1665. else
  1666. {
  1667. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1668. 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++)
  1669. {
  1670. 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"));
  1671. 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?
  1672. 3:
  1673. 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")));
  1674. 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));
  1675. }
  1676. }
  1677. // Optional item
  1678. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1679. {
  1680. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1681. }
  1682. else
  1683. {
  1684. sprintf((char*)txProfile.ValidFrom, " ");
  1685. }
  1686. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1687. {
  1688. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1689. }
  1690. else
  1691. {
  1692. sprintf((char*)txProfile.ValidTo, " ");
  1693. }
  1694. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1695. {
  1696. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1697. }
  1698. else
  1699. {
  1700. sprintf((char*)txProfile.RecurrencyKind, " ");
  1701. }
  1702. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1703. {
  1704. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1705. }
  1706. else
  1707. {
  1708. txProfile.TransactionId = -1;
  1709. }
  1710. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1711. {
  1712. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1713. }
  1714. else
  1715. {
  1716. txProfile.ChargingSchedule.Duration = 86400;
  1717. }
  1718. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1719. {
  1720. 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")));
  1721. }
  1722. else
  1723. {
  1724. 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));
  1725. }
  1726. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1727. {
  1728. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1729. }
  1730. else
  1731. {
  1732. txProfile.ChargingSchedule.MinChargingRate = -1;
  1733. }
  1734. }
  1735. }
  1736. }
  1737. json_object_put(obj);
  1738. }
  1739. fclose(fp);
  1740. /*
  1741. if(txProfile.ChargingProfileId != -1)
  1742. {
  1743. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1744. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1745. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1746. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1747. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1748. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1749. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1750. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1751. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1752. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1753. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1754. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1755. {
  1756. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1757. {
  1758. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1759. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1760. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1761. }
  1762. }
  1763. }
  1764. else
  1765. DEBUG_INFO("TxProfile not found.\n");*/
  1766. }
  1767. // Search default tx profile
  1768. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1769. if((access(profileFileName, F_OK))==-1)
  1770. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1771. if((access(profileFileName, F_OK))!=-1)
  1772. {
  1773. fp = fopen(profileFileName, "r");
  1774. while(getline(&line, &len, fp) != -1)
  1775. {
  1776. json_object *obj = NULL;
  1777. obj = json_tokener_parse(line);
  1778. if(is_error(obj))
  1779. {
  1780. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1781. }
  1782. else
  1783. {
  1784. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1785. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1786. )
  1787. {
  1788. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1789. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1790. )
  1791. {
  1792. struct tm tmFrom, tmTo;
  1793. struct timeb tbFrom, tbTo;
  1794. 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) &&
  1795. (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))
  1796. {
  1797. tmFrom.tm_year -= 1900;
  1798. tmFrom.tm_mon -= 1;
  1799. tbFrom.time = mktime(&tmFrom);
  1800. tmTo.tm_year -= 1900;
  1801. tmTo.tm_mon -= 1;
  1802. tbTo.time = mktime(&tmTo);
  1803. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1804. {
  1805. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1806. {
  1807. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1809. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1810. }
  1811. defaultTxProfile.ChargingProfileId = -1;
  1812. defaultTxProfile.StackLevel = -1;
  1813. if(defaultTxProfile.ChargingProfileId == -1)
  1814. DEBUG_INFO("TxDefaultProfile found.\n");
  1815. else
  1816. DEBUG_INFO("TxDefaultProfile updated.\n");
  1817. // Required item
  1818. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1819. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1820. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1821. if(isUnitA)
  1822. {
  1823. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1824. 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++)
  1825. {
  1826. 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"));
  1827. 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?
  1828. 3:
  1829. 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")));
  1830. 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")));
  1831. }
  1832. }
  1833. else
  1834. {
  1835. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1836. 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++)
  1837. {
  1838. 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"));
  1839. 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?
  1840. 3:
  1841. 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")));
  1842. 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));
  1843. }
  1844. }
  1845. // Optional item
  1846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1847. {
  1848. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1849. }
  1850. else
  1851. {
  1852. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1853. }
  1854. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1855. {
  1856. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1857. }
  1858. else
  1859. {
  1860. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1861. }
  1862. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1863. {
  1864. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1865. }
  1866. else
  1867. {
  1868. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1869. }
  1870. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1871. {
  1872. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1873. }
  1874. else
  1875. {
  1876. defaultTxProfile.TransactionId = -1;
  1877. }
  1878. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1879. {
  1880. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1881. }
  1882. else
  1883. {
  1884. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1885. }
  1886. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1887. {
  1888. 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")));
  1889. }
  1890. else
  1891. {
  1892. 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));
  1893. }
  1894. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1895. {
  1896. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1897. }
  1898. else
  1899. {
  1900. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1901. }
  1902. }
  1903. }
  1904. }
  1905. else
  1906. {
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1912. }
  1913. defaultTxProfile.ChargingProfileId = -1;
  1914. defaultTxProfile.StackLevel = -1;
  1915. if(defaultTxProfile.ChargingProfileId == -1)
  1916. DEBUG_INFO("TxDefaultProfile found.\n");
  1917. else
  1918. DEBUG_INFO("TxDefaultProfile updated.\n");
  1919. // Required item
  1920. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1921. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1922. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1923. if(isUnitA)
  1924. {
  1925. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1926. 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++)
  1927. {
  1928. 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"));
  1929. 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?
  1930. 3:
  1931. 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")));
  1932. 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")));
  1933. }
  1934. }
  1935. else
  1936. {
  1937. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1938. 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++)
  1939. {
  1940. 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"));
  1941. 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?
  1942. 3:
  1943. 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")));
  1944. 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));
  1945. }
  1946. }
  1947. // Optional item
  1948. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1949. {
  1950. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1951. }
  1952. else
  1953. {
  1954. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1955. }
  1956. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1957. {
  1958. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1959. }
  1960. else
  1961. {
  1962. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1963. }
  1964. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1965. {
  1966. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1967. }
  1968. else
  1969. {
  1970. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1971. }
  1972. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1973. {
  1974. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1975. }
  1976. else
  1977. {
  1978. defaultTxProfile.TransactionId = -1;
  1979. }
  1980. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1981. {
  1982. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1983. }
  1984. else
  1985. {
  1986. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1987. }
  1988. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1989. {
  1990. 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")));
  1991. }
  1992. else
  1993. {
  1994. 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));
  1995. }
  1996. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1997. {
  1998. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1999. }
  2000. else
  2001. {
  2002. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2003. }
  2004. }
  2005. }
  2006. }
  2007. json_object_put(obj);
  2008. }
  2009. fclose(fp);
  2010. /*
  2011. if(defaultTxProfile.ChargingProfileId != -1)
  2012. {
  2013. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2014. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2015. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2016. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2017. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2018. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2019. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2020. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2021. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2022. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2023. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2024. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2025. {
  2026. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2027. {
  2028. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2029. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2030. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2031. }
  2032. }
  2033. }
  2034. else
  2035. DEBUG_INFO("TxDefaultProfile not found.\n");
  2036. DEBUG_INFO("------------------------------------\n");*/
  2037. }
  2038. // Search max profile
  2039. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2040. if((access(profileFileName, F_OK))!=-1)
  2041. {
  2042. fp = fopen(profileFileName, "r");
  2043. while(getline(&line, &len, fp) != -1)
  2044. {
  2045. json_object *obj = NULL;
  2046. obj = json_tokener_parse(line);
  2047. if(is_error(obj))
  2048. {
  2049. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2050. }
  2051. else
  2052. {
  2053. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2054. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2055. )
  2056. {
  2057. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2058. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2059. )
  2060. {
  2061. struct tm tmFrom, tmTo;
  2062. struct timeb tbFrom, tbTo;
  2063. 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) &&
  2064. (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))
  2065. {
  2066. tmFrom.tm_year -= 1900;
  2067. tmFrom.tm_mon -= 1;
  2068. tbFrom.time = mktime(&tmFrom);
  2069. tmTo.tm_year -= 1900;
  2070. tmTo.tm_mon -= 1;
  2071. tbTo.time = mktime(&tmTo);
  2072. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2073. {
  2074. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2075. {
  2076. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2077. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2078. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2079. }
  2080. maxProfile.ChargingProfileId = -1;
  2081. maxProfile.StackLevel = -1;
  2082. if(maxProfile.ChargingProfileId == -1)
  2083. DEBUG_INFO("MaxProfile found.\n");
  2084. else
  2085. DEBUG_INFO("MaxProfile updated.\n");
  2086. // Required item
  2087. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2088. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2089. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2090. if(isUnitA)
  2091. {
  2092. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2093. 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++)
  2094. {
  2095. 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"));
  2096. 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?
  2097. 3:
  2098. 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")));
  2099. 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")));
  2100. }
  2101. }
  2102. else
  2103. {
  2104. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2105. 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++)
  2106. {
  2107. 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"));
  2108. 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?
  2109. 3:
  2110. 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")));
  2111. 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));
  2112. }
  2113. }
  2114. // Optional item
  2115. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2116. {
  2117. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2118. }
  2119. else
  2120. {
  2121. sprintf((char*)maxProfile.ValidFrom, " ");
  2122. }
  2123. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2124. {
  2125. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2126. }
  2127. else
  2128. {
  2129. sprintf((char*)maxProfile.ValidTo, " ");
  2130. }
  2131. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2132. {
  2133. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2134. }
  2135. else
  2136. {
  2137. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2138. }
  2139. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2140. {
  2141. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2142. }
  2143. else
  2144. {
  2145. maxProfile.TransactionId = -1;
  2146. }
  2147. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2148. {
  2149. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2150. }
  2151. else
  2152. {
  2153. maxProfile.ChargingSchedule.Duration = 86400;
  2154. }
  2155. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2156. {
  2157. 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")));
  2158. }
  2159. else
  2160. {
  2161. 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));
  2162. }
  2163. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2164. {
  2165. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2166. }
  2167. else
  2168. {
  2169. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2170. }
  2171. }
  2172. }
  2173. }
  2174. else
  2175. {
  2176. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2177. {
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2181. }
  2182. maxProfile.ChargingProfileId = -1;
  2183. maxProfile.StackLevel = -1;
  2184. if(maxProfile.ChargingProfileId == -1)
  2185. DEBUG_INFO("MaxProfile found.\n");
  2186. else
  2187. DEBUG_INFO("MaxProfile updated.\n");
  2188. // Required item
  2189. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2190. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2191. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2192. if(isUnitA)
  2193. {
  2194. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2195. 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++)
  2196. {
  2197. 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"));
  2198. 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?
  2199. 3:
  2200. 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")));
  2201. 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")));
  2202. }
  2203. }
  2204. else
  2205. {
  2206. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2207. 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++)
  2208. {
  2209. 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"));
  2210. 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?
  2211. 3:
  2212. 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")));
  2213. 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));
  2214. }
  2215. }
  2216. // Optional item
  2217. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2218. {
  2219. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2220. }
  2221. else
  2222. {
  2223. sprintf((char*)maxProfile.ValidFrom, " ");
  2224. }
  2225. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2226. {
  2227. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2228. }
  2229. else
  2230. {
  2231. sprintf((char*)maxProfile.ValidTo, " ");
  2232. }
  2233. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2234. {
  2235. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2236. }
  2237. else
  2238. {
  2239. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2240. }
  2241. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2242. {
  2243. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2244. }
  2245. else
  2246. {
  2247. maxProfile.TransactionId = -1;
  2248. }
  2249. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2250. {
  2251. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2252. }
  2253. else
  2254. {
  2255. maxProfile.ChargingSchedule.Duration = 86400;
  2256. }
  2257. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2258. {
  2259. 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")));
  2260. }
  2261. else
  2262. {
  2263. 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));
  2264. }
  2265. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2266. {
  2267. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2268. }
  2269. else
  2270. {
  2271. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2272. }
  2273. }
  2274. }
  2275. }
  2276. json_object_put(obj);
  2277. }
  2278. fclose(fp);
  2279. /*
  2280. if(maxProfile.ChargingProfileId !=-1)
  2281. {
  2282. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2283. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2284. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2285. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2286. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2287. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2288. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2289. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2290. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2291. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2292. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2293. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2294. {
  2295. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2296. {
  2297. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2298. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2299. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2300. }
  2301. }
  2302. }
  2303. else
  2304. DEBUG_INFO("MaxProfile not found.\n");
  2305. DEBUG_INFO("------------------------------------\n");*/
  2306. }
  2307. /*
  2308. * Align found profile start schedule & periods
  2309. */
  2310. //DEBUG_INFO("====================================\n");
  2311. /*
  2312. // For local test usage, force modify found profile start schedule info
  2313. 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);
  2314. 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);
  2315. 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);
  2316. */
  2317. if(txProfile.ChargingProfileId != -1)
  2318. {
  2319. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2320. {
  2321. if(txProfile.ChargingSchedule.Duration != -1)
  2322. {
  2323. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2324. 0:
  2325. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2326. }
  2327. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2328. {
  2329. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2330. {
  2331. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2332. 0:
  2333. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2334. if(idxPeriod > 0)
  2335. {
  2336. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2337. {
  2338. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2345. {
  2346. if(txProfile.ChargingSchedule.Duration != -1)
  2347. {
  2348. 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?
  2349. 0:
  2350. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2351. }
  2352. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2353. {
  2354. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2355. {
  2356. 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?
  2357. 0:
  2358. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2359. if(idxPeriod > 0)
  2360. {
  2361. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2362. {
  2363. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2364. }
  2365. }
  2366. }
  2367. }
  2368. }
  2369. else
  2370. {
  2371. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2372. {
  2373. if(txProfile.ChargingSchedule.Duration != -1)
  2374. {
  2375. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2376. 0:
  2377. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2378. }
  2379. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2380. {
  2381. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2382. {
  2383. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2384. 0:
  2385. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2386. if(idxPeriod > 0)
  2387. {
  2388. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2389. {
  2390. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. }
  2396. else
  2397. {
  2398. if(txProfile.ChargingSchedule.Duration != -1)
  2399. {
  2400. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2401. 0:
  2402. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2403. }
  2404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2405. {
  2406. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2407. {
  2408. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2409. 0:
  2410. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2411. if(idxPeriod > 0)
  2412. {
  2413. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2414. {
  2415. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2416. }
  2417. }
  2418. }
  2419. }
  2420. }
  2421. }
  2422. /*
  2423. DEBUG_INFO("txProfile after align.\n");
  2424. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2425. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2426. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2427. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2428. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2429. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2430. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2431. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2432. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2433. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2434. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2435. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2436. {
  2437. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2438. {
  2439. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2440. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2441. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2442. }
  2443. }*/
  2444. }
  2445. if(defaultTxProfile.ChargingProfileId != -1)
  2446. {
  2447. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2448. {
  2449. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2450. {
  2451. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2452. 0:
  2453. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2454. }
  2455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2456. {
  2457. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2458. {
  2459. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2460. 0:
  2461. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2462. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2463. {
  2464. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2465. }
  2466. if(idxPeriod > 0)
  2467. {
  2468. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2469. {
  2470. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2471. }
  2472. }
  2473. }
  2474. }
  2475. }
  2476. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2477. {
  2478. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2479. {
  2480. 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?
  2481. 0:
  2482. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2483. }
  2484. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2485. {
  2486. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2487. {
  2488. 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?
  2489. 0:
  2490. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2491. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2492. {
  2493. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2494. }
  2495. if(idxPeriod > 0)
  2496. {
  2497. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2498. {
  2499. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. else
  2506. {
  2507. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2508. {
  2509. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2510. {
  2511. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2512. 0:
  2513. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2514. }
  2515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2516. {
  2517. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2518. {
  2519. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2520. 0:
  2521. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2522. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2523. {
  2524. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2525. }
  2526. if(idxPeriod > 0)
  2527. {
  2528. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2529. {
  2530. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2531. }
  2532. }
  2533. }
  2534. }
  2535. }
  2536. else
  2537. {
  2538. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2539. {
  2540. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2541. 0:
  2542. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2543. }
  2544. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2545. {
  2546. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2547. {
  2548. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2549. 0:
  2550. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2551. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2552. {
  2553. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2554. }
  2555. if(idxPeriod > 0)
  2556. {
  2557. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2558. {
  2559. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2560. }
  2561. }
  2562. }
  2563. }
  2564. }
  2565. }
  2566. /*
  2567. DEBUG_INFO("defaultTxProfile after align.\n");
  2568. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2569. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2570. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2571. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2572. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2573. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2574. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2575. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2576. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2577. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2578. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2579. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2580. {
  2581. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2582. {
  2583. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2584. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2585. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2586. }
  2587. }
  2588. DEBUG_INFO("------------------------------------\n");*/
  2589. }
  2590. if(maxProfile.ChargingProfileId != -1)
  2591. {
  2592. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2593. {
  2594. if(maxProfile.ChargingSchedule.Duration != -1)
  2595. {
  2596. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2597. 0:
  2598. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2599. }
  2600. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2601. {
  2602. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2603. {
  2604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2605. 0:
  2606. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2607. if(idxPeriod > 0)
  2608. {
  2609. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2610. {
  2611. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2618. {
  2619. if(maxProfile.ChargingSchedule.Duration != -1)
  2620. {
  2621. 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?
  2622. 0:
  2623. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2624. }
  2625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2626. {
  2627. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2628. {
  2629. 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?
  2630. 0:
  2631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2632. if(idxPeriod > 0)
  2633. {
  2634. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2635. {
  2636. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2637. }
  2638. }
  2639. }
  2640. }
  2641. }
  2642. else
  2643. {
  2644. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2645. {
  2646. if(maxProfile.ChargingSchedule.Duration != -1)
  2647. {
  2648. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2649. 0:
  2650. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2651. }
  2652. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2653. {
  2654. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2655. {
  2656. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2657. 0:
  2658. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2659. if(idxPeriod > 0)
  2660. {
  2661. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2662. {
  2663. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2664. }
  2665. }
  2666. }
  2667. }
  2668. }
  2669. else
  2670. {
  2671. if(maxProfile.ChargingSchedule.Duration != -1)
  2672. {
  2673. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2674. 0:
  2675. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2676. }
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2680. {
  2681. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2682. 0:
  2683. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2684. if(idxPeriod > 0)
  2685. {
  2686. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2687. {
  2688. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. }
  2695. /*
  2696. DEBUG_INFO("MaxProfile after align.\n");
  2697. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2698. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2699. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2700. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2701. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2702. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2703. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2704. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2705. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2706. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2707. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2708. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2709. {
  2710. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2711. {
  2712. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2713. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2714. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2715. }
  2716. }
  2717. DEBUG_INFO("------------------------------------\n");*/
  2718. }
  2719. /*
  2720. * Merge to conposite schedule
  2721. */
  2722. //DEBUG_INFO("====================================\n");
  2723. // Find each profile period quantity
  2724. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2725. {
  2726. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2727. limitMax = idx+1;
  2728. }
  2729. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2730. {
  2731. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2732. limitDef = idx+1;
  2733. }
  2734. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2735. {
  2736. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2737. limitTx = idx+1;
  2738. }
  2739. // TxProfile found, composite schedule based on it
  2740. if(txProfile.ChargingProfileId != -1)
  2741. {
  2742. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2743. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2744. {
  2745. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2746. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2747. (txProfile.ChargingSchedule.Duration > 0))
  2748. {
  2749. if(maxProfile.ChargingProfileId != -1)
  2750. {
  2751. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2752. {
  2753. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2754. {
  2755. if((maxProfile.ChargingSchedule.Duration > 0))
  2756. {
  2757. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2758. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2759. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2760. }
  2761. else
  2762. {
  2763. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2764. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2765. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2766. }
  2767. }
  2768. if(idxMaxPeriod == (limitMax-1))
  2769. {
  2770. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2771. {
  2772. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2773. {
  2774. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2775. compositePeriodIdx++;
  2776. }
  2777. else
  2778. {
  2779. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2780. }
  2781. }
  2782. }
  2783. }
  2784. }
  2785. else
  2786. {
  2787. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2788. {
  2789. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2790. compositePeriodIdx++;
  2791. }
  2792. else
  2793. {
  2794. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2795. }
  2796. }
  2797. }
  2798. if(idxTxPeriod == (limitTx-1))
  2799. {
  2800. if(defaultTxProfile.ChargingProfileId != -1)
  2801. {
  2802. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2803. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2804. {
  2805. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2806. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2807. (defaultTxProfile.ChargingSchedule.Duration>0))
  2808. {
  2809. if(maxProfile.ChargingProfileId != -1)
  2810. {
  2811. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2812. {
  2813. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2814. {
  2815. if((maxProfile.ChargingSchedule.Duration > 0))
  2816. {
  2817. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2818. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2819. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2820. }
  2821. else
  2822. {
  2823. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2824. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2825. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2826. }
  2827. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2828. {
  2829. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2830. {
  2831. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2832. compositePeriodIdx++;
  2833. }
  2834. else
  2835. {
  2836. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2837. }
  2838. }
  2839. // Delete duplicate period
  2840. if(compositePeriodIdx > 1)
  2841. {
  2842. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2843. {
  2844. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2845. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2846. compositePeriodIdx -= 1;
  2847. }
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2853. {
  2854. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2855. compositePeriodIdx++;
  2856. }
  2857. else
  2858. {
  2859. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2860. }
  2861. break;
  2862. }
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2868. {
  2869. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2870. compositePeriodIdx++;
  2871. }
  2872. else
  2873. {
  2874. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2875. }
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. }
  2883. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2884. else if(defaultTxProfile.ChargingProfileId != -1)
  2885. {
  2886. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2887. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2888. {
  2889. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2890. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2891. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2892. {
  2893. if(maxProfile.ChargingProfileId != -1)
  2894. {
  2895. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2896. {
  2897. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2898. {
  2899. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2900. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2901. if((maxProfile.ChargingSchedule.Duration > 0))
  2902. {
  2903. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2904. }
  2905. else
  2906. {
  2907. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2908. }
  2909. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2910. {
  2911. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2912. {
  2913. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2914. compositePeriodIdx++;
  2915. }
  2916. else
  2917. {
  2918. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2919. }
  2920. }
  2921. // Delete duplicate period
  2922. if(compositePeriodIdx > 1)
  2923. {
  2924. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2925. {
  2926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2928. compositePeriodIdx -= 1;
  2929. }
  2930. }
  2931. }
  2932. else
  2933. {
  2934. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2935. {
  2936. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2937. compositePeriodIdx++;
  2938. }
  2939. else
  2940. {
  2941. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2942. }
  2943. break;
  2944. }
  2945. }
  2946. }
  2947. else
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2950. {
  2951. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2952. compositePeriodIdx++;
  2953. }
  2954. else
  2955. {
  2956. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2957. }
  2958. }
  2959. }
  2960. }
  2961. }
  2962. // Fill other period by MaxProfile
  2963. if(maxProfile.ChargingProfileId != -1)
  2964. {
  2965. if(compositePeriodIdx==0)
  2966. {
  2967. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2968. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2969. {
  2970. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2971. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2972. (maxProfile.ChargingSchedule.Duration > 0))
  2973. {
  2974. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2975. {
  2976. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2977. compositePeriodIdx++;
  2978. }
  2979. else
  2980. {
  2981. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2982. }
  2983. }
  2984. }
  2985. }
  2986. else
  2987. {
  2988. int lastCompositePeriodIdx = compositePeriodIdx;
  2989. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2990. {
  2991. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2992. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2993. (maxProfile.ChargingSchedule.Duration > 0))
  2994. {
  2995. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  2996. {
  2997. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  2998. {
  2999. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3000. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3001. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3002. }
  3003. else
  3004. {
  3005. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3006. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3007. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3008. }
  3009. }
  3010. if(tmpPeriod.Limit != -1)
  3011. {
  3012. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3013. {
  3014. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3015. {
  3016. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3017. compositePeriodIdx++;
  3018. }
  3019. else
  3020. {
  3021. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3022. }
  3023. }
  3024. // Delete duplicate period
  3025. if(compositePeriodIdx > 1)
  3026. {
  3027. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3028. {
  3029. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3030. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3031. compositePeriodIdx -= 1;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. }
  3038. }
  3039. compositeProfile->ChargingSchedule.Duration = durationReq;
  3040. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3041. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3042. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3043. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3044. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3045. {
  3046. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3047. {
  3048. compositeProfile->ChargingProfileId = 1;
  3049. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3050. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3051. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3052. }
  3053. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3054. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3055. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3056. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3057. }
  3058. if(line)
  3059. free(line);
  3060. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3061. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3062. }
  3063. //==========================================
  3064. // Init all share memory
  3065. //==========================================
  3066. int InitShareMemory()
  3067. {
  3068. int result = PASS;
  3069. int MeterSMId;
  3070. //creat ShmSysConfigAndInfo
  3071. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3072. {
  3073. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3074. result = FAIL;
  3075. }
  3076. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3077. {
  3078. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3079. result = FAIL;
  3080. }
  3081. else
  3082. {}
  3083. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3084. {
  3085. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3086. result = FAIL;
  3087. }
  3088. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3089. {
  3090. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3091. result = FAIL;
  3092. }
  3093. else
  3094. {}
  3095. //creat ShmPsuData
  3096. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3097. {
  3098. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3099. result = FAIL;
  3100. }
  3101. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3102. {
  3103. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3104. result = FAIL;
  3105. }
  3106. else
  3107. {}
  3108. //link ShmOCPP16Data
  3109. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3110. {
  3111. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3112. result = FAIL;
  3113. }
  3114. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3115. {
  3116. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3117. result = FAIL;
  3118. }
  3119. else
  3120. {}
  3121. //creat ShmOCPP16DataPH
  3122. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3123. {
  3124. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3125. result = FAIL;
  3126. }
  3127. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3128. {
  3129. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3130. result = FAIL;
  3131. }
  3132. else
  3133. {}
  3134. /****************************** For Initial Settings************************************************/
  3135. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3136. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3137. // allocate Configuration memory address
  3138. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3139. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3140. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3141. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3142. //offline MeterValue Interval
  3143. TempMeterValueInterval = 0;
  3144. return result;
  3145. }
  3146. int ProcessShareMemory()
  3147. {
  3148. int result = PASS;
  3149. if(InitShareMemory() == FAIL)
  3150. {
  3151. DEBUG_ERROR("InitShareMemory NG\n");
  3152. if(ShmStatusCodeData!=NULL)
  3153. {
  3154. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3155. }
  3156. result = FAIL;
  3157. }
  3158. // Model name parsing
  3159. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3160. {
  3161. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3162. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3163. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3164. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3165. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3166. ) // 'D' means DC
  3167. {
  3168. // DO series
  3169. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3170. {
  3171. SystemInitial += 1;
  3172. gunTotalNumber += 1;
  3173. gunType[gun_index] = GUN_TYPE_DO;
  3174. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3175. {
  3176. case Gun_Type_Chademo:
  3177. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3178. break;
  3179. case Gun_Type_CCS_2:
  3180. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3181. break;
  3182. case Gun_Type_GB:
  3183. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3184. break;
  3185. case Gun_Type_AC:
  3186. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3187. break;
  3188. default:
  3189. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3190. break;
  3191. }
  3192. }
  3193. }
  3194. else
  3195. {
  3196. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3197. {
  3198. SystemInitial += 1;
  3199. gunTotalNumber += 1;
  3200. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3201. {
  3202. case Gun_Type_Chademo:
  3203. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3204. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3205. break;
  3206. case Gun_Type_CCS_2:
  3207. gunType[gun_index] = GUN_TYPE_CCS;
  3208. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3209. break;
  3210. case Gun_Type_GB:
  3211. gunType[gun_index] = GUN_TYPE_GBT;
  3212. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3213. break;
  3214. case Gun_Type_AC:
  3215. gunType[gun_index] = GUN_TYPE_AC;
  3216. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3217. break;
  3218. default:
  3219. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3220. break;
  3221. }
  3222. }
  3223. }
  3224. }
  3225. else
  3226. {
  3227. DEBUG_ERROR("Model name parsing fail.\n");
  3228. result = FAIL;
  3229. }
  3230. if(result != PASS)sleep(5);
  3231. return result;
  3232. }
  3233. void checkRemoteStart(uint8_t connectorIdInt)
  3234. {
  3235. uint8_t tempIndex;
  3236. int result = PASS;
  3237. char cmdBuf[512];
  3238. //check Transaction active
  3239. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3240. {
  3241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3242. {
  3243. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3244. }
  3245. else
  3246. {
  3247. tempIndex = connectorIdInt -1;
  3248. }
  3249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3250. {
  3251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3252. {
  3253. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3254. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3255. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3256. {
  3257. //Reserved
  3258. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3259. }
  3260. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3261. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3262. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3263. {
  3264. //Reserved
  3265. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3266. result = FAIL;
  3267. goto end;
  3268. }
  3269. else
  3270. {
  3271. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3272. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3273. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3274. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3275. {
  3276. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3277. result = FAIL;
  3278. goto end;
  3279. }
  3280. }//END FOR ELSE
  3281. }
  3282. }// END FOR CHAdeMO_QUANTITY
  3283. }
  3284. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3285. {
  3286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3287. {
  3288. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3289. }
  3290. else
  3291. {
  3292. tempIndex = connectorIdInt -1;
  3293. }
  3294. for (int index = 0; index < CCS_QUANTITY; index++)
  3295. {
  3296. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3297. {
  3298. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3300. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3301. {
  3302. //Reserved
  3303. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3304. }
  3305. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3307. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3308. {
  3309. //Reserved
  3310. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3311. result = FAIL;
  3312. goto end;
  3313. }
  3314. else
  3315. {
  3316. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3317. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3318. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3319. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3320. {
  3321. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3322. result = FAIL;
  3323. goto end;
  3324. }
  3325. }// END FOR ELSE
  3326. }
  3327. }// END FOR CCS_QUANTITY
  3328. }
  3329. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3330. {
  3331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3332. {
  3333. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3334. }
  3335. else
  3336. {
  3337. tempIndex = connectorIdInt -1;
  3338. }
  3339. for (int index = 0; index < GB_QUANTITY; index++)
  3340. {
  3341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3342. {
  3343. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3344. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3345. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3346. {
  3347. //Reserved
  3348. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3349. }
  3350. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3351. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3352. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3353. {
  3354. //Reserved
  3355. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3356. result = FAIL;
  3357. goto end;
  3358. }
  3359. else
  3360. {
  3361. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3362. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3363. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3364. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3365. {
  3366. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3367. result = FAIL;
  3368. goto end;
  3369. }
  3370. }// END FOR ELSE
  3371. }
  3372. } // END FOR GB_QUANTITY
  3373. }
  3374. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3375. {
  3376. tempIndex = connectorIdInt -1;
  3377. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3378. {
  3379. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3380. {
  3381. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3382. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3383. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3384. {
  3385. //Reserved
  3386. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3387. }
  3388. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3389. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3390. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3391. {
  3392. //Reserved
  3393. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3394. result = FAIL;
  3395. goto end;
  3396. }
  3397. else
  3398. {
  3399. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3400. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3401. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3402. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3403. {
  3404. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3405. result = FAIL;
  3406. goto end;
  3407. }
  3408. }// END FOR ELSE
  3409. }
  3410. } // END FOR GB_QUANTITY
  3411. }
  3412. else
  3413. {
  3414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3415. {
  3416. tempIndex = 2;
  3417. }
  3418. else
  3419. {
  3420. tempIndex = connectorIdInt -1;
  3421. }
  3422. for (int index = 0; index < AC_QUANTITY; index++)
  3423. {
  3424. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3425. {
  3426. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3427. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3428. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3429. {
  3430. //Reserved
  3431. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3432. }
  3433. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3434. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3435. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3436. {
  3437. //Reserved
  3438. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3439. result = FAIL;
  3440. goto end;
  3441. }
  3442. else
  3443. {
  3444. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3445. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3446. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3447. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3448. {
  3449. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3450. result = FAIL;
  3451. goto end;
  3452. }
  3453. }//END FOR ELSE
  3454. }
  3455. }// END FOR AC_QUANTITY
  3456. }
  3457. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3458. {
  3459. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3460. {
  3461. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3462. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3463. {
  3464. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3465. system(cmdBuf);
  3466. }
  3467. }
  3468. else
  3469. {
  3470. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3471. result = FAIL;
  3472. }
  3473. }
  3474. end:
  3475. if(result == PASS)
  3476. {
  3477. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3478. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3479. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3480. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3482. }
  3483. }
  3484. void CheckSystemValue(void)
  3485. {
  3486. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3487. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3488. char filenmae[100]={0};
  3489. char str[100]={0};
  3490. int tempIndex = 0;
  3491. //===============================
  3492. // send Heartbeat
  3493. //===============================
  3494. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3495. {
  3496. //parameter for test
  3497. sendHeartbeatRequest(0);
  3498. //==============================================
  3499. // Reset Waiting Time
  3500. //==============================================
  3501. HeartBeatWithNOResponse += 2;
  3502. }
  3503. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3504. {
  3505. //==========================================
  3506. // Check remote start without connector id
  3507. //==========================================
  3508. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3509. {
  3510. int connectorIdInt = -1;
  3511. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3512. {
  3513. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3514. {
  3515. connectorIdInt = (gun_index+1);
  3516. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3517. checkRemoteStart(connectorIdInt);
  3518. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3519. break;
  3520. }
  3521. }
  3522. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3523. {
  3524. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3525. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3526. }
  3527. }
  3528. //==========================================
  3529. // csu trigger DataTransferReq
  3530. //==========================================
  3531. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3532. {
  3533. sendDataTransferRequest(gun_index);
  3534. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3535. }
  3536. //===============================
  3537. // CSU Trigger Authorize Request
  3538. //===============================
  3539. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3540. {
  3541. sendAuthorizeRequest(0);
  3542. authorizeRetryTimes = authorizeRetryTimes + 1;
  3543. if(authorizeRetryTimes < 3)
  3544. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3545. }
  3546. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3547. {
  3548. authorizeRetryTimes = 0;
  3549. SetOcppConnStatus(FALSE);
  3550. server_sign = FALSE;
  3551. }
  3552. 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))
  3553. {
  3554. sendAuthorizeRequest(0);
  3555. }
  3556. //==============================================
  3557. // Charger start transaction
  3558. //==============================================
  3559. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3560. {
  3561. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3562. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3563. sendStartTransactionRequest(gun_index);
  3564. refreshStartTimer(&clientTime.StartTransaction);
  3565. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3566. //storeTempStopTransaction(gun_index);
  3567. }
  3568. //==============================================
  3569. // Charger stop transaction
  3570. //==============================================
  3571. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3572. {
  3573. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3574. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3575. sendStopTransactionRequest(gun_index);
  3576. refreshStartTimer(&clientTime.StopTransaction);
  3577. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3578. }
  3579. //==============================================
  3580. // Charger status report
  3581. //==============================================
  3582. //--- Check Mode Change ---//
  3583. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3584. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3585. {
  3586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3587. {
  3588. tempIndex = ((gun_index==2) ? 1: 0);
  3589. }
  3590. else
  3591. {
  3592. tempIndex = gun_index;
  3593. }
  3594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3595. {
  3596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3597. {
  3598. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3599. {
  3600. // Sent unplug message for California pricing logic
  3601. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3602. {
  3603. uint8_t ts[20];
  3604. getNowDatetime(ts);
  3605. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3606. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3607. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3608. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3609. }
  3610. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3611. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3612. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3613. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3614. {
  3615. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3616. if((access(filenmae,F_OK))!=-1)
  3617. {
  3618. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3619. sprintf(str,"rm -f %s",filenmae);
  3620. system(str);
  3621. }
  3622. }
  3623. }
  3624. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3625. #if 1 // for TempStopTransaction
  3626. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3627. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3628. {
  3629. checkTempStopTransaction(gun_index);
  3630. }
  3631. #endif
  3632. }
  3633. }
  3634. }
  3635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3636. {
  3637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3638. {
  3639. tempIndex = ((gun_index==2) ? 1: 0);
  3640. }
  3641. else
  3642. {
  3643. tempIndex = gun_index;
  3644. }
  3645. for (int index = 0; index < CCS_QUANTITY; index++)
  3646. {
  3647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3648. {
  3649. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  3650. {
  3651. // Sent unplug message for California pricing logic
  3652. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3653. {
  3654. uint8_t ts[20];
  3655. getNowDatetime(ts);
  3656. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3657. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3658. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3659. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3660. }
  3661. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3662. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3663. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3664. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3665. {
  3666. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3667. if((access(filenmae,F_OK))!=-1)
  3668. {
  3669. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3670. sprintf(str,"rm -f %s",filenmae);
  3671. system(str);
  3672. }
  3673. }
  3674. }
  3675. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3676. #if 1 // for TempStopTransaction
  3677. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3678. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3679. {
  3680. checkTempStopTransaction(gun_index);
  3681. }
  3682. #endif
  3683. }
  3684. }
  3685. }
  3686. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3687. {
  3688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3689. {
  3690. tempIndex = ((gun_index==2) ? 1: 0);
  3691. }
  3692. else
  3693. {
  3694. tempIndex = gun_index;
  3695. }
  3696. for (int index = 0; index < GB_QUANTITY; index++)
  3697. {
  3698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3699. {
  3700. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3701. {
  3702. // Sent unplug message for California pricing logic
  3703. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3704. {
  3705. uint8_t ts[20];
  3706. getNowDatetime(ts);
  3707. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3708. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3710. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3711. }
  3712. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3713. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3714. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3715. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3716. {
  3717. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3718. if((access(filenmae,F_OK))!=-1)
  3719. {
  3720. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3721. sprintf(str,"rm -f %s",filenmae);
  3722. system(str);
  3723. }
  3724. }
  3725. }
  3726. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3727. #if 1 // for TempStopTransaction
  3728. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3729. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3730. {
  3731. checkTempStopTransaction(gun_index);
  3732. }
  3733. #endif
  3734. }
  3735. }
  3736. }
  3737. else if(gunType[gun_index] == GUN_TYPE_DO)
  3738. {
  3739. tempIndex = gun_index;
  3740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3741. {
  3742. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3743. {
  3744. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3745. {
  3746. // Sent unplug message for California pricing logic
  3747. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3748. {
  3749. uint8_t ts[20];
  3750. getNowDatetime(ts);
  3751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3754. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3755. }
  3756. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3757. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3758. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3759. 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
  3760. {
  3761. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3762. if((access(filenmae,F_OK))!=-1)
  3763. {
  3764. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3765. sprintf(str,"rm -f %s",filenmae);
  3766. system(str);
  3767. }
  3768. }
  3769. }
  3770. 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);
  3771. #if 1 // for TempStopTransaction
  3772. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3773. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3774. {
  3775. checkTempStopTransaction(gun_index);
  3776. }
  3777. #endif
  3778. }
  3779. }
  3780. }
  3781. else
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3784. {
  3785. tempIndex = 2;
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < AC_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3794. {
  3795. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3796. {
  3797. // Sent unplug message for California pricing logic
  3798. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3799. {
  3800. uint8_t ts[20];
  3801. getNowDatetime(ts);
  3802. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3803. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3804. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3805. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3806. }
  3807. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3808. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3809. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3810. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3811. {
  3812. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3813. if((access(filenmae,F_OK))!=-1)
  3814. {
  3815. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3816. sprintf(str,"rm -f %s",filenmae);
  3817. system(str);
  3818. }
  3819. }
  3820. }
  3821. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3822. #if 1 // for TempStopTransaction
  3823. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3824. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3825. {
  3826. checkTempStopTransaction(gun_index);
  3827. }
  3828. #endif
  3829. }
  3830. }// END
  3831. }
  3832. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  3833. (
  3834. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3835. )
  3836. )
  3837. {
  3838. if(SystemInitial > 0)
  3839. SystemInitial -= 1;
  3840. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3841. sendStatusNotificationRequest(gun_index);
  3842. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  3843. }
  3844. //==============================================
  3845. // CSU Trigger Smart Charging Profilw
  3846. //==============================================
  3847. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3848. {
  3849. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3850. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3851. }
  3852. //==============================================
  3853. // Meter report
  3854. //==============================================
  3855. // Trigger MeterValue
  3856. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3857. {
  3858. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3859. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3860. }
  3861. // ClockAlign MeterValue
  3862. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3863. {
  3864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3865. {
  3866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3867. {
  3868. tempIndex = ((gun_index==2) ? 1: 0);
  3869. }
  3870. else
  3871. {
  3872. tempIndex = gun_index;
  3873. }
  3874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3875. {
  3876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3877. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3878. {
  3879. reqClockAlignMeter[gun_index] = 1;
  3880. }
  3881. }// End for CHAdeMO
  3882. }
  3883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3884. {
  3885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3886. {
  3887. tempIndex = ((gun_index==2) ? 1: 0);
  3888. }
  3889. else
  3890. {
  3891. tempIndex = gun_index;
  3892. }
  3893. for (int index = 0; index < CCS_QUANTITY; index++)
  3894. {
  3895. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3896. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3897. {
  3898. reqClockAlignMeter[gun_index] = 1;
  3899. }
  3900. } // End for CCS
  3901. }
  3902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3903. {
  3904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3905. {
  3906. tempIndex = ((gun_index==2) ? 1: 0);
  3907. }
  3908. else
  3909. {
  3910. tempIndex = gun_index;
  3911. }
  3912. for (int index = 0; index < GB_QUANTITY; index++)
  3913. {
  3914. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3915. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3916. {
  3917. reqClockAlignMeter[gun_index] = 1;
  3918. }
  3919. }// End for GB
  3920. }
  3921. else if(gunType[gun_index] == GUN_TYPE_DO)
  3922. {
  3923. tempIndex = gun_index;
  3924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3925. {
  3926. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3927. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3928. {
  3929. reqClockAlignMeter[gun_index] = 1;
  3930. }
  3931. }
  3932. }
  3933. else
  3934. {
  3935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3936. {
  3937. tempIndex = 2;
  3938. }
  3939. else
  3940. {
  3941. tempIndex = gun_index;
  3942. }
  3943. for (int index = 0; index < AC_QUANTITY; index++)
  3944. {
  3945. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3946. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3947. {
  3948. reqClockAlignMeter[gun_index] = 1;
  3949. }
  3950. }//End for AC
  3951. }
  3952. }
  3953. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  3954. {
  3955. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3956. reqClockAlignMeter[gun_index] = 0;
  3957. }
  3958. // Sample period MeterValue
  3959. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
  3960. {
  3961. //check Transaction active
  3962. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3963. {
  3964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3965. {
  3966. tempIndex = ((gun_index==2) ? 1: 0);
  3967. }
  3968. else
  3969. {
  3970. tempIndex = gun_index;
  3971. }
  3972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3973. {
  3974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3975. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3976. {
  3977. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3978. {
  3979. reqSampleMeter[gun_index] = 1;
  3980. }
  3981. }
  3982. }// End for CHAdeMO
  3983. }
  3984. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3985. {
  3986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3987. {
  3988. tempIndex = ((gun_index==2) ? 1: 0);
  3989. }
  3990. else
  3991. {
  3992. tempIndex = gun_index;
  3993. }
  3994. for (int index = 0; index < CCS_QUANTITY; index++)
  3995. {
  3996. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3997. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3998. {
  3999. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4000. {
  4001. reqSampleMeter[gun_index] = 1;
  4002. }
  4003. }
  4004. } // End for CCS
  4005. }
  4006. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4007. {
  4008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4009. {
  4010. tempIndex = ((gun_index==2) ? 1: 0);
  4011. }
  4012. else
  4013. {
  4014. tempIndex = gun_index;
  4015. }
  4016. for (int index = 0; index < GB_QUANTITY; index++)
  4017. {
  4018. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4019. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4020. {
  4021. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4022. {
  4023. reqSampleMeter[gun_index] = 1;
  4024. }
  4025. }
  4026. }// End for GB
  4027. }
  4028. else if(gunType[gun_index] == GUN_TYPE_DO)
  4029. {
  4030. tempIndex = gun_index;
  4031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4032. {
  4033. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4034. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4035. {
  4036. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4037. {
  4038. reqSampleMeter[gun_index] = 1;
  4039. }
  4040. }
  4041. }
  4042. }
  4043. else
  4044. {
  4045. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4046. {
  4047. tempIndex = 2;
  4048. }
  4049. else
  4050. {
  4051. tempIndex = gun_index;
  4052. }
  4053. for (int index = 0; index < AC_QUANTITY; index++)
  4054. {
  4055. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4056. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4057. {
  4058. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4059. {
  4060. reqSampleMeter[gun_index] = 1;
  4061. }
  4062. }
  4063. }//End for AC
  4064. }
  4065. if(reqSampleMeter[gun_index] == 1)
  4066. {
  4067. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4068. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4069. //storeTempStopTransaction(gun_index);
  4070. }
  4071. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4072. }
  4073. //==============================================
  4074. // Check Connector reserved
  4075. //==============================================
  4076. //===============================
  4077. // Check if Reserve is expired
  4078. //===============================
  4079. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4080. {
  4081. double diff_t;
  4082. struct tm tp;
  4083. // current time
  4084. time_t t = time(NULL);
  4085. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4086. tp.tm_isdst = -1;
  4087. time_t utc = mktime(&tp);
  4088. diff_t = difftime(utc, t);
  4089. if(diff_t <= 0)
  4090. {
  4091. DEBUG_INFO("reserve expired.\n");
  4092. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4093. }
  4094. }//END OF Check if Reserve is expired
  4095. //==========================================
  4096. // csu trigger FirmwareStatusNotificationReq
  4097. //==========================================
  4098. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4099. {
  4100. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4101. }
  4102. //==========================================
  4103. // csu trigger DiagnosticsStatusNotificationReq
  4104. //==========================================
  4105. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4106. {
  4107. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4108. }
  4109. //==========================================
  4110. // csu trigger CancelReservationConf
  4111. //==========================================
  4112. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4113. {
  4114. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4115. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4116. }
  4117. //==========================================
  4118. // csu trigger ChangeAvailabilityConf
  4119. //==========================================
  4120. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4121. {
  4122. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4123. }
  4124. //==========================================
  4125. // csu trigger UnlockConnectorConf
  4126. //==========================================
  4127. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4128. {
  4129. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4130. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4131. }
  4132. //==========================================
  4133. // csu trigger ReserveNowConf
  4134. //==========================================
  4135. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4136. {
  4137. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4138. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4139. }
  4140. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4141. {
  4142. sendSignCertificateRequest();
  4143. }
  4144. }
  4145. }
  4146. //==========================================
  4147. // send request routine
  4148. //==========================================
  4149. int sendAuthorizeRequest(int gun_index)
  4150. {
  4151. mtrace();
  4152. int result = FAIL;
  4153. char message[100]={0};
  4154. char guid[37];
  4155. char tempdata[65]={0};
  4156. DEBUG_INFO("sendAuthorizeRequest...\n");
  4157. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4158. //Local Authorize
  4159. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4160. {
  4161. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4162. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4163. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4164. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4165. result = PASS;
  4166. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4167. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4168. authorizeRetryTimes = 0;
  4169. return result;
  4170. }
  4171. 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))||
  4172. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4173. {
  4174. // Query from cache
  4175. DEBUG_INFO("Authorize from cache.\n");
  4176. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4177. // Query from list
  4178. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4179. {
  4180. DEBUG_INFO("Authorize from list.\n");
  4181. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4182. }
  4183. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4184. {
  4185. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4186. {
  4187. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4188. }
  4189. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4190. {
  4191. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4192. }
  4193. if(!GetOcppConnStatus())
  4194. {
  4195. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4196. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4197. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4198. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4199. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4200. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4201. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4202. authorizeRetryTimes = 0;
  4203. return result;
  4204. }
  4205. }
  4206. else
  4207. {
  4208. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4209. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4210. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4211. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4212. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4213. else
  4214. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4215. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4216. result = PASS;
  4217. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4218. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4219. authorizeRetryTimes = 0;
  4220. return result;
  4221. }
  4222. }
  4223. //initialize struct Authorize
  4224. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4225. //get data from shared memory
  4226. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4227. random_uuid(guid);
  4228. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4229. LWS_Send(message);
  4230. sprintf(tempdata, "Authorize,%d", gun_index);
  4231. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4232. {
  4233. result = PASS;
  4234. DEBUG_INFO("Authorize mapItem pass\n");
  4235. }
  4236. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4237. return result;
  4238. }
  4239. int sendBootNotificationRequest(void)
  4240. {
  4241. mtrace();
  4242. int result = FAIL;
  4243. char message[500]={0}, payload[700]={0};
  4244. char guid[37]={0};
  4245. char tempdata[65]={0};
  4246. // Fill BootNotification fields
  4247. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4248. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4249. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4250. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4251. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4252. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4253. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4254. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4255. ShmOCPP16DataPH->ChargeBoxId
  4256. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4257. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4258. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4259. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4260. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4261. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4262. random_uuid(guid);
  4263. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4264. LWS_Send(message);
  4265. sprintf(tempdata, "BootNotification,0");
  4266. 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*/)
  4267. {
  4268. result = PASS;
  4269. }
  4270. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4271. strcpy(queuedata,message);
  4272. return result;
  4273. }
  4274. int sendDataTransferRequest(int gun_index)
  4275. {
  4276. mtrace();
  4277. char message[1000]={0};
  4278. char guid[37]={0};
  4279. char tempdata[65]={0};
  4280. int result = FAIL;
  4281. random_uuid(guid);
  4282. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4283. MESSAGE_TYPE_CALL,
  4284. guid,
  4285. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4286. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4287. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4288. LWS_Send(message);
  4289. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4290. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4291. {
  4292. result = PASS;
  4293. DEBUG_INFO("DataTransfer mapItem pass\n");
  4294. }
  4295. return result;
  4296. }
  4297. int sendDiagnosticsStatusNotificationRequest(char *status)
  4298. {
  4299. mtrace();
  4300. int result = FAIL;
  4301. char message[110]={0};
  4302. char guid[37]={0};
  4303. char tempdata[65]={0};
  4304. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4305. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4306. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4307. random_uuid(guid);
  4308. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4309. LWS_SendNow(message);
  4310. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4311. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4312. {
  4313. result = PASS;
  4314. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4315. }
  4316. //#ifdef SystemLogMessage
  4317. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4318. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4319. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4320. //#endif
  4321. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4322. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4323. //record status
  4324. if(strcmp(status,"Idle")==0)
  4325. {
  4326. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4327. }
  4328. else if(strcmp(status,"Uploaded")==0)
  4329. {
  4330. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4331. }
  4332. else if(strcmp(status,"UploadFailed")==0)
  4333. {
  4334. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4335. }
  4336. else if(strcmp(status,"Uploading")==0)
  4337. {
  4338. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4339. }
  4340. return result;
  4341. }
  4342. int sendFirmwareStatusNotificationRequest(char *status)
  4343. {
  4344. mtrace();
  4345. int result = FAIL;
  4346. char message[110]={0};
  4347. char guid[37]={0};
  4348. char tempdata[65]={0};
  4349. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4350. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4351. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4352. random_uuid(guid);
  4353. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4354. LWS_SendNow(message);
  4355. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4356. 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*/)
  4357. {
  4358. result = PASS;
  4359. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4360. }
  4361. //#ifdef SystemLogMessage
  4362. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4363. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4364. //#endif
  4365. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4366. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4367. //record status
  4368. if(strcmp(status,"Downloaded")==0)
  4369. {
  4370. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4371. }
  4372. else if(strcmp(status,"DownloadFailed")==0)
  4373. {
  4374. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4375. }
  4376. else if(strcmp(status,"Downloading")==0)
  4377. {
  4378. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4379. }
  4380. else if(strcmp(status,"Idle")==0)
  4381. {
  4382. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4383. }
  4384. else if(strcmp(status,"InstallationFailed")==0)
  4385. {
  4386. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4387. }
  4388. else if(strcmp(status,"Installing")==0)
  4389. {
  4390. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4391. }
  4392. else if(strcmp(status,"Installed")==0)
  4393. {
  4394. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4395. }
  4396. return result;
  4397. }
  4398. int sendHeartbeatRequest(int gun_index)
  4399. {
  4400. mtrace();
  4401. int result = FAIL;
  4402. char message[80]={0};
  4403. char guid[37]={0};
  4404. char tempdata[65]={0};
  4405. random_uuid(guid);
  4406. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4407. , MESSAGE_TYPE_CALL
  4408. , guid );
  4409. LWS_Send(message);
  4410. sprintf(tempdata, "Heartbeat,%d", 0);
  4411. 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*/)
  4412. {
  4413. result = PASS;
  4414. }
  4415. return result;
  4416. }
  4417. int sendStartTransactionRequest(int gun_index)
  4418. {
  4419. mtrace();
  4420. int result = FAIL;
  4421. char message[250]={0};
  4422. char guid[37]={0};
  4423. struct timeval tmnow;
  4424. struct tm *tm;
  4425. char buf[28];//, usec_buf[6];
  4426. char tempdata[65]={0};
  4427. int tempIndex = 0;
  4428. DEBUG_INFO("sendStartTransactionRequest...\n");
  4429. gettimeofday(&tmnow, NULL);
  4430. time_t t;
  4431. t = time(NULL);
  4432. /*UTC time and date*/
  4433. tm = gmtime(&t);
  4434. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4435. #if 0 // remove temporally
  4436. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4437. strcat(buf,".");
  4438. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4439. strcat(buf,usec_buf);
  4440. #endif
  4441. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4442. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4443. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4444. // clear StartTransaction Response
  4445. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4446. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4447. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4448. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4449. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4450. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4451. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4452. {
  4453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4454. {
  4455. tempIndex = ((gun_index==2) ? 1: 0);
  4456. }
  4457. else
  4458. {
  4459. tempIndex = gun_index;
  4460. }
  4461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4462. {
  4463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4464. {
  4465. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4466. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4467. }
  4468. }
  4469. }
  4470. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4471. {
  4472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4473. {
  4474. tempIndex = ((gun_index==2) ? 1: 0);
  4475. }
  4476. else
  4477. {
  4478. tempIndex = gun_index;
  4479. }
  4480. for (int index = 0; index < CCS_QUANTITY; index++)
  4481. {
  4482. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4483. {
  4484. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4485. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4486. }
  4487. }
  4488. }
  4489. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4490. {
  4491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4492. {
  4493. tempIndex = ((gun_index==2) ? 1: 0);
  4494. }
  4495. else
  4496. {
  4497. tempIndex = gun_index;
  4498. }
  4499. for (int index = 0; index < GB_QUANTITY; index++)
  4500. {
  4501. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4502. {
  4503. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4504. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4505. }
  4506. }
  4507. }
  4508. else if(gunType[gun_index] == GUN_TYPE_DO)
  4509. {
  4510. tempIndex = gun_index;
  4511. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4512. {
  4513. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4514. {
  4515. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4516. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4517. }
  4518. }
  4519. }
  4520. else
  4521. {
  4522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4523. {
  4524. tempIndex = 2;
  4525. }
  4526. else
  4527. {
  4528. tempIndex = gun_index;
  4529. }
  4530. for (int index = 0; index < AC_QUANTITY; index++)
  4531. {
  4532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4533. {
  4534. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4535. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4536. }
  4537. }
  4538. }
  4539. random_uuid(guid);
  4540. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4541. {
  4542. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4543. , gun_index +1
  4544. , MESSAGE_TYPE_CALL
  4545. , guid
  4546. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4547. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4548. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4549. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4550. }
  4551. else
  4552. {
  4553. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4554. , gun_index +1
  4555. , MESSAGE_TYPE_CALL
  4556. , guid
  4557. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4558. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4559. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4560. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4561. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4562. }
  4563. #if 1
  4564. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4565. 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*/)
  4566. {
  4567. result = PASS;
  4568. }
  4569. #endif
  4570. strcpy(queuedata, message);
  4571. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4572. OCPP_insert_transaction_msg(YES, queuedata);
  4573. return result;
  4574. }
  4575. int sendStatusNotificationRequest(int gun_index)
  4576. {
  4577. mtrace();
  4578. int result = FAIL;
  4579. char message[600]={0};
  4580. char guid[37];
  4581. int currentStatus = 0;
  4582. struct timeval tmnow;
  4583. struct tm *tm;
  4584. char buf[28];//, usec_buf[6];
  4585. char tempdata[65]={0};
  4586. int tempIndex = 0;
  4587. uint8_t isStateChanged = TRUE;
  4588. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4589. gettimeofday(&tmnow, NULL);
  4590. time_t t;
  4591. t = time(NULL);
  4592. /*UTC time and date*/
  4593. tm = gmtime(&t);
  4594. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4595. #if 0 // remove temporally
  4596. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4597. strcat(buf,".");
  4598. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4599. strcat(buf,usec_buf);
  4600. #endif
  4601. //printf("%s",buf);
  4602. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4603. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4604. // it's option
  4605. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4606. /*
  4607. enum _SYSTEM_STATUS
  4608. {
  4609. S_BOOTING = 0,
  4610. S_IDLE, = 1
  4611. S_AUTHORIZING, =2
  4612. S_REASSIGN_CHECK, =3
  4613. S_REASSIGN, =4
  4614. S_PRECHARGE, =5
  4615. S_PREPARING_FOR_EV, =6
  4616. S_PREPARING_FOR_EVSE, =7
  4617. S_CHARGING, =8
  4618. S_TERMINATING, =9
  4619. S_COMPLETE, =10
  4620. S_ALARM, =11
  4621. S_FAULT =12
  4622. }
  4623. */
  4624. //check Transaction active
  4625. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4626. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4627. {
  4628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4629. {
  4630. tempIndex = ((gun_index==2) ? 1: 0);
  4631. }
  4632. else
  4633. {
  4634. tempIndex = gun_index;
  4635. }
  4636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4637. {
  4638. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4639. {
  4640. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4641. {
  4642. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4643. {
  4644. currentStatus = Preparing; //OCPP Status: Preparing
  4645. }
  4646. else
  4647. {
  4648. currentStatus = Available; //OCPP Status: Available
  4649. }
  4650. }
  4651. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4652. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4653. ) //S_PRECHARGE
  4654. {
  4655. currentStatus = Preparing; //OCPP Status: Preparing
  4656. }
  4657. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4658. {
  4659. currentStatus = Charging; //OCPP Status: Charging
  4660. }
  4661. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4662. {
  4663. currentStatus = Finishing; //OCPP Status: Finishing
  4664. }
  4665. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4666. {
  4667. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4668. }
  4669. 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
  4670. {
  4671. currentStatus = Unavailable; //OCPP Status: Unavailable
  4672. }
  4673. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4674. {
  4675. currentStatus = Faulted; //OCPP Status: Faulted
  4676. }
  4677. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4678. {
  4679. currentStatus = Reserved; //OCPP Status: Reserved
  4680. }
  4681. } //end of the same index
  4682. }//end of for CHAdeMO_QUANTITY
  4683. }
  4684. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4685. {
  4686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4687. {
  4688. tempIndex = ((gun_index==2) ? 1: 0);
  4689. }
  4690. else
  4691. {
  4692. tempIndex = gun_index;
  4693. }
  4694. for (int index = 0; index < CCS_QUANTITY; index++)
  4695. {
  4696. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4697. {
  4698. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4699. {
  4700. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4701. {
  4702. currentStatus = Preparing; //OCPP Status: Preparing
  4703. }
  4704. else
  4705. {
  4706. currentStatus = Available; //OCPP Status: Available
  4707. }
  4708. }
  4709. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4710. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4711. ) //S_PRECHARGE
  4712. {
  4713. currentStatus = Preparing; //OCPP Status: Preparing
  4714. }
  4715. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4716. {
  4717. currentStatus = Charging; //OCPP Status: Charging
  4718. }
  4719. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4720. {
  4721. currentStatus = Finishing; //OCPP Status: Finishing
  4722. }
  4723. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4724. {
  4725. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4726. }
  4727. 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
  4728. {
  4729. currentStatus = Unavailable; //OCPP Status : Unavailable
  4730. }
  4731. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4732. {
  4733. currentStatus = Faulted; //OCPP Status: Faulted
  4734. }
  4735. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4736. {
  4737. currentStatus = Reserved; //OCPP Status: Reserved
  4738. }
  4739. } //end of the same index
  4740. } // end of for CCS_QUANTITY
  4741. }
  4742. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4743. {
  4744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4745. {
  4746. tempIndex = ((gun_index==2) ? 1: 0);
  4747. }
  4748. else
  4749. {
  4750. tempIndex = gun_index;
  4751. }
  4752. for (int index = 0; index < GB_QUANTITY; index++)
  4753. {
  4754. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4755. {
  4756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4757. {
  4758. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4759. {
  4760. currentStatus = Preparing; //OCPP Status: Preparing
  4761. }
  4762. else
  4763. {
  4764. currentStatus = Available; //OCPP Status: Available
  4765. }
  4766. }
  4767. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4768. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4769. ) //S_PRECHARGE
  4770. {
  4771. currentStatus = Preparing; //OCPP Status: Preparing
  4772. }
  4773. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4774. {
  4775. currentStatus = Charging; //OCPP Status: Charging
  4776. }
  4777. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4778. {
  4779. currentStatus = Finishing; //OCPP Status: Finishing
  4780. }
  4781. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4782. {
  4783. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4784. }
  4785. 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
  4786. {
  4787. currentStatus = Unavailable; //OCPP Status: Unavailable
  4788. }
  4789. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4790. {
  4791. currentStatus = Faulted; //OCPP Status: Faulted
  4792. }
  4793. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4794. {
  4795. currentStatus = Reserved; //OCPP Status: Reserved
  4796. }
  4797. } //end of the same index
  4798. } // end of for GB_QUANTITY
  4799. }
  4800. else if(gunType[gun_index] == GUN_TYPE_DO)
  4801. {
  4802. tempIndex = gun_index;
  4803. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4804. {
  4805. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4806. {
  4807. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4808. {
  4809. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4810. {
  4811. currentStatus = Preparing; //OCPP Status: Preparing
  4812. }
  4813. else
  4814. {
  4815. currentStatus = Available; //OCPP Status: Available
  4816. }
  4817. }
  4818. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4819. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4820. ) //S_PRECHARGE
  4821. {
  4822. currentStatus = Preparing; //OCPP Status: Preparing
  4823. }
  4824. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4825. {
  4826. currentStatus = Charging; //OCPP Status: Charging
  4827. }
  4828. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4829. {
  4830. currentStatus = Finishing; //OCPP Status: Finishing
  4831. }
  4832. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4833. {
  4834. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4835. }
  4836. 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
  4837. {
  4838. currentStatus = Unavailable; //OCPP Status: Unavailable
  4839. }
  4840. 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
  4841. {
  4842. currentStatus = Faulted; //OCPP Status: Faulted
  4843. }
  4844. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4845. {
  4846. currentStatus = Reserved; //OCPP Status: Reserved
  4847. }
  4848. } //end of the same index
  4849. }
  4850. }
  4851. else
  4852. {
  4853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4854. {
  4855. tempIndex = 2;
  4856. }
  4857. else
  4858. {
  4859. tempIndex = gun_index;
  4860. }
  4861. for (int index = 0; index < AC_QUANTITY; index++)
  4862. {
  4863. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4864. {
  4865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4866. {
  4867. 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))
  4868. {
  4869. currentStatus = Preparing; //OCPP Status: Preparing
  4870. }
  4871. else
  4872. {
  4873. currentStatus = Available; //OCPP Status: Available
  4874. }
  4875. }
  4876. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4877. {
  4878. currentStatus = Preparing; //OCPP Status: Preparing
  4879. }
  4880. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4881. {
  4882. currentStatus = Charging; //OCPP Status: Charging
  4883. }
  4884. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4885. {
  4886. currentStatus = Finishing; //OCPP Status: Finishing
  4887. }
  4888. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4889. {
  4890. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4891. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4892. else
  4893. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4894. }
  4895. 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
  4896. {
  4897. currentStatus = Unavailable; //OCPP Status: Unavailable
  4898. }
  4899. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4900. {
  4901. currentStatus = Faulted; //OCPP Status: Faulted
  4902. }
  4903. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4904. {
  4905. currentStatus = Reserved; //OCPP Status: Reserved
  4906. }
  4907. }//end of the same index
  4908. }//end of for AC_QUANTITY
  4909. }
  4910. //it's option
  4911. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4912. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4913. {
  4914. isStateChanged = FALSE;
  4915. }
  4916. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4917. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4918. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4919. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4920. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4921. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4922. random_uuid(guid);
  4923. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4924. , MESSAGE_TYPE_CALL
  4925. , guid
  4926. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4927. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4928. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4929. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4930. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4931. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4932. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4933. if((server_sign == TRUE) && isStateChanged)
  4934. {
  4935. LWS_Send(message);
  4936. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4937. 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*/)
  4938. {
  4939. //DEBUG_ERROR("statusNotification mapitem pass");
  4940. result = PASS;
  4941. }
  4942. }
  4943. else
  4944. {
  4945. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4946. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4947. result = PASS;
  4948. }
  4949. return result;
  4950. }
  4951. int sendStopTransactionRequest(int gun_index)
  4952. {
  4953. mtrace();
  4954. int result = FAIL;
  4955. //char message[1500]={0};
  4956. char guid[37]={0};
  4957. char tempdata[65]={0};
  4958. int tempIndex = 0;
  4959. char TempStopTransaction[256];
  4960. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4961. //int idx_sample=0;
  4962. DEBUG_INFO("sendStopTransactionRequest \n");
  4963. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4964. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4965. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4966. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4967. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4968. {
  4969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4970. {
  4971. tempIndex = ((gun_index==2) ? 1: 0);
  4972. }
  4973. else
  4974. {
  4975. tempIndex = gun_index;
  4976. }
  4977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4978. {
  4979. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4980. {
  4981. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4982. }
  4983. }// END OF CHAdeMO_QUANTITY
  4984. }
  4985. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4986. {
  4987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4988. {
  4989. tempIndex = ((gun_index==2) ? 1: 0);
  4990. }
  4991. else
  4992. {
  4993. tempIndex = gun_index;
  4994. }
  4995. for (int index = 0; index < CCS_QUANTITY; index++)
  4996. {
  4997. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4998. {
  4999. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5000. }
  5001. }// END OF CCS_QUANTITY
  5002. }
  5003. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5004. {
  5005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5006. {
  5007. tempIndex = ((gun_index==2) ? 1: 0);
  5008. }
  5009. else
  5010. {
  5011. tempIndex = gun_index;
  5012. }
  5013. for (int index = 0; index < GB_QUANTITY; index++)
  5014. {
  5015. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5016. {
  5017. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5018. }
  5019. }// END OF GB_QUANTITY
  5020. }
  5021. else if(gunType[gun_index] == GUN_TYPE_DO)
  5022. {
  5023. tempIndex = gun_index;
  5024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5025. {
  5026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5027. {
  5028. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5029. }
  5030. }// END OF GB_QUANTITY
  5031. }
  5032. else
  5033. {
  5034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5035. {
  5036. tempIndex = 2;
  5037. }
  5038. else
  5039. {
  5040. tempIndex = gun_index;
  5041. }
  5042. for (int index = 0; index < AC_QUANTITY; index++)
  5043. {
  5044. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5045. {
  5046. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5047. }
  5048. }// END OF AC_QUANTITY
  5049. }
  5050. //====================================== Stop Transaction Time =====================================================
  5051. struct timeval tmnow;
  5052. struct tm *tm;
  5053. char buf[28];//, usec_buf[6];
  5054. gettimeofday(&tmnow, NULL);
  5055. time_t t;
  5056. t = time(NULL);
  5057. /*UTC time and date*/
  5058. tm = gmtime(&t);
  5059. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5061. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5062. random_uuid(guid);
  5063. /***********************************transactionData******************************************************/
  5064. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5065. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5066. //=================================
  5067. // Transaction_Begin
  5068. //=================================
  5069. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5070. {
  5071. //============================================ Energy.Active.Import.Interval ================================
  5072. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5075. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5076. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5077. 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))
  5078. {
  5079. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5080. }
  5081. else
  5082. {
  5083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5084. }
  5085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5087. }
  5088. //=================================
  5089. // Transaction_End
  5090. //=================================
  5091. // ================================= Current.Import L1 ===============================================
  5092. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5093. {
  5094. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5095. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5096. {
  5097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5098. {
  5099. tempIndex = ((gun_index==2) ? 1: 0);
  5100. }
  5101. else
  5102. {
  5103. tempIndex = gun_index;
  5104. }
  5105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5106. {
  5107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5108. {
  5109. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5110. }
  5111. }// End of for CHAdeMO_QUANTITY
  5112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5113. }
  5114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5115. {
  5116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5117. {
  5118. tempIndex = ((gun_index==2) ? 1: 0);
  5119. }
  5120. else
  5121. {
  5122. tempIndex = gun_index;
  5123. }
  5124. for (int index = 0; index < CCS_QUANTITY; index++)
  5125. {
  5126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5127. {
  5128. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5129. }
  5130. }// End of for CCS_QUANTITY
  5131. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5132. }
  5133. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5134. {
  5135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5136. {
  5137. tempIndex = ((gun_index==2) ? 1: 0);
  5138. }
  5139. else
  5140. {
  5141. tempIndex = gun_index;
  5142. }
  5143. for (int index = 0; index < GB_QUANTITY; index++)
  5144. {
  5145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5146. {
  5147. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5148. }
  5149. }// End of for GB_QUANTITY
  5150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5151. }
  5152. else if(gunType[gun_index] == GUN_TYPE_DO)
  5153. {
  5154. tempIndex = gun_index;
  5155. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5156. {
  5157. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5158. {
  5159. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5160. }
  5161. }
  5162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5163. }
  5164. else
  5165. {
  5166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5167. {
  5168. tempIndex = 2;
  5169. }
  5170. else
  5171. {
  5172. tempIndex = gun_index;
  5173. }
  5174. for (int index = 0; index < AC_QUANTITY; index++)
  5175. {
  5176. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5177. {
  5178. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5179. }
  5180. }// End of for AC_QUANTITY
  5181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5182. }
  5183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5186. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5187. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5188. }
  5189. // ================================= Energy.Active.Import.Interval ==============================================
  5190. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5191. {
  5192. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5193. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5194. {
  5195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5196. {
  5197. tempIndex = ((gun_index==2) ? 1: 0);
  5198. }
  5199. else
  5200. {
  5201. tempIndex = gun_index;
  5202. }
  5203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5204. {
  5205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5206. {
  5207. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5208. }
  5209. }// END OF CHAdeMO_QUANTITY
  5210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5211. }
  5212. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5213. {
  5214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5215. {
  5216. tempIndex = ((gun_index==2) ? 1: 0);
  5217. }
  5218. else
  5219. {
  5220. tempIndex = gun_index;
  5221. }
  5222. for (int index = 0; index < CCS_QUANTITY; index++)
  5223. {
  5224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5225. {
  5226. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5227. }
  5228. }// END OF CCS_QUANTITY
  5229. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5230. }
  5231. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5232. {
  5233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5234. {
  5235. tempIndex = ((gun_index==2) ? 1: 0);
  5236. }
  5237. else
  5238. {
  5239. tempIndex = gun_index;
  5240. }
  5241. for (int index = 0; index < GB_QUANTITY; index++)
  5242. {
  5243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5244. {
  5245. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5246. }
  5247. }// END OF GB_QUANTITY
  5248. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5249. }
  5250. else if(gunType[gun_index] == GUN_TYPE_DO)
  5251. {
  5252. tempIndex = gun_index;
  5253. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5254. {
  5255. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5256. {
  5257. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5258. }
  5259. }
  5260. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5261. }
  5262. else
  5263. {
  5264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5265. {
  5266. tempIndex = 2;
  5267. }
  5268. else
  5269. {
  5270. tempIndex = gun_index;
  5271. }
  5272. for (int index = 0; index < AC_QUANTITY; index++)
  5273. {
  5274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5275. {
  5276. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5277. }
  5278. }// END OF AC_QUANTITY
  5279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5280. }
  5281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5283. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5284. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5285. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5286. }
  5287. //=================================== Power.Active.Import ==================================================
  5288. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5289. {
  5290. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5291. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5292. {
  5293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5294. {
  5295. tempIndex = ((gun_index==2) ? 1: 0);
  5296. }
  5297. else
  5298. {
  5299. tempIndex = gun_index;
  5300. }
  5301. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5302. {
  5303. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5304. {
  5305. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5306. }
  5307. } // End for CHAdeMO_QUANTITY
  5308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5309. }
  5310. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5311. {
  5312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5313. {
  5314. tempIndex = ((gun_index==2) ? 1: 0);
  5315. }
  5316. else
  5317. {
  5318. tempIndex = gun_index;
  5319. }
  5320. for (int index = 0; index < CCS_QUANTITY; index++)
  5321. {
  5322. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5323. {
  5324. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5325. }
  5326. } // END for CCS_QUANTITY
  5327. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5328. }
  5329. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5330. {
  5331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5332. {
  5333. tempIndex = ((gun_index==2) ? 1: 0);
  5334. }
  5335. else
  5336. {
  5337. tempIndex = gun_index;
  5338. }
  5339. for (int index = 0; index < GB_QUANTITY; index++)
  5340. {
  5341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5342. {
  5343. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5344. }
  5345. }// END for GB_QUANTITY
  5346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5347. }
  5348. else if(gunType[gun_index] == GUN_TYPE_DO)
  5349. {
  5350. tempIndex = gun_index;
  5351. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5352. {
  5353. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5354. {
  5355. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5356. }
  5357. }
  5358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5359. }
  5360. else
  5361. {
  5362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5363. {
  5364. tempIndex = 2;
  5365. }
  5366. else
  5367. {
  5368. tempIndex = gun_index;
  5369. }
  5370. for (int index = 0; index < AC_QUANTITY; index++)
  5371. {
  5372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5373. {
  5374. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5375. }
  5376. } // END for AC_QUANTITY
  5377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5378. }
  5379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5382. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5383. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5384. }
  5385. //============================ Voltage L1 ====================================
  5386. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5387. {
  5388. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5389. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5390. {
  5391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5392. {
  5393. tempIndex = ((gun_index==2) ? 1: 0);
  5394. }
  5395. else
  5396. {
  5397. tempIndex = gun_index;
  5398. }
  5399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5400. {
  5401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5402. {
  5403. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5404. }
  5405. } // END OF FOR CHAdeMO_QUANTITY
  5406. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5407. }
  5408. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5409. {
  5410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5411. {
  5412. tempIndex = ((gun_index==2) ? 1: 0);
  5413. }
  5414. else
  5415. {
  5416. tempIndex = gun_index;
  5417. }
  5418. for (int index = 0; index < CCS_QUANTITY; index++)
  5419. {
  5420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5421. {
  5422. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5423. }
  5424. } // END OF FOR CCS_QUANTITY
  5425. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5426. }
  5427. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5428. {
  5429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5430. {
  5431. tempIndex = ((gun_index==2) ? 1: 0);
  5432. }
  5433. else
  5434. {
  5435. tempIndex = gun_index;
  5436. }
  5437. for (int index = 0; index < GB_QUANTITY; index++)
  5438. {
  5439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5440. {
  5441. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5442. }
  5443. } // END OF FOR GB_QUANTITY
  5444. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5445. }
  5446. else if(gunType[gun_index] == GUN_TYPE_DO)
  5447. {
  5448. tempIndex = gun_index;
  5449. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5450. {
  5451. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5452. {
  5453. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5454. }
  5455. }
  5456. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5457. }
  5458. else
  5459. {
  5460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5461. {
  5462. tempIndex = 2;
  5463. }
  5464. else
  5465. {
  5466. tempIndex = gun_index;
  5467. }
  5468. for (int index = 0; index < AC_QUANTITY; index++)
  5469. {
  5470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5471. {
  5472. 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
  5473. }
  5474. } // END OF FOR AC_QUANTITY
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5476. }
  5477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5482. }
  5483. //====================== End SoC ================================
  5484. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5485. {
  5486. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5487. 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))
  5488. {
  5489. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5490. {
  5491. tempIndex = ((gun_index==2) ? 1: 0);
  5492. }
  5493. else
  5494. {
  5495. tempIndex = gun_index;
  5496. }
  5497. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5498. {
  5499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5500. {
  5501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5502. {
  5503. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5504. }
  5505. }
  5506. }
  5507. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5508. {
  5509. for (int index = 0; index < CCS_QUANTITY; index++)
  5510. {
  5511. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5512. {
  5513. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5514. }
  5515. }
  5516. }
  5517. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5518. {
  5519. for (int index = 0; index < GB_QUANTITY; index++)
  5520. {
  5521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5522. {
  5523. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5524. }
  5525. }
  5526. }
  5527. else if(gunType[gun_index] == GUN_TYPE_DO)
  5528. {
  5529. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5532. {
  5533. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5534. }
  5535. }
  5536. }
  5537. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5539. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5540. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5541. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5542. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5543. } // END FOR DC CASE
  5544. }
  5545. // ================================= Current.Import L2 ===============================================
  5546. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5547. {
  5548. // AC 3 phse L2 current
  5549. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5550. {
  5551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5552. {
  5553. tempIndex = 2;
  5554. }
  5555. else
  5556. {
  5557. tempIndex = gun_index;
  5558. }
  5559. for (int index = 0; index < AC_QUANTITY; index++)
  5560. {
  5561. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5562. {
  5563. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5564. }
  5565. }// End of for AC_QUANTITY
  5566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5567. }
  5568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5571. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5573. }
  5574. // ================================= Current.Import L3 ===============================================
  5575. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5576. {
  5577. // AC 3 phse L3 current
  5578. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5579. {
  5580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5581. {
  5582. tempIndex = 2;
  5583. }
  5584. else
  5585. {
  5586. tempIndex = gun_index;
  5587. }
  5588. for (int index = 0; index < AC_QUANTITY; index++)
  5589. {
  5590. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5591. {
  5592. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5593. }
  5594. }// End of for AC_QUANTITY
  5595. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5596. }
  5597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5601. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5602. }
  5603. //============================ Voltage L2 ====================================
  5604. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5605. {
  5606. // AC 3 phse L2 voltage
  5607. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5608. {
  5609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5610. {
  5611. tempIndex = 2;
  5612. }
  5613. else
  5614. {
  5615. tempIndex = gun_index;
  5616. }
  5617. for (int index = 0; index < AC_QUANTITY; index++)
  5618. {
  5619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5620. {
  5621. 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
  5622. }
  5623. } // END OF FOR AC_QUANTITY
  5624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5625. }
  5626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5631. }
  5632. //============================ Voltage L3 ====================================
  5633. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5634. {
  5635. // AC 3 phse L3 voltage
  5636. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5637. {
  5638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5639. {
  5640. tempIndex = 2;
  5641. }
  5642. else
  5643. {
  5644. tempIndex = gun_index;
  5645. }
  5646. for (int index = 0; index < AC_QUANTITY; index++)
  5647. {
  5648. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5649. {
  5650. 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
  5651. }
  5652. } // END OF FOR AC_QUANTITY
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5654. }
  5655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5660. }
  5661. //====================== Start SoC ================================
  5662. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5663. {
  5664. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5665. 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))
  5666. {
  5667. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5668. {
  5669. tempIndex = ((gun_index==2) ? 1: 0);
  5670. }
  5671. else
  5672. {
  5673. tempIndex = gun_index;
  5674. }
  5675. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5676. {
  5677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5678. {
  5679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5680. {
  5681. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5682. }
  5683. }
  5684. }
  5685. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5686. {
  5687. for (int index = 0; index < CCS_QUANTITY; index++)
  5688. {
  5689. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5690. {
  5691. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5692. }
  5693. }
  5694. }
  5695. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5696. {
  5697. for (int index = 0; index < GB_QUANTITY; index++)
  5698. {
  5699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5700. {
  5701. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5702. }
  5703. }
  5704. }
  5705. else if(gunType[gun_index] == GUN_TYPE_DO)
  5706. {
  5707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5708. {
  5709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5710. {
  5711. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5712. }
  5713. }
  5714. }
  5715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5718. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5719. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5720. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5721. } // END FOR DC CASE
  5722. }
  5723. //================================================ Message create ====================================================
  5724. json_object *StopTransaction = json_object_new_object();
  5725. json_object *transactionDatas = json_object_new_array();
  5726. json_object *sampledValues = json_object_new_array();
  5727. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5728. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5729. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5730. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5731. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5732. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5733. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5734. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5735. {
  5736. json_object *transactionData = json_object_new_object();
  5737. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5738. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5739. {
  5740. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5741. {
  5742. json_object *sampledValue = json_object_new_object();
  5743. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5744. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5745. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5746. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5747. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5748. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5749. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5750. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5751. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5752. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5753. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5754. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5755. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5756. json_object_array_add(sampledValues, sampledValue);
  5757. }
  5758. }
  5759. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5760. json_object_array_add(transactionDatas, transactionData);
  5761. }
  5762. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5763. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5764. ,MESSAGE_TYPE_CALL
  5765. ,guid
  5766. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5767. json_object_put(StopTransaction);
  5768. #if 1 // for TempStopTransaction
  5769. //Delete TempStopTransaction
  5770. if((access(TempStopTransaction,F_OK))!=-1)
  5771. {
  5772. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5773. }
  5774. #endif
  5775. #if 1
  5776. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5777. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5778. {
  5779. result = PASS;
  5780. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5781. }
  5782. #endif
  5783. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5784. OCPP_insert_transaction_msg(NO, queuedata);
  5785. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5786. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5787. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5788. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5789. {
  5790. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5791. }
  5792. //for test
  5793. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5794. return result;
  5795. }
  5796. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5797. {
  5798. mtrace();
  5799. int result = FAIL;
  5800. char guid[37]={0};
  5801. char tempdata[65]={0};
  5802. int tempIndex = 0;
  5803. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5804. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5805. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5806. //set value
  5807. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5808. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5809. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5810. -1);
  5811. random_uuid(guid);
  5812. //UTC Date time
  5813. struct timeval tmnow;
  5814. struct tm *tm;
  5815. char buf[28];//, usec_buf[6];
  5816. gettimeofday(&tmnow, NULL);
  5817. time_t t;
  5818. t = time(NULL);
  5819. /*UTC time and date*/
  5820. tm = gmtime(&t);
  5821. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5823. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5824. //********************************(1)Current.Import L1************************************************/
  5825. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5826. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5827. (dataType == ReadingContext_Trigger))
  5828. {
  5829. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5830. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5831. {
  5832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5833. {
  5834. tempIndex = ((gun_index==2) ? 1: 0);
  5835. }
  5836. else
  5837. {
  5838. tempIndex = gun_index;
  5839. }
  5840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5841. {
  5842. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5843. {
  5844. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5845. }
  5846. }
  5847. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5848. }
  5849. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5850. {
  5851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5852. {
  5853. tempIndex = ((gun_index==2) ? 1: 0);
  5854. }
  5855. else
  5856. {
  5857. tempIndex = gun_index;
  5858. }
  5859. for (int index = 0; index < CCS_QUANTITY; index++)
  5860. {
  5861. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5862. {
  5863. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5864. }
  5865. }
  5866. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5867. }
  5868. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5869. {
  5870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5871. {
  5872. tempIndex = ((gun_index==2) ? 1: 0);
  5873. }
  5874. else
  5875. {
  5876. tempIndex = gun_index;
  5877. }
  5878. for (int index = 0; index < GB_QUANTITY; index++)
  5879. {
  5880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5881. {
  5882. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5883. }
  5884. }
  5885. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5886. }
  5887. else if(gunType[gun_index] == GUN_TYPE_DO)
  5888. {
  5889. tempIndex = gun_index;
  5890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5891. {
  5892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5893. {
  5894. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5895. }
  5896. }
  5897. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5898. }
  5899. else
  5900. {
  5901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5902. {
  5903. tempIndex = 2;
  5904. }
  5905. else
  5906. {
  5907. tempIndex = gun_index;
  5908. }
  5909. for (int index = 0; index < AC_QUANTITY; index++)
  5910. {
  5911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5912. {
  5913. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5914. }
  5915. }
  5916. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5917. }
  5918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5919. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5923. }
  5924. //********************************(2)Energy.Active.Import.Register ************************************************/
  5925. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5926. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5927. (dataType == ReadingContext_Trigger))
  5928. {
  5929. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5930. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5931. {
  5932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5933. {
  5934. tempIndex = ((gun_index==2) ? 1: 0);
  5935. }
  5936. else
  5937. {
  5938. tempIndex = gun_index;
  5939. }
  5940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5941. {
  5942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5943. {
  5944. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5945. }
  5946. }
  5947. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5948. }
  5949. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5950. {
  5951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5952. {
  5953. tempIndex = ((gun_index==2) ? 1: 0);
  5954. }
  5955. else
  5956. {
  5957. tempIndex = gun_index;
  5958. }
  5959. for (int index = 0; index < CCS_QUANTITY; index++)
  5960. {
  5961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5962. {
  5963. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5964. }
  5965. }
  5966. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5967. }
  5968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5969. {
  5970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5971. {
  5972. tempIndex = ((gun_index==2) ? 1: 0);
  5973. }
  5974. else
  5975. {
  5976. tempIndex = gun_index;
  5977. }
  5978. for (int index = 0; index < GB_QUANTITY; index++)
  5979. {
  5980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5981. {
  5982. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5983. }
  5984. }
  5985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5986. }
  5987. else if(gunType[gun_index] == GUN_TYPE_DO)
  5988. {
  5989. tempIndex = gun_index;
  5990. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5991. {
  5992. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5993. {
  5994. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5995. }
  5996. }
  5997. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5998. }
  5999. else
  6000. {
  6001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6002. {
  6003. tempIndex = 2;
  6004. }
  6005. else
  6006. {
  6007. tempIndex = gun_index;
  6008. }
  6009. for (int index = 0; index < AC_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6012. {
  6013. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6014. }
  6015. }
  6016. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6017. }
  6018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6022. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6023. }
  6024. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6025. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6026. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6027. (dataType == ReadingContext_Trigger))
  6028. {
  6029. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6030. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6031. {
  6032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6033. {
  6034. tempIndex = ((gun_index==2) ? 1: 0);
  6035. }
  6036. else
  6037. {
  6038. tempIndex = gun_index;
  6039. }
  6040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6045. }
  6046. } // END OF FOR CHAdeMO_QUANTITY
  6047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6048. }
  6049. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6050. {
  6051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6052. {
  6053. tempIndex = ((gun_index==2) ? 1: 0);
  6054. }
  6055. else
  6056. {
  6057. tempIndex = gun_index;
  6058. }
  6059. for (int index = 0; index < CCS_QUANTITY; index++)
  6060. {
  6061. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6062. {
  6063. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6064. }
  6065. } // END OF CCS_QUANTITY
  6066. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6067. }
  6068. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6069. {
  6070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6071. {
  6072. tempIndex = ((gun_index==2) ? 1: 0);
  6073. }
  6074. else
  6075. {
  6076. tempIndex = gun_index;
  6077. }
  6078. for (int index = 0; index < GB_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6081. {
  6082. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6083. }
  6084. } // END OF GB_QUANTITY
  6085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6086. }
  6087. else if(gunType[gun_index] == GUN_TYPE_DO)
  6088. {
  6089. tempIndex = gun_index;
  6090. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6093. {
  6094. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6095. }
  6096. }
  6097. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6098. }
  6099. else
  6100. {
  6101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6102. {
  6103. tempIndex = 2;
  6104. }
  6105. else
  6106. {
  6107. tempIndex = gun_index;
  6108. }
  6109. for (int index = 0; index < AC_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6112. {
  6113. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6114. }
  6115. }
  6116. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6117. }
  6118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6119. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6120. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6121. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6122. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6123. }
  6124. //********************************(4)Power.Active.Import************************************************/
  6125. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6126. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6127. (dataType == ReadingContext_Trigger))
  6128. {
  6129. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6130. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6131. {
  6132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6133. {
  6134. tempIndex = ((gun_index==2) ? 1: 0);
  6135. }
  6136. else
  6137. {
  6138. tempIndex = gun_index;
  6139. }
  6140. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6141. {
  6142. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6143. {
  6144. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6145. }
  6146. } // END OF FOR
  6147. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6148. }
  6149. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6150. {
  6151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6152. {
  6153. tempIndex = ((gun_index==2) ? 1: 0);
  6154. }
  6155. else
  6156. {
  6157. tempIndex = gun_index;
  6158. }
  6159. for (int index = 0; index < CCS_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6162. {
  6163. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6164. }
  6165. }
  6166. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6167. }
  6168. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6169. {
  6170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6171. {
  6172. tempIndex = ((gun_index==2) ? 1: 0);
  6173. }
  6174. else
  6175. {
  6176. tempIndex = gun_index;
  6177. }
  6178. for (int index = 0; index < GB_QUANTITY; index++)
  6179. {
  6180. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6181. {
  6182. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6183. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6184. }
  6185. }
  6186. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6187. }
  6188. else if(gunType[gun_index] == GUN_TYPE_DO)
  6189. {
  6190. tempIndex = gun_index;
  6191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6192. {
  6193. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6194. {
  6195. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6196. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6197. }
  6198. }
  6199. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6200. }
  6201. else
  6202. {
  6203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6204. {
  6205. tempIndex = 2;
  6206. }
  6207. else
  6208. {
  6209. tempIndex = gun_index;
  6210. }
  6211. for (int index = 0; index < AC_QUANTITY; index++)
  6212. {
  6213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6214. {
  6215. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6216. }
  6217. }
  6218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6219. }
  6220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6221. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6222. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6223. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6224. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6225. }
  6226. //***********************************************(5)VOLTAGE L1******************************************************/
  6227. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6228. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6229. (dataType == ReadingContext_Trigger))
  6230. {
  6231. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6232. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6233. {
  6234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6235. {
  6236. tempIndex = ((gun_index==2) ? 1: 0);
  6237. }
  6238. else
  6239. {
  6240. tempIndex = gun_index;
  6241. }
  6242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6243. {
  6244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6245. {
  6246. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6247. }
  6248. }
  6249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6250. }
  6251. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6252. {
  6253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6254. {
  6255. tempIndex = ((gun_index==2) ? 1: 0);
  6256. }
  6257. else
  6258. {
  6259. tempIndex = gun_index;
  6260. }
  6261. for (int index = 0; index < CCS_QUANTITY; index++)
  6262. {
  6263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6264. {
  6265. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6266. }
  6267. }
  6268. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6269. }
  6270. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6271. {
  6272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6273. {
  6274. tempIndex = ((gun_index==2) ? 1: 0);
  6275. }
  6276. else
  6277. {
  6278. tempIndex = gun_index;
  6279. }
  6280. for (int index = 0; index < GB_QUANTITY; index++)
  6281. {
  6282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6283. {
  6284. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6285. }
  6286. }
  6287. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6288. }
  6289. else if(gunType[gun_index] == GUN_TYPE_DO)
  6290. {
  6291. tempIndex = gun_index;
  6292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6293. {
  6294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6295. {
  6296. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6297. }
  6298. }
  6299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6300. }
  6301. else
  6302. {
  6303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6304. {
  6305. tempIndex = 2;
  6306. }
  6307. else
  6308. {
  6309. tempIndex = gun_index;
  6310. }
  6311. for (int index = 0; index < AC_QUANTITY; index++)
  6312. {
  6313. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6314. {
  6315. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6316. }
  6317. }
  6318. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6319. }
  6320. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6321. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6322. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6323. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6324. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6325. }
  6326. //***********************************************(6)SOC******************************************************/
  6327. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6328. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6329. (dataType == ReadingContext_Trigger))
  6330. {
  6331. 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))
  6332. {
  6333. //idx_sample=5;
  6334. //sampledValue = NULL;
  6335. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6336. {
  6337. tempIndex = ((gun_index==2) ? 1: 0);
  6338. }
  6339. else
  6340. {
  6341. tempIndex = gun_index;
  6342. }
  6343. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6344. {
  6345. //tempIndex = ((gun_index==2) ? 1: 0);
  6346. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6347. {
  6348. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6349. {
  6350. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6351. }
  6352. }
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6355. {
  6356. //tempIndex = ((gun_index==2) ? 1: 0);
  6357. for (int index = 0; index < CCS_QUANTITY; index++)
  6358. {
  6359. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6360. {
  6361. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6362. }
  6363. }
  6364. }
  6365. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6366. {
  6367. //tempIndex = ((gun_index==2) ? 1: 0);
  6368. for (int index = 0; index < GB_QUANTITY; index++)
  6369. {
  6370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6371. {
  6372. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6373. }
  6374. }
  6375. }
  6376. else if(gunType[gun_index] == GUN_TYPE_DO)
  6377. {
  6378. //tempIndex = ((gun_index==2) ? 1: 0);
  6379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6380. {
  6381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6382. {
  6383. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6384. }
  6385. }
  6386. }
  6387. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6388. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6389. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6390. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6391. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6392. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6393. }
  6394. }
  6395. //********************************(7)Current.Import L2************************************************/
  6396. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6397. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6398. (dataType == ReadingContext_Trigger))
  6399. {
  6400. // Only for AC 3 phase
  6401. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6402. {
  6403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6404. {
  6405. tempIndex = 2;
  6406. }
  6407. else
  6408. {
  6409. tempIndex = gun_index;
  6410. }
  6411. for (int index = 0; index < AC_QUANTITY; index++)
  6412. {
  6413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6414. {
  6415. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6416. }
  6417. }
  6418. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6419. }
  6420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6422. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6423. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6425. }
  6426. //********************************(8)Current.Import L3************************************************/
  6427. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6428. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6429. (dataType == ReadingContext_Trigger))
  6430. {
  6431. // Only for AC 3 phase
  6432. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6433. {
  6434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6435. {
  6436. tempIndex = 2;
  6437. }
  6438. else
  6439. {
  6440. tempIndex = gun_index;
  6441. }
  6442. for (int index = 0; index < AC_QUANTITY; index++)
  6443. {
  6444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6445. {
  6446. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6447. }
  6448. }
  6449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6450. }
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6456. }
  6457. //***********************************************(9)VOLTAGE L2******************************************************/
  6458. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6459. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6460. (dataType == ReadingContext_Trigger))
  6461. {
  6462. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6463. {
  6464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6465. {
  6466. tempIndex = 2;
  6467. }
  6468. else
  6469. {
  6470. tempIndex = gun_index;
  6471. }
  6472. for (int index = 0; index < AC_QUANTITY; index++)
  6473. {
  6474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6475. {
  6476. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6477. }
  6478. }
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6480. }
  6481. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6483. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6484. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6485. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6486. }
  6487. //***********************************************(10)VOLTAGE L3******************************************************/
  6488. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6489. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6490. (dataType == ReadingContext_Trigger))
  6491. {
  6492. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6493. {
  6494. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6495. {
  6496. tempIndex = 2;
  6497. }
  6498. else
  6499. {
  6500. tempIndex = gun_index;
  6501. }
  6502. for (int index = 0; index < AC_QUANTITY; index++)
  6503. {
  6504. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6505. {
  6506. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6507. }
  6508. }
  6509. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6510. }
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6513. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6514. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6515. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6516. }
  6517. //***********************************************(11)Current.Offered******************************************************/
  6518. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6519. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6520. (dataType == ReadingContext_Trigger))
  6521. {
  6522. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6523. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6524. {
  6525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6526. {
  6527. tempIndex = ((gun_index==2) ? 1: 0);
  6528. }
  6529. else
  6530. {
  6531. tempIndex = gun_index;
  6532. }
  6533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6534. {
  6535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6536. {
  6537. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6538. }
  6539. } // END OF FOR CHAdeMO_QUANTITY
  6540. }
  6541. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6542. {
  6543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6544. {
  6545. tempIndex = ((gun_index==2) ? 1: 0);
  6546. }
  6547. else
  6548. {
  6549. tempIndex = gun_index;
  6550. }
  6551. for (int index = 0; index < CCS_QUANTITY; index++)
  6552. {
  6553. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6554. {
  6555. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6556. }
  6557. } // END OF CCS_QUANTITY
  6558. }
  6559. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6560. {
  6561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6562. {
  6563. tempIndex = ((gun_index==2) ? 1: 0);
  6564. }
  6565. else
  6566. {
  6567. tempIndex = gun_index;
  6568. }
  6569. for (int index = 0; index < GB_QUANTITY; index++)
  6570. {
  6571. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6572. {
  6573. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6574. }
  6575. } // END OF GB_QUANTITY
  6576. }
  6577. else if(gunType[gun_index] == GUN_TYPE_DO)
  6578. {
  6579. tempIndex = gun_index;
  6580. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6581. {
  6582. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6583. {
  6584. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6585. }
  6586. }
  6587. }
  6588. else
  6589. {
  6590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6591. {
  6592. tempIndex = 2;
  6593. }
  6594. else
  6595. {
  6596. tempIndex = gun_index;
  6597. }
  6598. for (int index = 0; index < AC_QUANTITY; index++)
  6599. {
  6600. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6601. {
  6602. uint16_t currentOffer;
  6603. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6604. {
  6605. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6606. }
  6607. else
  6608. {
  6609. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6610. }
  6611. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6612. }
  6613. }
  6614. }
  6615. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6616. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6617. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6618. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6619. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6620. }
  6621. //***********************************************(12)Power.Offered******************************************************/
  6622. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6623. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6624. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6625. {
  6626. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6627. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6628. {
  6629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6630. {
  6631. tempIndex = ((gun_index==2) ? 1: 0);
  6632. }
  6633. else
  6634. {
  6635. tempIndex = gun_index;
  6636. }
  6637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6638. {
  6639. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6640. {
  6641. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6642. }
  6643. } // END OF FOR CHAdeMO_QUANTITY
  6644. }
  6645. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6646. {
  6647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6648. {
  6649. tempIndex = ((gun_index==2) ? 1: 0);
  6650. }
  6651. else
  6652. {
  6653. tempIndex = gun_index;
  6654. }
  6655. for (int index = 0; index < CCS_QUANTITY; index++)
  6656. {
  6657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6658. {
  6659. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6660. }
  6661. } // END OF CCS_QUANTITY
  6662. }
  6663. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6664. {
  6665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6666. {
  6667. tempIndex = ((gun_index==2) ? 1: 0);
  6668. }
  6669. else
  6670. {
  6671. tempIndex = gun_index;
  6672. }
  6673. for (int index = 0; index < GB_QUANTITY; index++)
  6674. {
  6675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6676. {
  6677. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6678. }
  6679. } // END OF GB_QUANTITY
  6680. }
  6681. else if(gunType[gun_index] == GUN_TYPE_DO)
  6682. {
  6683. tempIndex = gun_index;
  6684. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6685. {
  6686. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6687. {
  6688. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6689. }
  6690. }
  6691. }
  6692. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6693. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6694. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6695. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6696. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6697. }
  6698. // Message create ====================================================================================================
  6699. if(TRUE)
  6700. {
  6701. json_object *MeterValueReq = json_object_new_object();
  6702. json_object *MeterValues = json_object_new_array();
  6703. json_object *sampledValues = json_object_new_array();
  6704. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6705. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6706. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6707. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6708. {
  6709. json_object *MeterValue = json_object_new_object();
  6710. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6711. {
  6712. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6713. {
  6714. json_object *sampledValue = json_object_new_object();
  6715. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6716. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6717. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6718. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6719. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6720. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6721. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6722. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6723. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6724. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6725. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6726. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6727. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6728. json_object_array_add(sampledValues, sampledValue);
  6729. }
  6730. }
  6731. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6732. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6733. json_object_array_add(MeterValues, MeterValue);
  6734. }
  6735. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6736. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6737. ,gun_index + 1
  6738. ,MESSAGE_TYPE_CALL
  6739. ,guid
  6740. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6741. json_object_put(MeterValueReq);
  6742. }
  6743. // Put request guid to hash map
  6744. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6745. 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*/)
  6746. {
  6747. result = PASS;
  6748. //DEBUG_INFO("MeterValues mapitem pass\n");
  6749. }
  6750. if((dataType != ReadingContext_Trigger) &&
  6751. (dataType != ReadingContext_Sample_Clock) &&
  6752. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6753. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6754. else
  6755. {
  6756. if(FirstHeartBeat)
  6757. LWS_Send(queuedata +2);
  6758. }
  6759. return result;
  6760. }
  6761. int sendLogStatusNotificationRequest(char *status)
  6762. {
  6763. mtrace();
  6764. int result = PASS;
  6765. char message[4096]={0};
  6766. char guid[37]={0};
  6767. char tempdata[128]={0};
  6768. json_object *LogStatusNotification = json_object_new_object();
  6769. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6770. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6771. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6772. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6773. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6774. random_uuid(guid);
  6775. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6776. json_object_put(LogStatusNotification);
  6777. LWS_Send(message);
  6778. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6779. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6780. {
  6781. result = PASS;
  6782. }
  6783. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6784. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6785. return result;
  6786. }
  6787. int sendSecurityEventNotificationRequest()
  6788. {
  6789. mtrace();
  6790. int result = PASS;
  6791. char message[4096]={0};
  6792. char guid[37]={0};
  6793. char tempdata[128]={0};
  6794. json_object *SecurityEventNotification = json_object_new_object();
  6795. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6796. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6797. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6798. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6799. random_uuid(guid);
  6800. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6801. json_object_put(SecurityEventNotification);
  6802. LWS_Send(message);
  6803. sprintf(tempdata, "SecurityEventNotification,0");
  6804. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6805. {
  6806. result = PASS;
  6807. }
  6808. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6809. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6810. return result;
  6811. }
  6812. int sendSignCertificateRequest()
  6813. {
  6814. mtrace();
  6815. int result = PASS;
  6816. char message[4096]={0};
  6817. char guid[37]={0};
  6818. char tempdata[128]={0};
  6819. json_object *SignCertificate = json_object_new_object();
  6820. DEBUG_INFO("sendSignCertificateRequest...\n");
  6821. // Read csr file content
  6822. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6823. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6824. char *line = NULL;
  6825. size_t len = 0;
  6826. while(getline(&line, &len, fp) != -1)
  6827. {
  6828. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6829. {
  6830. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6831. }
  6832. }
  6833. fclose(fp);
  6834. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6835. random_uuid(guid);
  6836. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6837. json_object_put(SignCertificate);
  6838. LWS_Send(message);
  6839. sprintf(tempdata, "SignCertificate,0");
  6840. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6841. {
  6842. result = PASS;
  6843. }
  6844. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6845. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6846. return result;
  6847. }
  6848. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6849. {
  6850. mtrace();
  6851. int result = PASS;
  6852. char message[110]={0};
  6853. char guid[37]={0};
  6854. char tempdata[65]={0};
  6855. json_object *FirmwareStatusNotification = json_object_new_object();
  6856. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6857. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6858. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6859. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6860. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6861. random_uuid(guid);
  6862. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6863. json_object_put(FirmwareStatusNotification);
  6864. LWS_Send(message);
  6865. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6866. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6867. {
  6868. result = PASS;
  6869. }
  6870. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6871. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6872. return result;
  6873. }
  6874. //==========================================
  6875. // send confirm routine
  6876. //==========================================
  6877. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6878. {
  6879. mtrace();
  6880. int result = FAIL;
  6881. char message[100]={0};
  6882. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6883. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6884. LWS_Send(message);
  6885. result = TRUE;
  6886. return result;
  6887. }
  6888. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6889. {
  6890. mtrace();
  6891. int result = FAIL;
  6892. char message[100]={0};
  6893. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6894. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6895. LWS_Send(message);
  6896. result = TRUE;
  6897. return result;
  6898. }
  6899. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6900. {
  6901. mtrace();
  6902. int result = FAIL;
  6903. char message[100]={0};
  6904. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6905. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6906. LWS_Send(message);
  6907. result = TRUE;
  6908. return result;
  6909. }
  6910. int sendClearCacheConfirmation(char *uuid,char *payload)
  6911. {
  6912. mtrace();
  6913. int result = FAIL;
  6914. char message[500]={0};
  6915. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6916. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6917. LWS_Send(message);
  6918. return result;
  6919. }
  6920. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6921. {
  6922. mtrace();
  6923. int result = FAIL;
  6924. char message[500]={0};
  6925. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6926. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6927. LWS_Send(message);
  6928. return result;
  6929. }
  6930. int sendDataTransferConfirmation(char *uuid,char *payload)
  6931. {
  6932. mtrace();
  6933. char statusStr[20]={0};
  6934. char dataStr[10]={0};
  6935. char sstr[20]={0};
  6936. int c = 0;
  6937. char *loc;
  6938. int result = FAIL;
  6939. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6940. /**********************status**************************/
  6941. loc = strstr(payload, "status");
  6942. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6943. c = 0;
  6944. while (loc[3+strlen("status")+c] != '\"')
  6945. {
  6946. sstr[c] = loc[3+strlen("status")+c];
  6947. c++;
  6948. }
  6949. sstr[c] = '\0';
  6950. strcpy(statusStr, sstr);
  6951. /**********************data**************************/
  6952. loc = strstr(payload, "data");
  6953. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6954. c = 0;
  6955. while (loc[3+strlen("data")+c] != '\"')
  6956. {
  6957. sstr[c] = loc[3+strlen("data")+c];
  6958. c++;
  6959. }
  6960. sstr[c] = '\0';
  6961. strcpy(dataStr, sstr);
  6962. return result;
  6963. }
  6964. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6965. {
  6966. mtrace();
  6967. int result = FAIL;
  6968. char message[1000]={0};
  6969. int CompositeScheduleIndex = 0;
  6970. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6971. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6972. if(nPeriod == 0)
  6973. {
  6974. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6975. {
  6976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6977. ,MESSAGE_TYPE_CALLRESULT
  6978. ,uuid
  6979. ,payload
  6980. ,connectorIdInt);
  6981. }
  6982. else
  6983. {
  6984. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6985. ,MESSAGE_TYPE_CALLRESULT
  6986. ,uuid
  6987. ,payload
  6988. ,connectorIdInt
  6989. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6990. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6991. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6992. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6993. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6994. }
  6995. }
  6996. else
  6997. {
  6998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6999. ,MESSAGE_TYPE_CALLRESULT
  7000. ,uuid
  7001. ,payload
  7002. ,connectorIdInt
  7003. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7004. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7005. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7006. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7007. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7008. {
  7009. if (idx_sample == 0)
  7010. {
  7011. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7012. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7013. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7014. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7015. }
  7016. else
  7017. {
  7018. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7019. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7020. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7021. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7022. }
  7023. }
  7024. sprintf(message + strlen(message), "]}}]");
  7025. }
  7026. LWS_Send(message);
  7027. result = TRUE;
  7028. return result;
  7029. }
  7030. int sendGetConfigurationConfirmation(char *uuid)
  7031. {
  7032. mtrace();
  7033. int result = FAIL;
  7034. int MaxKeySupported = 0;
  7035. int sentConfigurationNumber= 0;
  7036. int sentunConfigurationNumber= 0;
  7037. char message[1024*10]={0};
  7038. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7039. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7040. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7041. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7042. ,MESSAGE_TYPE_CALLRESULT
  7043. ,uuid );
  7044. //configuration key
  7045. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7046. {
  7047. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7048. {
  7049. if (sentConfigurationNumber == 0)
  7050. {
  7051. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7052. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7053. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7054. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7055. }
  7056. else
  7057. {
  7058. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7059. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7060. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7061. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7062. }
  7063. sentConfigurationNumber = sentConfigurationNumber + 1;
  7064. }
  7065. }
  7066. sprintf(message + strlen(message), "]");
  7067. if(UnknownKeynum != 0)
  7068. {
  7069. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7070. //unkown key
  7071. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7072. {
  7073. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7074. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7075. if(sentunConfigurationNumber == 0)
  7076. {
  7077. sprintf(message + strlen(message), "\"%s\""
  7078. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7079. }
  7080. else
  7081. {
  7082. sprintf(message + strlen(message), ",\"%s\""
  7083. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7084. }
  7085. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7086. }
  7087. sprintf(message + strlen(message), "]");
  7088. }
  7089. sprintf(message + strlen(message), "}]");
  7090. LWS_Send(message);
  7091. return result;
  7092. }
  7093. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7094. {
  7095. mtrace();
  7096. int result = FAIL;
  7097. char message[400]={0};
  7098. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7099. if(strcmp(payload,"")==0)
  7100. {
  7101. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7102. }
  7103. else
  7104. {
  7105. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7106. }
  7107. LWS_Send(message);
  7108. result = TRUE;
  7109. return result;
  7110. }
  7111. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7112. {
  7113. mtrace();
  7114. int result = FAIL;
  7115. char message[80]={0};
  7116. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7117. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7118. LWS_Send(message);
  7119. result = TRUE;
  7120. return result;
  7121. }
  7122. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7123. {
  7124. mtrace();
  7125. int result = FAIL;
  7126. char message[80]={0};
  7127. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7128. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7129. LWS_Send(message);
  7130. result = TRUE;
  7131. return result;
  7132. }
  7133. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7134. {
  7135. mtrace();
  7136. int result = FAIL;
  7137. char message[80]={0};
  7138. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7139. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7140. LWS_Send(message);
  7141. result = TRUE;
  7142. return result;
  7143. }
  7144. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7145. {
  7146. mtrace();
  7147. int result = FAIL;
  7148. char message[80]={0};
  7149. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7150. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7151. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7152. LWS_Send(message);
  7153. result = TRUE;
  7154. return result;
  7155. }
  7156. int sendResetConfirmation(char *uuid,char *payload)
  7157. {
  7158. mtrace();
  7159. int result = FAIL;
  7160. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7161. char message[80]={0};
  7162. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7163. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7164. LWS_Send(message);
  7165. result = TRUE;
  7166. return result;
  7167. }
  7168. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7169. {
  7170. mtrace();
  7171. int result = FAIL;
  7172. char message[500]={0};
  7173. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7174. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7175. LWS_Send(message);
  7176. result = TRUE;
  7177. return result;
  7178. }
  7179. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7180. {
  7181. mtrace();
  7182. int result = FAIL;
  7183. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7184. char message[80]={0};
  7185. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7186. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7187. LWS_Send(message);
  7188. result = TRUE;
  7189. return result;
  7190. }
  7191. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7192. {
  7193. mtrace();
  7194. int result = FAIL;
  7195. char message[80]={0};
  7196. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7197. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7198. LWS_Send(message);
  7199. result = TRUE;
  7200. return result;
  7201. }
  7202. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7203. {
  7204. mtrace();
  7205. int result = FAIL;
  7206. char message[80]={0};
  7207. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7208. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7209. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7210. LWS_Send(message);
  7211. result = TRUE;
  7212. return result;
  7213. }
  7214. int sendUpdateFirmwareConfirmation(char *uuid)
  7215. {
  7216. mtrace();
  7217. int result = FAIL;
  7218. char message[60]={0};
  7219. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7220. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7221. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7222. LWS_Send(message);
  7223. result = TRUE;
  7224. return result;
  7225. }
  7226. int sendCertificateSignedConfirmation(char *uuid)
  7227. {
  7228. mtrace();
  7229. int result = PASS;
  7230. char message[4096]={0};
  7231. json_object *CertificateSigned = json_object_new_object();
  7232. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7233. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7234. sprintf(message,"[%d,\"%s\",%s]"
  7235. ,MESSAGE_TYPE_CALLRESULT
  7236. ,uuid
  7237. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7238. json_object_put(CertificateSigned);
  7239. LWS_Send(message);
  7240. return result;
  7241. }
  7242. int sendDeleteCertificateConfirmation(char *uuid)
  7243. {
  7244. mtrace();
  7245. int result = PASS;
  7246. char message[4096]={0};
  7247. json_object *DeleteCertificate = json_object_new_object();
  7248. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7249. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7250. sprintf(message,"[%d,\"%s\",%s]"
  7251. ,MESSAGE_TYPE_CALLRESULT
  7252. ,uuid
  7253. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7254. json_object_put(DeleteCertificate);
  7255. LWS_Send(message);
  7256. return result;
  7257. }
  7258. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7259. {
  7260. mtrace();
  7261. int result = PASS;
  7262. char message[4096]={0};
  7263. json_object *ExtendedTriggerMessage = json_object_new_object();
  7264. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7265. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7266. sprintf(message,"[%d,\"%s\",%s]"
  7267. ,MESSAGE_TYPE_CALLRESULT
  7268. ,uuid
  7269. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7270. json_object_put(ExtendedTriggerMessage);
  7271. LWS_Send(message);
  7272. return result;
  7273. }
  7274. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7275. {
  7276. mtrace();
  7277. int result = PASS;
  7278. char message[4096]={0};
  7279. json_object *GetInstalledCertificateIds = json_object_new_object();
  7280. json_object *certificateHashDataDatas = json_object_new_array();
  7281. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7282. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7283. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7284. {
  7285. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7286. {
  7287. json_object *certificateHashData = json_object_new_object();
  7288. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7289. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7290. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7291. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7292. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7293. }
  7294. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7295. }
  7296. else
  7297. {
  7298. json_object_put(certificateHashDataDatas);
  7299. }
  7300. sprintf(message,"[%d,\"%s\",%s]"
  7301. ,MESSAGE_TYPE_CALLRESULT
  7302. ,uuid
  7303. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7304. json_object_put(GetInstalledCertificateIds);
  7305. LWS_Send(message);
  7306. return result;
  7307. }
  7308. int sendGetLogConfirmation(char *uuid)
  7309. {
  7310. mtrace();
  7311. int result = PASS;
  7312. char message[4096]={0};
  7313. json_object *GetLog = json_object_new_object();
  7314. DEBUG_INFO("sendGetLogConfirmation...\n");
  7315. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7316. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7317. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7318. sprintf(message,"[%d,\"%s\",%s]"
  7319. ,MESSAGE_TYPE_CALLRESULT
  7320. ,uuid
  7321. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7322. json_object_put(GetLog);
  7323. LWS_Send(message);
  7324. return result;
  7325. }
  7326. int sendInstallCertificateConfirmation(char *uuid)
  7327. {
  7328. mtrace();
  7329. int result = PASS;
  7330. char message[4096]={0};
  7331. json_object *InstallCertificate = json_object_new_object();
  7332. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7333. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7334. sprintf(message,"[%d,\"%s\",%s]"
  7335. ,MESSAGE_TYPE_CALLRESULT
  7336. ,uuid
  7337. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7338. json_object_put(InstallCertificate);
  7339. LWS_Send(message);
  7340. return result;
  7341. }
  7342. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7343. {
  7344. mtrace();
  7345. int result = PASS;
  7346. char message[4096]={0};
  7347. json_object *SignedUpdateFirmware = json_object_new_object();
  7348. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7349. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7350. sprintf(message,"[%d,\"%s\",%s]"
  7351. ,MESSAGE_TYPE_CALLRESULT
  7352. ,uuid
  7353. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7354. json_object_put(SignedUpdateFirmware);
  7355. LWS_Send(message);
  7356. return result;
  7357. }
  7358. int sendUnknownConfirmation(char *uuid)
  7359. {
  7360. mtrace();
  7361. int result = PASS;
  7362. char message[256]={0};
  7363. DEBUG_INFO("sendUnknownConfirmation...\n");
  7364. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7365. LWS_Send(message);
  7366. return result;
  7367. }
  7368. //==========================================
  7369. // Handle server request routine Start
  7370. //==========================================
  7371. int handleCancelReservationRequest(char *uuid, char *payload)
  7372. {
  7373. mtrace();
  7374. int result = FAIL;
  7375. int gunNO = 0;
  7376. int reservationIdInt = -1;
  7377. char comfirmstr[20];
  7378. DEBUG_INFO("handleCancelReservationRequest...\n");
  7379. json_object *CancelReservation;
  7380. CancelReservation = json_tokener_parse(payload);
  7381. if(!is_error(CancelReservation))
  7382. {
  7383. // Required data
  7384. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7385. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7386. }
  7387. json_object_put(CancelReservation);
  7388. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7389. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7390. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7391. if(reservationIdInt != -1)
  7392. {
  7393. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7394. //check Transaction active
  7395. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7397. {
  7398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7399. {
  7400. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7401. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7402. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7403. {
  7404. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7405. }
  7406. else
  7407. {
  7408. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7409. }
  7410. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7411. goto end;
  7412. }
  7413. }
  7414. for (int index = 0; index < CCS_QUANTITY; index++)
  7415. {
  7416. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7417. {
  7418. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7419. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7420. if(gunType[2] == GUN_TYPE_CCS)
  7421. {
  7422. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7423. }
  7424. else
  7425. {
  7426. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7427. }
  7428. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7429. goto end;
  7430. }
  7431. }
  7432. for (int index = 0; index < GB_QUANTITY; index++)
  7433. {
  7434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7435. {
  7436. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7437. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7438. if(gunType[2] == GUN_TYPE_GBT)
  7439. {
  7440. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7441. }
  7442. else
  7443. {
  7444. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7445. }
  7446. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7447. goto end;
  7448. }
  7449. }
  7450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7451. {
  7452. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7453. {
  7454. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7455. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7456. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7457. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7458. goto end;
  7459. }
  7460. }
  7461. for (int index = 0; index < AC_QUANTITY; index++)
  7462. {
  7463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7464. {
  7465. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7466. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7468. {
  7469. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7470. }
  7471. else
  7472. {
  7473. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7474. }
  7475. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7476. goto end;
  7477. }
  7478. }
  7479. }
  7480. //The reservationId does NOT match the reservationId
  7481. sendCancelReservationConfirmation(uuid, comfirmstr);
  7482. end:
  7483. // Fill in ocpp packet uuid
  7484. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7485. return result;
  7486. }
  7487. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7488. {
  7489. mtrace();
  7490. int result = FAIL;
  7491. int gunIndex = -1;
  7492. char typeStr[16]={0};
  7493. char comfirmstr[20];
  7494. int specificId = FALSE;
  7495. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7496. json_object *ChangeAvailability;
  7497. ChangeAvailability = json_tokener_parse(payload);
  7498. if(!is_error(ChangeAvailability))
  7499. {
  7500. // Required data
  7501. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7502. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7503. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7504. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7505. }
  7506. json_object_put(ChangeAvailability);
  7507. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7508. {
  7509. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7510. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7511. }
  7512. else if(gunIndex == 0)
  7513. {
  7514. for(int i=0; i < gunTotalNumber; i++)
  7515. {
  7516. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7517. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7518. }
  7519. }
  7520. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7522. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7523. {
  7524. specificId = TRUE;
  7525. }
  7526. if(specificId == FALSE)
  7527. goto end;
  7528. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7529. {
  7530. //----------------------gunIndex is 0 ------------------------------------------------//
  7531. if(gunIndex == 0)
  7532. {
  7533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7534. {
  7535. for(int i=0; i < gunTotalNumber; i++)
  7536. {
  7537. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7538. {
  7539. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7540. {
  7541. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7542. {
  7543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7544. goto end;
  7545. }
  7546. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7547. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7548. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7549. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7550. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7551. {
  7552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7553. goto end;
  7554. }
  7555. }
  7556. }//END FOR CHAdeMO_QUANTITY
  7557. for (int index = 0; index < CCS_QUANTITY; index++)
  7558. {
  7559. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7560. {
  7561. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7562. {
  7563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7564. goto end;
  7565. }
  7566. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7567. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7568. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7569. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7570. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7571. {
  7572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7573. goto end;
  7574. }
  7575. }
  7576. }//END FOR CCS_QUANTITY
  7577. for (int index = 0; index < GB_QUANTITY; index++)
  7578. {
  7579. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7580. {
  7581. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7582. {
  7583. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7584. goto end;
  7585. }
  7586. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7590. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7591. {
  7592. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7593. goto end;
  7594. }
  7595. }
  7596. }// END FOR GB_QUANTITY
  7597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7598. {
  7599. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7600. {
  7601. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7602. {
  7603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7604. goto end;
  7605. }
  7606. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7608. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7609. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7610. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7611. {
  7612. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7613. goto end;
  7614. }
  7615. }
  7616. }// END FOR GENERAL_GUN_QUANTITY
  7617. for (int index = 0; index < AC_QUANTITY; index++)
  7618. {
  7619. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7620. {
  7621. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7622. {
  7623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7624. goto end;
  7625. }
  7626. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7628. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7629. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7630. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7631. {
  7632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7633. goto end;
  7634. }
  7635. }
  7636. }//END FOR AC_QUANTITY
  7637. }// END FOR gunTotalNumber
  7638. }
  7639. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7640. {
  7641. for(int i=0; i < gunTotalNumber; i++)
  7642. {
  7643. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7644. {
  7645. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7646. goto end;
  7647. }
  7648. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7649. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7651. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7652. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7653. {
  7654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7655. goto end;
  7656. }
  7657. }
  7658. }
  7659. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7660. goto end;
  7661. }
  7662. //----------------------gunIndex is not 0 ------------------------------------------------//
  7663. //check Transaction active
  7664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7665. {
  7666. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7667. {
  7668. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7669. {
  7670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7671. goto end;
  7672. }
  7673. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7676. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7677. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7678. {
  7679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7680. goto end;
  7681. }
  7682. else
  7683. {
  7684. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7686. goto end;
  7687. }
  7688. }
  7689. }//END FOR CHAdeMO_QUANTITY
  7690. for (int index = 0; index < CCS_QUANTITY; index++)
  7691. {
  7692. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7693. {
  7694. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7695. {
  7696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7697. goto end;
  7698. }
  7699. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7700. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7701. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7702. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7703. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7704. {
  7705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7706. goto end;
  7707. }
  7708. else
  7709. {
  7710. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7712. goto end;
  7713. }
  7714. }
  7715. }//END FOR CCS_QUANTITY
  7716. for (int index = 0; index < GB_QUANTITY; index++)
  7717. {
  7718. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7719. {
  7720. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7721. {
  7722. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7723. goto end;
  7724. }
  7725. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7726. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7727. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7728. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7729. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7730. {
  7731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7732. goto end;
  7733. }
  7734. else
  7735. {
  7736. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7738. goto end;
  7739. }
  7740. }
  7741. }// END FOR GB_QUANTITY
  7742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7743. {
  7744. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7745. {
  7746. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7747. {
  7748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7749. goto end;
  7750. }
  7751. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7754. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7755. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7756. {
  7757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7758. goto end;
  7759. }
  7760. else
  7761. {
  7762. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7763. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7764. goto end;
  7765. }
  7766. }
  7767. }// END FOR GENERAL_GUN_QUANTITY
  7768. for (int index = 0; index < AC_QUANTITY; index++)
  7769. {
  7770. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7771. {
  7772. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7773. {
  7774. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7775. goto end;
  7776. }
  7777. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7779. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7780. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7781. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7782. {
  7783. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7784. goto end;
  7785. }
  7786. else
  7787. {
  7788. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7789. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7790. goto end;
  7791. }
  7792. }
  7793. }//END FOR AC_QUANTITY
  7794. }//END FOR AvailabilityTypeStr[Inoperative]
  7795. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7796. {
  7797. //----------------------gunIndex is 0 ------------------------------------------------//
  7798. if(gunIndex == 0)
  7799. {
  7800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7801. {
  7802. for(int i=0; i < gunTotalNumber; i++)
  7803. {
  7804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7805. {
  7806. 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
  7807. {
  7808. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7809. goto end;
  7810. }
  7811. }//END FOR CHAdeMO_QUANTITY
  7812. for (int index = 0; index < CCS_QUANTITY; index++)
  7813. {
  7814. 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
  7815. {
  7816. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7817. goto end;
  7818. }
  7819. }//END FOR CCS_QUANTITY
  7820. for (int index = 0; index < GB_QUANTITY; index++)
  7821. {
  7822. 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
  7823. {
  7824. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7825. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7826. goto end;
  7827. }
  7828. }// END FOR GB_QUANTITY
  7829. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7830. {
  7831. 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
  7832. {
  7833. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7835. goto end;
  7836. }
  7837. }// END FOR GENERAL_GUN_QUANTITY
  7838. for (int index = 0; index < AC_QUANTITY; index++)
  7839. {
  7840. 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
  7841. {
  7842. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7843. goto end;
  7844. }
  7845. }//END FOR CHAdeMO_QUANTITY
  7846. }// END FOR gunTotalNumber
  7847. }
  7848. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7849. {
  7850. for(int i=0; i < gunTotalNumber; i++)
  7851. {
  7852. for (int index = 0; index < AC_QUANTITY; index++)
  7853. {
  7854. 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
  7855. {
  7856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7857. goto end;
  7858. }
  7859. }//END FOR CHAdeMO_QUANTITY
  7860. } // END FOR gunTotalNumber
  7861. }
  7862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7863. goto end;
  7864. }
  7865. //----------------------gunIndex is not 0 ------------------------------------------------//
  7866. //check Transaction active
  7867. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7868. {
  7869. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7870. {
  7871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7872. goto end;
  7873. }
  7874. }//END FOR CHAdeMO_QUANTITY
  7875. for (int index = 0; index < CCS_QUANTITY; index++)
  7876. {
  7877. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7878. {
  7879. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7880. goto end;
  7881. }
  7882. }//END FOR CCS_QUANTITY
  7883. for (int index = 0; index < GB_QUANTITY; index++)
  7884. {
  7885. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7886. {
  7887. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7888. goto end;
  7889. }
  7890. }// END FOR GB_QUANTITY
  7891. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7892. {
  7893. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7894. {
  7895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7896. goto end;
  7897. }
  7898. }// END FOR GENERAL_GUN_QUANTITY
  7899. for (int index = 0; index < AC_QUANTITY; index++)
  7900. {
  7901. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7902. {
  7903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7904. goto end;
  7905. }
  7906. }//END FOR AC_QUANTITY
  7907. }//END FOR AvailabilityTypeStr[Operative]
  7908. end:
  7909. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7910. {
  7911. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7912. }
  7913. else
  7914. {
  7915. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7916. }
  7917. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7918. {
  7919. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7920. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7921. }
  7922. else if(gunIndex == 0)
  7923. {
  7924. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7925. {
  7926. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7927. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7928. }
  7929. }
  7930. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7931. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7932. return result;
  7933. }
  7934. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7935. {
  7936. mtrace();
  7937. int result = FAIL;
  7938. char keystr[40]={0};
  7939. char valuestr[256]={0};
  7940. char comfirmstr[20]={0};
  7941. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7942. json_object *ChangeConfiguration;
  7943. ChangeConfiguration = json_tokener_parse(payload);
  7944. if(!is_error(ChangeConfiguration))
  7945. {
  7946. // Required data
  7947. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7948. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7949. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7950. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7951. }
  7952. json_object_put(ChangeConfiguration);
  7953. if((uuid==NULL) || (payload ==NULL) )
  7954. {
  7955. DEBUG_ERROR("Payload is null\n");
  7956. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7957. }
  7958. else
  7959. {
  7960. int status = setKeyValue(keystr, valuestr);
  7961. switch(status)
  7962. {
  7963. case ConfigurationStatus_Accepted:
  7964. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7965. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7966. StoreConfigurationTable();
  7967. break;
  7968. case RebootRequired:
  7969. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7970. StoreConfigurationTable();
  7971. break;
  7972. case NotSupported:
  7973. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7974. break;
  7975. case ConfigurationStatus_Rejected:
  7976. default:
  7977. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7978. break;
  7979. }
  7980. }
  7981. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7982. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7983. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7984. {
  7985. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7986. SetOcppConnStatus(FALSE);
  7987. }
  7988. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7989. {
  7990. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7991. }
  7992. return result;
  7993. }
  7994. int handleClearCacheRequest(char *uuid, char *payload)
  7995. {
  7996. mtrace();
  7997. int result = FAIL;
  7998. char comfirmstr[20];
  7999. char rmFileCmd[100]={0};
  8000. struct stat stats;
  8001. DEBUG_INFO("handleClearCacheRequest...\n");
  8002. stat("/Storage/OCPP_PH", &stats);
  8003. // Check for directory existence
  8004. if (S_ISDIR(stats.st_mode) == 1)
  8005. {}
  8006. else
  8007. {
  8008. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8009. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8010. system(rmFileCmd);
  8011. }
  8012. if(OCPP_cleanLocalCache())
  8013. {
  8014. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8015. }
  8016. else
  8017. {
  8018. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8019. }
  8020. sendClearCacheConfirmation(uuid, comfirmstr);
  8021. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8022. return result;
  8023. }
  8024. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8025. {
  8026. mtrace();
  8027. int result = FAIL;
  8028. int resultRename;
  8029. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8030. char chargingProfilePurposeStr[26]={0};
  8031. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8032. char tempchargingProfilePurposeStr[26]={0};
  8033. char str[100]={0};
  8034. char fname[200]={0};
  8035. char comfirmstr[20]={0};
  8036. char word[1600]={0};
  8037. int clearflag = FALSE;
  8038. int chargingProfileIdIsNULL = FALSE;
  8039. int connectorIsNULL = FALSE;
  8040. int chargingProfilePurposeIsNULL = FALSE;
  8041. int stackLevelIsNULL = FALSE;
  8042. //int GotoEnd = FALSE;
  8043. FILE *fptr1, *fptr2;
  8044. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8045. int n_chargingProfile=0;
  8046. int isEmptyFile = FALSE;
  8047. char sLineWord[1600]={0};
  8048. char chargingProfiles[10][100]={0};
  8049. int ChargeProfileCount = 0;
  8050. int ch;
  8051. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8052. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8053. json_object *ClearChargingProfile;
  8054. ClearChargingProfile = json_tokener_parse(payload);
  8055. if(!is_error(ClearChargingProfile))
  8056. {
  8057. // Optional data
  8058. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8059. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8060. else
  8061. chargingProfileIdIsNULL = TRUE;
  8062. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8063. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8064. else
  8065. connectorIsNULL = TRUE;
  8066. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8067. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8068. else
  8069. chargingProfilePurposeIsNULL = TRUE;
  8070. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8071. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8072. else
  8073. stackLevelIsNULL = TRUE;
  8074. }
  8075. json_object_put(ClearChargingProfile);
  8076. if(connectorIsNULL == FALSE)
  8077. {
  8078. switch(connectorIdInt)
  8079. {
  8080. case 0:
  8081. if(chargingProfilePurposeIsNULL == TRUE)
  8082. {
  8083. int l = 0;
  8084. strcpy(fname, ChargePointMaxProfile_JSON);
  8085. if((access(fname,F_OK))!=-1)
  8086. {
  8087. strcpy(chargingProfiles[l], fname);
  8088. l = l + 1;
  8089. }
  8090. strcpy(fname, TxDefaultProfile_0_JSON);
  8091. if((access(fname,F_OK))!=-1)
  8092. {
  8093. strcpy(chargingProfiles[l], fname);
  8094. l = l + 1;
  8095. }
  8096. ChargeProfileCount = l;
  8097. }
  8098. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8099. {
  8100. strcpy(fname, ChargePointMaxProfile_JSON);
  8101. if((access(fname,F_OK))!=-1)
  8102. {
  8103. strcpy(chargingProfiles[0], fname);
  8104. ChargeProfileCount = 1;
  8105. }
  8106. }
  8107. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8108. {
  8109. strcpy(fname, TxDefaultProfile_0_JSON);
  8110. if((access(fname,F_OK))!=-1)
  8111. {
  8112. strcpy(chargingProfiles[0], fname);
  8113. ChargeProfileCount = 1;
  8114. }
  8115. }
  8116. break;
  8117. default:
  8118. if(chargingProfilePurposeIsNULL == TRUE)
  8119. {
  8120. int m = 0;
  8121. memset(fname, 0, ARRAY_SIZE(fname));
  8122. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8123. if((access(fname,F_OK))!=-1)
  8124. {
  8125. strcpy(chargingProfiles[m], fname);
  8126. m = m + 1;
  8127. }
  8128. memset(fname, 0, ARRAY_SIZE(fname));
  8129. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8130. if((access(fname,F_OK))!=-1)
  8131. {
  8132. strcpy(chargingProfiles[m], fname);
  8133. m = m + 1;
  8134. }
  8135. ChargeProfileCount = m;
  8136. }
  8137. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8138. {
  8139. //strcpy(fname, TxDefaultProfile_1_JSON);
  8140. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8141. if((access(fname,F_OK))!=-1)
  8142. {
  8143. strcpy(chargingProfiles[0], fname);
  8144. ChargeProfileCount = 1;
  8145. }
  8146. }
  8147. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8148. {
  8149. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8150. if((access(fname,F_OK))!=-1)
  8151. {
  8152. strcpy(chargingProfiles[0], fname);
  8153. ChargeProfileCount = 1;
  8154. }
  8155. //strcpy(fname, TxProfile_1_JSON);
  8156. }
  8157. //strcpy(fname, ChargePointMaxProfile_JSON );
  8158. break;
  8159. }
  8160. }
  8161. else // Check all Charging Profiles
  8162. {
  8163. int i = 0;
  8164. char fnametemp[200]={0};
  8165. ChargeProfileCount = 0;
  8166. //Check ChargePointMaxProfile.json exit
  8167. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8168. {
  8169. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8170. i = i + 1;
  8171. }
  8172. //Check TxDefaultProfile_0.json exit
  8173. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8174. {
  8175. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8176. i = i + 1;
  8177. }
  8178. //Check TxDefaultProfile_%d.json
  8179. for(int j=1; j <= gunTotalNumber; j++)
  8180. {
  8181. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8182. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8183. if((access(fnametemp,F_OK))!=-1)
  8184. {
  8185. strcpy(chargingProfiles[i], fnametemp);
  8186. i = i + 1;
  8187. }
  8188. }
  8189. //Check TxProfile_%d.json
  8190. for(int j=1; j <= gunTotalNumber; j++)
  8191. {
  8192. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8193. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8194. if((access(fnametemp,F_OK))!=-1)
  8195. {
  8196. strcpy(chargingProfiles[i], fnametemp);
  8197. i = i + 1;
  8198. }
  8199. }
  8200. ChargeProfileCount = i;
  8201. }// End connectorIsNULL is TRUE
  8202. if(ChargeProfileCount == 0)
  8203. {
  8204. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8205. goto end;
  8206. }
  8207. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8208. {
  8209. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8210. goto end;
  8211. }
  8212. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8213. {
  8214. memset(str, 0, ARRAY_SIZE(str));
  8215. // clear temp file
  8216. sprintf(str,"rm -f %s",temp);
  8217. system(str);
  8218. for(int k=0; k < ChargeProfileCount; k++)
  8219. {
  8220. memset(str, 0, ARRAY_SIZE(str));
  8221. //clear file in C
  8222. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8223. system(str);
  8224. }
  8225. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8226. goto end;
  8227. }
  8228. else if(connectorIsNULL == TRUE)
  8229. {
  8230. for(int k=0; k < ChargeProfileCount; k++)
  8231. {
  8232. fptr1 = fopen(chargingProfiles[k], "r");
  8233. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8234. //Check Charging Profile Count
  8235. while(fscanf(fptr1, "%s", word) != EOF)
  8236. {
  8237. //DEBUG_INFO("word=%s\n",word);
  8238. if(strstr(word, "chargingProfileId")!= NULL)
  8239. {
  8240. //DEBUG_INFO("test chargingProfileId \n");
  8241. n_chargingProfile = n_chargingProfile + 1;
  8242. //DEBUG_INFO("chargingProfileId Found\n");
  8243. }
  8244. }
  8245. rewind(fptr1);
  8246. //search Charging Profile Element
  8247. //int i= 0;
  8248. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8249. {
  8250. json_object *tmpProfilee;
  8251. tmpProfilee = json_tokener_parse(sLineWord);
  8252. if(!is_error(tmpProfilee))
  8253. {
  8254. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8255. {
  8256. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8257. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8258. }
  8259. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8260. {
  8261. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8262. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8263. }
  8264. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8265. {
  8266. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8267. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8268. }
  8269. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8270. {
  8271. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8272. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8273. }
  8274. }
  8275. json_object_put(tmpProfilee);
  8276. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8277. {
  8278. //------- not write to fptr2-------//
  8279. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8280. //clearflag = TRUE;
  8281. }
  8282. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8283. {
  8284. //------- not write to fptr2-------//
  8285. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8286. }
  8287. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8288. {
  8289. //------- not write to fptr2-------//
  8290. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8291. }
  8292. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8293. {
  8294. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8295. }
  8296. else
  8297. {
  8298. fprintf(fptr2, sLineWord);//writing data into file
  8299. }
  8300. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8301. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8302. if(clearflag == TRUE)
  8303. {
  8304. fclose(fptr1);
  8305. fclose(fptr2);
  8306. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8307. system(str);
  8308. // clear temp file
  8309. sprintf(str,"rm -f %s",temp);
  8310. system(str);
  8311. }
  8312. else
  8313. {
  8314. fclose(fptr1);
  8315. fclose(fptr2);
  8316. memset(str, 0, ARRAY_SIZE(str));
  8317. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8318. system(str);
  8319. resultRename = rename(temp, chargingProfiles[k]);
  8320. if(resultRename == 0)
  8321. {
  8322. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8323. }
  8324. else
  8325. {
  8326. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8327. }
  8328. if(comfirmstr[0]== 0)
  8329. {
  8330. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8331. }
  8332. //Check chargingProfile is empty file
  8333. /*------ Read the file ----------------*/
  8334. fptr1=fopen(chargingProfiles[k],"r");
  8335. ch=fgetc(fptr1);
  8336. rewind(fptr1);
  8337. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8338. if(ch!=EOF)
  8339. {
  8340. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8341. {
  8342. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8343. if(sLineWord[0]=='\0')
  8344. {
  8345. isEmptyFile = TRUE;
  8346. break;
  8347. }
  8348. else
  8349. {
  8350. isEmptyFile = FALSE;
  8351. break;
  8352. }
  8353. }
  8354. }
  8355. else
  8356. isEmptyFile = TRUE;
  8357. fclose(fptr1);
  8358. if(isEmptyFile == TRUE)
  8359. {
  8360. memset(str, 0, ARRAY_SIZE(str));
  8361. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8362. system(str);
  8363. }
  8364. }
  8365. }// End of while(int k=0; k < ChargePointCount; k++)
  8366. }
  8367. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8368. {
  8369. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8370. for(int k=0; k < ChargeProfileCount; k++)
  8371. {
  8372. fptr1 = fopen(chargingProfiles[k], "r");
  8373. fptr2 = fopen(temp, "w+");
  8374. //Check Charging Profile Count
  8375. while(fscanf(fptr1, "%s", word) != EOF)
  8376. {
  8377. //DEBUG_INFO("word=%s\n",word);
  8378. if(strstr(word, "chargingProfileId")!= NULL)
  8379. {
  8380. n_chargingProfile = n_chargingProfile + 1;
  8381. }
  8382. }
  8383. rewind(fptr1);
  8384. //search Charging Profile Element
  8385. //int i= 0;
  8386. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8387. {
  8388. json_object *tmpProfilee;
  8389. tmpProfilee = json_tokener_parse(sLineWord);
  8390. if(!is_error(tmpProfilee))
  8391. {
  8392. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8393. {
  8394. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8395. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8396. }
  8397. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8398. {
  8399. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8400. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8401. }
  8402. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8403. {
  8404. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8405. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8406. }
  8407. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8408. {
  8409. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8410. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8411. }
  8412. }
  8413. json_object_put(tmpProfilee);
  8414. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8415. {
  8416. //------- not write to fptr2-------//
  8417. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8418. //clearflag = TRUE;
  8419. }
  8420. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8421. {
  8422. //------- not write to fptr2-------//
  8423. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8424. }
  8425. else if(stackLevelIsNULL == TRUE)
  8426. {
  8427. //Clear Whole File
  8428. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8429. clearflag = TRUE;
  8430. break;
  8431. }
  8432. else
  8433. {
  8434. fprintf(fptr2, sLineWord);//writing data into file
  8435. }
  8436. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8437. }
  8438. if(clearflag == TRUE)
  8439. {
  8440. fclose(fptr1);
  8441. fclose(fptr2);
  8442. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8443. system(str);
  8444. // clear temp file
  8445. sprintf(str,"rm -f %s",temp);
  8446. system(str);
  8447. }
  8448. else
  8449. {
  8450. fclose(fptr1);
  8451. fclose(fptr2);
  8452. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8453. system(str);
  8454. resultRename = rename(temp, chargingProfiles[k]);
  8455. if(resultRename == 0)
  8456. {
  8457. DEBUG_INFO("File ChargingProfile renamed successfully");
  8458. }
  8459. else
  8460. {
  8461. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8462. }
  8463. if(comfirmstr[0]== 0)
  8464. {
  8465. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8466. }
  8467. //Check chargingProfile is empty file
  8468. /*------ Read the file ----------------*/
  8469. fptr1=fopen(chargingProfiles[k],"r");
  8470. ch=fgetc(fptr1);
  8471. rewind(fptr1);
  8472. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8473. if(ch!=EOF)
  8474. {
  8475. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8476. {
  8477. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8478. if(sLineWord[0]=='\0')
  8479. {
  8480. isEmptyFile = TRUE;
  8481. break;
  8482. }
  8483. else
  8484. {
  8485. isEmptyFile = FALSE;
  8486. break;
  8487. }
  8488. }
  8489. }
  8490. else
  8491. isEmptyFile = TRUE;
  8492. fclose(fptr1);
  8493. if(isEmptyFile == TRUE)
  8494. {
  8495. memset(str, 0, ARRAY_SIZE(str));
  8496. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8497. system(str);
  8498. }
  8499. /*------- End of reading ---------------*/
  8500. }
  8501. } // while(int k=0; k < ChargeProfileCount; k++)
  8502. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8503. end:
  8504. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8505. {
  8506. if(connectorIdInt == 0)
  8507. {
  8508. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8509. {
  8510. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8511. }
  8512. }
  8513. else
  8514. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8515. }
  8516. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8517. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8518. return result;
  8519. }
  8520. void createFirmwareVersionByDataTransfer(void)
  8521. {
  8522. json_object *FirmwareDataTransfer = json_object_new_object();
  8523. // AC & DC model
  8524. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8525. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8526. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8527. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8528. // DC model
  8529. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8530. {
  8531. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8532. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8533. (gunType[3] != GUN_TYPE_UNKNOWN))
  8534. {
  8535. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8536. }
  8537. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8538. {
  8539. // DS DM DW
  8540. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8541. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8542. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8543. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8544. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8545. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8546. }
  8547. else
  8548. {
  8549. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8550. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8551. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8552. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8553. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8554. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8555. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8556. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8557. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8558. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8559. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8560. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8561. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8562. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8563. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8564. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8565. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8566. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8567. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8568. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8569. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8570. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8571. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8572. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8573. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8574. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8575. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8576. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8577. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8578. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8579. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8580. }
  8581. }
  8582. // 4G model
  8583. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8584. {
  8585. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8586. }
  8587. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8588. json_object_put(FirmwareDataTransfer);
  8589. }
  8590. int handleDataTransferRequest(char *uuid, char *payload)
  8591. {
  8592. mtrace();
  8593. json_object *response = json_object_new_object();
  8594. int result = FAIL;
  8595. char tempvendorId[255]={0};
  8596. char tempmessageId[50]={0};
  8597. char tempdata[512]={0};
  8598. char message[2048]={0};
  8599. DEBUG_INFO("handleDataTransferRequest...\n");
  8600. if((uuid != NULL) && (payload != NULL))
  8601. {
  8602. json_object *DataTransfer;
  8603. DataTransfer = json_tokener_parse(payload);
  8604. if(!is_error(DataTransfer))
  8605. {
  8606. // Required data
  8607. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8608. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8609. // Optional data
  8610. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8611. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8612. if(json_object_object_get(DataTransfer, "data") != NULL)
  8613. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8614. result = PASS;
  8615. }
  8616. json_object_put(DataTransfer);
  8617. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8618. {
  8619. // Send all moudle firmware version on EVSE
  8620. createFirmwareVersionByDataTransfer();
  8621. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8622. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  8623. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8624. json_object_put(response);
  8625. }
  8626. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8627. {
  8628. system("/usr/bin/run_tmate_restart.sh &");
  8629. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8630. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8631. json_object_put(response);
  8632. }
  8633. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8634. {
  8635. json_object *data;
  8636. data = json_tokener_parse(tempdata);
  8637. if(!is_error(data))
  8638. {
  8639. 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))
  8640. {
  8641. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8642. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8643. if(json_object_object_get(data, "SOC") != NULL)
  8644. {
  8645. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8646. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8647. }
  8648. if(json_object_object_get(data, "Energy") != NULL)
  8649. {
  8650. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8651. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8652. }
  8653. if(json_object_object_get(data, "Duration") != NULL)
  8654. {
  8655. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8656. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8657. }
  8658. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8659. }
  8660. else
  8661. {
  8662. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8663. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8664. }
  8665. }
  8666. else
  8667. {
  8668. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8669. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8670. }
  8671. json_object_put(data);
  8672. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8673. json_object_put(response);
  8674. }
  8675. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8676. {
  8677. json_object *data;
  8678. data = json_tokener_parse(tempdata);
  8679. if(!is_error(data))
  8680. {
  8681. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8682. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8683. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8684. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8685. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8686. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8687. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8688. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8689. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8690. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8691. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8692. }
  8693. else
  8694. {
  8695. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8696. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8697. }
  8698. json_object_put(data);
  8699. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8700. json_object_put(response);
  8701. }
  8702. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8703. {
  8704. json_object *data;
  8705. data = json_tokener_parse(tempdata);
  8706. if(!is_error(data))
  8707. {
  8708. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8709. if(json_object_object_get(data, "idToken") != NULL)
  8710. {
  8711. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8712. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8713. }
  8714. if(json_object_object_get(data, "price") != NULL)
  8715. {
  8716. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8717. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8718. }
  8719. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8720. }
  8721. else
  8722. {
  8723. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8724. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8725. }
  8726. json_object_put(data);
  8727. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8728. json_object_put(response);
  8729. }
  8730. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8731. {
  8732. json_object *data;
  8733. data = json_tokener_parse(tempdata);
  8734. if(!is_error(data))
  8735. {
  8736. if(json_object_object_get(data, "txId") != NULL)
  8737. {
  8738. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8739. for(int idx = 0;idx<gunTotalNumber;idx++)
  8740. {
  8741. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8742. {
  8743. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8744. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8745. if(json_object_object_get(data, "description") != NULL)
  8746. {
  8747. // California pricing V1.0
  8748. DEBUG_INFO("California pricing V1.0\n");
  8749. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8750. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8751. }
  8752. else
  8753. {
  8754. // California pricing V1.1
  8755. DEBUG_INFO("California pricing V1.1\n");
  8756. if(json_object_object_get(data, "timestamp") != NULL)
  8757. {
  8758. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8759. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8760. }
  8761. if(json_object_object_get(data, "meterValue") != NULL)
  8762. {
  8763. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8764. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8765. }
  8766. if(json_object_object_get(data, "cost") != NULL)
  8767. {
  8768. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8769. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8770. }
  8771. if(json_object_object_get(data, "state") != NULL)
  8772. {
  8773. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8774. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8775. }
  8776. if(json_object_object_get(data, "chargingPrice") != NULL)
  8777. {
  8778. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8779. {
  8780. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8781. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8782. }
  8783. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8784. {
  8785. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8786. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8787. }
  8788. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8789. {
  8790. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8791. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8792. }
  8793. }
  8794. if(json_object_object_get(data, "idlePrice") != NULL)
  8795. {
  8796. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8797. {
  8798. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8799. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8800. }
  8801. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8802. {
  8803. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8804. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8805. }
  8806. }
  8807. if(json_object_object_get(data, "nextPeriod") != NULL)
  8808. {
  8809. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8810. {
  8811. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8812. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8813. }
  8814. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8815. {
  8816. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8817. {
  8818. 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")));
  8819. 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"));
  8820. }
  8821. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8822. {
  8823. 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")));
  8824. 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"));
  8825. }
  8826. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8827. {
  8828. 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")));
  8829. 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"));
  8830. }
  8831. }
  8832. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8833. {
  8834. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8835. {
  8836. 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")));
  8837. 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"));
  8838. }
  8839. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8840. {
  8841. 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")));
  8842. 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"));
  8843. }
  8844. }
  8845. }
  8846. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8847. {
  8848. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8849. {
  8850. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8851. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8852. }
  8853. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8854. {
  8855. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8856. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8857. }
  8858. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8859. {
  8860. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8861. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8862. }
  8863. }
  8864. }
  8865. }
  8866. }
  8867. }
  8868. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8869. }
  8870. else
  8871. {
  8872. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8873. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8874. }
  8875. json_object_put(data);
  8876. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8877. json_object_put(response);
  8878. }
  8879. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8880. {
  8881. json_object *data;
  8882. data = json_tokener_parse(tempdata);
  8883. if(!is_error(data))
  8884. {
  8885. if(json_object_object_get(data, "txId") != NULL)
  8886. {
  8887. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8888. for(int idx = 0;idx<gunTotalNumber;idx++)
  8889. {
  8890. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8891. {
  8892. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8893. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8894. if(json_object_object_get(data, "description") != NULL)
  8895. {
  8896. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8897. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8898. }
  8899. }
  8900. }
  8901. }
  8902. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8903. }
  8904. else
  8905. {
  8906. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8907. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8908. }
  8909. json_object_put(data);
  8910. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8911. json_object_put(response);
  8912. }
  8913. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8914. {
  8915. json_object *data;
  8916. data = json_tokener_parse(tempdata);
  8917. if(!is_error(data))
  8918. {
  8919. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8920. if(json_object_object_get(data, "Content_Type") != NULL)
  8921. {
  8922. 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))
  8923. {
  8924. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8925. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8926. {
  8927. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8928. }
  8929. }
  8930. else
  8931. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8932. }
  8933. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8934. }
  8935. else
  8936. {
  8937. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8938. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8939. }
  8940. json_object_put(data);
  8941. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8942. json_object_put(response);
  8943. }
  8944. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8945. {
  8946. json_object *data;
  8947. data = json_tokener_parse(tempdata);
  8948. if(!is_error(data))
  8949. {
  8950. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8951. if(json_object_object_get(data, "Page_Index") != NULL)
  8952. {
  8953. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8954. }
  8955. if(json_object_object_get(data, "Duration") != NULL)
  8956. {
  8957. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8958. }
  8959. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8960. }
  8961. else
  8962. {
  8963. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8964. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8965. }
  8966. json_object_put(data);
  8967. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8968. json_object_put(response);
  8969. }
  8970. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8971. {
  8972. json_object *data;
  8973. data = json_tokener_parse(tempdata);
  8974. if(!is_error(data))
  8975. {
  8976. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8977. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8978. {
  8979. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8980. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8981. else
  8982. {
  8983. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8984. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8985. }
  8986. }
  8987. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8988. {
  8989. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8990. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8991. else
  8992. {
  8993. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8994. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8995. }
  8996. }
  8997. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8998. {
  8999. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9000. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9001. else
  9002. {
  9003. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9004. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9005. }
  9006. }
  9007. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9008. {
  9009. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9010. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9011. else
  9012. {
  9013. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9014. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9015. }
  9016. }
  9017. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9018. {
  9019. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9020. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9021. else
  9022. {
  9023. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9024. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9025. }
  9026. }
  9027. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9028. {
  9029. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9030. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9031. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9032. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9033. else
  9034. {
  9035. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9036. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9037. }
  9038. }
  9039. if(json_object_object_get(data, "isAuthentication") != NULL)
  9040. {
  9041. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9042. {
  9043. case 0:
  9044. case 1:
  9045. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9046. break;
  9047. default:
  9048. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9049. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9050. break;
  9051. }
  9052. }
  9053. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9054. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9055. }
  9056. else
  9057. {
  9058. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9059. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9060. }
  9061. json_object_put(data);
  9062. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9063. json_object_put(response);
  9064. }
  9065. else
  9066. {
  9067. // Can not find valid message id
  9068. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9069. }
  9070. }
  9071. else
  9072. {
  9073. // Payload is null
  9074. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9075. }
  9076. LWS_Send(message);
  9077. return result;
  9078. }
  9079. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9080. {
  9081. mtrace();
  9082. int result = FAIL;
  9083. int connectorIdInt, durationInt;
  9084. char chargingRateUnitStr[4]={0};
  9085. char comfirmstr[20];
  9086. int confirmPeriods = 0;
  9087. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9088. json_object *GetCompositeSchedule;
  9089. GetCompositeSchedule = json_tokener_parse(payload);
  9090. if(!is_error(GetCompositeSchedule))
  9091. {
  9092. // Required data
  9093. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9094. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9095. else
  9096. connectorIdInt = -1;
  9097. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9098. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9099. else
  9100. durationInt = 86400;
  9101. // Optional data
  9102. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9103. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9104. }
  9105. json_object_put(GetCompositeSchedule);
  9106. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9107. if((connectorIdInt == 0) ||
  9108. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9109. {
  9110. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9111. struct StructChargingProfile tmpProfile[1];
  9112. if(strstr(chargingRateUnitStr, "W") != NULL)
  9113. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9114. else
  9115. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9116. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9117. {
  9118. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9119. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9120. }
  9121. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9122. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9123. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9124. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9125. {
  9126. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9127. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9128. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9129. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9130. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9131. {
  9132. confirmPeriods = idx;
  9133. break;
  9134. }
  9135. }
  9136. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9137. {
  9138. confirmPeriods += 1;
  9139. }
  9140. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9141. }
  9142. else
  9143. {
  9144. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9145. }
  9146. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9147. return result;
  9148. }
  9149. int handleGetConfigurationRequest(char *uuid, char *payload)
  9150. {
  9151. mtrace();
  9152. int result = FAIL;
  9153. int MaxKeySupported = 0;
  9154. int n_keys = 0;
  9155. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9156. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9157. json_object *GetConfiguration;
  9158. GetConfiguration = json_tokener_parse(payload);
  9159. if(!is_error(GetConfiguration))
  9160. {
  9161. // Optional data
  9162. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9163. {
  9164. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9165. {
  9166. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9167. n_keys = idx + 1;
  9168. }
  9169. }
  9170. }
  9171. json_object_put(GetConfiguration);
  9172. UnknownKeynum = 0;
  9173. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9174. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9175. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9176. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9177. if(n_keys != 0)
  9178. {
  9179. for(int i=0;i<n_keys;i++)
  9180. {
  9181. getKeyValue(requestKey[i]);
  9182. }
  9183. }
  9184. else
  9185. {
  9186. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9187. getKeyValue("");
  9188. }
  9189. processUnkownKey();
  9190. sendGetConfigurationConfirmation(uuid);
  9191. return result;
  9192. }
  9193. static char fnamePlusPath[100]={0};
  9194. static char fnamePWithNoPath[60]={0};
  9195. void checkUploadLog(void)
  9196. {
  9197. FILE *fp;
  9198. /* Open the command for reading. */
  9199. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9200. if (fp == NULL) {
  9201. DEBUG_WARN("Failed to run command\n" );
  9202. exit(1);
  9203. }
  9204. int ftppathlen = 0;
  9205. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9206. int i = 0;
  9207. /* Read the output a line at a time - output it. */
  9208. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9209. if(i==0)
  9210. {
  9211. ftppathlen = strlen(fnamePlusPath);
  9212. DEBUG_INFO("%s\n", fnamePlusPath);
  9213. fnamePlusPath[ftppathlen]='\0';
  9214. break;
  9215. }
  9216. i= i+1;
  9217. }
  9218. /* close */
  9219. pclose(fp);
  9220. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9221. {
  9222. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9223. {
  9224. fnamePlusPath[k]='\0';
  9225. }
  9226. }
  9227. i=1;
  9228. //char fname[60]={0};
  9229. while(i < ftppathlen)
  9230. {
  9231. int len=ftppathlen-i;
  9232. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9233. {
  9234. DEBUG_INFO("compare '/' all right\n");
  9235. break;
  9236. }
  9237. i=i+1;
  9238. }
  9239. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9240. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9241. fnamePWithNoPath[i+1] = '\0';
  9242. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9243. {
  9244. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9245. {
  9246. fnamePWithNoPath[j]='\0';
  9247. }
  9248. }
  9249. FILE* fp1 = fopen(fnamePlusPath, "r");
  9250. if (fp1)
  9251. {
  9252. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9253. // file exists
  9254. fclose(fp1);
  9255. }
  9256. else
  9257. {
  9258. // file doesn't exist
  9259. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9260. }
  9261. }
  9262. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9263. {
  9264. mtrace();
  9265. int result = FAIL;
  9266. time_t CurrentTime;
  9267. struct tm *tm;
  9268. pthread_t th_Status;
  9269. CurrentTime = time(NULL);
  9270. tm = localtime(&CurrentTime);
  9271. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9272. 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);
  9273. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9274. if(!interLock.isGetDiagnosticGoing)
  9275. {
  9276. interLock.isGetDiagnosticGoing = 1;
  9277. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9278. sleep(1);
  9279. }
  9280. else
  9281. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9282. return result;
  9283. }
  9284. void* GetDiagnosticsProcess(void* data)
  9285. {
  9286. pthread_detach(pthread_self());
  9287. mtrace();
  9288. int retriesInt=0, retryIntervalInt=0;
  9289. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9290. 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};
  9291. int port=0;
  9292. int isSuccess = FALSE;
  9293. char ftpbuf[200]={0};
  9294. char cmdBuf[2048];
  9295. struct tm *tmNow;
  9296. time_t CurrentTime;
  9297. struct tm tmStart;
  9298. struct tm tmStop;
  9299. CurrentTime = time(NULL);
  9300. tmNow=localtime(&CurrentTime);
  9301. uint16_t targetYear, targetMonth;
  9302. json_object *GetDiagnostics;
  9303. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9304. GetDiagnostics = json_tokener_parse(data);
  9305. if(!is_error(GetDiagnostics))
  9306. {
  9307. // Required data
  9308. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9309. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9310. // Optional data
  9311. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9312. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9313. else
  9314. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9315. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9316. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9317. else
  9318. retryIntervalInt = 30;
  9319. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9320. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9321. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9322. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9323. }
  9324. json_object_put(GetDiagnostics);
  9325. // Pack log to compress file
  9326. 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) &&
  9327. (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))
  9328. {
  9329. // Pack system log
  9330. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9331. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9332. targetYear = tmStart.tm_year;
  9333. targetMonth = tmStart.tm_mon;
  9334. do
  9335. {
  9336. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9337. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9338. if(targetMonth+1>=13)
  9339. {
  9340. targetYear += 1;
  9341. targetMonth = 1;
  9342. }
  9343. else
  9344. {
  9345. targetMonth += 1;
  9346. }
  9347. }while((targetYear < (tmNow->tm_year+1900)) ||
  9348. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9349. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9350. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9351. system(cmdBuf);
  9352. // Pack charging & event log
  9353. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9354. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9355. targetYear = tmStart.tm_year;
  9356. targetMonth = tmStart.tm_mon;
  9357. do
  9358. {
  9359. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9360. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9361. if(targetMonth+1>=13)
  9362. {
  9363. targetYear += 1;
  9364. targetMonth = 1;
  9365. }
  9366. else
  9367. {
  9368. targetMonth += 1;
  9369. }
  9370. }while((targetYear < (tmNow->tm_year+1900)) ||
  9371. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9372. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9373. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9374. system(cmdBuf);
  9375. // Combine log file
  9376. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9377. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9378. }
  9379. else
  9380. {
  9381. system("exec /root/logPackTools 'log' 6");
  9382. }
  9383. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9384. system(cmdBuf);
  9385. checkUploadLog();
  9386. //****************location*******************/
  9387. if(strcmp(locationstr,"")==0)
  9388. {
  9389. DEBUG_INFO("location is <Empty>!\n");
  9390. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9391. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9392. goto end;
  9393. }
  9394. memset(protocol, 0, ARRAY_SIZE(protocol));
  9395. memset(user, 0, ARRAY_SIZE(user) );
  9396. memset(password, 0, ARRAY_SIZE(password));
  9397. memset(host, 0, ARRAY_SIZE(host));
  9398. memset(path, 0, ARRAY_SIZE(path));
  9399. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9400. memset(host1, 0, ARRAY_SIZE(host1));
  9401. memset(path1, 0, ARRAY_SIZE(path1));
  9402. /*location: ftp://user:password@host:port/path*/
  9403. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9404. if((access(fnamePlusPath,F_OK))!=-1)
  9405. {
  9406. DEBUG_INFO("fnamePlusPath exist.\n");
  9407. }
  9408. else
  9409. {
  9410. DEBUG_INFO("fnamePlusPath not exist!\n");
  9411. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9412. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9413. goto end;
  9414. }
  9415. if(strchr(locationstr,'@')==NULL)
  9416. {
  9417. sscanf(locationstr,
  9418. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9419. protocol, host, &port, path);
  9420. strcpy(user,"anonymous");
  9421. strcpy(password,"");
  9422. }
  9423. else
  9424. {
  9425. //DEBUG_INFO("pch=%s\n", pch);
  9426. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9427. protocol, user, password, host, &port, path);
  9428. }
  9429. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9430. {
  9431. DEBUG_INFO("protocol is not ftp/http ! \n");
  9432. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9433. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9434. goto end;
  9435. }
  9436. if(strncmp(locationstr,"http", 4) == 0)
  9437. {
  9438. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9439. sprintf(ftppath,"/%s", path);
  9440. do
  9441. {
  9442. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9443. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9444. sleep(3);
  9445. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9446. if(!isSuccess)
  9447. {
  9448. DEBUG_INFO("Diagnostics fail.\n");
  9449. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9450. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9451. sleep(retryIntervalInt);
  9452. }
  9453. else
  9454. {
  9455. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9456. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9457. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9458. }
  9459. retriesInt--;
  9460. }while((isSuccess == 0)&&(retriesInt >= 0));
  9461. }
  9462. else
  9463. {
  9464. sscanf(host,"%[^/]%s",host1, path1);
  9465. if(strlen(path) > 0)
  9466. sprintf(ftppath,"/%s", path);
  9467. else
  9468. sprintf(ftppath,"/%s", path1);
  9469. int ftppathlen=strlen(ftppath);
  9470. int i=1;
  9471. char filenametemp[50];
  9472. while(i < ftppathlen)
  9473. {
  9474. int len=ftppathlen-i;
  9475. if(ftppath[len]== 47) // '/' ascll code: 47
  9476. {
  9477. DEBUG_INFO("find '/' all right\n");
  9478. break;
  9479. }
  9480. i=i+1;
  9481. }
  9482. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9483. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9484. filenametemp[i+1] = 0;
  9485. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9486. if(port == 0)
  9487. port = 21;
  9488. do
  9489. {
  9490. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9491. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9492. sleep(3);
  9493. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9494. if(!isSuccess)
  9495. {
  9496. DEBUG_INFO("Diagnostics fail.\n");
  9497. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9498. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9499. sleep(retryIntervalInt);
  9500. }
  9501. else
  9502. {
  9503. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9504. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9505. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9506. }
  9507. retriesInt--;
  9508. }while((!isSuccess)&&(retriesInt >= 0));
  9509. }
  9510. end:
  9511. system("rm -f /mnt/*");
  9512. sleep(5);
  9513. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9514. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9515. interLock.isGetDiagnosticGoing = 0;
  9516. pthread_exit(NULL);
  9517. }
  9518. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9519. {
  9520. mtrace();
  9521. int result = FAIL;
  9522. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9523. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9524. {
  9525. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9526. locallistVersion = -1;
  9527. }
  9528. else
  9529. {
  9530. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9531. OCPP_getListVerion();
  9532. }
  9533. //from db.OCPP_getListVerion
  9534. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9535. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9536. sendGetLocalListVersionConfirmation(uuid,"");
  9537. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9538. return result;
  9539. }
  9540. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9541. {
  9542. mtrace();
  9543. int result = FAIL;
  9544. int connectorIdInt=-1;
  9545. int tempIndex = 0;
  9546. int connectorIdIsNULL, chargingProfileIsNULL;
  9547. char comfirmstr[20]={0};
  9548. char cmdBuf[512];
  9549. json_object *RemoteStartTransaction;
  9550. FILE *fp;
  9551. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9552. if(server_pending == TRUE)
  9553. {
  9554. return 0;
  9555. }
  9556. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9557. RemoteStartTransaction = json_tokener_parse(payload);
  9558. if(!is_error(RemoteStartTransaction))
  9559. {
  9560. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9561. {
  9562. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9563. }
  9564. else
  9565. {
  9566. connectorIdIsNULL = TRUE;
  9567. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9568. {
  9569. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9570. {
  9571. connectorIdIsNULL = FALSE;
  9572. connectorIdInt = (gun_index+1);
  9573. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9574. break;
  9575. }
  9576. }
  9577. }
  9578. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9579. {
  9580. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9581. // Required data
  9582. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9583. // Optional data
  9584. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9585. {
  9586. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9587. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9588. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9589. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9590. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9591. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9592. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9593. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9594. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9595. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9596. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9597. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9598. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9599. {
  9600. 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")));
  9601. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9602. 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"));
  9603. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9604. 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"));
  9605. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9606. 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")));
  9607. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9608. {
  9609. 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++)
  9610. {
  9611. 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"));
  9612. 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"));
  9613. 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)
  9614. 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"));
  9615. }
  9616. }
  9617. }
  9618. }
  9619. else
  9620. {
  9621. chargingProfileIsNULL = TRUE;
  9622. }
  9623. }
  9624. }
  9625. else
  9626. {
  9627. connectorIdIsNULL = TRUE;
  9628. }
  9629. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9630. {
  9631. DEBUG_WARN("Connector id is NULL\n.");
  9632. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9633. goto end;
  9634. }
  9635. /*
  9636. enum _SYSTEM_STATUS
  9637. {
  9638. S_BOOTING = 0,
  9639. S_IDLE, = 1
  9640. S_AUTHORIZING, = 2
  9641. S_REASSIGN_CHECK, = 3
  9642. S_REASSIGN, = 4
  9643. S_PRECHARGE, = 5
  9644. S_PREPARING_FOR_EV, = 6
  9645. S_PREPARING_FOR_EVSE, = 7
  9646. S_CHARGING, = 8
  9647. S_TERMINATING, = 9
  9648. S_COMPLETE, = 10
  9649. S_ALARM, = 11
  9650. S_FAULT = 12
  9651. }
  9652. */
  9653. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9654. {
  9655. //check Transaction active
  9656. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9657. {
  9658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9659. {
  9660. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9661. }
  9662. else
  9663. {
  9664. tempIndex = connectorIdInt -1;
  9665. }
  9666. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9667. {
  9668. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9669. {
  9670. 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))
  9671. {
  9672. //Reserved
  9673. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9674. }
  9675. 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))
  9676. {
  9677. //Reserved
  9678. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9680. goto end;
  9681. }
  9682. else
  9683. {
  9684. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9685. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9686. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9687. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9688. {
  9689. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9691. goto end;
  9692. }
  9693. }//END FOR ELSE
  9694. }
  9695. }// END FOR CHAdeMO_QUANTITY
  9696. }
  9697. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9698. {
  9699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9700. {
  9701. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9702. }
  9703. else
  9704. {
  9705. tempIndex = connectorIdInt -1;
  9706. }
  9707. for (int index = 0; index < CCS_QUANTITY; index++)
  9708. {
  9709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9710. {
  9711. 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))
  9712. {
  9713. //Reserved
  9714. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9715. }
  9716. 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))
  9717. {
  9718. //Reserved
  9719. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9720. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9721. goto end;
  9722. }
  9723. else
  9724. {
  9725. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9726. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9727. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9728. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9729. {
  9730. DEBUG_WARN("CCS connector not allow start\n.");
  9731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9732. goto end;
  9733. }
  9734. }// END FOR ELSE
  9735. }
  9736. }// END FOR CCS_QUANTITY
  9737. }
  9738. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9739. {
  9740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9741. {
  9742. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9743. }
  9744. else
  9745. {
  9746. tempIndex = connectorIdInt -1;
  9747. }
  9748. for (int index = 0; index < GB_QUANTITY; index++)
  9749. {
  9750. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9751. {
  9752. 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))
  9753. {
  9754. //Reserved
  9755. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9756. }
  9757. 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))
  9758. {
  9759. //Reserved
  9760. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9761. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9762. goto end;
  9763. }
  9764. else
  9765. {
  9766. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9767. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9768. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9769. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9770. {
  9771. DEBUG_WARN("GB connector not allow start\n.");
  9772. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9773. goto end;
  9774. }
  9775. }// END FOR ELSE
  9776. }
  9777. } // END FOR GB_QUANTITY
  9778. }
  9779. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9780. {
  9781. tempIndex = connectorIdInt -1;
  9782. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9783. {
  9784. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9785. {
  9786. 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))
  9787. {
  9788. //Reserved
  9789. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9790. }
  9791. 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))
  9792. {
  9793. //Reserved
  9794. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9795. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9796. goto end;
  9797. }
  9798. else
  9799. {
  9800. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9801. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9802. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9803. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9804. {
  9805. DEBUG_WARN("GB connector not allow start\n.");
  9806. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9807. goto end;
  9808. }
  9809. }// END FOR ELSE
  9810. }
  9811. } // END FOR GB_QUANTITY
  9812. }
  9813. else
  9814. {
  9815. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9816. {
  9817. tempIndex = 2;
  9818. }
  9819. else
  9820. {
  9821. tempIndex = connectorIdInt -1;
  9822. }
  9823. for (int index = 0; index < AC_QUANTITY; index++)
  9824. {
  9825. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9826. {
  9827. 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))
  9828. {
  9829. //Reserved
  9830. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9831. }
  9832. 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))
  9833. {
  9834. //Reserved
  9835. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9836. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9837. goto end;
  9838. }
  9839. else
  9840. {
  9841. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9842. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9843. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9844. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9845. {
  9846. DEBUG_WARN("AC connector not allow start\n.");
  9847. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9848. goto end;
  9849. }
  9850. }//END FOR ELSE
  9851. }
  9852. }// END FOR AC_QUANTITY
  9853. }
  9854. if(chargingProfileIsNULL == FALSE)
  9855. {
  9856. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9857. {
  9858. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9859. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9860. //memset idTag
  9861. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9862. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9863. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9864. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9865. // Save profile to file
  9866. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9867. system(cmdBuf);
  9868. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9869. fp = fopen(cmdBuf, "w");
  9870. 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));
  9871. fclose(fp);
  9872. }
  9873. else
  9874. {
  9875. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9876. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9877. }
  9878. }
  9879. else
  9880. {
  9881. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9882. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9883. //memset idTag
  9884. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9885. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9886. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9887. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9888. }
  9889. }
  9890. else
  9891. {
  9892. DEBUG_WARN("Connector id over\n.");
  9893. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9894. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9895. }
  9896. end:
  9897. json_object_put(RemoteStartTransaction);
  9898. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9899. {
  9900. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9901. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9902. }
  9903. //OCPP send RemoteStartConfirmation by first.
  9904. sendRemoteStartConfirmation(uuid, comfirmstr);
  9905. return result;
  9906. }
  9907. int handleRemoteStartRequest(char *uuid, char *payload)
  9908. {
  9909. mtrace();
  9910. int result = PASS;
  9911. int connectorIdInt=-1;
  9912. int tempIndex = 0;
  9913. char comfirmstr[20]={0};
  9914. char cmdBuf[512];
  9915. json_object *RemoteStartTransaction;
  9916. FILE *fp;
  9917. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9918. if(server_pending == TRUE)
  9919. {
  9920. result = FAIL;
  9921. }
  9922. RemoteStartTransaction = json_tokener_parse(payload);
  9923. if(!is_error(RemoteStartTransaction))
  9924. {
  9925. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9926. {
  9927. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9928. }
  9929. else
  9930. {
  9931. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9932. {
  9933. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9934. {
  9935. connectorIdInt = (gun_index+1);
  9936. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9937. break;
  9938. }
  9939. }
  9940. }
  9941. if(connectorIdInt == 0)
  9942. {
  9943. DEBUG_WARN("Connector id shall not equal 0.\n");
  9944. result = FAIL;
  9945. }
  9946. else if(connectorIdInt == -1)
  9947. {
  9948. DEBUG_INFO("Connector id does not specific.\n");
  9949. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9950. {
  9951. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  9952. // Required data
  9953. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9954. // Optional data
  9955. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9956. {
  9957. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9958. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9959. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9960. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9961. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9962. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9963. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9964. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9965. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9966. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9967. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9968. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9969. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9970. {
  9971. 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")));
  9972. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9973. 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"));
  9974. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9975. 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"));
  9976. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9977. 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")));
  9978. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9979. {
  9980. 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++)
  9981. {
  9982. 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"));
  9983. 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"));
  9984. 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)
  9985. 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"));
  9986. }
  9987. }
  9988. }
  9989. }
  9990. else
  9991. {
  9992. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  9993. }
  9994. }
  9995. }
  9996. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  9997. {
  9998. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  9999. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10000. // Required data
  10001. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10002. // Optional data
  10003. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10004. {
  10005. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10006. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10007. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10008. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10009. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10010. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10011. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10012. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10013. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10014. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10015. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10016. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10017. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10018. {
  10019. 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")));
  10020. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10021. 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"));
  10022. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10023. 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"));
  10024. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10025. 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")));
  10026. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10027. {
  10028. 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++)
  10029. {
  10030. 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"));
  10031. 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"));
  10032. 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)
  10033. 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"));
  10034. }
  10035. }
  10036. }
  10037. }
  10038. else
  10039. {
  10040. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10041. }
  10042. }
  10043. else
  10044. {
  10045. DEBUG_WARN("Connector id is over maximun value.\n");
  10046. result = FAIL;
  10047. }
  10048. }
  10049. if(result == PASS)
  10050. {
  10051. if(connectorIdInt > 0)
  10052. {
  10053. //check Transaction active
  10054. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10055. {
  10056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10057. {
  10058. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10059. }
  10060. else
  10061. {
  10062. tempIndex = connectorIdInt -1;
  10063. }
  10064. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10065. {
  10066. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10067. {
  10068. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10069. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10070. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10071. {
  10072. //Reserved
  10073. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10074. }
  10075. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10076. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10077. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10078. {
  10079. //Reserved
  10080. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10081. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10082. goto end;
  10083. }
  10084. else
  10085. {
  10086. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10087. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10088. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10089. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10090. {
  10091. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10092. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10093. goto end;
  10094. }
  10095. }//END FOR ELSE
  10096. }
  10097. }// END FOR CHAdeMO_QUANTITY
  10098. }
  10099. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10100. {
  10101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10102. {
  10103. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10104. }
  10105. else
  10106. {
  10107. tempIndex = connectorIdInt -1;
  10108. }
  10109. for (int index = 0; index < CCS_QUANTITY; index++)
  10110. {
  10111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10112. {
  10113. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10114. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10115. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10116. {
  10117. //Reserved
  10118. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10119. }
  10120. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10121. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10122. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10123. {
  10124. //Reserved
  10125. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10126. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10127. goto end;
  10128. }
  10129. else
  10130. {
  10131. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10132. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10133. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10134. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10135. {
  10136. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10138. goto end;
  10139. }
  10140. }// END FOR ELSE
  10141. }
  10142. }// END FOR CCS_QUANTITY
  10143. }
  10144. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10145. {
  10146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10147. {
  10148. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10149. }
  10150. else
  10151. {
  10152. tempIndex = connectorIdInt -1;
  10153. }
  10154. for (int index = 0; index < GB_QUANTITY; index++)
  10155. {
  10156. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10157. {
  10158. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10159. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10160. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10161. {
  10162. //Reserved
  10163. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10164. }
  10165. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10166. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10167. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10168. {
  10169. //Reserved
  10170. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10171. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10172. goto end;
  10173. }
  10174. else
  10175. {
  10176. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10177. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10178. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10179. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10180. {
  10181. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10182. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10183. goto end;
  10184. }
  10185. }// END FOR ELSE
  10186. }
  10187. } // END FOR GB_QUANTITY
  10188. }
  10189. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10190. {
  10191. tempIndex = connectorIdInt -1;
  10192. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10193. {
  10194. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10195. {
  10196. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10197. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10198. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10199. {
  10200. //Reserved
  10201. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10202. }
  10203. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10204. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10205. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10206. {
  10207. //Reserved
  10208. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10210. goto end;
  10211. }
  10212. else
  10213. {
  10214. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10215. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10216. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10217. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10218. {
  10219. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10220. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10221. goto end;
  10222. }
  10223. }// END FOR ELSE
  10224. }
  10225. } // END FOR GB_QUANTITY
  10226. }
  10227. else
  10228. {
  10229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10230. {
  10231. tempIndex = 2;
  10232. }
  10233. else
  10234. {
  10235. tempIndex = connectorIdInt -1;
  10236. }
  10237. for (int index = 0; index < AC_QUANTITY; index++)
  10238. {
  10239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10240. {
  10241. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10242. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10243. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10244. {
  10245. //Reserved
  10246. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10247. }
  10248. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10249. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10250. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10251. {
  10252. //Reserved
  10253. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10254. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10255. goto end;
  10256. }
  10257. else
  10258. {
  10259. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10260. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10261. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10262. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10263. {
  10264. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10265. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10266. goto end;
  10267. }
  10268. }//END FOR ELSE
  10269. }
  10270. }// END FOR AC_QUANTITY
  10271. }
  10272. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10273. {
  10274. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10275. {
  10276. // Save profile to file
  10277. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10278. system(cmdBuf);
  10279. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10280. fp = fopen(cmdBuf, "w");
  10281. 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));
  10282. fclose(fp);
  10283. }
  10284. else
  10285. {
  10286. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10287. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10288. goto end;
  10289. }
  10290. }
  10291. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10292. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10293. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10294. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10295. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10296. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10297. }
  10298. else
  10299. {
  10300. uint8_t isHasIdleConnector = FALSE;
  10301. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10302. {
  10303. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10304. {
  10305. isHasIdleConnector = TRUE;
  10306. break;
  10307. }
  10308. }
  10309. if(isHasIdleConnector == TRUE)
  10310. {
  10311. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10312. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10313. {
  10314. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10315. {
  10316. // Save profile to file
  10317. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10318. system(cmdBuf);
  10319. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10320. fp = fopen(cmdBuf, "w");
  10321. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10322. fclose(fp);
  10323. refreshStartTimer(&clientTime.RemoteStartWait);
  10324. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10325. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10326. }
  10327. else
  10328. {
  10329. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10330. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10331. }
  10332. }
  10333. }
  10334. else
  10335. {
  10336. DEBUG_INFO("There is not any connector is idle.\n");
  10337. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10338. }
  10339. }
  10340. }
  10341. else
  10342. {
  10343. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10344. }
  10345. end:
  10346. json_object_put(RemoteStartTransaction);
  10347. sendRemoteStartConfirmation(uuid, comfirmstr);
  10348. return result;
  10349. }
  10350. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10351. {
  10352. mtrace();
  10353. int result = FAIL;
  10354. int match = FALSE;
  10355. int GunNO = 0;
  10356. int tempIndex = 0;
  10357. int transactionIdInt=0;
  10358. int transactionIdIsNULL= TRUE;
  10359. char comfirmstr[20];
  10360. json_object *RemoteStopTransaction;
  10361. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10362. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10363. if(server_pending == TRUE)
  10364. {
  10365. return 0;
  10366. }
  10367. RemoteStopTransaction = json_tokener_parse(payload);
  10368. if(!is_error(RemoteStopTransaction))
  10369. {
  10370. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10371. {
  10372. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10373. transactionIdIsNULL = FALSE;
  10374. }
  10375. }
  10376. json_object_put(RemoteStopTransaction);
  10377. if(transactionIdIsNULL == FALSE)
  10378. {
  10379. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10380. {
  10381. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10382. {
  10383. //check Transaction active
  10384. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10385. {
  10386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10387. {
  10388. tempIndex = ((gun_index==2) ? 1: 0);
  10389. }
  10390. else
  10391. {
  10392. tempIndex = gun_index;
  10393. }
  10394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10395. {
  10396. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10397. {
  10398. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10399. {
  10400. match = TRUE;
  10401. GunNO = gun_index;
  10402. }
  10403. }
  10404. }// END FOR CHAdeMO_QUANTITY
  10405. }
  10406. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10407. {
  10408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10409. {
  10410. tempIndex = ((gun_index==2) ? 1: 0);
  10411. }
  10412. else
  10413. {
  10414. tempIndex = gun_index;
  10415. }
  10416. for (int index = 0; index < CCS_QUANTITY; index++)
  10417. {
  10418. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10419. {
  10420. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10421. {
  10422. match = TRUE;
  10423. GunNO = gun_index;
  10424. }
  10425. }
  10426. }// END FOR CCS_QUANTITY
  10427. }
  10428. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10429. {
  10430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10431. {
  10432. tempIndex = ((gun_index==2) ? 1: 0);
  10433. }
  10434. else
  10435. {
  10436. tempIndex = gun_index;
  10437. }
  10438. for (int index = 0; index < GB_QUANTITY; index++)
  10439. {
  10440. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10441. {
  10442. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10443. {
  10444. match = TRUE;
  10445. GunNO = gun_index;
  10446. }
  10447. }
  10448. }// END FOR GB_QUANTITY
  10449. }
  10450. else if(gunType[gun_index] == GUN_TYPE_DO)
  10451. {
  10452. tempIndex = gun_index;
  10453. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10454. {
  10455. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10456. {
  10457. 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
  10458. {
  10459. match = TRUE;
  10460. GunNO = gun_index;
  10461. }
  10462. }
  10463. }// END FOR GB_QUANTITY
  10464. }
  10465. else
  10466. {
  10467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10468. {
  10469. tempIndex = 2;
  10470. }
  10471. else
  10472. {
  10473. tempIndex = gun_index;
  10474. }
  10475. for (int index = 0; index < AC_QUANTITY; index++)
  10476. {
  10477. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10478. {
  10479. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10480. {
  10481. match = TRUE;
  10482. GunNO = gun_index;
  10483. }
  10484. }
  10485. }// END FOR CHAdeMO_QUANTITY
  10486. } // END FOR AC ELSE
  10487. }// CHECK IF ResponseTransactionId == transactionIdInt
  10488. }//END FOR
  10489. if( match == TRUE)
  10490. {
  10491. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10492. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10493. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10494. }
  10495. else
  10496. {
  10497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10498. }
  10499. }
  10500. else
  10501. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10502. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10503. return result;
  10504. }
  10505. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10506. {
  10507. mtrace();
  10508. int result = FAIL;
  10509. int connectorIdInt=0, reservationIdInt=0;
  10510. int tempIndex = 0;
  10511. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10512. char comfirmstr[20]={0};
  10513. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10514. int c = 0;
  10515. char *loc;
  10516. //char *ptr;
  10517. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10518. strcpy(sstrtemp, stringtrimspace(payload));
  10519. //***(1)connectorId ****/
  10520. c=0;
  10521. loc = strstr(sstrtemp, "connectorId");
  10522. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10523. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10524. {
  10525. sstr[c] = loc[strlen("connectorId")+2+c];
  10526. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10527. c++;
  10528. }
  10529. sstr[c] = '\0';
  10530. connectorIdInt = atoi(sstr);
  10531. //***(2)expiryDate ****/
  10532. loc = strstr(sstrtemp, "expiryDate");
  10533. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10534. c = 0;
  10535. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10536. {
  10537. sstr[c] = loc[3+strlen("expiryDate")+c];
  10538. c++;
  10539. }
  10540. sstr[c] = '\0';
  10541. strcpy(expiryDatestr, sstr);
  10542. //***(3)idTag ****/
  10543. loc = strstr(sstrtemp, "idTag");
  10544. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10545. c = 0;
  10546. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10547. {
  10548. sstr[c] = loc[3+strlen("idTag")+c];
  10549. c++;
  10550. }
  10551. sstr[c] = '\0';
  10552. strcpy(idTagstr, sstr);
  10553. //***(4)parentIdTag ****/
  10554. loc = strstr(sstrtemp, "parentIdTag");
  10555. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10556. c = 0;
  10557. if(loc == NULL)
  10558. {
  10559. strcpy(parentIdTagstr, "");
  10560. }
  10561. else
  10562. {
  10563. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10564. {
  10565. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10566. c++;
  10567. }
  10568. sstr[c] = '\0';
  10569. strcpy(parentIdTagstr, sstr);
  10570. }
  10571. //***(5)reservationId ****/
  10572. c=0;
  10573. loc = strstr(sstrtemp, "reservationId");
  10574. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10575. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10576. {
  10577. sstr[c] = loc[strlen("reservationId")+2+c];
  10578. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10579. c++;
  10580. }
  10581. sstr[c] = '\0';
  10582. reservationIdInt = atoi(sstr);
  10583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10584. /*
  10585. enum SYSTEM_STATUS
  10586. {
  10587. SYS_MODE_BOOTING = 0,
  10588. SYS_MODE_IDLE = 1,
  10589. SYS_MODE_AUTHORIZING = 2,
  10590. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10591. SYS_MODE_REASSIGN = 4,
  10592. SYS_MODE_PREPARING = 5,
  10593. SYS_MODE_PREPARE_FOR_EV = 6,
  10594. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10595. SYS_MODE_CHARGING = 8,
  10596. SYS_MODE_TERMINATING = 9,
  10597. SYS_MODE_COMPLETE = 10,
  10598. SYS_MODE_ALARM = 11,
  10599. SYS_MODE_FAULT = 12,
  10600. SYS_MODE_RESERVATION = 13,
  10601. SYS_MODE_BOOKING = 14,
  10602. SYS_MODE_MAINTAIN = 15,
  10603. SYS_MODE_DEBUG = 16,
  10604. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10605. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10606. SYS_MODE_UPDATE = 19
  10607. };
  10608. */
  10609. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10610. {
  10611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10612. goto end;
  10613. }
  10614. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10615. {
  10616. //check Transaction active
  10617. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10618. {
  10619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10620. {
  10621. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10622. }
  10623. else
  10624. {
  10625. tempIndex = connectorIdInt -1;
  10626. }
  10627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10628. {
  10629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10630. {
  10631. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10632. {
  10633. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10634. {
  10635. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10636. {
  10637. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10639. }
  10640. 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'))
  10641. {
  10642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10643. }
  10644. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10645. {
  10646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10647. }
  10648. else
  10649. {
  10650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10651. }
  10652. }
  10653. 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
  10654. {
  10655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10656. }
  10657. }
  10658. else
  10659. {
  10660. //replace reservation
  10661. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10663. }
  10664. }
  10665. } // END FOR CHAdeMO_QUANTITY
  10666. }
  10667. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10668. {
  10669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10670. {
  10671. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10672. }
  10673. else
  10674. {
  10675. tempIndex = connectorIdInt -1;
  10676. }
  10677. for (int index = 0; index < CCS_QUANTITY; index++)
  10678. {
  10679. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10680. {
  10681. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10682. {
  10683. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10684. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10685. {
  10686. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10687. {
  10688. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10690. }
  10691. 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'))
  10692. {
  10693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10694. }
  10695. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10696. {
  10697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10698. }
  10699. else
  10700. {
  10701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10702. }
  10703. }
  10704. 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
  10705. {
  10706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10707. }
  10708. }
  10709. else
  10710. {
  10711. //replace reservation
  10712. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10714. }
  10715. }
  10716. } // END FOR CCS_QUANTITY
  10717. }
  10718. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10719. {
  10720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10721. {
  10722. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10723. }
  10724. else
  10725. {
  10726. tempIndex = connectorIdInt -1;
  10727. }
  10728. for (int index = 0; index < GB_QUANTITY; index++)
  10729. {
  10730. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10731. {
  10732. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10733. {
  10734. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10735. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10736. {
  10737. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10738. {
  10739. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10740. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10741. }
  10742. 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'))
  10743. {
  10744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10745. }
  10746. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10747. {
  10748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10749. }
  10750. else
  10751. {
  10752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10753. }
  10754. }
  10755. 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
  10756. {
  10757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10758. }
  10759. }
  10760. else
  10761. {
  10762. //replace reservation
  10763. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10765. }
  10766. }
  10767. }// END FOR GB_QUANTITY
  10768. }
  10769. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10770. {
  10771. tempIndex = connectorIdInt -1;
  10772. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10773. {
  10774. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10775. {
  10776. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10777. {
  10778. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10779. 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
  10780. {
  10781. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10782. {
  10783. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10785. }
  10786. 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'))
  10787. {
  10788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10789. }
  10790. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10791. {
  10792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10793. }
  10794. else
  10795. {
  10796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10797. }
  10798. }
  10799. 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
  10800. {
  10801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10802. }
  10803. }
  10804. else
  10805. {
  10806. //replace reservation
  10807. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10809. }
  10810. }
  10811. }// END FOR GB_QUANTITY
  10812. }
  10813. else
  10814. {
  10815. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10816. {
  10817. tempIndex = 2;
  10818. }
  10819. else
  10820. {
  10821. tempIndex = (connectorIdInt -1);
  10822. }
  10823. for (int index = 0; index < AC_QUANTITY; index++)
  10824. {
  10825. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10826. {
  10827. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10828. {
  10829. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10830. {
  10831. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10832. {
  10833. 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))
  10834. {
  10835. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10836. }
  10837. else
  10838. {
  10839. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10841. }
  10842. }
  10843. 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'))
  10844. {
  10845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10846. }
  10847. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10848. {
  10849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10850. }
  10851. else
  10852. {
  10853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10854. }
  10855. }
  10856. 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
  10857. {
  10858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10859. }
  10860. }
  10861. else
  10862. {
  10863. //replace reservation
  10864. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10866. }
  10867. }
  10868. } // END FOR AC_QUANTITY
  10869. }
  10870. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10871. }
  10872. else if(connectorIdInt == 0)
  10873. {
  10874. //check Transaction active
  10875. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10876. {
  10877. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10878. {
  10879. 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'))
  10880. {
  10881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10882. goto end;
  10883. }
  10884. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10885. {
  10886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10887. goto end;
  10888. }
  10889. 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
  10890. {
  10891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10892. goto end;
  10893. }
  10894. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10895. {
  10896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10897. goto end;
  10898. }
  10899. }
  10900. }// END FOR CHAdeMO_QUANTITY
  10901. for (int index = 0; index < CCS_QUANTITY; index++)
  10902. {
  10903. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10904. {
  10905. 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'))
  10906. {
  10907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10908. goto end;
  10909. }
  10910. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10911. {
  10912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10913. goto end;
  10914. }
  10915. 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
  10916. {
  10917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10918. goto end;
  10919. }
  10920. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10921. {
  10922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10923. goto end;
  10924. }
  10925. }
  10926. } // END FOR CCS_QUANTITY
  10927. for (int index = 0; index < GB_QUANTITY; index++)
  10928. {
  10929. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10930. {
  10931. 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'))
  10932. {
  10933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10934. goto end;
  10935. }
  10936. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10937. {
  10938. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10939. goto end;
  10940. }
  10941. 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
  10942. {
  10943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10944. goto end;
  10945. }
  10946. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10947. {
  10948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10949. goto end;
  10950. }
  10951. }
  10952. } // END FOR GB_QUANTITY
  10953. for (int index = 0; index < AC_QUANTITY; index++)
  10954. {
  10955. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10956. {
  10957. 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'))
  10958. {
  10959. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10960. goto end;
  10961. }
  10962. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10963. {
  10964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10965. goto end;
  10966. }
  10967. 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
  10968. {
  10969. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10970. goto end;
  10971. }
  10972. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10973. {
  10974. 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))
  10975. {
  10976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10977. goto end;
  10978. }
  10979. }
  10980. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10981. {
  10982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10983. goto end;
  10984. }
  10985. }
  10986. }// END FOR AC_QUANTITY
  10987. //The connectorId is 0
  10988. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10990. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10991. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10992. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10993. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10994. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10995. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  10996. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  10997. result = TRUE;
  10998. return result;
  10999. }
  11000. else
  11001. {
  11002. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11003. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11004. }
  11005. if(strcmp(comfirmstr,"Accepted") == 0)
  11006. {
  11007. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11008. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11009. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11010. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11011. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11012. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11013. result = TRUE;
  11014. return result;
  11015. }
  11016. end:
  11017. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11018. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11019. return result;
  11020. }
  11021. int handleResetRequest(char *uuid, char *payload)
  11022. {
  11023. mtrace();
  11024. int result = FAIL;
  11025. char sstr[10]={0},sstrtemp[30]={ 0 };
  11026. char typestr[10]={0};
  11027. char comfirmstr[20]={0};
  11028. int c = 0;
  11029. char *loc;
  11030. DEBUG_INFO("handleResetRequest...\n");
  11031. strcpy(sstrtemp, stringtrimspace(payload));
  11032. loc = strstr(sstrtemp, "type");
  11033. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11034. c = 0;
  11035. while (loc[3+strlen("type")+c] != '\"')
  11036. {
  11037. sstr[c] = loc[3+strlen("type")+c];
  11038. c++;
  11039. }
  11040. sstr[c] = '\0';
  11041. strcpy(typestr,sstr);
  11042. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11043. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11044. {
  11045. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11046. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11047. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11048. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11049. }
  11050. else
  11051. {
  11052. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11053. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11054. result = PASS;
  11055. }
  11056. sendResetConfirmation(uuid, comfirmstr);
  11057. return result;
  11058. }
  11059. int handleSendLocalListRequest(char *uuid, char *payload)
  11060. {
  11061. mtrace();
  11062. int result = FAIL;
  11063. char comfirmstr[20];
  11064. int checkState_Faulted = FALSE;
  11065. json_object *SendLocalList;
  11066. DEBUG_INFO("handleSendLocalListRequest...\n");
  11067. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11068. {
  11069. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11070. goto end;
  11071. }
  11072. //check Charge Point state
  11073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11074. {
  11075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11076. {
  11077. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11078. }
  11079. }
  11080. for (int index = 0; index < CCS_QUANTITY; index++)
  11081. {
  11082. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11083. {
  11084. checkState_Faulted = TRUE; //OCPP Status
  11085. }
  11086. }
  11087. for (int index = 0; index < GB_QUANTITY; index++)
  11088. {
  11089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11090. {
  11091. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11092. }
  11093. }
  11094. //check Charge Point state
  11095. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11096. {
  11097. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11098. {
  11099. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11100. }
  11101. }
  11102. //check Charge Point state
  11103. for (int index = 0; index < AC_QUANTITY; index++)
  11104. {
  11105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11106. {
  11107. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11108. }
  11109. }
  11110. if(checkState_Faulted == TRUE)
  11111. {
  11112. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11113. goto end;
  11114. }
  11115. // Parsing payload
  11116. SendLocalList = json_tokener_parse(payload);
  11117. if(!is_error(SendLocalList))
  11118. {
  11119. // Required data
  11120. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11121. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11122. // Optional data
  11123. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11124. {
  11125. //Check UpdateType
  11126. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11127. {
  11128. //Local list full update
  11129. DEBUG_INFO("Local list full update.\n");
  11130. OCPP_getListVerion();
  11131. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11132. {
  11133. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11134. goto end;
  11135. }
  11136. OCPP_cleanLocalList();
  11137. }
  11138. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11139. {
  11140. //Local list different update
  11141. DEBUG_INFO("Local list different update.\n");
  11142. OCPP_getListVerion();
  11143. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11144. {
  11145. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11146. goto end;
  11147. }
  11148. }
  11149. else
  11150. {
  11151. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11152. goto end;
  11153. }
  11154. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11155. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11156. {
  11157. 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")));
  11158. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11159. {
  11160. 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")));
  11161. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11162. 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")));
  11163. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11164. 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")));
  11165. }
  11166. // Add to db
  11167. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11168. {
  11169. //Local list full update
  11170. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11171. idx,
  11172. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11173. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11174. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11175. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11176. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11177. // update list
  11178. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11179. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11180. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11181. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11182. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11183. }
  11184. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11185. {
  11186. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11187. idx,
  11188. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11189. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11190. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11191. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11192. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11193. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11194. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11195. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11196. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11197. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11198. }
  11199. }
  11200. }
  11201. else
  11202. {
  11203. //Check UpdateType
  11204. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11205. {
  11206. //Local list full update
  11207. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11208. OCPP_cleanLocalList();
  11209. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11210. goto end;
  11211. }
  11212. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11213. {
  11214. //Local list different update
  11215. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11216. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11217. goto end;
  11218. }
  11219. }
  11220. result = PASS;
  11221. }
  11222. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11223. end:
  11224. json_object_put(SendLocalList);
  11225. sendSendLocalListConfirmation(uuid, comfirmstr);
  11226. return result;
  11227. }
  11228. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11229. {
  11230. mtrace();
  11231. int result = FAIL;
  11232. struct StructSetChargingProfile SetProfileReq = {0};
  11233. int tempchargingProfileIdInt;
  11234. int chargingSchedulePeriodCount = 0;
  11235. char comfirmstr[20]={0};
  11236. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11237. char rmFileCmd[128]={0};
  11238. int profileQuantity = 0;
  11239. json_object *SetChargingProfile;
  11240. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11241. SetChargingProfile = json_tokener_parse(payload);
  11242. if(!is_error(SetChargingProfile))
  11243. {
  11244. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11245. {
  11246. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11247. }
  11248. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11249. {
  11250. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11251. {
  11252. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11253. }
  11254. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11255. {
  11256. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11257. }
  11258. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11259. {
  11260. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11261. }
  11262. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11263. {
  11264. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11265. }
  11266. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11267. {
  11268. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11269. }
  11270. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11271. {
  11272. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11273. }
  11274. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11275. {
  11276. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11277. }
  11278. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11279. {
  11280. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11281. }
  11282. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11283. {
  11284. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11285. {
  11286. 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")));
  11287. }
  11288. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11289. {
  11290. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11291. }
  11292. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11293. {
  11294. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11295. }
  11296. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11297. {
  11298. 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")));
  11299. }
  11300. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11301. {
  11302. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11303. if(chargingSchedulePeriodCount <= 10)
  11304. {
  11305. 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++)
  11306. {
  11307. 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)
  11308. {
  11309. 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"));
  11310. }
  11311. 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)
  11312. {
  11313. 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"));
  11314. }
  11315. 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)
  11316. {
  11317. 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"));
  11318. }
  11319. }
  11320. }
  11321. }
  11322. }
  11323. }
  11324. }
  11325. // Profile periods quantity check
  11326. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11327. {
  11328. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11329. goto end;
  11330. }
  11331. // Check invalid limit
  11332. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11333. {
  11334. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11335. {
  11336. 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)))) ||
  11337. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11338. {
  11339. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11340. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11341. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11342. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11343. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11344. goto end;
  11345. }
  11346. }
  11347. }
  11348. else
  11349. {
  11350. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11351. {
  11352. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:modelnameInfo.ParsingInfo[0].Current)))
  11353. {
  11354. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11355. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11356. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11357. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11358. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11359. goto end;
  11360. }
  11361. }
  11362. }
  11363. // Profile purpose info check
  11364. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11365. {
  11366. FILE *fp;
  11367. char dataLine[4096]={0};
  11368. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11369. if(SetProfileReq.ConnectorId != 0)
  11370. {
  11371. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11372. goto end;
  11373. }
  11374. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11375. if (!fp)
  11376. {
  11377. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11378. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11379. }
  11380. else
  11381. {
  11382. while(fscanf(fp, "%s", dataLine) != EOF)
  11383. {
  11384. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11385. {
  11386. profileQuantity += 1;
  11387. }
  11388. }
  11389. }
  11390. fclose(fp);
  11391. }
  11392. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11393. {
  11394. FILE *fp;
  11395. char dataLine[4096]={0};
  11396. char filename[128]={0};
  11397. int tmpProfileQuantity;
  11398. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11399. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11400. {
  11401. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11402. goto end;
  11403. }
  11404. if(SetProfileReq.ConnectorId == 0)
  11405. {
  11406. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11407. {
  11408. tmpProfileQuantity = 0;
  11409. memset(filename, 0, ARRAY_SIZE(filename));
  11410. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11411. fp = fopen(filename, "r");
  11412. if (!fp)
  11413. {
  11414. DEBUG_INFO("%s does not create.\n", filename);
  11415. fp = fopen(filename, "w+");
  11416. }
  11417. else
  11418. {
  11419. while(fscanf(fp, "%s", dataLine) != EOF)
  11420. {
  11421. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11422. {
  11423. tmpProfileQuantity += 1;
  11424. }
  11425. }
  11426. }
  11427. fclose(fp);
  11428. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11429. }
  11430. }
  11431. else
  11432. {
  11433. memset(filename, 0, ARRAY_SIZE(filename));
  11434. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11435. fp = fopen(filename, "r");
  11436. if (!fp)
  11437. {
  11438. DEBUG_INFO("%s does not create.\n", filename);
  11439. fp = fopen(filename, "w+");
  11440. }
  11441. else
  11442. {
  11443. while(fscanf(fp, "%s", dataLine) != EOF)
  11444. {
  11445. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11446. {
  11447. profileQuantity += 1;
  11448. }
  11449. }
  11450. }
  11451. fclose(fp);
  11452. }
  11453. }
  11454. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11455. {
  11456. int isMatchTransactiodId= FALSE;
  11457. FILE *fp;
  11458. char dataLine[4096]={0};
  11459. char filename[128]={0};
  11460. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11461. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11462. if(SetProfileReq.ConnectorId == 0)
  11463. {
  11464. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11465. goto end;
  11466. }
  11467. int tempIndex = 0;
  11468. //check Transaction active
  11469. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11470. {
  11471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11472. {
  11473. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11474. }
  11475. else
  11476. {
  11477. tempIndex = SetProfileReq.ConnectorId -1;
  11478. }
  11479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11480. {
  11481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11482. {
  11483. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11484. {
  11485. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11486. {
  11487. isMatchTransactiodId = TRUE;
  11488. break;
  11489. }
  11490. }
  11491. }
  11492. }
  11493. }
  11494. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11495. {
  11496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11497. {
  11498. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11499. }
  11500. else
  11501. {
  11502. tempIndex = SetProfileReq.ConnectorId -1;
  11503. }
  11504. for (int index = 0; index < CCS_QUANTITY; index++)
  11505. {
  11506. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11507. {
  11508. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11509. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11510. {
  11511. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11512. {
  11513. isMatchTransactiodId = TRUE;
  11514. break;
  11515. }
  11516. }
  11517. }
  11518. }
  11519. }
  11520. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11521. {
  11522. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11523. {
  11524. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11525. }
  11526. else
  11527. {
  11528. tempIndex = SetProfileReq.ConnectorId -1;
  11529. }
  11530. for (int index = 0; index < GB_QUANTITY; index++)
  11531. {
  11532. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11533. {
  11534. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11535. {
  11536. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11537. {
  11538. isMatchTransactiodId = TRUE;
  11539. break;
  11540. }
  11541. }
  11542. }
  11543. }
  11544. }
  11545. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11546. {
  11547. tempIndex = SetProfileReq.ConnectorId -1;
  11548. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11549. {
  11550. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11551. {
  11552. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11553. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11554. {
  11555. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11556. {
  11557. isMatchTransactiodId = TRUE;
  11558. break;
  11559. }
  11560. }
  11561. }
  11562. }
  11563. }
  11564. else
  11565. {
  11566. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11567. {
  11568. tempIndex = 2;
  11569. }
  11570. else
  11571. {
  11572. tempIndex = (SetProfileReq.ConnectorId -1);
  11573. }
  11574. for (int index = 0; index < AC_QUANTITY; index++)
  11575. {
  11576. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11577. {
  11578. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11579. {
  11580. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11581. {
  11582. isMatchTransactiodId = TRUE;
  11583. break;
  11584. }
  11585. }
  11586. }
  11587. }
  11588. }
  11589. //check Transaction active
  11590. if(isMatchTransactiodId == FALSE)
  11591. {
  11592. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11593. goto end;
  11594. }
  11595. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11596. {
  11597. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11598. goto end;
  11599. }
  11600. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11601. fp = fopen(filename, "r");
  11602. if (!fp)
  11603. {
  11604. DEBUG_INFO("%s does not create.\n", filename);
  11605. fp = fopen(filename, "w+");
  11606. }
  11607. else
  11608. {
  11609. //Check Charging Profile Count
  11610. while(fscanf(fp, "%s", dataLine) != EOF)
  11611. {
  11612. //DEBUG_INFO("word=%s\n",word);
  11613. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11614. {
  11615. profileQuantity += 1;
  11616. }
  11617. }
  11618. }
  11619. fclose(fp);
  11620. }
  11621. // Check ChargeProfileMaxStackLevel
  11622. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11623. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11624. {
  11625. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11626. goto end;
  11627. }
  11628. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11629. {
  11630. FILE *fp;
  11631. char dataLine[4096]={0};
  11632. char fnametemp[128]={0};
  11633. int tmpProfileQuantity;
  11634. //Check ChargePointMaxProfile.json exit
  11635. profileQuantity = 0;
  11636. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11637. {
  11638. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11639. //Check Charging Profile Count
  11640. tmpProfileQuantity = 0;
  11641. while(fscanf(fp, "%s", dataLine) != EOF)
  11642. {
  11643. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11644. {
  11645. profileQuantity += 1;
  11646. tmpProfileQuantity += 1;
  11647. }
  11648. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11649. }
  11650. fclose(fp);
  11651. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11652. }
  11653. //Check TxDefaultProfile_%d.json
  11654. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11655. {
  11656. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11657. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11658. if((access(fnametemp,F_OK))!=-1)
  11659. {
  11660. fp = fopen(fnametemp, "r");
  11661. //Check Charging Profile Count
  11662. tmpProfileQuantity = 0;
  11663. while(fscanf(fp, "%s", dataLine) != EOF)
  11664. {
  11665. //DEBUG_INFO("word=%s\n",word);
  11666. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11667. {
  11668. profileQuantity += 1;
  11669. tmpProfileQuantity += 1;
  11670. }
  11671. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11672. }
  11673. fclose(fp);
  11674. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11675. }
  11676. }
  11677. //Check TxProfile_%d.json
  11678. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11679. {
  11680. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11681. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11682. if((access(fnametemp,F_OK))!=-1)
  11683. {
  11684. fp = fopen(fnametemp, "r");
  11685. //Check Charging Profile Count
  11686. tmpProfileQuantity = 0;
  11687. while(fscanf(fp, "%s", dataLine) != EOF)
  11688. {
  11689. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11690. {
  11691. profileQuantity += 1;
  11692. tmpProfileQuantity += 1;
  11693. }
  11694. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11695. }
  11696. fclose(fp);
  11697. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11698. }
  11699. }
  11700. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11701. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11702. {
  11703. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11704. goto end;
  11705. }
  11706. }
  11707. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11708. //**********************************Write to File********************************************************/
  11709. {
  11710. FILE *infile;
  11711. FILE *outfile;
  11712. char dataLine[4096]={0};
  11713. char filename[128]={0};
  11714. int chkChar=0;
  11715. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11716. {
  11717. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11718. {
  11719. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11720. }
  11721. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11722. {
  11723. if(SetProfileReq.ConnectorId==0)
  11724. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11725. else
  11726. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11727. }
  11728. else
  11729. {
  11730. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11731. }
  11732. infile = fopen (filename, "r");
  11733. outfile = fopen (tempfile, "w");
  11734. chkChar = fgetc(infile);
  11735. rewind(infile);
  11736. if(chkChar == EOF)
  11737. {
  11738. // Profile is empty
  11739. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11740. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11741. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11742. fclose(infile);
  11743. fclose(outfile);
  11744. sprintf(rmFileCmd,"rm -f %s",filename);
  11745. system(rmFileCmd);
  11746. rename(tempfile, filename);
  11747. }
  11748. else
  11749. {
  11750. // Profile is not empty
  11751. int ChargingProfileAdded = FALSE;
  11752. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11753. {
  11754. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11755. json_object *tmpChargingProfile;
  11756. tmpChargingProfile = json_tokener_parse(dataLine);
  11757. if(!is_error(SetChargingProfile))
  11758. {
  11759. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11760. {
  11761. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11762. {
  11763. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11764. }
  11765. }
  11766. }
  11767. json_object_put(tmpChargingProfile);
  11768. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11769. {
  11770. if(ChargingProfileAdded == FALSE)
  11771. {
  11772. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11773. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11774. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11775. ChargingProfileAdded = TRUE;
  11776. }
  11777. }
  11778. else
  11779. {
  11780. fprintf(outfile,"%s\n",dataLine);
  11781. if(ChargingProfileAdded == FALSE)
  11782. {
  11783. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11784. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11785. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11786. ChargingProfileAdded = TRUE;
  11787. }
  11788. }
  11789. } // end of while loop
  11790. fclose(infile);
  11791. fclose(outfile);
  11792. sprintf(rmFileCmd,"rm -f %s",filename);
  11793. system(rmFileCmd);
  11794. rename(tempfile, filename);
  11795. }
  11796. }
  11797. sleep(1);
  11798. result = TRUE;
  11799. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11800. }
  11801. end:
  11802. json_object_put(SetChargingProfile);
  11803. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11804. {
  11805. if(SetProfileReq.ConnectorId == 0)
  11806. {
  11807. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11808. {
  11809. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11810. }
  11811. }
  11812. else
  11813. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11814. }
  11815. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11816. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11817. return result;
  11818. }
  11819. int handleTriggerMessageRequest(char *uuid, char *payload)
  11820. {
  11821. mtrace();
  11822. int result = FAIL;
  11823. int connectorIdIsNULL = FALSE;
  11824. int connectorIdInt =0;
  11825. char sstr[40]={0},sstrtemp[100]={ 0 };
  11826. char requestedMessagestr[40]={0};
  11827. char comfirmstr[20]={0};
  11828. int c = 0;
  11829. char *loc;
  11830. DEBUG_INFO("handleTriggerMessageRequest\n");
  11831. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11832. strcpy(sstrtemp, stringtrimspace(payload));
  11833. c = 0;
  11834. loc = strstr(sstrtemp, "requestedMessage");
  11835. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11836. {
  11837. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11838. c++;
  11839. }
  11840. sstr[c] = '\0';
  11841. strcpy(requestedMessagestr, sstr);
  11842. c = 0;
  11843. loc = strstr(sstrtemp, "connectorId");
  11844. if(loc == NULL)
  11845. {
  11846. connectorIdIsNULL = TRUE;
  11847. }
  11848. else
  11849. {
  11850. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11851. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11852. {
  11853. sstr[c] = loc[strlen("connectorId")+2+c];
  11854. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11855. c++;
  11856. }
  11857. sstr[c] = '\0';
  11858. connectorIdInt = atoi(sstr);
  11859. }
  11860. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11861. {
  11862. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11863. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11864. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11865. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11866. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11867. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11868. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11869. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11870. {
  11871. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11872. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11873. return TRUE;
  11874. }
  11875. else
  11876. {
  11877. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11878. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11879. }
  11880. }
  11881. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11882. {
  11883. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11884. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11885. return TRUE;
  11886. }
  11887. //==========================
  11888. // Trigger message
  11889. //==========================
  11890. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11891. {
  11892. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11893. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11894. {
  11895. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11896. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11897. }
  11898. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11899. }
  11900. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11901. {
  11902. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11903. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11904. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11905. }
  11906. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11907. {
  11908. //sendBootNotificationRequest();
  11909. server_sign = FALSE;
  11910. }
  11911. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11912. {
  11913. refreshStartTimer(&clientTime.Heartbeat);
  11914. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  11915. }
  11916. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11917. {
  11918. if(connectorIdIsNULL == FALSE)
  11919. {
  11920. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11921. {
  11922. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11923. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11924. }
  11925. }
  11926. else
  11927. {
  11928. for(int idx=0;idx< gunTotalNumber;idx++)
  11929. {
  11930. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11931. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11932. }
  11933. }
  11934. }
  11935. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11936. {
  11937. if(connectorIdIsNULL == FALSE)
  11938. {
  11939. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11940. {
  11941. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11942. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11943. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11944. }
  11945. }
  11946. else
  11947. {
  11948. for(int idx=0;idx< gunTotalNumber;idx++)
  11949. {
  11950. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11951. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11952. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11953. }
  11954. }
  11955. }
  11956. return result;
  11957. }
  11958. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11959. {
  11960. mtrace();
  11961. int result = FAIL;
  11962. int connectorIdInt =0;
  11963. char comfirmstr[20]={0};
  11964. int tempIndex = 0;
  11965. json_object *UnlockConnector;
  11966. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11967. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11968. UnlockConnector = json_tokener_parse(payload);
  11969. if(!is_error(UnlockConnector))
  11970. {
  11971. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11972. {
  11973. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11974. }
  11975. }
  11976. json_object_put(UnlockConnector);
  11977. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11978. if(gunTotalNumber == 0)
  11979. {
  11980. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11981. goto end;
  11982. }
  11983. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11984. {
  11985. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11986. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11987. goto end;
  11988. }
  11989. else
  11990. {
  11991. //check Transaction active
  11992. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11993. {
  11994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11995. {
  11996. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11997. }
  11998. else
  11999. {
  12000. tempIndex = connectorIdInt -1;
  12001. }
  12002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12003. {
  12004. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12005. {
  12006. //stop Transaction
  12007. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12008. }
  12009. }
  12010. }
  12011. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12012. {
  12013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12014. {
  12015. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12016. }
  12017. else
  12018. {
  12019. tempIndex = connectorIdInt -1;
  12020. }
  12021. for (int index = 0; index < CCS_QUANTITY; index++)
  12022. {
  12023. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12024. {
  12025. //stop Transaction
  12026. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12027. }
  12028. }
  12029. }
  12030. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12031. {
  12032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12033. {
  12034. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12035. }
  12036. else
  12037. {
  12038. tempIndex = connectorIdInt -1;
  12039. }
  12040. for (int index = 0; index < GB_QUANTITY; index++)
  12041. {
  12042. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12043. {
  12044. //stop Transaction
  12045. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12046. }
  12047. }
  12048. }
  12049. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12050. {
  12051. tempIndex = connectorIdInt -1;
  12052. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12053. {
  12054. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12055. {
  12056. //stop Transaction
  12057. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12058. }
  12059. }
  12060. }
  12061. else
  12062. {
  12063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12064. {
  12065. tempIndex = 2;
  12066. }
  12067. else
  12068. {
  12069. tempIndex = connectorIdInt-1;
  12070. }
  12071. for (int index = 0; index < AC_QUANTITY; index++)
  12072. {
  12073. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12074. {
  12075. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12076. }
  12077. }
  12078. }
  12079. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12080. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12081. result = TRUE;
  12082. return result;
  12083. }
  12084. end:
  12085. //json_object_put(obj); --- remove temporally
  12086. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12087. return result;
  12088. }
  12089. static char UpdateFirmwarepayloadData[300]={0};
  12090. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12091. {
  12092. mtrace();
  12093. int result = FAIL;
  12094. pthread_t t;
  12095. sendUpdateFirmwareConfirmation(uuid);
  12096. memset(UpdateFirmwarepayloadData, 0, 300);
  12097. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12098. if(!interLock.isUpdateFirmwareGoing)
  12099. {
  12100. interLock.isUpdateFirmwareGoing = 1;
  12101. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12102. sleep(1);
  12103. }
  12104. else
  12105. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12106. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12107. return result;
  12108. }
  12109. void *UpdateFirmwareProcess(void *data)
  12110. {
  12111. pthread_detach(pthread_self());
  12112. mtrace();
  12113. int retriesInt =0, retryIntervalInt=0;
  12114. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12115. int port=0;
  12116. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12117. int isSuccess = 0;
  12118. char ftpbuf[512];
  12119. char temp[100];
  12120. char * pch;
  12121. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12122. json_object *UpdateFirmware;
  12123. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12124. if(!is_error(UpdateFirmware))
  12125. {
  12126. // Required data
  12127. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12128. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12129. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12130. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12131. // Optional data
  12132. if(json_object_object_get(UpdateFirmware, "retries"))
  12133. {
  12134. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12135. }
  12136. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12137. {
  12138. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12139. }
  12140. }
  12141. json_object_put(UpdateFirmware);
  12142. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12143. memset(path, 0, ARRAY_SIZE(path));
  12144. // Wait retrieveData
  12145. if(strlen(retrieveDatestr) > 10)
  12146. {
  12147. do
  12148. {
  12149. sleep(1);
  12150. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12151. }
  12152. // Ready to download
  12153. system("rm -f /mnt/*");
  12154. if(strncmp(locationstr,"http", 4) == 0)
  12155. {
  12156. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12157. sprintf(ftppath,"/%s", path);
  12158. DEBUG_INFO("locationstr: %s\n", locationstr);
  12159. DEBUG_INFO("protocol: %s\n",protocol);
  12160. DEBUG_INFO("host: %s\n",host);
  12161. DEBUG_INFO("path: %s\n",path);
  12162. DEBUG_INFO("ftppath: %s\n",ftppath);
  12163. int ftppathlen=strlen(ftppath);
  12164. int i=1;
  12165. char filenametemp[50];
  12166. while(i < ftppathlen)
  12167. {
  12168. int len=ftppathlen-i;
  12169. if(ftppath[len]== 47) // '/' ascll code: 47
  12170. {
  12171. DEBUG_INFO("compare '/' all right\n");
  12172. break;
  12173. }
  12174. i=i+1;
  12175. }
  12176. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12177. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12178. filenametemp[i+1] = 0;
  12179. do
  12180. {
  12181. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12182. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12183. sleep(1);
  12184. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12185. if(!isSuccess)
  12186. {
  12187. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12188. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12189. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12190. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12191. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12192. }
  12193. else
  12194. {
  12195. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12196. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12197. }
  12198. retriesInt--;
  12199. }while((isSuccess == 0)&&(retriesInt >= 0));
  12200. }
  12201. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12202. {
  12203. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12204. memset(temp, 0, ARRAY_SIZE(temp));
  12205. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12206. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12207. int ftppathlen=strlen(ftpbuf);
  12208. int i=1;
  12209. char filenametemp[50];
  12210. while(i < ftppathlen)
  12211. {
  12212. int len=ftppathlen-i;
  12213. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12214. {
  12215. DEBUG_INFO(" compare '/' all right\n");
  12216. break;
  12217. }
  12218. i=i+1;
  12219. }
  12220. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12221. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12222. filenametemp[i+1] = 0;
  12223. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12224. pch=strchr(temp,'@');
  12225. if(pch==NULL)
  12226. {
  12227. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12228. protocol, host, &port, path);
  12229. strcpy(user,"anonymous");
  12230. strcpy(password,"");
  12231. }
  12232. else
  12233. {
  12234. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12235. protocol, user, password, host, &port, path);
  12236. }
  12237. sscanf(host,"%[^/]%s",host1, path1);
  12238. sprintf(ftppath,"%s", path1);
  12239. //DEBUG_INFO("protocol =%s\n",protocol);
  12240. //DEBUG_INFO("user =%s\n",user);
  12241. //DEBUG_INFO("password =%s\n",password);
  12242. //DEBUG_INFO("host1 =%s\n",host1);
  12243. //DEBUG_INFO("port =%d\n",port);
  12244. //DEBUG_INFO("path1 =%s\n",path1);
  12245. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12246. //ftpFile(host, user, password, port, ftppath, fname);
  12247. //download firmware pthred
  12248. if(port == 0)
  12249. {
  12250. port = 21;
  12251. }
  12252. do
  12253. {
  12254. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12255. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12256. sleep(1);
  12257. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12258. if(!isSuccess)
  12259. {
  12260. //BulldogUtil.sleepMs(interval*1000);
  12261. DEBUG_INFO("Update firmware request and download file fail.\n");
  12262. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12263. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12264. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12265. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12266. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12267. }
  12268. else
  12269. {
  12270. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12271. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12272. }
  12273. retriesInt--;
  12274. }while((!isSuccess)&&(retriesInt >= 0));
  12275. }
  12276. else
  12277. {
  12278. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12279. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12280. sleep(1);
  12281. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12282. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12283. }
  12284. // OCPPPH only, must announce CSU upgrade firmware
  12285. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12286. interLock.isUpdateFirmwareGoing = 0;
  12287. pthread_exit(NULL);
  12288. }
  12289. int handleCertificateSignedRequest(char *uuid, char *payload)
  12290. {
  12291. mtrace();
  12292. int result = PASS;
  12293. json_object *CertificateSigned;
  12294. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12295. CertificateSigned = json_tokener_parse(payload);
  12296. if(!is_error(CertificateSigned))
  12297. {
  12298. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12299. }
  12300. json_object_put(CertificateSigned);
  12301. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12302. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12303. fclose(fp);
  12304. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12305. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12306. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12307. sendCertificateSignedConfirmation(uuid);
  12308. return result;
  12309. }
  12310. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12311. {
  12312. mtrace();
  12313. int result = PASS;
  12314. json_object *DeleteCertificate;
  12315. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12316. DeleteCertificate = json_tokener_parse(payload);
  12317. if(!is_error(DeleteCertificate))
  12318. {
  12319. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12320. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12321. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12322. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12323. }
  12324. json_object_put(DeleteCertificate);
  12325. /*
  12326. * TODO: Delete certificateSigned process
  12327. */
  12328. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12329. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12330. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12331. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12332. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12333. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12334. sendDeleteCertificateConfirmation(uuid);
  12335. return result;
  12336. }
  12337. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12338. {
  12339. mtrace();
  12340. int result = PASS;
  12341. json_object *ExtendedTriggerMessage;
  12342. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12343. ExtendedTriggerMessage = json_tokener_parse(payload);
  12344. if(!is_error(ExtendedTriggerMessage))
  12345. {
  12346. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12347. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12348. {
  12349. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12350. }
  12351. else
  12352. {
  12353. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12354. }
  12355. }
  12356. json_object_put(ExtendedTriggerMessage);
  12357. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12358. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12359. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12360. {
  12361. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12362. }
  12363. else
  12364. {
  12365. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12366. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12367. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12368. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12369. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12370. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12371. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12372. {
  12373. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12374. }
  12375. else
  12376. {
  12377. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12378. }
  12379. }
  12380. sendExtendedTriggerMessageConfirmation(uuid);
  12381. //==========================
  12382. // Trigger message
  12383. //==========================
  12384. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12385. {
  12386. //sendBootNotificationRequest();
  12387. server_sign = FALSE;
  12388. }
  12389. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12390. {
  12391. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12392. }
  12393. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12394. {
  12395. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12396. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12397. {
  12398. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12399. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12400. }
  12401. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12402. }
  12403. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12404. {
  12405. refreshStartTimer(&clientTime.Heartbeat);
  12406. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12407. }
  12408. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12409. {
  12410. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12411. {
  12412. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12413. }
  12414. else
  12415. {
  12416. for(int idx=0;idx< gunTotalNumber;idx++)
  12417. {
  12418. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12419. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12420. }
  12421. }
  12422. }
  12423. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12424. {
  12425. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12426. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12427. {
  12428. 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\" &");
  12429. }
  12430. }
  12431. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12432. {
  12433. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12434. {
  12435. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12436. }
  12437. else
  12438. {
  12439. for(int idx=0;idx< gunTotalNumber;idx++)
  12440. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12441. }
  12442. }
  12443. return result;
  12444. }
  12445. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12446. {
  12447. mtrace();
  12448. int result = PASS;
  12449. json_object *GetInstalledCertificateIds;
  12450. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12451. GetInstalledCertificateIds = json_tokener_parse(payload);
  12452. if(!is_error(GetInstalledCertificateIds))
  12453. {
  12454. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12455. }
  12456. json_object_put(GetInstalledCertificateIds);
  12457. /*
  12458. * TODO: Return installed certificate process
  12459. */
  12460. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12461. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12462. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12463. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12464. sendGetInstalledCertificateIdsConfirmation(uuid);
  12465. return result;
  12466. }
  12467. int handleGetLogRequest(char *uuid, char *payload)
  12468. {
  12469. mtrace();
  12470. int result = PASS;
  12471. json_object *GetLog;
  12472. DEBUG_INFO("handleGetLogRequest...\n");
  12473. GetLog = json_tokener_parse(payload);
  12474. if(!is_error(GetLog))
  12475. {
  12476. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12477. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12478. if(json_object_object_get(GetLog, "retries") != NULL)
  12479. {
  12480. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12481. }
  12482. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12483. {
  12484. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12485. }
  12486. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12487. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12488. {
  12489. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12490. }
  12491. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12492. {
  12493. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12494. }
  12495. }
  12496. json_object_put(GetLog);
  12497. /*
  12498. * TODO: Upload log process
  12499. */
  12500. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12501. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12502. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12503. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12504. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12505. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12506. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12507. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12508. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12509. sendGetLogConfirmation(uuid);
  12510. return result;
  12511. }
  12512. int handleInstallCertificateRequest(char *uuid, char *payload)
  12513. {
  12514. mtrace();
  12515. int result = PASS;
  12516. json_object *InstallCertificate;
  12517. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12518. InstallCertificate = json_tokener_parse(payload);
  12519. if(!is_error(InstallCertificate))
  12520. {
  12521. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12522. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12523. /*
  12524. * TODO: Install certificate process
  12525. */
  12526. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12527. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12528. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12529. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12530. sendInstallCertificateConfirmation(uuid);
  12531. }
  12532. json_object_put(InstallCertificate);
  12533. return result;
  12534. }
  12535. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12536. {
  12537. mtrace();
  12538. int result = PASS;
  12539. json_object *SignedUpdateFirmware;
  12540. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12541. SignedUpdateFirmware = json_tokener_parse(payload);
  12542. if(!is_error(SignedUpdateFirmware))
  12543. {
  12544. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12545. {
  12546. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12547. }
  12548. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12549. {
  12550. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12551. }
  12552. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12553. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12554. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12555. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12556. {
  12557. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12558. }
  12559. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12560. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12561. }
  12562. json_object_put(SignedUpdateFirmware);
  12563. /*
  12564. * TODO: Upgrade firmware process
  12565. */
  12566. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12567. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12568. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12569. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12570. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12571. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12572. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12573. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12574. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12575. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12576. sendInstallCertificateConfirmation(uuid);
  12577. return result;
  12578. }
  12579. int handleUnknownRequest(char *uuid, char *payload)
  12580. {
  12581. mtrace();
  12582. int result = PASS;
  12583. DEBUG_INFO("handleUnknownRequest...\n");
  12584. sendUnknownConfirmation(uuid);
  12585. result = PASS;
  12586. return result;
  12587. }
  12588. //==========================================
  12589. // Handle server response routine
  12590. //==========================================
  12591. void handleAuthorizeResponse(char *payload, int gun_index)
  12592. {
  12593. mtrace();
  12594. char expiryDatestr[30]={0};
  12595. char parentIdTagstr[20]={0};
  12596. char statusstr[20]={0};
  12597. int expiryDateISNULL=FALSE;
  12598. int parentIdTagISNULL=FALSE;
  12599. DEBUG_INFO("handleAuthorizeResponse...\n");
  12600. json_object *Authorize;
  12601. Authorize = json_tokener_parse(payload);
  12602. if(!is_error(Authorize))
  12603. {
  12604. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12605. {
  12606. // Required data
  12607. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12608. // Optional data
  12609. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12610. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12611. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12612. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12613. }
  12614. }
  12615. json_object_put(Authorize);
  12616. if(expiryDateISNULL == FALSE)
  12617. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12618. if(parentIdTagISNULL == FALSE)
  12619. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12620. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12621. //Update idTag information to authorization cache if supproted
  12622. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12623. {
  12624. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12625. }
  12626. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12627. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12628. authorizeRetryTimes = 0;
  12629. }
  12630. void handleBootNotificationResponse(char *payload, int gun_index)
  12631. {
  12632. mtrace();
  12633. char statusStr[12]={0};
  12634. char currentTimeStr[30]={0};
  12635. int intervalInt = 0;
  12636. DEBUG_INFO("handleBootNotificationResponse...\n");
  12637. json_object *BootNotification;
  12638. BootNotification = json_tokener_parse(payload);
  12639. if(!is_error(BootNotification))
  12640. {
  12641. // Required data
  12642. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12643. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12644. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12645. }
  12646. json_object_put(BootNotification);
  12647. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12648. BootNotificationInterval = intervalInt;
  12649. HeartBeatWaitTime = intervalInt;
  12650. //write back to ShmOCPP16DataPH->BootNotification
  12651. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12652. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12653. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12654. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12655. {
  12656. if((intervalInt == 0) || (intervalInt >= 10))
  12657. {
  12658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  12659. HeartBeatWaitTime = intervalInt;
  12660. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  12661. }
  12662. server_sign = TRUE;
  12663. server_pending =FALSE;
  12664. }
  12665. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12666. {
  12667. server_pending = TRUE;
  12668. }
  12669. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12670. srand(time(NULL));
  12671. refreshStartTimer(&clientTime.Heartbeat);
  12672. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12673. SetOcppConnStatus(TRUE);
  12674. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12675. }
  12676. void handleDataTransferResponse(char *payload, int gun_index)
  12677. {
  12678. char sstr[160]={0};//sstr[200]={ 0 };
  12679. int c = 0;
  12680. char *loc;
  12681. DEBUG_INFO("handleDataTransferResponse ...\n");
  12682. loc = strstr(payload, "status");
  12683. c = 0;
  12684. while (loc[3+strlen("status")+c] != '\"')
  12685. {
  12686. sstr[c] = loc[3+strlen("status")+c];
  12687. c++;
  12688. }
  12689. sstr[c] = '\0';
  12690. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12691. }
  12692. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12693. {
  12694. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12695. //struct json_object *obj;
  12696. // obj = json_tokener_parse(payload);
  12697. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12698. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12699. //No fields are defined.
  12700. }
  12701. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12702. {
  12703. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12704. //struct json_object *obj;
  12705. // obj = json_tokener_parse(payload);
  12706. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12707. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12708. //No fields are defined.
  12709. }
  12710. void handleHeartbeatResponse(char *payload, int gun_index)
  12711. {
  12712. mtrace();
  12713. DEBUG_INFO("handleHeartbeatResponse...\n");
  12714. json_object *Heartbeat;
  12715. Heartbeat = json_tokener_parse(payload);
  12716. if(!is_error(Heartbeat))
  12717. {
  12718. // Required data
  12719. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12720. }
  12721. json_object_put(Heartbeat);
  12722. if(FirstHeartBeat == 0)
  12723. {
  12724. FirstHeartBeat = 1;
  12725. DEBUG_INFO("FirstHeartBeat \n");
  12726. }
  12727. HeartBeatWithNOResponse = 0;
  12728. refreshStartTimer(&clientTime.Heartbeat);
  12729. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12730. }
  12731. void handleMeterValuesResponse(char *payload, int gun_index)
  12732. {
  12733. mtrace();
  12734. DEBUG_INFO("handleMeterValuesResponse...\n");
  12735. isQueueSendable = 1;
  12736. }
  12737. void handleStartTransactionResponse(char *payload, int gun_index)
  12738. {
  12739. mtrace();
  12740. //int transactionIdInt = 0;
  12741. FILE *outfile;
  12742. char data[100]={0};
  12743. DEBUG_INFO("handleStartTransactionResponse...\n");
  12744. json_object *StartTransaction;
  12745. StartTransaction = json_tokener_parse(payload);
  12746. if(!is_error(StartTransaction))
  12747. {
  12748. // Required data
  12749. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12750. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12751. // Optional data
  12752. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12753. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12754. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12755. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12756. }
  12757. json_object_put(StartTransaction);
  12758. isQueueSendable = 1;
  12759. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12760. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12761. //-----------Start : write to the Queue TransactionId file -----------------//
  12762. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12763. {}
  12764. else
  12765. {
  12766. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12767. if(log == NULL)
  12768. {
  12769. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12770. return ;
  12771. }
  12772. else
  12773. {
  12774. fclose(log);
  12775. }
  12776. }
  12777. // open file for writing
  12778. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12779. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12780. {
  12781. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12782. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12783. fputs(data, outfile);
  12784. fclose (outfile);
  12785. }
  12786. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12787. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12788. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12789. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12790. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12791. }
  12792. void handleStatusNotificationResponse(char *payload, int gun_index)
  12793. {
  12794. mtrace();
  12795. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12796. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12797. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12798. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12799. }
  12800. void handleStopTransactionnResponse(char *payload, int gun_index)
  12801. {
  12802. mtrace();
  12803. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12804. json_object *StopTransaction;
  12805. StopTransaction = json_tokener_parse(payload);
  12806. if(!is_error(StopTransaction))
  12807. {
  12808. // Optional data
  12809. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12810. {
  12811. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12812. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12813. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12814. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12815. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12816. }
  12817. }
  12818. json_object_put(StopTransaction);
  12819. isQueueSendable = 1;
  12820. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12821. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12822. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12823. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12824. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12825. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  12826. }
  12827. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12828. {
  12829. mtrace();
  12830. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12831. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12832. }
  12833. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12834. {
  12835. mtrace();
  12836. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12837. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12838. }
  12839. void handleSignCertificateResponse(char *payload, int gun_index)
  12840. {
  12841. mtrace();
  12842. DEBUG_INFO("handleSignCertificateResponse...\n");
  12843. json_object *SignCertificate;
  12844. SignCertificate = json_tokener_parse(payload);
  12845. if(!is_error(SignCertificate))
  12846. {
  12847. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12848. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12849. }
  12850. json_object_put(SignCertificate);
  12851. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12852. }
  12853. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12854. {
  12855. mtrace();
  12856. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12857. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12858. }
  12859. //==========================================
  12860. // Handle Error routine
  12861. //==========================================
  12862. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12863. {
  12864. mtrace();
  12865. #ifdef SystemLogMessage
  12866. DEBUG_INFO("errorCode: %s\n", errorCode);
  12867. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12868. DEBUG_INFO("errorDetails: %s\n", payload);
  12869. #endif
  12870. }
  12871. //===============================================
  12872. // Common routine
  12873. //===============================================
  12874. int initialConfigurationTable(void)
  12875. {
  12876. //clock_t start_t, end_t, total_t;
  12877. FILE *fp;
  12878. FILE *outfile;
  12879. char str[512]={0};
  12880. char sstr[256]={0};
  12881. int c = 0;
  12882. char *loc;
  12883. int confVersion = 10;
  12884. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12885. //start_t = clock();
  12886. //printf("Starting of the program, start_t = %ld\n", start_t);
  12887. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12888. // Check configuration file size is correct
  12889. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12890. {
  12891. struct stat st;
  12892. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12893. if(st.st_size < 3100)
  12894. {
  12895. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12896. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12897. }
  12898. }
  12899. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12900. {
  12901. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12902. if(outfile == NULL)
  12903. {
  12904. DEBUG_INFO("Error opening file\n");
  12905. return FALSE;
  12906. }
  12907. /*Core Profile*/
  12908. //AllowOfflineTxForUnknownId
  12909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12913. //AuthorizationCacheEnabled
  12914. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12918. //AuthorizeRemoteTxRequests
  12919. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12923. //BlinkRepeat
  12924. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12928. //ClockAlignedDataInterval
  12929. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12930. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12933. //ConnectionTimeOut
  12934. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12938. //GetConfigurationMaxKeys
  12939. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12941. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12943. // HeartbeatInterval
  12944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12948. // LightIntensity
  12949. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12953. // LocalAuthorizeOffline
  12954. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12955. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12958. // LocalPreAuthorize
  12959. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12963. // MaxEnergyOnInvalidId
  12964. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12968. // MeterValuesAlignedData
  12969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12971. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12972. 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" );
  12973. else
  12974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12976. // MeterValuesAlignedDataMaxLength
  12977. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12979. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12981. else
  12982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12984. // MeterValuesSampledData
  12985. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12987. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12988. 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" );
  12989. else
  12990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12992. // MeterValuesSampledDataMaxLength
  12993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12995. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12997. else
  12998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13000. // MeterValueSampleInterval
  13001. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13003. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13005. // MinimumStatusDuration
  13006. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13009. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13011. // NumberOfConnectors
  13012. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13014. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13015. {
  13016. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13017. }
  13018. else
  13019. {
  13020. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13021. }
  13022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13023. // ResetRetries
  13024. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13025. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13026. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13028. // ConnectorPhaseRotation
  13029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13033. // ConnectorPhaseRotationMaxLength
  13034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13038. // StopTransactionOnEVSideDisconnect
  13039. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13043. // StopTransactionOnInvalidId
  13044. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13046. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13048. // StopTxnAlignedData
  13049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13053. // StopTxnAlignedDataMaxLength
  13054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13058. // StopTxnSampledData
  13059. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13060. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13063. else
  13064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13066. // StopTxnSampledDataMaxLength
  13067. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13070. {
  13071. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13072. }
  13073. else
  13074. {
  13075. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13076. }
  13077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13078. // SupportedFeatureProfiles
  13079. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13080. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13081. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13083. // SupportedFeatureProfilesMaxLength
  13084. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13088. // TransactionMessageAttempts
  13089. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13092. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13094. // TransactionMessageRetryInterval
  13095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13098. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13100. // UnlockConnectorOnEVSideDisconnect
  13101. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13105. // WebSocketPingInterval
  13106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13110. // QueueOffLineMeterValues
  13111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13115. // AuthorizationKey
  13116. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13120. // SecurityProfile
  13121. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13123. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13125. // DefaultPrice
  13126. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13130. // CustomDisplayCostAndPrice
  13131. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13135. // CustomIdleFeeAfterStop
  13136. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13138. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13140. // SystemUptimeSec
  13141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13145. // FreeVend
  13146. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13150. // Configuration Version
  13151. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13155. //* Local Auth List Management Profile*/
  13156. #if 0
  13157. //For OCTT Test Case
  13158. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13159. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13161. #endif
  13162. #if 1
  13163. //LocalAuthListEnabled
  13164. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13168. #endif
  13169. //LocalAuthListMaxLength
  13170. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13174. //SendLocalListMaxLength
  13175. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13179. //ReserveConnectorZeroSupported
  13180. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13184. //* Smart Charging Profile */
  13185. //ChargeProfileMaxStackLevel
  13186. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13190. // ChargingScheduleAllowedChargingRateUnit
  13191. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13195. // ChargingScheduleMaxPeriods
  13196. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13200. // ConnectorSwitch3to1PhaseSupported
  13201. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13205. // MaxChargingProfilesInstalled
  13206. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13210. fclose(outfile);
  13211. }
  13212. else
  13213. {
  13214. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13215. char keystr[60]={0};
  13216. char readonlystr[10]={0};
  13217. char valuestr[256]={0};
  13218. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13219. if(fp == NULL) {
  13220. DEBUG_INFO("Error opening file");
  13221. return FALSE;
  13222. }
  13223. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13224. {
  13225. //DEBUG_INFO("Get Configuration \n");
  13226. if(strlen(str) > 0)
  13227. {
  13228. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13229. //*************************key*********************************/
  13230. if(strstr(str, "key") != NULL)
  13231. {
  13232. loc = strstr(str, "key");
  13233. c = 0;
  13234. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13235. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13236. {
  13237. sstr[c] = loc[strlen("key")+3+c];
  13238. c++;
  13239. }
  13240. sstr[c] = '\0';
  13241. strcpy(keystr,sstr);
  13242. }
  13243. //*************************readonly*********************************/
  13244. if(strstr(str, "readonly") != NULL)
  13245. {
  13246. loc = strstr(str, "readonly");
  13247. c = 0;
  13248. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13249. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13250. {
  13251. sstr[c] = loc[strlen("readonly")+2+c];
  13252. c++;
  13253. }
  13254. sstr[c] = '\0';
  13255. strcpy(readonlystr,sstr);
  13256. }
  13257. //*************************value*********************************/
  13258. if(strstr(str, "value") != NULL)
  13259. {
  13260. loc = strstr(str, "value");
  13261. c = 0;
  13262. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13263. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13264. {
  13265. sstr[c] = loc[strlen("value")+3+c];
  13266. c++;
  13267. }
  13268. sstr[c] = '\0';
  13269. strcpy(valuestr,sstr);
  13270. }
  13271. // DEBUG_INFO("keystr=%s\n",keystr);
  13272. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13273. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13274. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13275. {
  13276. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13277. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13278. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13279. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13280. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13281. }
  13282. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13283. {
  13284. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13285. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13286. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13287. }
  13288. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13289. {
  13290. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13291. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13292. }
  13293. if(strcmp(keystr, "BlinkRepeat") == 0)
  13294. {
  13295. //Charger.BlinkRepeat = Integer.parseInt(value);
  13296. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13297. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13298. }
  13299. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13300. {
  13301. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13303. }
  13304. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13305. {
  13306. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13308. }
  13309. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13310. {
  13311. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13312. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13313. }
  13314. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13315. {
  13316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13317. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13318. HeartBeatWaitTime = atoi(valuestr);
  13319. }
  13320. if(strcmp(keystr, "LightIntensity") == 0)
  13321. {
  13322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13324. }
  13325. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13326. {
  13327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13329. }
  13330. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13331. {
  13332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13334. }
  13335. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13336. {
  13337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13338. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13339. }
  13340. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13341. {
  13342. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13343. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13344. }
  13345. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13346. {
  13347. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13348. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13349. }
  13350. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13351. {
  13352. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13353. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13354. }
  13355. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13356. {
  13357. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13358. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13359. }
  13360. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13361. {
  13362. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13363. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13364. }
  13365. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13366. {
  13367. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13368. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13369. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13370. }
  13371. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13372. {
  13373. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13374. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13375. }
  13376. if(strcmp(keystr, "ResetRetries") == 0)
  13377. {
  13378. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13379. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13380. }
  13381. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13382. {
  13383. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13384. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13385. }
  13386. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13387. {
  13388. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13389. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13390. }
  13391. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13392. {
  13393. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13394. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13395. }
  13396. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13397. {
  13398. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13399. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13400. }
  13401. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13402. {
  13403. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13404. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13405. }
  13406. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13407. {
  13408. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13409. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13410. }
  13411. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13412. {
  13413. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13414. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13415. }
  13416. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13417. {
  13418. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13419. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13420. }
  13421. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13422. {
  13423. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13424. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13425. }
  13426. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13427. {
  13428. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13429. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13430. }
  13431. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13432. {
  13433. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13434. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13435. TransactionMessageAttemptsValue = atoi(valuestr);
  13436. }
  13437. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13438. {
  13439. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13440. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13441. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13442. }
  13443. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13444. {
  13445. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13446. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13447. }
  13448. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13449. {
  13450. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13451. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13452. }
  13453. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13454. {
  13455. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13456. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13457. }
  13458. if(strcmp(keystr, "AuthorizationKey") == 0)
  13459. {
  13460. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13461. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13462. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  13463. }
  13464. if(strcmp(keystr, "SecurityProfile") == 0)
  13465. {
  13466. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13467. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13468. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13469. }
  13470. if(strcmp(keystr, "DefaultPrice") == 0)
  13471. {
  13472. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13473. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13474. }
  13475. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13476. {
  13477. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13479. }
  13480. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13481. {
  13482. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13484. }
  13485. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13486. {
  13487. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13488. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13489. }
  13490. if(strcmp(keystr, "FreeVend") == 0)
  13491. {
  13492. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13493. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13494. }
  13495. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13496. {
  13497. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13498. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13499. }
  13500. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13501. {
  13502. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13503. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13504. }
  13505. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13506. {
  13507. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13508. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13509. }
  13510. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13511. {
  13512. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13513. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13514. }
  13515. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13516. {
  13517. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13518. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13519. }
  13520. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13521. {
  13522. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13523. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13524. }
  13525. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13526. {
  13527. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13528. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13529. }
  13530. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13531. {
  13532. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13533. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13534. }
  13535. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13536. {
  13537. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13538. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13539. }
  13540. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13541. {
  13542. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13543. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13544. }
  13545. }
  13546. }
  13547. fclose(fp);
  13548. }
  13549. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13550. {
  13551. return PASS;
  13552. }
  13553. else
  13554. {
  13555. return FAIL;
  13556. }
  13557. }
  13558. void StoreConfigurationTable(void)
  13559. {
  13560. FILE *outfile;
  13561. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13562. if(outfile == NULL)
  13563. {
  13564. DEBUG_INFO("Error opening file");
  13565. return ;
  13566. }
  13567. /*Core Profile*/
  13568. //AllowOfflineTxForUnknownId
  13569. /*
  13570. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13571. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13572. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13574. */
  13575. //DEBUG_INFO("data=%s\n",data);
  13576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13577. //AuthorizationCacheEnabled
  13578. /*
  13579. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13582. */
  13583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13584. //AuthorizeRemoteTxRequests
  13585. /*
  13586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13589. */
  13590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13591. //BlinkRepeat
  13592. /*
  13593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13594. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13595. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13596. */
  13597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13598. //ClockAlignedDataInterval
  13599. /*
  13600. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13603. */
  13604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13605. //ConnectionTimeOut
  13606. /*
  13607. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13610. */
  13611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13612. //GetConfigurationMaxKeys
  13613. /*
  13614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13616. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13617. */
  13618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13619. // HeartbeatInterval
  13620. /*
  13621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13624. */
  13625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13626. // LightIntensity
  13627. /*
  13628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13631. */
  13632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13633. // LocalAuthorizeOffline
  13634. /*
  13635. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13638. */
  13639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13640. // LocalPreAuthorize
  13641. /*
  13642. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13645. */
  13646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13647. // MaxEnergyOnInvalidId
  13648. /*
  13649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13650. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13652. */
  13653. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13655. // MeterValuesAlignedData
  13656. /*
  13657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13659. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13660. */
  13661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13662. // MeterValuesAlignedDataMaxLength
  13663. /*
  13664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13667. */
  13668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13669. // MeterValuesSampledData
  13670. /*
  13671. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13673. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13674. */
  13675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13676. // MeterValuesSampledDataMaxLength
  13677. /*
  13678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13681. */
  13682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13683. // MeterValueSampleInterval
  13684. /*
  13685. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13687. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13688. */
  13689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13690. // MinimumStatusDuration
  13691. /*
  13692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13695. */
  13696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13697. // NumberOfConnectors
  13698. /*
  13699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13701. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13702. {
  13703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13704. }
  13705. else
  13706. {
  13707. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13708. }
  13709. */
  13710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13711. // ResetRetries
  13712. /*
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13716. */
  13717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13718. // ConnectorPhaseRotation
  13719. /*
  13720. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13721. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13723. */
  13724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13725. // ConnectorPhaseRotationMaxLength
  13726. /*
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13729. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13730. */
  13731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13732. // StopTransactionOnEVSideDisconnect
  13733. /*
  13734. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13735. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13736. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13737. */
  13738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13739. // StopTransactionOnInvalidId
  13740. /*
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13744. */
  13745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13746. // StopTxnAlignedData
  13747. /*
  13748. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13749. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13750. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13751. */
  13752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13753. // StopTxnAlignedDataMaxLength
  13754. /*
  13755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13756. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13758. */
  13759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13760. // StopTxnSampledData
  13761. /*
  13762. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13765. */
  13766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13767. // StopTxnSampledDataMaxLength
  13768. /*
  13769. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13770. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13771. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13772. */
  13773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13774. // SupportedFeatureProfiles
  13775. /*
  13776. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13778. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13779. */
  13780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13781. // SupportedFeatureProfilesMaxLength
  13782. /*
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13786. */
  13787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13788. // TransactionMessageAttempts
  13789. /*
  13790. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13792. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13793. */
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13795. // TransactionMessageRetryInterval
  13796. /*
  13797. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13800. */
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13802. // UnlockConnectorOnEVSideDisconnect
  13803. /*
  13804. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13807. */
  13808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13809. // WebSocketPingInterval
  13810. /*
  13811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13814. */
  13815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13816. // QueueOffLineMeterValues
  13817. /*
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13821. */
  13822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13823. // AuthorizationKey
  13824. /*
  13825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13828. */
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13830. // SecurityProfile
  13831. /*
  13832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13835. */
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13837. // DefaultPrice
  13838. /*
  13839. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13842. */
  13843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13844. // CustomDisplayCostAndPrice
  13845. /*
  13846. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13849. */
  13850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13851. // CustomIdleFeeAfterStop
  13852. /*
  13853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13856. */
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13858. // SystemUptimeSec
  13859. /*
  13860. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13863. */
  13864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13865. // FreeVend
  13866. /*
  13867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  13870. */
  13871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13872. // ConfigurationVersion
  13873. /*
  13874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13877. */
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13879. //* Local Auth List Management Profile*/
  13880. //LocalAuthListEnabled
  13881. /*
  13882. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13885. */
  13886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13887. //LocalAuthListMaxLength
  13888. /*
  13889. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13892. */
  13893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13894. //SendLocalListMaxLength
  13895. /*
  13896. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13899. */
  13900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13901. //ReserveConnectorZeroSupported
  13902. /*
  13903. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13906. */
  13907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13908. //* Smart Charging Profile */
  13909. //ChargeProfileMaxStackLevel
  13910. /*
  13911. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13913. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13914. */
  13915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13916. // ChargingScheduleAllowedChargingRateUnit
  13917. /*
  13918. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13921. */
  13922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13923. // ChargingScheduleMaxPeriods
  13924. /*
  13925. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13927. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13928. */
  13929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13930. // ConnectorSwitch3to1PhaseSupported
  13931. /*
  13932. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13934. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13935. */
  13936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13937. // MaxChargingProfilesInstalled
  13938. /*
  13939. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13942. */
  13943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13944. fclose(outfile);
  13945. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13946. }
  13947. void getKeyValue(char *keyReq)
  13948. {
  13949. int isEmpty = FALSE;
  13950. int isKnowKey = FALSE;
  13951. DEBUG_INFO("keyReq = %s\n", keyReq);
  13952. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13953. isEmpty = TRUE;
  13954. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13955. {
  13956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13958. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13959. {
  13960. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13961. }
  13962. else
  13963. {
  13964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13965. }
  13966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13967. isKnowKey = TRUE;
  13968. }
  13969. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13970. {
  13971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13973. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13974. {
  13975. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13976. }
  13977. else
  13978. {
  13979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13980. }
  13981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13982. isKnowKey = TRUE;
  13983. }
  13984. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13985. {
  13986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13988. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13989. {
  13990. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13991. }
  13992. else
  13993. {
  13994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13995. }
  13996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13997. isKnowKey = TRUE;
  13998. }
  13999. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14000. {
  14001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14003. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14004. {
  14005. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14006. }
  14007. else
  14008. {
  14009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14010. }
  14011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14012. isKnowKey = TRUE;
  14013. }
  14014. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14015. {
  14016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14018. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14019. {
  14020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14021. }
  14022. else
  14023. {
  14024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14025. }
  14026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14027. isKnowKey = TRUE;
  14028. }
  14029. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14030. {
  14031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14033. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14034. {
  14035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14036. }
  14037. else
  14038. {
  14039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14040. }
  14041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14042. isKnowKey = TRUE;
  14043. }
  14044. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14045. {
  14046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14048. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14049. {
  14050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14051. }
  14052. else
  14053. {
  14054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14055. }
  14056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14057. isKnowKey = TRUE;
  14058. }
  14059. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14060. {
  14061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14063. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14064. {
  14065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14066. }
  14067. else
  14068. {
  14069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14070. }
  14071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14072. isKnowKey = TRUE;
  14073. }
  14074. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14075. {
  14076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14078. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14079. {
  14080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14081. }
  14082. else
  14083. {
  14084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14085. }
  14086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14087. isKnowKey = TRUE;
  14088. }
  14089. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14090. {
  14091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14093. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14094. {
  14095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14096. }
  14097. else
  14098. {
  14099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14100. }
  14101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14102. isKnowKey = TRUE;
  14103. }
  14104. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14105. {
  14106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14108. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14109. {
  14110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14111. }
  14112. else
  14113. {
  14114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14115. }
  14116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14117. isKnowKey = TRUE;
  14118. }
  14119. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14120. {
  14121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14123. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14124. {
  14125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14126. }
  14127. else
  14128. {
  14129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14130. }
  14131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14132. isKnowKey = TRUE;
  14133. }
  14134. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14135. {
  14136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14138. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14139. {
  14140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14141. }
  14142. else
  14143. {
  14144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14145. }
  14146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14147. isKnowKey = TRUE;
  14148. }
  14149. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14150. {
  14151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14153. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14154. {
  14155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14156. }
  14157. else
  14158. {
  14159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14160. }
  14161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14162. isKnowKey = TRUE;
  14163. }
  14164. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14165. {
  14166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14168. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14169. {
  14170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14171. }
  14172. else
  14173. {
  14174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14175. }
  14176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14177. isKnowKey = TRUE;
  14178. }
  14179. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14180. {
  14181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14183. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14184. {
  14185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14186. }
  14187. else
  14188. {
  14189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14190. }
  14191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14192. isKnowKey = TRUE;
  14193. }
  14194. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14195. {
  14196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14198. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14199. {
  14200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14201. }
  14202. else
  14203. {
  14204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14205. }
  14206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14207. isKnowKey = TRUE;
  14208. }
  14209. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14210. {
  14211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14213. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14214. {
  14215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14216. }
  14217. else
  14218. {
  14219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14220. }
  14221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14222. isKnowKey = TRUE;
  14223. }
  14224. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14225. {
  14226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14228. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14229. {
  14230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14231. }
  14232. else
  14233. {
  14234. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14235. }
  14236. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14238. isKnowKey = TRUE;
  14239. }
  14240. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14241. {
  14242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14244. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14245. {
  14246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14247. }
  14248. else
  14249. {
  14250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14251. }
  14252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14253. isKnowKey = TRUE;
  14254. }
  14255. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14256. {
  14257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14259. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14260. {
  14261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14262. }
  14263. else
  14264. {
  14265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14266. }
  14267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14268. isKnowKey = TRUE;
  14269. }
  14270. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14271. {
  14272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14274. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14275. {
  14276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14277. }
  14278. else
  14279. {
  14280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14281. }
  14282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14283. isKnowKey = TRUE;
  14284. }
  14285. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14286. {
  14287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14289. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14290. {
  14291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14292. }
  14293. else
  14294. {
  14295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14296. }
  14297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14298. isKnowKey = TRUE;
  14299. }
  14300. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14301. {
  14302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14304. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14305. {
  14306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14307. }
  14308. else
  14309. {
  14310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14311. }
  14312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14313. isKnowKey = TRUE;
  14314. }
  14315. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14316. {
  14317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14319. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14320. {
  14321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14322. }
  14323. else
  14324. {
  14325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14326. }
  14327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14328. isKnowKey = TRUE;
  14329. }
  14330. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14331. {
  14332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14334. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14335. {
  14336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14337. }
  14338. else
  14339. {
  14340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14341. }
  14342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14343. isKnowKey = TRUE;
  14344. }
  14345. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14346. {
  14347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14349. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14350. {
  14351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14352. }
  14353. else
  14354. {
  14355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14356. }
  14357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14358. isKnowKey = TRUE;
  14359. }
  14360. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14361. {
  14362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14364. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14365. {
  14366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14367. }
  14368. else
  14369. {
  14370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14371. }
  14372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14373. isKnowKey = TRUE;
  14374. }
  14375. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14376. {
  14377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14379. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14380. {
  14381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14382. }
  14383. else
  14384. {
  14385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14386. }
  14387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14388. isKnowKey = TRUE;
  14389. }
  14390. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14391. {
  14392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14394. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14395. {
  14396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14397. }
  14398. else
  14399. {
  14400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14401. }
  14402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14403. isKnowKey = TRUE;
  14404. }
  14405. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14406. {
  14407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14409. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14410. {
  14411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14412. }
  14413. else
  14414. {
  14415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14416. }
  14417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14418. isKnowKey = TRUE;
  14419. }
  14420. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14421. {
  14422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14424. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14425. {
  14426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14427. }
  14428. else
  14429. {
  14430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14431. }
  14432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14433. isKnowKey = TRUE;
  14434. }
  14435. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14436. {
  14437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14439. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14440. {
  14441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14442. }
  14443. else
  14444. {
  14445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14446. }
  14447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14448. isKnowKey = TRUE;
  14449. }
  14450. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14451. {
  14452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14454. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14455. {
  14456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14457. }
  14458. else
  14459. {
  14460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14461. }
  14462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14463. isKnowKey = TRUE;
  14464. }
  14465. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14466. {
  14467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14469. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14470. {
  14471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14472. }
  14473. else
  14474. {
  14475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14476. }
  14477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14478. isKnowKey = TRUE;
  14479. }
  14480. /*
  14481. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14482. {
  14483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14485. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14486. {
  14487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14488. }
  14489. else
  14490. {
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14492. }
  14493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14494. isKnowKey = TRUE;
  14495. }*/
  14496. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14497. {
  14498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14500. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14501. {
  14502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14503. }
  14504. else
  14505. {
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14507. }
  14508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14509. isKnowKey = TRUE;
  14510. }
  14511. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14512. {
  14513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14515. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14516. {
  14517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14518. }
  14519. else
  14520. {
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14522. }
  14523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14524. isKnowKey = TRUE;
  14525. }
  14526. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14527. {
  14528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14530. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14531. {
  14532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14533. }
  14534. else
  14535. {
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14537. }
  14538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14539. isKnowKey = TRUE;
  14540. }
  14541. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14542. {
  14543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14545. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14546. {
  14547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14548. }
  14549. else
  14550. {
  14551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14552. }
  14553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14554. isKnowKey = TRUE;
  14555. }
  14556. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14557. {
  14558. struct sysinfo s_info;
  14559. int error = sysinfo(&s_info);
  14560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14562. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14563. {
  14564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14565. }
  14566. else
  14567. {
  14568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14569. }
  14570. if(error != 0)
  14571. {
  14572. DEBUG_WARN("System uptime get error: %d\n", error);
  14573. }
  14574. else
  14575. {
  14576. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14577. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14578. }
  14579. isKnowKey = TRUE;
  14580. }
  14581. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14582. {
  14583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14585. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14586. {
  14587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14588. }
  14589. else
  14590. {
  14591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14592. }
  14593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14594. isKnowKey = TRUE;
  14595. }
  14596. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14597. {
  14598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14600. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14601. {
  14602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14603. }
  14604. else
  14605. {
  14606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14607. }
  14608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14609. isKnowKey = TRUE;
  14610. }
  14611. #if 1
  14612. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14613. {
  14614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14616. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14617. {
  14618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14619. }
  14620. else
  14621. {
  14622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14623. }
  14624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14625. isKnowKey = TRUE;
  14626. }
  14627. #endif
  14628. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14629. {
  14630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14632. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14633. {
  14634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14635. }
  14636. else
  14637. {
  14638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14639. }
  14640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14641. isKnowKey = TRUE;
  14642. }
  14643. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14644. {
  14645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14647. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14648. {
  14649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14650. }
  14651. else
  14652. {
  14653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14654. }
  14655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14656. isKnowKey = TRUE;
  14657. }
  14658. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14659. {
  14660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14662. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14663. {
  14664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14665. }
  14666. else
  14667. {
  14668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14669. }
  14670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14671. isKnowKey = TRUE;
  14672. }
  14673. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14674. {
  14675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14677. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14678. {
  14679. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14680. }
  14681. else
  14682. {
  14683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14684. }
  14685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14686. isKnowKey = TRUE;
  14687. }
  14688. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14689. {
  14690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14692. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14693. {
  14694. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14695. }
  14696. else
  14697. {
  14698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14699. }
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14701. isKnowKey = TRUE;
  14702. }
  14703. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14704. {
  14705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14707. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14708. {
  14709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14710. }
  14711. else
  14712. {
  14713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14714. }
  14715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14716. isKnowKey = TRUE;
  14717. }
  14718. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14719. {
  14720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14722. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14723. {
  14724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14725. }
  14726. else
  14727. {
  14728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14729. }
  14730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14731. isKnowKey = TRUE;
  14732. }
  14733. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14734. {
  14735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14737. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14738. {
  14739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14740. }
  14741. else
  14742. {
  14743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14744. }
  14745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14746. isKnowKey = TRUE;
  14747. }
  14748. //=========================================================
  14749. if(!isEmpty && !isKnowKey)
  14750. {
  14751. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14752. strcpy(unknownkey[UnknownKeynum], keyReq);
  14753. UnknownKeynum = UnknownKeynum + 1;
  14754. }
  14755. }
  14756. void processUnkownKey(void)
  14757. {
  14758. DEBUG_INFO("processUnkownKey...\n");
  14759. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14760. for(int index=0; index < UnknownKeynum; index++)
  14761. {
  14762. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14763. {
  14764. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14765. }
  14766. }
  14767. }
  14768. int setKeyValue(char *key, char *value)
  14769. {
  14770. int isSuccess = NotSupported;
  14771. int check_ascii=0;
  14772. char str[256]={0};
  14773. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14774. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14775. {
  14776. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14777. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14778. {
  14779. strcpy(str, (const char*)value);
  14780. for(int i = 0; str[i]; i++){
  14781. str[i] = tolower(str[i]);
  14782. }
  14783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14784. isSuccess = ConfigurationStatus_Accepted;
  14785. }
  14786. else
  14787. {
  14788. isSuccess = ConfigurationStatus_Rejected;
  14789. }
  14790. }
  14791. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14792. {
  14793. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14794. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14795. {
  14796. strcpy(str, (const char*)value);
  14797. for(int i = 0; str[i]; i++){
  14798. str[i] = tolower(str[i]);
  14799. }
  14800. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14801. isSuccess = ConfigurationStatus_Accepted;
  14802. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  14803. }
  14804. else
  14805. {
  14806. isSuccess = ConfigurationStatus_Rejected;
  14807. }
  14808. }
  14809. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14810. {
  14811. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14812. {
  14813. strcpy(str, (const char*)value);
  14814. for(int i = 0; str[i]; i++)
  14815. {
  14816. str[i] = tolower(str[i]);
  14817. }
  14818. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14820. isSuccess = ConfigurationStatus_Accepted;
  14821. }
  14822. else
  14823. {
  14824. isSuccess = ConfigurationStatus_Rejected;
  14825. }
  14826. }
  14827. if(strcmp(key, "BlinkRepeat") == 0)
  14828. {
  14829. //Charger.BlinkRepeat = Integer.parseInt(value);
  14830. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14831. {
  14832. check_ascii = value[0];
  14833. if( (check_ascii < 48) || (check_ascii > 57) )
  14834. {
  14835. isSuccess = ConfigurationStatus_Rejected;
  14836. }
  14837. else
  14838. {
  14839. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14840. isSuccess = ConfigurationStatus_Accepted;
  14841. }
  14842. }
  14843. else
  14844. {
  14845. isSuccess = ConfigurationStatus_Rejected;
  14846. }
  14847. }
  14848. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14849. {
  14850. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14851. {
  14852. check_ascii = value[0];
  14853. if( (check_ascii < 48) || (check_ascii > 57) )
  14854. {
  14855. isSuccess = ConfigurationStatus_Rejected;
  14856. }
  14857. else
  14858. {
  14859. if((atoi(value) == 0) || (atoi(value) >= 5))
  14860. {
  14861. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14862. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14863. isSuccess = ConfigurationStatus_Accepted;
  14864. }
  14865. else
  14866. isSuccess = ConfigurationStatus_Rejected;
  14867. }
  14868. }
  14869. else
  14870. {
  14871. isSuccess = ConfigurationStatus_Rejected;
  14872. }
  14873. }
  14874. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14875. {
  14876. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14877. {
  14878. check_ascii = value[0];
  14879. if( (check_ascii < 48) || (check_ascii > 57) )
  14880. {
  14881. isSuccess = ConfigurationStatus_Rejected;
  14882. }
  14883. else
  14884. {
  14885. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14886. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14887. isSuccess = ConfigurationStatus_Accepted;
  14888. }
  14889. }
  14890. else
  14891. {
  14892. isSuccess = ConfigurationStatus_Rejected;
  14893. }
  14894. }
  14895. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14896. {
  14897. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14898. {
  14899. check_ascii = value[0];
  14900. if( (check_ascii < 48) || (check_ascii > 57) )
  14901. {
  14902. isSuccess = ConfigurationStatus_Rejected;
  14903. }
  14904. else
  14905. {
  14906. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14907. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14908. isSuccess = ConfigurationStatus_Accepted;
  14909. }
  14910. }
  14911. else
  14912. {
  14913. isSuccess = ConfigurationStatus_Rejected;
  14914. }
  14915. }
  14916. if(strcmp(key, "HeartbeatInterval") == 0)
  14917. {
  14918. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14919. {
  14920. check_ascii = value[0];
  14921. if( (check_ascii < 48) || (check_ascii > 57) )
  14922. {
  14923. isSuccess = ConfigurationStatus_Rejected;
  14924. }
  14925. else
  14926. {
  14927. if((atoi(value) == 0) || (atoi(value) >= 10))
  14928. {
  14929. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14930. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14931. HeartBeatWaitTime = atoi(value);
  14932. isSuccess = ConfigurationStatus_Accepted;
  14933. }
  14934. else
  14935. {
  14936. isSuccess = ConfigurationStatus_Rejected;
  14937. }
  14938. }
  14939. }
  14940. else
  14941. {
  14942. isSuccess = ConfigurationStatus_Rejected;
  14943. }
  14944. }
  14945. if(strcmp(key, "LightIntensity") == 0)
  14946. {
  14947. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14948. {
  14949. check_ascii = value[0];
  14950. if( (check_ascii < 48) || (check_ascii > 57) )
  14951. {
  14952. isSuccess = ConfigurationStatus_Rejected;
  14953. }
  14954. else
  14955. {
  14956. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14957. isSuccess = ConfigurationStatus_Accepted;
  14958. }
  14959. }
  14960. else
  14961. {
  14962. isSuccess = ConfigurationStatus_Rejected;
  14963. }
  14964. }
  14965. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14966. {
  14967. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14968. {
  14969. strcpy(str, (const char*)value);
  14970. for(int i = 0; str[i]; i++)
  14971. {
  14972. str[i] = tolower(str[i]);
  14973. }
  14974. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14975. isSuccess = ConfigurationStatus_Accepted;
  14976. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14977. }
  14978. else
  14979. {
  14980. isSuccess = ConfigurationStatus_Rejected;
  14981. }
  14982. }
  14983. if(strcmp(key, "LocalPreAuthorize") == 0)
  14984. {
  14985. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14986. {
  14987. strcpy(str, (const char*)value);
  14988. for(int i = 0; str[i]; i++)
  14989. {
  14990. str[i] = tolower(str[i]);
  14991. }
  14992. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14993. isSuccess = ConfigurationStatus_Accepted;
  14994. }
  14995. else
  14996. {
  14997. isSuccess = ConfigurationStatus_Rejected;
  14998. }
  14999. }
  15000. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15001. {
  15002. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15003. {
  15004. check_ascii = value[0];
  15005. if( (check_ascii < 48) || (check_ascii > 57) )
  15006. {
  15007. isSuccess = ConfigurationStatus_Rejected;
  15008. }
  15009. else
  15010. {
  15011. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15012. isSuccess = ConfigurationStatus_Accepted;
  15013. }
  15014. }
  15015. else
  15016. {
  15017. isSuccess = ConfigurationStatus_Rejected;
  15018. }
  15019. }
  15020. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15021. {
  15022. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15023. {
  15024. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15025. isSuccess = ConfigurationStatus_Accepted;
  15026. }
  15027. else
  15028. {
  15029. isSuccess = ConfigurationStatus_Rejected;
  15030. }
  15031. }
  15032. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15033. {
  15034. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15035. {
  15036. check_ascii = value[0];
  15037. if( (check_ascii < 48) || (check_ascii > 57) )
  15038. {
  15039. isSuccess = ConfigurationStatus_Rejected;
  15040. }
  15041. else
  15042. {
  15043. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15044. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15045. isSuccess = ConfigurationStatus_Accepted;
  15046. }
  15047. }
  15048. else
  15049. {
  15050. isSuccess = ConfigurationStatus_Rejected;
  15051. }
  15052. }
  15053. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15054. {
  15055. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15056. {
  15057. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15058. isSuccess = ConfigurationStatus_Accepted;
  15059. }
  15060. else
  15061. {
  15062. isSuccess = ConfigurationStatus_Rejected;
  15063. }
  15064. }
  15065. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15066. {
  15067. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15068. {
  15069. check_ascii = value[0];
  15070. if( (check_ascii < 48) || (check_ascii > 57) )
  15071. {
  15072. isSuccess = ConfigurationStatus_Rejected;
  15073. }
  15074. else
  15075. {
  15076. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15077. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15078. isSuccess = ConfigurationStatus_Accepted;
  15079. }
  15080. }
  15081. else
  15082. {
  15083. isSuccess = ConfigurationStatus_Rejected;
  15084. }
  15085. }
  15086. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15087. {
  15088. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15089. {
  15090. check_ascii = value[0];
  15091. if( (check_ascii < 48) || (check_ascii > 57) )
  15092. {
  15093. isSuccess = ConfigurationStatus_Rejected;
  15094. }
  15095. else
  15096. {
  15097. if((atoi(value) == 0) || (atoi(value) >= 5))
  15098. {
  15099. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15100. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15101. isSuccess = ConfigurationStatus_Accepted;
  15102. }
  15103. else
  15104. {
  15105. isSuccess = ConfigurationStatus_Rejected;
  15106. }
  15107. }
  15108. }
  15109. else
  15110. {
  15111. isSuccess = ConfigurationStatus_Rejected;
  15112. }
  15113. }
  15114. if(strcmp(key, "MinimumStatusDuration") == 0)
  15115. {
  15116. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15117. {
  15118. check_ascii = value[0];
  15119. if( (check_ascii < 48) || (check_ascii > 57) )
  15120. {
  15121. isSuccess = ConfigurationStatus_Rejected;
  15122. }
  15123. else
  15124. {
  15125. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15126. {
  15127. isSuccess = ConfigurationStatus_Rejected;
  15128. }
  15129. else
  15130. {
  15131. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15132. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15133. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15134. isSuccess = ConfigurationStatus_Accepted;
  15135. }
  15136. }
  15137. }
  15138. else
  15139. {
  15140. isSuccess = ConfigurationStatus_Rejected;
  15141. }
  15142. }
  15143. if(strcmp(key, "NumberOfConnectors") == 0)
  15144. {
  15145. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15146. {
  15147. check_ascii = value[0];
  15148. if( (check_ascii < 48) || (check_ascii > 57) )
  15149. {
  15150. isSuccess = ConfigurationStatus_Rejected;
  15151. }
  15152. else
  15153. {
  15154. //Charger.ResetRetries = Integer.parseInt(value);
  15155. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15156. isSuccess = ConfigurationStatus_Accepted;
  15157. }
  15158. }
  15159. else
  15160. {
  15161. isSuccess = ConfigurationStatus_Rejected;
  15162. }
  15163. }
  15164. if(strcmp(key, "ResetRetries") == 0)
  15165. {
  15166. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15167. {
  15168. check_ascii = value[0];
  15169. if( (check_ascii < 48) || (check_ascii > 57) )
  15170. {
  15171. isSuccess = ConfigurationStatus_Rejected;
  15172. }
  15173. else
  15174. {
  15175. //Charger.ResetRetries = Integer.parseInt(value);
  15176. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15177. isSuccess = ConfigurationStatus_Accepted;
  15178. }
  15179. }
  15180. else
  15181. {
  15182. isSuccess = ConfigurationStatus_Rejected;
  15183. }
  15184. }
  15185. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15186. {
  15187. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15188. {
  15189. strcpy(str, (const char*)value);
  15190. for(int i = 0; str[i]; i++)
  15191. {
  15192. str[i] = tolower(str[i]);
  15193. }
  15194. if(strcmp(str, "notapplicable")== 0)
  15195. {
  15196. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15197. isSuccess = ConfigurationStatus_Accepted;
  15198. }
  15199. else if(strcmp(str, "unknown")== 0)
  15200. {
  15201. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15202. isSuccess = ConfigurationStatus_Accepted;
  15203. }
  15204. else if(strcmp(str, "rst")== 0)
  15205. {
  15206. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15207. isSuccess = ConfigurationStatus_Accepted;
  15208. }
  15209. else if(strcmp(str, "rts")== 0)
  15210. {
  15211. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15212. isSuccess = ConfigurationStatus_Accepted;
  15213. }
  15214. else if(strcmp(str, "srt")== 0)
  15215. {
  15216. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15217. isSuccess = ConfigurationStatus_Accepted;
  15218. }
  15219. else if(strcmp(str, "str")== 0)
  15220. {
  15221. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15222. isSuccess = ConfigurationStatus_Accepted;
  15223. }
  15224. else if(strcmp(str, "trs")== 0)
  15225. {
  15226. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15227. isSuccess = ConfigurationStatus_Accepted;
  15228. }
  15229. else if(strcmp(str, "tsr")== 0)
  15230. {
  15231. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15232. isSuccess = ConfigurationStatus_Accepted;
  15233. }
  15234. else
  15235. {
  15236. isSuccess = ConfigurationStatus_Rejected;
  15237. }
  15238. }
  15239. else
  15240. {
  15241. isSuccess = ConfigurationStatus_Rejected;
  15242. }
  15243. }
  15244. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15245. {
  15246. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15247. {
  15248. check_ascii = value[0];
  15249. if( (check_ascii < 48) || (check_ascii > 57) )
  15250. {
  15251. isSuccess = ConfigurationStatus_Rejected;
  15252. }
  15253. else
  15254. {
  15255. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15256. isSuccess = ConfigurationStatus_Accepted;
  15257. }
  15258. }
  15259. else
  15260. {
  15261. isSuccess = ConfigurationStatus_Rejected;
  15262. }
  15263. }
  15264. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15265. {
  15266. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15267. {
  15268. strcpy(str, (const char*)value);
  15269. for(int i = 0; str[i]; i++)
  15270. {
  15271. str[i] = tolower(str[i]);
  15272. }
  15273. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15274. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15275. isSuccess = ConfigurationStatus_Accepted;
  15276. }
  15277. else
  15278. {
  15279. isSuccess = ConfigurationStatus_Rejected;
  15280. }
  15281. }
  15282. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15283. {
  15284. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15285. {
  15286. strcpy(str, (const char*)value);
  15287. for(int i = 0; str[i]; i++)
  15288. {
  15289. str[i] = tolower(str[i]);
  15290. }
  15291. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15293. isSuccess = ConfigurationStatus_Accepted;
  15294. }
  15295. else
  15296. {
  15297. isSuccess = ConfigurationStatus_Rejected;
  15298. }
  15299. }
  15300. if(strcmp(key, "StopTxnAlignedData") == 0)
  15301. {
  15302. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15303. {
  15304. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15305. isSuccess = ConfigurationStatus_Accepted;
  15306. }
  15307. else
  15308. {
  15309. isSuccess = ConfigurationStatus_Rejected;
  15310. }
  15311. }
  15312. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15313. {
  15314. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15315. {
  15316. check_ascii = value[0];
  15317. if( (check_ascii < 48) || (check_ascii > 57) )
  15318. {
  15319. isSuccess = ConfigurationStatus_Rejected;
  15320. }
  15321. else
  15322. {
  15323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15324. isSuccess = ConfigurationStatus_Accepted;
  15325. }
  15326. }
  15327. else
  15328. {
  15329. isSuccess = ConfigurationStatus_Rejected;
  15330. }
  15331. }
  15332. if(strcmp(key, "StopTxnSampledData") == 0)
  15333. {
  15334. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15335. {
  15336. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15337. isSuccess = ConfigurationStatus_Accepted;
  15338. }
  15339. else
  15340. {
  15341. isSuccess = ConfigurationStatus_Rejected;
  15342. }
  15343. }
  15344. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15345. {
  15346. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15347. {
  15348. check_ascii = value[0];
  15349. if( (check_ascii < 48) || (check_ascii > 57) )
  15350. {
  15351. isSuccess = ConfigurationStatus_Rejected;
  15352. }
  15353. else
  15354. {
  15355. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15356. isSuccess = ConfigurationStatus_Accepted;
  15357. }
  15358. }
  15359. else
  15360. {
  15361. isSuccess = ConfigurationStatus_Rejected;
  15362. }
  15363. }
  15364. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15365. {
  15366. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15367. {
  15368. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15369. isSuccess = ConfigurationStatus_Accepted;
  15370. }
  15371. else
  15372. {
  15373. isSuccess = ConfigurationStatus_Rejected;
  15374. }
  15375. }
  15376. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15377. {
  15378. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15379. {
  15380. check_ascii = value[0];
  15381. if( (check_ascii < 48) || (check_ascii > 57) )
  15382. {
  15383. isSuccess = ConfigurationStatus_Rejected;
  15384. }
  15385. else
  15386. {
  15387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15388. isSuccess = ConfigurationStatus_Accepted;
  15389. }
  15390. }
  15391. else
  15392. {
  15393. isSuccess = ConfigurationStatus_Rejected;
  15394. }
  15395. }
  15396. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15397. {
  15398. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15399. {
  15400. check_ascii = value[0];
  15401. if( (check_ascii < 48) || (check_ascii > 57) )
  15402. {
  15403. isSuccess = ConfigurationStatus_Rejected;
  15404. }
  15405. else
  15406. {
  15407. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15408. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15409. TransactionMessageAttemptsValue = atoi(value);
  15410. isSuccess = ConfigurationStatus_Accepted;
  15411. }
  15412. }
  15413. else
  15414. {
  15415. isSuccess = ConfigurationStatus_Rejected;
  15416. }
  15417. }
  15418. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15419. {
  15420. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15421. {
  15422. check_ascii = value[0];
  15423. if( (check_ascii < 48) || (check_ascii > 57) )
  15424. {
  15425. isSuccess = ConfigurationStatus_Rejected;
  15426. }
  15427. else
  15428. {
  15429. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15430. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15431. TransactionMessageRetryIntervalValue = atoi(value);
  15432. isSuccess = ConfigurationStatus_Accepted;
  15433. }
  15434. }
  15435. else
  15436. {
  15437. isSuccess = ConfigurationStatus_Rejected;
  15438. }
  15439. }
  15440. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15441. {
  15442. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15443. {
  15444. strcpy(str, (const char*)value);
  15445. for(int i = 0; str[i]; i++)
  15446. {
  15447. str[i] = tolower(str[i]);
  15448. }
  15449. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15450. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15451. isSuccess = ConfigurationStatus_Accepted;
  15452. }
  15453. else
  15454. {
  15455. isSuccess = ConfigurationStatus_Rejected;
  15456. }
  15457. }
  15458. if(strcmp(key, "WebSocketPingInterval") == 0)
  15459. {
  15460. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15461. {
  15462. check_ascii = value[0];
  15463. if( (check_ascii < 48) || (check_ascii > 57) )
  15464. {
  15465. isSuccess = ConfigurationStatus_Rejected;
  15466. }
  15467. else
  15468. {
  15469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15470. isSuccess = ConfigurationStatus_Accepted;
  15471. if((atoi(value) == 0) || (atoi(value) >= 10))
  15472. {
  15473. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15474. isSuccess = ConfigurationStatus_Accepted;
  15475. }
  15476. else
  15477. isSuccess = ConfigurationStatus_Rejected;
  15478. }
  15479. }
  15480. else
  15481. {
  15482. isSuccess = ConfigurationStatus_Rejected;
  15483. }
  15484. }
  15485. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15486. {
  15487. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15488. {
  15489. strcpy(str, (const char*)value);
  15490. for(int i = 0; str[i]; i++)
  15491. {
  15492. str[i] = tolower(str[i]);
  15493. }
  15494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15495. isSuccess = ConfigurationStatus_Accepted;
  15496. }
  15497. else
  15498. {
  15499. isSuccess = ConfigurationStatus_Rejected;
  15500. }
  15501. }
  15502. if(strcmp(key, "AuthorizationKey") == 0)
  15503. {
  15504. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15505. {
  15506. strcpy(str, (const char*)value);
  15507. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15508. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15509. isSuccess = ConfigurationStatus_Accepted;
  15510. }
  15511. else
  15512. {
  15513. isSuccess = ConfigurationStatus_Rejected;
  15514. }
  15515. }
  15516. if(strcmp(key, "SecurityProfile") == 0)
  15517. {
  15518. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15519. {
  15520. check_ascii = value[0];
  15521. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15522. {
  15523. isSuccess = ConfigurationStatus_Rejected;
  15524. }
  15525. else if(check_ascii == 0x33)
  15526. {
  15527. isSuccess = NotSupported;
  15528. }
  15529. else
  15530. {
  15531. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15532. {
  15533. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15534. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  15535. isSuccess = ConfigurationStatus_Accepted;
  15536. }
  15537. else
  15538. isSuccess = ConfigurationStatus_Rejected;
  15539. }
  15540. }
  15541. else
  15542. {
  15543. isSuccess = ConfigurationStatus_Rejected;
  15544. }
  15545. }
  15546. if(strcmp(key, "DefaultPrice") == 0)
  15547. {
  15548. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15549. {
  15550. strcpy(str, (const char*)value);
  15551. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15552. isSuccess = ConfigurationStatus_Accepted;
  15553. }
  15554. else
  15555. {
  15556. isSuccess = ConfigurationStatus_Rejected;
  15557. }
  15558. }
  15559. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15560. {
  15561. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15562. {
  15563. strcpy(str, (const char*)value);
  15564. for(int i = 0; str[i]; i++)
  15565. {
  15566. str[i] = tolower(str[i]);
  15567. }
  15568. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15569. isSuccess = ConfigurationStatus_Accepted;
  15570. }
  15571. else
  15572. {
  15573. isSuccess = ConfigurationStatus_Rejected;
  15574. }
  15575. }
  15576. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15577. {
  15578. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15579. {
  15580. strcpy(str, (const char*)value);
  15581. for(int i = 0; str[i]; i++)
  15582. {
  15583. str[i] = tolower(str[i]);
  15584. }
  15585. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15586. isSuccess = ConfigurationStatus_Accepted;
  15587. }
  15588. else
  15589. {
  15590. isSuccess = ConfigurationStatus_Rejected;
  15591. }
  15592. }
  15593. if(strcmp(key, "SystemUptimeSec") == 0)
  15594. {
  15595. isSuccess = NotSupported;
  15596. }
  15597. if(strcmp(key, "FreeVend") == 0)
  15598. {
  15599. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15600. {
  15601. strcpy(str, (const char*)value);
  15602. for(int i = 0; str[i]; i++)
  15603. {
  15604. str[i] = tolower(str[i]);
  15605. }
  15606. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15607. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15608. isSuccess = ConfigurationStatus_Accepted;
  15609. }
  15610. else
  15611. {
  15612. isSuccess = ConfigurationStatus_Rejected;
  15613. }
  15614. }
  15615. #if 0
  15616. //For OCPP Test Case
  15617. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15618. {
  15619. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15620. {
  15621. strcpy(str, (const char*)value);
  15622. for(int i = 0; str[i]; i++)
  15623. {
  15624. str[i] = tolower(str[i]);
  15625. }
  15626. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15627. isSuccess = ConfigurationStatus_Accepted;
  15628. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15629. }
  15630. else
  15631. {
  15632. isSuccess = ConfigurationStatus_Rejected;
  15633. }
  15634. }
  15635. #endif
  15636. #if 1
  15637. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15638. {
  15639. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15640. {
  15641. strcpy(str, (const char*)value);
  15642. for(int i = 0; str[i]; i++)
  15643. {
  15644. str[i] = tolower(str[i]);
  15645. }
  15646. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15647. isSuccess = ConfigurationStatus_Accepted;
  15648. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15649. }
  15650. else
  15651. {
  15652. isSuccess = ConfigurationStatus_Rejected;
  15653. }
  15654. }
  15655. #endif
  15656. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15657. {
  15658. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15659. {
  15660. check_ascii = value[0];
  15661. if( (check_ascii < 48) || (check_ascii > 57) )
  15662. {
  15663. isSuccess = ConfigurationStatus_Rejected;
  15664. }
  15665. else
  15666. {
  15667. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15668. isSuccess = ConfigurationStatus_Accepted;
  15669. }
  15670. }
  15671. else
  15672. {
  15673. isSuccess = ConfigurationStatus_Rejected;
  15674. }
  15675. }
  15676. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15677. {
  15678. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15679. {
  15680. check_ascii = value[0];
  15681. if( (check_ascii < 48) || (check_ascii > 57) )
  15682. {
  15683. isSuccess = ConfigurationStatus_Rejected;
  15684. }
  15685. else
  15686. {
  15687. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15688. isSuccess = ConfigurationStatus_Accepted;
  15689. }
  15690. }
  15691. else
  15692. {
  15693. isSuccess = ConfigurationStatus_Rejected;
  15694. }
  15695. }
  15696. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15697. {
  15698. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15699. {
  15700. strcpy(str, (const char*)value);
  15701. for(int i = 0; str[i]; i++)
  15702. {
  15703. str[i] = tolower(str[i]);
  15704. }
  15705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15706. isSuccess = ConfigurationStatus_Accepted;
  15707. }
  15708. else
  15709. {
  15710. isSuccess = ConfigurationStatus_Rejected;
  15711. }
  15712. }
  15713. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15714. {
  15715. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15716. {
  15717. check_ascii = value[0];
  15718. if( (check_ascii < 48) || (check_ascii > 57) )
  15719. {
  15720. isSuccess = ConfigurationStatus_Rejected;
  15721. }
  15722. else
  15723. {
  15724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15725. isSuccess = ConfigurationStatus_Accepted;
  15726. }
  15727. }
  15728. else
  15729. {
  15730. isSuccess = ConfigurationStatus_Rejected;
  15731. }
  15732. }
  15733. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15734. {
  15735. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15736. {
  15737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15738. isSuccess = ConfigurationStatus_Accepted;
  15739. }
  15740. else
  15741. {
  15742. isSuccess = ConfigurationStatus_Rejected;
  15743. }
  15744. }
  15745. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15746. {
  15747. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15748. {
  15749. check_ascii = value[0];
  15750. if( (check_ascii < 48) || (check_ascii > 57) )
  15751. {
  15752. isSuccess = ConfigurationStatus_Rejected;
  15753. }
  15754. else
  15755. {
  15756. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15757. isSuccess = ConfigurationStatus_Accepted;
  15758. }
  15759. }
  15760. else
  15761. {
  15762. isSuccess = ConfigurationStatus_Rejected;
  15763. }
  15764. }
  15765. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15766. {
  15767. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15768. {
  15769. strcpy(str, (const char*)value);
  15770. for(int i = 0; str[i]; i++)
  15771. {
  15772. str[i] = tolower(str[i]);
  15773. }
  15774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15775. isSuccess = ConfigurationStatus_Accepted;
  15776. }
  15777. else
  15778. {
  15779. isSuccess = ConfigurationStatus_Rejected;
  15780. }
  15781. }
  15782. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15783. {
  15784. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15785. {
  15786. check_ascii = value[0];
  15787. if( (check_ascii < 48) || (check_ascii > 57) )
  15788. {
  15789. isSuccess = ConfigurationStatus_Rejected;
  15790. }
  15791. else
  15792. {
  15793. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15794. isSuccess = ConfigurationStatus_Accepted;
  15795. }
  15796. }
  15797. else
  15798. {
  15799. isSuccess = ConfigurationStatus_Rejected;
  15800. }
  15801. }
  15802. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15803. return isSuccess;
  15804. }
  15805. int TransactionMessageAttemptsGet(void)
  15806. {
  15807. return TransactionMessageAttemptsValue;
  15808. }
  15809. int FirstHeartBeatResponse(void)
  15810. {
  15811. return FirstHeartBeat;
  15812. }
  15813. int TransactionMessageRetryIntervalGet(void)
  15814. {
  15815. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15816. }
  15817. int ReadHttpStatus(int sock)
  15818. {
  15819. //char c;
  15820. char buff[1024]="",*ptr=buff+1;
  15821. int bytes_received, status;
  15822. DEBUG_INFO("Begin Response ..\n");
  15823. while((bytes_received = recv(sock, ptr, 1, 0))){
  15824. if(bytes_received==-1){
  15825. perror("ReadHttpStatus");
  15826. exit(1);
  15827. }
  15828. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15829. ptr++;
  15830. }
  15831. *ptr=0;
  15832. ptr=buff+1;
  15833. sscanf(ptr,"%*s %d ", &status);
  15834. DEBUG_INFO("%s\n",ptr);
  15835. DEBUG_INFO("status=%d\n",status);
  15836. DEBUG_INFO("End Response ..\n");
  15837. return (bytes_received>0)?status:0;
  15838. }
  15839. //the only filed that it parsed is 'Content-Length'
  15840. int ParseHeader(int sock)
  15841. {
  15842. //char c;
  15843. char buff[1024]="",*ptr=buff+4;
  15844. int bytes_received;
  15845. DEBUG_INFO("Begin HEADER ..\n");
  15846. while((bytes_received = recv(sock, ptr, 1, 0))){
  15847. if(bytes_received==-1){
  15848. perror("Parse Header");
  15849. exit(1);
  15850. }
  15851. if(
  15852. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15853. (ptr[-1]=='\r') && (*ptr=='\n' )
  15854. ) break;
  15855. ptr++;
  15856. }
  15857. *ptr=0;
  15858. ptr=buff+4;
  15859. //printf("%s",ptr);
  15860. if(bytes_received){
  15861. ptr=strstr(ptr,"Content-Length:");
  15862. if(ptr){
  15863. sscanf(ptr,"%*s %d",&bytes_received);
  15864. }else
  15865. bytes_received=-1; //unknown size
  15866. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15867. }
  15868. DEBUG_INFO("End HEADER ..\n");
  15869. return bytes_received ;
  15870. }
  15871. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15872. {
  15873. int result = TRUE;
  15874. char rmFileCmd[100]={0};
  15875. char FilePath[100]={0};
  15876. char ftpbuf[200];
  15877. int systemresult;
  15878. sprintf(FilePath,"/mnt/%s",filename);
  15879. system("ping 8.8.8.8 &");
  15880. if((access(FilePath,F_OK))!=-1)
  15881. {
  15882. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15883. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15884. system(rmFileCmd);
  15885. }
  15886. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15887. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15888. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15889. systemresult = system(ftpbuf);
  15890. if(systemresult != 0)
  15891. {
  15892. DEBUG_INFO("http DownLoad error!\n");
  15893. result = FALSE;
  15894. }
  15895. system("pkill ping");
  15896. return result;
  15897. }
  15898. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15899. {
  15900. int result = TRUE;
  15901. char rmFileCmd[100]={0};
  15902. char FilePath[100]={0};
  15903. char ftpbuf[200];
  15904. int systemresult;
  15905. sprintf(FilePath,"/mnt/%s",filename);
  15906. system("ping 8.8.8.8 &");
  15907. if((access(FilePath,F_OK))!=-1)
  15908. {
  15909. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15910. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15911. system(rmFileCmd);
  15912. }
  15913. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15914. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15915. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15916. systemresult = system(ftpbuf);
  15917. if(systemresult != 0)
  15918. {
  15919. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15920. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15921. systemresult = system(ftpbuf);
  15922. if(systemresult != 0)
  15923. {
  15924. DEBUG_WARN("wget error!\n");
  15925. result = FALSE;
  15926. }
  15927. }
  15928. system("pkill ping");
  15929. return result;
  15930. }
  15931. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15932. {
  15933. char rmFileCmd[100]={0};
  15934. char FilePath[100]={0};
  15935. char buf[512];
  15936. int systemresult = 0;
  15937. //DEBUG_INFO("filename=%s\n",filename);
  15938. //DEBUG_INFO("url=%s\n",url);
  15939. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15940. if((access(FilePath,F_OK))!=-1)
  15941. {
  15942. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15943. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15944. system(rmFileCmd);
  15945. }
  15946. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15947. if(fp == NULL)
  15948. {
  15949. DEBUG_INFO("log is NULL\n");
  15950. return FALSE;
  15951. }
  15952. else
  15953. {
  15954. fprintf(fp, "%s\n", url);
  15955. fprintf(fp, "%s\n", filename);
  15956. fclose(fp);
  15957. }
  15958. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15959. if(phpFP == NULL)
  15960. {
  15961. DEBUG_INFO("PHP upload fail.\n");
  15962. return FALSE;
  15963. }
  15964. else
  15965. {
  15966. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15967. {
  15968. if(strstr(buf, "result") != NULL)
  15969. {
  15970. sscanf(buf, "result: %d", &systemresult);
  15971. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15972. }
  15973. }
  15974. pclose(phpFP);
  15975. }
  15976. if(systemresult != 1)
  15977. {
  15978. DEBUG_INFO("HTTP upload error!\n");
  15979. return FALSE;
  15980. }
  15981. return TRUE;
  15982. }
  15983. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15984. {
  15985. int result = FALSE;
  15986. char ftpbuf[200];
  15987. int systemresult;
  15988. /*
  15989. // Domaind name transfer to IP address
  15990. struct hostent* server;
  15991. char *IPbuffer;
  15992. server = gethostbyname(location);
  15993. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  15994. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15995. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  15996. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  15997. systemresult = system(ftpbuf);
  15998. if(systemresult != 0)
  15999. {
  16000. DEBUG_INFO("ftpput error!\n");
  16001. }
  16002. else
  16003. {
  16004. result = TRUE;
  16005. DEBUG_INFO("ftpput OK!\n");
  16006. }
  16007. return result;
  16008. }
  16009. int GetOcppServerURL()
  16010. {
  16011. int result = FALSE;
  16012. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16013. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16014. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16015. struct yuarel url;
  16016. char urlStr[512];
  16017. // OCPPPH only
  16018. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16019. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16020. {
  16021. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16022. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16023. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16024. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16025. if(yuarel_parse(&url, urlStr) != -1)
  16026. {
  16027. sprintf(OcppProtocol, "%s", url.scheme);
  16028. sprintf(OcppHost, "%s", url.host);
  16029. if(url.path == NULL)
  16030. OcppTempPath[0] = '\0';
  16031. else
  16032. sprintf(OcppTempPath, "%s", url.path);
  16033. if(url.port == 0)
  16034. {
  16035. if(strcmp(OcppProtocol, "wss") == 0)
  16036. OcppPort = 443;
  16037. else
  16038. OcppPort = 80;
  16039. }
  16040. else
  16041. OcppPort = url.port;
  16042. result = TRUE;
  16043. }
  16044. }
  16045. else
  16046. {
  16047. strcpy(OcppHost,"");
  16048. }
  16049. return result;
  16050. }
  16051. int GetOcppPath()
  16052. {
  16053. int result = FALSE;
  16054. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16055. {
  16056. if(OcppTempPath == NULL)
  16057. {
  16058. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16059. }
  16060. else
  16061. {
  16062. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16063. }
  16064. result = TRUE;
  16065. goto End;
  16066. }
  16067. else
  16068. {
  16069. strcpy(OcppPath,"");
  16070. }
  16071. End:
  16072. return result;
  16073. }
  16074. int GetOcppPort()
  16075. {
  16076. return OcppPort;
  16077. }
  16078. int GetOcppConnStatus(void)
  16079. {
  16080. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  16081. }
  16082. void SetOcppConnStatus(uint8_t status)
  16083. {
  16084. ShmOCPP16DataPH->OcppConnStatus = status;
  16085. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  16086. }
  16087. int GetHeartBeatWithNOResponse(void)
  16088. {
  16089. return HeartBeatWithNOResponse;
  16090. }
  16091. void SetHeartBeatWithNOResponse(void)
  16092. {
  16093. HeartBeatWithNOResponse = 0;
  16094. }
  16095. void GetStartTransactionIdTag(int gun_index)
  16096. {
  16097. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16098. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16099. }
  16100. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16101. {
  16102. char ch;
  16103. FILE *fptr1;
  16104. int temptransactionId;
  16105. char str[100]={0};
  16106. temptransactionId = 0;
  16107. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16108. {
  16109. DEBUG_INFO("IdTag is empty.\n");
  16110. return temptransactionId;
  16111. }
  16112. /*------ Read the file ----------------*/
  16113. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16114. if (!fptr1)
  16115. {
  16116. DEBUG_INFO("QueueTransactionId file open error.\n");
  16117. //printf(" File not found or unable to open the input file!!\n");
  16118. return temptransactionId;
  16119. }
  16120. ch=fgetc(fptr1);
  16121. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16122. rewind(fptr1);
  16123. if(ch!=EOF)
  16124. {
  16125. // printf("%c",ch);
  16126. while (fgets(str, 100, fptr1) != NULL)
  16127. {
  16128. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16129. if(str[0]=='\0')
  16130. {
  16131. break;
  16132. }
  16133. char *revbuf[8] = {0}; // Variable store string split
  16134. int num = 0;// Quantity after string split
  16135. DEBUG_INFO("Transaction queue data= %s\n", str);
  16136. splitstring(str,",",revbuf,&num); // String split
  16137. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16138. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16139. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16140. DEBUG_INFO("------------------------------\n");
  16141. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16142. {
  16143. if(isStopTransaction)
  16144. {
  16145. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16146. {
  16147. temptransactionId = atoi(revbuf[2]);
  16148. //break;
  16149. }
  16150. }
  16151. else
  16152. {
  16153. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16154. {
  16155. temptransactionId = atoi(revbuf[2]);
  16156. //break;
  16157. }
  16158. }
  16159. }
  16160. }
  16161. }
  16162. else
  16163. DEBUG_INFO("EOF\n");
  16164. fclose(fptr1);
  16165. /*------- End of reading ---------------*/
  16166. return temptransactionId;
  16167. }
  16168. void SetTransactionIdZero(int transactionId)
  16169. {
  16170. char ch;
  16171. FILE *fptr1, *fptr2;
  16172. int temptransactionId = 0;
  16173. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16174. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16175. if (!fptr1)
  16176. {
  16177. //printf(" File not found or unable to open the input file!!\n");
  16178. return ;
  16179. }
  16180. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16181. if (!fptr2)
  16182. {
  16183. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16184. fclose(fptr1);
  16185. return ;
  16186. }
  16187. ch=fgetc(fptr1);
  16188. rewind(fptr1);
  16189. if(ch!=EOF)
  16190. {
  16191. // copy all contents to the temporary file except the specific line
  16192. while (fgets(str, 100, fptr1) != NULL)
  16193. {
  16194. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16195. if(str[0]=='\0')
  16196. {
  16197. break;
  16198. }
  16199. char *revbuf[8] = {0};
  16200. int num = 0;
  16201. strcpy(strtemp, str);
  16202. splitstring(str,",",revbuf,&num);
  16203. if(revbuf[2][0] != '\0')
  16204. {
  16205. temptransactionId = atoi(revbuf[2]);
  16206. if(transactionId != temptransactionId)
  16207. {
  16208. fprintf(fptr2, "%s\n", strtemp);
  16209. }
  16210. }
  16211. }
  16212. }
  16213. fclose(fptr1);
  16214. fclose(fptr2);
  16215. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16216. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16217. /*------ Read the file ----------------*/
  16218. }
  16219. int InternetDisconnect(void)
  16220. {
  16221. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16222. }
  16223. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16224. void storeTempStopTransaction(int gun_index)
  16225. {
  16226. char guid[37]={0};
  16227. int tempIndex = 0;
  16228. char TempStopTransaction[256];
  16229. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16230. DEBUG_INFO("storeTempStopTransaction...\n");
  16231. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16232. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16233. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16234. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16235. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16236. {
  16237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16238. {
  16239. tempIndex = ((gun_index==2) ? 1: 0);
  16240. }
  16241. else
  16242. {
  16243. tempIndex = gun_index;
  16244. }
  16245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16246. {
  16247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16248. {
  16249. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16250. }
  16251. }// END OF CHAdeMO_QUANTITY
  16252. }
  16253. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16254. {
  16255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16256. {
  16257. tempIndex = ((gun_index==2) ? 1: 0);
  16258. }
  16259. else
  16260. {
  16261. tempIndex = gun_index;
  16262. }
  16263. for (int index = 0; index < CCS_QUANTITY; index++)
  16264. {
  16265. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16266. {
  16267. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16268. }
  16269. }// END OF CCS_QUANTITY
  16270. }
  16271. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16272. {
  16273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16274. {
  16275. tempIndex = ((gun_index==2) ? 1: 0);
  16276. }
  16277. else
  16278. {
  16279. tempIndex = gun_index;
  16280. }
  16281. for (int index = 0; index < GB_QUANTITY; index++)
  16282. {
  16283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16284. {
  16285. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16286. }
  16287. }// END OF GB_QUANTITY
  16288. }
  16289. else if(gunType[gun_index] == GUN_TYPE_DO)
  16290. {
  16291. tempIndex = gun_index;
  16292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16293. {
  16294. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16295. {
  16296. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16297. }
  16298. }
  16299. }
  16300. else
  16301. {
  16302. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16303. {
  16304. tempIndex = 2;
  16305. }
  16306. else
  16307. {
  16308. tempIndex = gun_index;
  16309. }
  16310. for (int index = 0; index < AC_QUANTITY; index++)
  16311. {
  16312. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16313. {
  16314. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16315. }
  16316. }// END OF AC_QUANTITY
  16317. }
  16318. //Stop Transaction Time
  16319. struct timeval tmnow;
  16320. struct tm *tm;
  16321. char buf[28];//, usec_buf[6];
  16322. gettimeofday(&tmnow, NULL);
  16323. time_t t;
  16324. t = time(NULL);
  16325. /*UTC time and date*/
  16326. tm = gmtime(&t);
  16327. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16328. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16329. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16330. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16331. random_uuid(guid);
  16332. /***********************************transactionData******************************************************/
  16333. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16335. //=================================
  16336. //1. Transaction_Begin
  16337. //=================================
  16338. //============================== Energy.Active.Import.Interval ===========================================
  16339. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16340. {
  16341. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16342. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16343. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16344. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  16345. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16346. 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))
  16347. {
  16348. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16349. }
  16350. else
  16351. {
  16352. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16353. }
  16354. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16355. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16356. }
  16357. //=================================
  16358. //2. Transaction_End
  16359. //=================================
  16360. //2.1====================================== Current.Import L1 ==============================================
  16361. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16362. {
  16363. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16364. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16365. {
  16366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16367. {
  16368. tempIndex = ((gun_index==2) ? 1: 0);
  16369. }
  16370. else
  16371. {
  16372. tempIndex = gun_index;
  16373. }
  16374. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16375. {
  16376. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16377. {
  16378. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16379. }
  16380. }// End of for CHAdeMO_QUANTITY
  16381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16382. }
  16383. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16384. {
  16385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16386. {
  16387. tempIndex = ((gun_index==2) ? 1: 0);
  16388. }
  16389. else
  16390. {
  16391. tempIndex = gun_index;
  16392. }
  16393. for (int index = 0; index < CCS_QUANTITY; index++)
  16394. {
  16395. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16396. {
  16397. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16398. }
  16399. }// End of for CCS_QUANTITY
  16400. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16401. }
  16402. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16403. {
  16404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16405. {
  16406. tempIndex = ((gun_index==2) ? 1: 0);
  16407. }
  16408. else
  16409. {
  16410. tempIndex = gun_index;
  16411. }
  16412. for (int index = 0; index < GB_QUANTITY; index++)
  16413. {
  16414. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16415. {
  16416. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16417. }
  16418. }// End of for GB_QUANTITY
  16419. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16420. }
  16421. else if(gunType[gun_index] == GUN_TYPE_DO)
  16422. {
  16423. tempIndex = gun_index;
  16424. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16425. {
  16426. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16427. {
  16428. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16429. }
  16430. }
  16431. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16432. }
  16433. else
  16434. {
  16435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16436. {
  16437. tempIndex = 2;
  16438. }
  16439. else
  16440. {
  16441. tempIndex = gun_index;
  16442. }
  16443. for (int index = 0; index < AC_QUANTITY; index++)
  16444. {
  16445. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16446. {
  16447. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16448. }
  16449. }// End of for AC_QUANTITY
  16450. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16451. }
  16452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16455. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16456. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16457. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16458. }
  16459. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16460. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16461. {
  16462. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16463. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16464. {
  16465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16466. {
  16467. tempIndex = ((gun_index==2) ? 1: 0);
  16468. }
  16469. else
  16470. {
  16471. tempIndex = gun_index;
  16472. }
  16473. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16474. {
  16475. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16476. {
  16477. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16478. }
  16479. }// END OF CHAdeMO_QUANTITY
  16480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16481. }
  16482. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16483. {
  16484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16485. {
  16486. tempIndex = ((gun_index==2) ? 1: 0);
  16487. }
  16488. else
  16489. {
  16490. tempIndex = gun_index;
  16491. }
  16492. for (int index = 0; index < CCS_QUANTITY; index++)
  16493. {
  16494. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16495. {
  16496. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16497. }
  16498. }// END OF CCS_QUANTITY
  16499. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16500. }
  16501. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16502. {
  16503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16504. {
  16505. tempIndex = ((gun_index==2) ? 1: 0);
  16506. }
  16507. else
  16508. {
  16509. tempIndex = gun_index;
  16510. }
  16511. for (int index = 0; index < GB_QUANTITY; index++)
  16512. {
  16513. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16514. {
  16515. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16516. }
  16517. }// END OF GB_QUANTITY
  16518. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16519. }
  16520. else if(gunType[gun_index] == GUN_TYPE_DO)
  16521. {
  16522. tempIndex = gun_index;
  16523. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16524. {
  16525. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16526. {
  16527. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16528. }
  16529. }
  16530. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16531. }
  16532. else
  16533. {
  16534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16535. {
  16536. tempIndex = 2;
  16537. }
  16538. else
  16539. {
  16540. tempIndex = gun_index;
  16541. }
  16542. for (int index = 0; index < AC_QUANTITY; index++)
  16543. {
  16544. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16545. {
  16546. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16547. }
  16548. }// END OF AC_QUANTITY
  16549. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16550. }
  16551. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16554. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16555. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16557. }
  16558. //2.3====================================== Power.Active.Import =========================================
  16559. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16560. {
  16561. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16562. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16563. {
  16564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16565. {
  16566. tempIndex = ((gun_index==2) ? 1: 0);
  16567. }
  16568. else
  16569. {
  16570. tempIndex = gun_index;
  16571. }
  16572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16573. {
  16574. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16575. {
  16576. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16577. }
  16578. } // End for CHAdeMO_QUANTITY
  16579. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16580. }
  16581. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16582. {
  16583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16584. {
  16585. tempIndex = ((gun_index==2) ? 1: 0);
  16586. }
  16587. else
  16588. {
  16589. tempIndex = gun_index;
  16590. }
  16591. for (int index = 0; index < CCS_QUANTITY; index++)
  16592. {
  16593. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16594. {
  16595. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16596. }
  16597. } // END for CCS_QUANTITY
  16598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16599. }
  16600. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16601. {
  16602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16603. {
  16604. tempIndex = ((gun_index==2) ? 1: 0);
  16605. }
  16606. else
  16607. {
  16608. tempIndex = gun_index;
  16609. }
  16610. for (int index = 0; index < GB_QUANTITY; index++)
  16611. {
  16612. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16613. {
  16614. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16615. }
  16616. }// END for GB_QUANTITY
  16617. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16618. }
  16619. else if(gunType[gun_index] == GUN_TYPE_DO)
  16620. {
  16621. tempIndex = gun_index;
  16622. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16623. {
  16624. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16625. {
  16626. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16627. }
  16628. }
  16629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16630. }
  16631. else
  16632. {
  16633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16634. {
  16635. tempIndex = 2;
  16636. }
  16637. else
  16638. {
  16639. tempIndex = gun_index;
  16640. }
  16641. for (int index = 0; index < AC_QUANTITY; index++)
  16642. {
  16643. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16644. {
  16645. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16646. }
  16647. } // END for AC_QUANTITY
  16648. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16649. }
  16650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16653. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16656. }
  16657. //2.4====================================== Voltage L1 ====================================================
  16658. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16659. {
  16660. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16661. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16662. {
  16663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16664. {
  16665. tempIndex = ((gun_index==2) ? 1: 0);
  16666. }
  16667. else
  16668. {
  16669. tempIndex = gun_index;
  16670. }
  16671. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16672. {
  16673. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16674. {
  16675. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16676. }
  16677. } // END OF FOR CHAdeMO_QUANTITY
  16678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16679. }
  16680. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16681. {
  16682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16683. {
  16684. tempIndex = ((gun_index==2) ? 1: 0);
  16685. }
  16686. else
  16687. {
  16688. tempIndex = gun_index;
  16689. }
  16690. for (int index = 0; index < CCS_QUANTITY; index++)
  16691. {
  16692. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16693. {
  16694. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16695. }
  16696. } // END OF FOR CCS_QUANTITY
  16697. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16698. }
  16699. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16700. {
  16701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16702. {
  16703. tempIndex = ((gun_index==2) ? 1: 0);
  16704. }
  16705. else
  16706. {
  16707. tempIndex = gun_index;
  16708. }
  16709. for (int index = 0; index < GB_QUANTITY; index++)
  16710. {
  16711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16712. {
  16713. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16714. }
  16715. } // END OF FOR GB_QUANTITY
  16716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16717. }
  16718. else if(gunType[gun_index] == GUN_TYPE_DO)
  16719. {
  16720. tempIndex = gun_index;
  16721. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16722. {
  16723. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16724. {
  16725. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16726. }
  16727. }
  16728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16729. }
  16730. else
  16731. {
  16732. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16733. {
  16734. tempIndex = 2;
  16735. }
  16736. else
  16737. {
  16738. tempIndex = gun_index;
  16739. }
  16740. for (int index = 0; index < AC_QUANTITY; index++)
  16741. {
  16742. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16743. {
  16744. 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
  16745. }
  16746. } // END OF FOR AC_QUANTITY
  16747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16748. }
  16749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16752. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16754. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16755. }
  16756. //2.5============================================== End SoC =========================================================
  16757. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16758. {
  16759. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16760. 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))
  16761. {
  16762. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16763. {
  16764. tempIndex = ((gun_index==2) ? 1: 0);
  16765. }
  16766. else
  16767. {
  16768. tempIndex = gun_index;
  16769. }
  16770. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16771. {
  16772. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16773. {
  16774. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16775. {
  16776. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16777. }
  16778. }
  16779. }
  16780. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16781. {
  16782. for (int index = 0; index < CCS_QUANTITY; index++)
  16783. {
  16784. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16785. {
  16786. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16787. }
  16788. }
  16789. }
  16790. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16791. {
  16792. for (int index = 0; index < GB_QUANTITY; index++)
  16793. {
  16794. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16795. {
  16796. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16797. }
  16798. }
  16799. }
  16800. else if(gunType[gun_index] == GUN_TYPE_DO)
  16801. {
  16802. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16803. {
  16804. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16805. {
  16806. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16807. }
  16808. }
  16809. }
  16810. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16811. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16812. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16813. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16814. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16815. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16816. } // END FOR DC CASE
  16817. }
  16818. //2.6====================================== Current.Import L2 ==============================================
  16819. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16820. {
  16821. // AC 3 phase L2 current
  16822. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16823. {
  16824. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16825. {
  16826. tempIndex = 2;
  16827. }
  16828. else
  16829. {
  16830. tempIndex = gun_index;
  16831. }
  16832. for (int index = 0; index < AC_QUANTITY; index++)
  16833. {
  16834. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16835. {
  16836. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16837. }
  16838. }// End of for AC_QUANTITY
  16839. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16840. }
  16841. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16843. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16844. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16845. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16846. }
  16847. //2.7====================================== Current.Import L3 ==============================================
  16848. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16849. {
  16850. // AC 3 phase L3 current
  16851. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16852. {
  16853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16854. {
  16855. tempIndex = 2;
  16856. }
  16857. else
  16858. {
  16859. tempIndex = gun_index;
  16860. }
  16861. for (int index = 0; index < AC_QUANTITY; index++)
  16862. {
  16863. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16864. {
  16865. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16866. }
  16867. }// End of for AC_QUANTITY
  16868. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16869. }
  16870. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16871. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16874. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16875. }
  16876. //2.9====================================== Voltage L2 ====================================================
  16877. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16878. {
  16879. // AC 3 phase L2 volatge
  16880. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16881. {
  16882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16883. {
  16884. tempIndex = 2;
  16885. }
  16886. else
  16887. {
  16888. tempIndex = gun_index;
  16889. }
  16890. for (int index = 0; index < AC_QUANTITY; index++)
  16891. {
  16892. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16893. {
  16894. 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
  16895. }
  16896. } // END OF FOR AC_QUANTITY
  16897. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16898. }
  16899. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16900. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16904. }
  16905. //2.10====================================== Voltage L3 ====================================================
  16906. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16907. {
  16908. // AC 3 phase L3 volatge
  16909. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16910. {
  16911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16912. {
  16913. tempIndex = 2;
  16914. }
  16915. else
  16916. {
  16917. tempIndex = gun_index;
  16918. }
  16919. for (int index = 0; index < AC_QUANTITY; index++)
  16920. {
  16921. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16922. {
  16923. 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
  16924. }
  16925. } // END OF FOR AC_QUANTITY
  16926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16927. }
  16928. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16929. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16930. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16931. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16932. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16933. }
  16934. //====================== Start SoC ================================
  16935. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16936. {
  16937. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16938. 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))
  16939. {
  16940. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16941. {
  16942. tempIndex = ((gun_index==2) ? 1: 0);
  16943. }
  16944. else
  16945. {
  16946. tempIndex = gun_index;
  16947. }
  16948. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16949. {
  16950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16951. {
  16952. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16953. {
  16954. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16955. }
  16956. }
  16957. }
  16958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16959. {
  16960. for (int index = 0; index < CCS_QUANTITY; index++)
  16961. {
  16962. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16963. {
  16964. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16965. }
  16966. }
  16967. }
  16968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16969. {
  16970. for (int index = 0; index < GB_QUANTITY; index++)
  16971. {
  16972. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16973. {
  16974. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16975. }
  16976. }
  16977. }
  16978. else if(gunType[gun_index] == GUN_TYPE_DO)
  16979. {
  16980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16981. {
  16982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16983. {
  16984. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16985. }
  16986. }
  16987. }
  16988. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16989. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16990. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16991. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16992. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16993. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16994. } // END FOR DC CASE
  16995. }
  16996. //======================================== Message create ==============================================
  16997. json_object *StopTransaction = json_object_new_object();
  16998. json_object *transactionDatas = json_object_new_array();
  16999. json_object *sampledValues = json_object_new_array();
  17000. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17001. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17002. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17003. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17004. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17005. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17006. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17007. {
  17008. json_object *transactionData = json_object_new_object();
  17009. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17010. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17011. {
  17012. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17013. {
  17014. json_object *sampledValue = json_object_new_object();
  17015. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17016. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17017. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17018. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17019. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17020. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17021. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17022. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17023. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17024. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17025. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17026. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17027. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17028. json_object_array_add(sampledValues, sampledValue);
  17029. }
  17030. }
  17031. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17032. json_object_array_add(transactionDatas, transactionData);
  17033. }
  17034. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17035. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17036. ,MESSAGE_TYPE_CALL
  17037. ,guid
  17038. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17039. json_object_put(StopTransaction);
  17040. // Check File "TempStopTransaction" Exist
  17041. if((access(TempStopTransaction,F_OK))!=-1)
  17042. {
  17043. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17044. fclose(fopen(TempStopTransaction, "w"));
  17045. }
  17046. else
  17047. {
  17048. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17049. FILE *log = fopen(TempStopTransaction, "w+");
  17050. if(log == NULL)
  17051. {
  17052. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17053. return ;
  17054. }
  17055. else
  17056. {
  17057. fclose(log);
  17058. }
  17059. }
  17060. //Add TempStopTransaction | Update TempStopTransaction
  17061. // open file for writing
  17062. FILE *outfile;
  17063. outfile = fopen (TempStopTransaction, "a");
  17064. //DEBUG_INFO("data = %s\n", queuedata);
  17065. fputs(queuedata, outfile);
  17066. fputs("\n", outfile);
  17067. fclose (outfile);
  17068. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17069. }
  17070. void checkTempStopTransaction(int gun_index)
  17071. {
  17072. FILE *fptr1;
  17073. char ch;
  17074. char str[QUEUE_MESSAGE_LENGTH]={0};
  17075. char guid[37]={0};
  17076. char tempdata[65]={0};
  17077. char connectorStr[2]={0};
  17078. char TempStopTransaction[256];
  17079. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17080. fptr1 = fopen(TempStopTransaction, "r");
  17081. //TempStopTransaction格式: 槍號,StopTransaction封包
  17082. if (!fptr1)
  17083. {
  17084. //printf(" File not found or unable to open the input file!!\n");
  17085. return ;
  17086. }
  17087. ch=fgetc(fptr1);
  17088. //printf(" Now the content of the file %s is : \n",fname);
  17089. rewind(fptr1);
  17090. if(ch!=EOF)
  17091. {
  17092. // copy all contents to the temporary file except the specific line
  17093. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17094. {
  17095. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17096. if(str[0]=='\0')
  17097. {
  17098. break;
  17099. }
  17100. //TempStopTransaction格式: 槍號,StopTransaction封包
  17101. strncpy(connectorStr, str, 1);
  17102. if(atoi(connectorStr) != (gun_index+1))
  17103. {
  17104. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17105. fclose(fptr1);
  17106. return ;
  17107. }
  17108. //random_uuid(guid);
  17109. strncpy(guid, str+6, 36); //copy guid
  17110. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17111. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17112. {
  17113. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17114. }
  17115. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17116. OCPP_insert_transaction_msg(NO, str);
  17117. memset(str,0,ARRAY_SIZE(str));
  17118. }
  17119. }
  17120. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17121. fclose(fptr1);
  17122. remove(TempStopTransaction); // remove the original file
  17123. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17124. }
  17125. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17126. {
  17127. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17128. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17129. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17130. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17131. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17132. }
  17133. int GetWebSocketPingInterval(void)
  17134. {
  17135. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17136. }
  17137. int GetServerSign(void)
  17138. {
  17139. return server_sign;
  17140. }
  17141. uint8_t GetOcppSecurityProfile()
  17142. {
  17143. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17144. }
  17145. void GetOcppChargerBoxId(uint8_t *data)
  17146. {
  17147. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17148. }
  17149. void GetOcppSecurityPassword(uint8_t *data)
  17150. {
  17151. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17152. }
  17153. void SetOcppVersion(uint8_t *version)
  17154. {
  17155. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17156. DEBUG_INFO("ocpp version: %s\n", version);
  17157. if(strstr((char*)version, "ocpp1.6") != NULL)
  17158. {
  17159. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17160. }
  17161. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17162. {
  17163. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17164. system("pkill OcppBackend");
  17165. }
  17166. }
  17167. void SetServerSign(int value)
  17168. {
  17169. server_sign = value;
  17170. }
  17171. int GetBootNotificationInterval(void)
  17172. {
  17173. return BootNotificationInterval;
  17174. }
  17175. int GetInternetConn(void)
  17176. {
  17177. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17178. }
  17179. int GetBackendConnectionTimeout(void)
  17180. {
  17181. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17182. }
  17183. int isConnectorInitMode(int gun_index)
  17184. {
  17185. int tempIndex = 0;
  17186. int result = TRUE;
  17187. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17188. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17189. {
  17190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17191. {
  17192. tempIndex = ((gun_index==2) ? 1: 0);
  17193. }
  17194. else
  17195. {
  17196. tempIndex = gun_index;
  17197. }
  17198. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17199. {
  17200. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17201. {
  17202. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17203. } //end of the same index
  17204. }//end of for CHAdeMO_QUANTITY
  17205. }
  17206. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17207. {
  17208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17209. {
  17210. tempIndex = ((gun_index==2) ? 1: 0);
  17211. }
  17212. else
  17213. {
  17214. tempIndex = gun_index;
  17215. }
  17216. for (int index = 0; index < CCS_QUANTITY; index++)
  17217. {
  17218. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17219. {
  17220. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17221. } //end of the same index
  17222. } // end of for CCS_QUANTITY
  17223. }
  17224. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17225. {
  17226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17227. {
  17228. tempIndex = ((gun_index==2) ? 1: 0);
  17229. }
  17230. else
  17231. {
  17232. tempIndex = gun_index;
  17233. }
  17234. for (int index = 0; index < GB_QUANTITY; index++)
  17235. {
  17236. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17237. {
  17238. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17239. } //end of the same index
  17240. } // end of for GB_QUANTITY
  17241. }
  17242. else if(gunType[gun_index] == GUN_TYPE_DO)
  17243. {
  17244. tempIndex = gun_index;
  17245. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17246. {
  17247. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17248. {
  17249. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17250. } //end of the same index
  17251. }
  17252. }
  17253. else
  17254. {
  17255. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17256. {
  17257. tempIndex = 2;
  17258. }
  17259. else
  17260. {
  17261. tempIndex = gun_index;
  17262. }
  17263. for (int index = 0; index < AC_QUANTITY; index++)
  17264. {
  17265. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17266. {
  17267. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17268. }//end of the same index
  17269. }//end of for AC_QUANTITY
  17270. }
  17271. return result;
  17272. }
  17273. void refreshProcDogTimer()
  17274. {
  17275. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17276. }
  17277. void InitialSystemValue(void)
  17278. {
  17279. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17280. locallistVersion=0;
  17281. BootNotificationInterval = 0;
  17282. authorizeRetryTimes = 0;
  17283. GunStatusInterval = 10;
  17284. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17285. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17286. //Hear Beat
  17287. HeartBeatWithNOResponse = 0;
  17288. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17289. FirstHeartBeat = 0;
  17290. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17291. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17292. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17293. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17294. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17295. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17296. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17297. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17298. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17299. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17300. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17301. //Status && ConnectorPlugIn Setting
  17302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17303. {
  17304. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17305. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17306. }
  17307. for (int index = 0; index < CCS_QUANTITY; index++)
  17308. {
  17309. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17310. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17311. }
  17312. for (int index = 0; index < GB_QUANTITY; index++)
  17313. {
  17314. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17315. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17316. }
  17317. for (int index = 0; index < AC_QUANTITY; index++)
  17318. {
  17319. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17320. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17321. }
  17322. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17323. {
  17324. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17325. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17326. }
  17327. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17328. {
  17329. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17330. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17331. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17332. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17333. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17334. }
  17335. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17336. refreshStartTimer(&clientTime.Heartbeat);
  17337. sleep(1);
  17338. }
  17339. void LWS_Send(char *str)
  17340. {
  17341. //=====================================================
  17342. // Check InternetConn 0: disconnected, 1: connected
  17343. //====================================================
  17344. if(GetOcppConnStatus() == 0)
  17345. {
  17346. DEBUG_INFO("offline now !!!\n");
  17347. return;
  17348. }
  17349. // Only disable isWebsocketSendable operation initiated by charger
  17350. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17351. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17352. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17353. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17354. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17355. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17356. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17357. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17358. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17359. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17360. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17361. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17362. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17363. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17364. {
  17365. isWebsocketSendable = 0;
  17366. }
  17367. pthread_mutex_lock(&lock_send);
  17368. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17369. sprintf((char *)SendBuffer, "%s", str);
  17370. SendBufLen = strlen(str);
  17371. pthread_mutex_unlock(&lock_send);
  17372. lws_callback_on_writable(wsi_client);
  17373. //lws_service(context, 0);
  17374. //sleep(1);
  17375. }
  17376. void LWS_SendNow(char *str)
  17377. {
  17378. //=====================================================
  17379. // Check InternetConn 0: disconnected, 1: connected
  17380. //====================================================
  17381. if(GetOcppConnStatus() == 0)
  17382. {
  17383. DEBUG_INFO("offline now !!!\n");
  17384. return;
  17385. }
  17386. // Only disable isWebsocketSendable operation initiated by charger
  17387. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17388. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17389. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17390. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17391. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17392. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17393. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17394. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17395. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17396. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17397. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17398. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17399. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17400. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17401. {
  17402. isWebsocketSendable = 0;
  17403. }
  17404. pthread_mutex_lock(&lock_send);
  17405. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17406. sprintf((char *)SendBuffer, "%s", str);
  17407. SendBufLen = strlen(str);
  17408. pthread_mutex_unlock(&lock_send);
  17409. lws_callback_on_writable(wsi_client);
  17410. lws_service(context, 0);
  17411. //sleep(1);
  17412. }