MessageHandler.c 881 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947
  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 void ChageWebSocketPingInterval(int WebSocketPingInterval);
  85. extern sqlite3 *db;
  86. int TransactionMessageAttemptsGet(void);
  87. int TransactionMessageRetryIntervalGet(void);
  88. int GetOcppConnStatus(void);
  89. void SetOcppConnStatus(uint8_t status);
  90. int setKeyValue(char *key, char *value);
  91. void OCPP_get_TableAuthlocalAllData(void);
  92. void processUnkownKey(void);
  93. struct InterLock
  94. {
  95. unsigned char isGetDiagnosticGoing:1;
  96. unsigned char isUpdateFirmwareGoing:1;
  97. }interLock;
  98. struct ClientTime
  99. {
  100. struct timespec Heartbeat;
  101. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  102. struct timespec StartTransaction;
  103. struct timespec StopTransaction;
  104. struct timespec MeterValues[CONNECTOR_QUANTITY];
  105. struct timespec RemoteStartWait;
  106. }clientTime;
  107. typedef union
  108. {
  109. //Operations Initiated by Central System
  110. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  111. struct
  112. {
  113. //CsMsgValue[0]
  114. unsigned char StatusNotificationReq:1; //bit 0,
  115. unsigned char StatusNotificationConf:1; //bit 1,
  116. unsigned char TriggerMeterValue:1; //bit 2,
  117. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  118. unsigned char isOnCharging:1; //bit 4.
  119. unsigned char :3; //bit 5~7
  120. }bits[CONNECTOR_QUANTITY];
  121. }CpinitiateMsg;
  122. CpinitiateMsg cpinitateMsg;
  123. //GetConfiguration Array
  124. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  125. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  126. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  127. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  128. #if 0
  129. static char *ChargePointErrorCodeStr[] = {
  130. MACROSTR(ConnectorLockFailure),
  131. MACROSTR(EVCommunicationError),
  132. MACROSTR(GroundFailure),
  133. MACROSTR(HighTemperature),
  134. MACROSTR(InternalError),
  135. MACROSTR(LocalListConflict),
  136. MACROSTR(NoError),
  137. MACROSTR(OtherError),
  138. MACROSTR(OverCurrentFailure),
  139. MACROSTR(OverVoltage),
  140. MACROSTR(PowerMeterFailure),
  141. MACROSTR(PowerSwitchFailure),
  142. MACROSTR(ReaderFailure),
  143. MACROSTR(ResetFailure),
  144. MACROSTR(UnderVoltage),
  145. MACROSTR(WeakSignal)
  146. };
  147. #endif
  148. static char * ChargePointStatusStr[] = {
  149. MACROSTR(Available),
  150. MACROSTR(Preparing),
  151. MACROSTR(Charging),
  152. MACROSTR(SuspendedEVSE),
  153. MACROSTR(SuspendedEV),
  154. MACROSTR(Finishing),
  155. MACROSTR(Reserved),
  156. MACROSTR(Unavailable),
  157. MACROSTR(Faulted)
  158. };
  159. static char *RegistrationStatusStr[] = {
  160. MACROSTR(Accepted),
  161. MACROSTR(Pending),
  162. MACROSTR(Rejected)
  163. };
  164. static char *AvailabilityTypeStr[] = {
  165. MACROSTR(Inoperative),
  166. MACROSTR(Operative)
  167. };
  168. static char *AvailabilityStatusStr[] = {
  169. MACROSTR(Accepted),
  170. MACROSTR(Rejected),
  171. MACROSTR(Scheduled)
  172. };
  173. static char *ConfigurationStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(RebootRequired),
  177. MACROSTR(NotSupported)
  178. };
  179. static char *ClearCacheStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected)
  182. };
  183. static char *ChargingProfilePurposeTypeStr[] = {
  184. MACROSTR(ChargePointMaxProfile),
  185. MACROSTR(TxDefaultProfile),
  186. MACROSTR(TxProfile)
  187. };
  188. static char *ChargingProfileStatusStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Rejected),
  191. MACROSTR(NotSupported)
  192. };
  193. static char *ClearChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Unknown)
  196. };
  197. static char *GetCompositeScheduleStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Rejected)
  200. };
  201. static char *UpdateTypeStr[] = {
  202. MACROSTR(Differential),
  203. MACROSTR(Full)
  204. };
  205. static char *UpdateStatusStr[] = {
  206. MACROSTR(Accepted),
  207. MACROSTR(Failed),
  208. MACROSTR(NotSupported),
  209. MACROSTR(VersionMismatch)
  210. };
  211. static char *RemoteStartStopStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Rejected)
  214. };
  215. static char *ReservationStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Faulted),
  218. MACROSTR(Occupied),
  219. MACROSTR(Rejected),
  220. MACROSTR(Unavailable)
  221. };
  222. static char *ResetTypeStr[] = {
  223. MACROSTR(Hard),
  224. MACROSTR(Soft)
  225. };
  226. static char *ResetStatusStr[] = {
  227. MACROSTR(Accepted),
  228. MACROSTR(Rejected)
  229. };
  230. static char * DiagnosticsStatusStr[] = {
  231. MACROSTR(Idle),
  232. MACROSTR(Uploaded),
  233. MACROSTR(UploadFailed),
  234. MACROSTR(Uploading)
  235. };
  236. static char * FirmwareStatusStr[] = {
  237. MACROSTR(Downloaded),
  238. MACROSTR(DownloadFailed),
  239. MACROSTR(Downloading),
  240. MACROSTR(Idle),
  241. MACROSTR(InstallationFailed),
  242. MACROSTR(Installing),
  243. MACROSTR(Installed)
  244. };
  245. static char * MessageTriggerStr[] = {
  246. MACROSTR(BootNotification),
  247. MACROSTR(DiagnosticsStatusNotification),
  248. MACROSTR(FirmwareStatusNotification),
  249. MACROSTR(Heartbeat),
  250. MACROSTR(MeterValues),
  251. MACROSTR(StatusNotification)
  252. };
  253. static char * TriggerMessageStatusStr[] = {
  254. MACROSTR(Accepted),
  255. MACROSTR(Rejected),
  256. MACROSTR(NotImplemented)
  257. };
  258. static char * UnlockStatusStr[] = {
  259. MACROSTR(Unlocked),
  260. MACROSTR(UnlockFailed),
  261. MACROSTR(NotSupported)
  262. };
  263. #if 0
  264. static char * StopTransactionReasonStr[] = {
  265. MACROSTR(EmergencyStop),
  266. MACROSTR(EVDisconnected),
  267. MACROSTR(HardReset),
  268. MACROSTR(Local),
  269. MACROSTR(Other),
  270. MACROSTR(PowerLoss),
  271. MACROSTR(Reboot),
  272. MACROSTR(Remote),
  273. MACROSTR(SoftReset),
  274. MACROSTR(UnlockCommand),
  275. MACROSTR(DeAuthorized)
  276. };
  277. #endif
  278. static char * CancelReservationStatusStr[] = {
  279. MACROSTR(Accepted),
  280. MACROSTR(Rejected)
  281. };
  282. static char * ReadingContextStr[] = {
  283. MACROSTR(Interruption.Begin),
  284. MACROSTR(Interruption.End),
  285. MACROSTR(Other),
  286. MACROSTR(Sample.Clock),
  287. MACROSTR(Sample.Periodic),
  288. MACROSTR(Transaction.Begin),
  289. MACROSTR(Transaction.End),
  290. MACROSTR(Trigger)
  291. };
  292. static char * ValueFormatStr[] = {
  293. MACROSTR(Raw),
  294. MACROSTR(SignedData)
  295. };
  296. static char * MeasurandStr[] = {
  297. MACROSTR(Current.Export),
  298. MACROSTR(Current.Import),
  299. MACROSTR(Current.Offered),
  300. MACROSTR(Energy.Active.Export.Register),
  301. MACROSTR(Energy.Active.Import.Register),
  302. MACROSTR(Energy.Reactive.Export.Register),
  303. MACROSTR(Energy.Reactive.Import.Register),
  304. MACROSTR(Energy.Active.Export.Interval),
  305. MACROSTR(Energy.Active.Import.Interval),
  306. MACROSTR(Energy.Reactive.Export.Interval),
  307. MACROSTR(Energy.Reactive.Import.Interval),
  308. MACROSTR(Frequency),
  309. MACROSTR(Power.Active.Export),
  310. MACROSTR(Power.Active.Import),
  311. MACROSTR(Power.Factor),
  312. MACROSTR(Power.Offered),
  313. MACROSTR(Power.Reactive.ExportMACROSTR),
  314. MACROSTR(Power.Reactive.Import),
  315. MACROSTR(RPM),
  316. MACROSTR(SoC),
  317. MACROSTR(Temperature),
  318. MACROSTR(Voltage)
  319. };
  320. static char * LocationStr[] = {
  321. MACROSTR(Body),
  322. MACROSTR(Cable),
  323. MACROSTR(EV),
  324. MACROSTR(Inlet),
  325. MACROSTR(Outlet)
  326. };
  327. static char * PhaseStr[] = {
  328. MACROSTR(L1),
  329. MACROSTR(L2),
  330. MACROSTR(L3),
  331. MACROSTR(N),
  332. MACROSTR(L1-N),
  333. MACROSTR(L2-N),
  334. MACROSTR(L3-N),
  335. MACROSTR(L1-L2),
  336. MACROSTR(L2-L3),
  337. MACROSTR(L3-L1)
  338. };
  339. static char * UnitOfMeasureStr[] = {
  340. MACROSTR(Wh),
  341. MACROSTR(kWh),
  342. MACROSTR(varh),
  343. MACROSTR(kvarh),
  344. MACROSTR(W),
  345. MACROSTR(kW),
  346. MACROSTR(VA),
  347. MACROSTR(kVA),
  348. MACROSTR(var),
  349. MACROSTR(kvar),
  350. MACROSTR(A),
  351. MACROSTR(V),
  352. MACROSTR(Celsius),
  353. MACROSTR(Fahrenheit),
  354. MACROSTR(K),
  355. MACROSTR(Percent)
  356. };
  357. //=========================================
  358. // Save configuration
  359. //=========================================
  360. int runShellCmd(const char*cmd)
  361. {
  362. int result = FAIL;
  363. char buf[256];
  364. FILE *fp;
  365. fp = popen(cmd, "r");
  366. if(fp != NULL)
  367. {
  368. while(fgets(buf, sizeof(buf), fp) != NULL)
  369. {
  370. DEBUG_INFO("%s\n", buf);
  371. }
  372. result = PASS;
  373. }
  374. pclose(fp);
  375. return result;
  376. }
  377. int StoreUsrConfigData(struct SysConfigData *UsrData)
  378. {
  379. int result = PASS;
  380. int fd,wrd;
  381. unsigned int i,Chk;
  382. unsigned char *ptr, *BufTmp;
  383. int MtdBlockSize = 0x300000;
  384. Chk=0;
  385. ptr=(unsigned char *)UsrData;
  386. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  387. {
  388. memset(BufTmp,0,MtdBlockSize);
  389. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  390. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  391. Chk+=*(BufTmp+i);
  392. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  393. // Output configuration to file.
  394. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  395. if (fd < 0)
  396. {
  397. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  398. free(BufTmp);
  399. return 0;
  400. }
  401. wrd=write(fd, BufTmp, MtdBlockSize);
  402. close(fd);
  403. if(wrd<MtdBlockSize)
  404. {
  405. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  406. free(BufTmp);
  407. return 0;
  408. }
  409. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  410. DEBUG_INFO("Erase /dev/mtd10.\n");
  411. runShellCmd("flash_erase /dev/mtd10 0 0");
  412. DEBUG_INFO("Write /dev/mtd10.\n");
  413. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  414. DEBUG_INFO("Erase /dev/mtd11.\n");
  415. runShellCmd("flash_erase /dev/mtd11 0 0");
  416. DEBUG_INFO("Write /dev/mtd11.\n");
  417. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  418. system("rm -f /mnt/EvseConfig.bin");
  419. DEBUG_INFO("EvseConfig write to flash OK\n");
  420. }
  421. else
  422. {
  423. DEBUG_ERROR("alloc BlockSize NG\r\n");
  424. result = FAIL;
  425. }
  426. if(BufTmp!=NULL)
  427. free(BufTmp);
  428. return result;
  429. }
  430. //=========================================
  431. // Sqlite3 related function
  432. //=========================================
  433. static int selectSqlCount = 0;
  434. static int callback(void *data, int argc, char **argv, char **azColName){
  435. int i;
  436. //printf("%s: ", (const char*)data);
  437. selectSqlCount = argc;
  438. for(i = 0; i<argc; i++){
  439. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  440. }
  441. //printf("\n");
  442. return 0;
  443. }
  444. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  445. //int i;
  446. //printf("%s:\n", (const char*)data);
  447. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  448. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  449. return 0;
  450. }
  451. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  452. //printf("%s:\n", (const char*)data);
  453. //idTag
  454. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  455. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  456. //parentIdTag
  457. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  458. //expir_date
  459. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  460. //status
  461. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  462. //version
  463. if(columenCount > 5)
  464. idTagQuery.listVersionInt = atoi(columnValue[5]);
  465. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  466. return 0;
  467. }
  468. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  469. {
  470. // localversion = argv[5] ? atoi(argv[5]) : 0;
  471. // printf("localversion=%d\n", localversion);
  472. return 0;
  473. }
  474. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  475. {
  476. for (int i = 0; i < n_columns; i++)
  477. {
  478. DEBUG_INFO("%s\t", col_values[i]);
  479. }
  480. DEBUG_INFO("\n");
  481. return 0;
  482. }
  483. int OCPP_cleanLocalCache()
  484. {
  485. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  486. char *errMsg = 0;
  487. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  488. if (SQLITE_OK != rc)
  489. {
  490. DEBUG_INFO("SQL error: %s\n",errMsg);
  491. return FALSE;
  492. }
  493. return TRUE;
  494. }
  495. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  496. {
  497. int isSuccess = TRUE;
  498. int ret = 0;
  499. //const char* data = "Callback function called";
  500. char sql[300];
  501. char zErrMsg[200];
  502. memset(sql, 0, 300);
  503. memset(zErrMsg, 0, 200);
  504. 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);
  505. //* Execute SQL statement */
  506. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  507. if( ret != SQLITE_OK )
  508. {
  509. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  510. isSuccess = FALSE;
  511. }
  512. return isSuccess;
  513. }
  514. void OCPP_getIdTagFromLocalCache(char idTag[])
  515. {
  516. int rc = 0;
  517. char sql[100];
  518. char zErrMsg[100];
  519. memset(sql, 0, 100);
  520. memset(zErrMsg, 0, 100);
  521. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  522. memset(&idTagQuery, 0, sizeof(idTagQuery));
  523. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  524. /* Execute SQL statement */
  525. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  526. if( rc != SQLITE_OK )
  527. {
  528. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  529. }
  530. }
  531. void OCPP_getListVerion()
  532. {
  533. int rc = 0;
  534. // const char* data = "Callback function called";
  535. char sql[100];
  536. char zErrMsg[100];
  537. memset(sql, 0, 100);
  538. memset(zErrMsg, 0, 100);
  539. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  540. /* Execute SQL statement */
  541. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  542. if( rc != SQLITE_OK )
  543. {
  544. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  545. }
  546. }
  547. void OCPP_get_TableAuthlocalAllData(void)
  548. {
  549. int rc = 0;
  550. char sql[100];
  551. char zErrMsg[100];
  552. memset(sql, 0, 100);
  553. memset(zErrMsg, 0, 100);
  554. sprintf(sql,"select * from ocpp_auth_local ");
  555. /* Execute SQL statement */
  556. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  557. if( rc != SQLITE_OK )
  558. {
  559. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  560. }
  561. //return ver;
  562. }
  563. int OCPP_cleanLocalList()
  564. {
  565. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  566. char *errMsg = 0;
  567. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  568. if (SQLITE_OK != rc)
  569. {
  570. DEBUG_INFO("%s\n",errMsg);
  571. return FALSE;
  572. }
  573. return TRUE;
  574. }
  575. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  576. {
  577. int isSuccess = FALSE;
  578. int ret = 0;
  579. //const char* data = "Callback function called";
  580. char sql[300];
  581. char zErrMsg[200];
  582. memset(sql, 0, 300);
  583. memset(zErrMsg, 0, 200);
  584. 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);
  585. //* Execute SQL statement */
  586. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  587. if( ret != SQLITE_OK )
  588. {
  589. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  590. return isSuccess;
  591. }
  592. memset(sql, 0, 300);
  593. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  594. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  595. if( ret != SQLITE_OK )
  596. {
  597. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  598. return isSuccess;
  599. }
  600. isSuccess = TRUE;
  601. return isSuccess;
  602. }
  603. void OCPP_getIdTagFromLocalList(char idTag[])
  604. {
  605. int rc = 0;
  606. // const char* data = "Callback function called";
  607. char sql[100];
  608. char zErrMsg[100];
  609. memset(sql, 0, 100);
  610. memset(zErrMsg, 0, 100);
  611. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  612. memset(&idTagQuery, 0, sizeof(idTagQuery));
  613. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  614. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  615. /* Execute SQL statement */
  616. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  617. if( rc != SQLITE_OK )
  618. {
  619. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  620. }
  621. //return ver;
  622. }
  623. void OCPP_deleteIdTagFromLocalList(char idTag[])
  624. {
  625. //int ver = 0;
  626. //int isSuccess = FALSE;
  627. int rc = 0;
  628. char sql[100];
  629. char zErrMsg[100];
  630. memset(sql, 0, 100);
  631. memset(zErrMsg, 0, 100);
  632. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  633. //* Execute SQL statement */
  634. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  635. if( rc != SQLITE_OK )
  636. {
  637. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  638. }
  639. }
  640. int getCurrentYear()
  641. {
  642. int result = 0;
  643. time_t CurrentTime;
  644. struct tm *tm;
  645. CurrentTime = time(NULL);
  646. tm=localtime(&CurrentTime);
  647. result = (tm->tm_year + 1900);
  648. return result;
  649. }
  650. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  651. {
  652. int result = PASS;
  653. char* errMsg = NULL;
  654. char sqlStr[8192];
  655. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  656. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  657. {
  658. result = FAIL;
  659. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  660. }
  661. 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));
  662. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  663. {
  664. result = FAIL;
  665. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  666. }
  667. return result;
  668. }
  669. //==========================================
  670. // Check time passed since today
  671. //==========================================
  672. long long DiffTimebWithNow(struct timeb ST)
  673. {
  674. //return milli-second
  675. struct timeb ET;
  676. long long StartTime,StopTime;
  677. ftime(&ET);
  678. StartTime=(long long)ST.time;
  679. StopTime=(long long)ET.time;
  680. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  681. }
  682. int getTimePassSinceToday(uint8_t gun_index)
  683. {
  684. int result = -1;
  685. static time_t lastTime[4];
  686. time_t t;
  687. struct tm *tmStartToday;
  688. struct timeb tbStartToday;
  689. t=time(NULL);
  690. if(difftime(t, lastTime[gun_index])>0)
  691. {
  692. tmStartToday=localtime(&t);
  693. tmStartToday->tm_hour = 0;
  694. tmStartToday->tm_min = 0;
  695. tmStartToday->tm_sec = 0;
  696. tbStartToday.time = mktime(tmStartToday);
  697. tbStartToday.millitm = 0;
  698. result = DiffTimebWithNow(tbStartToday)/1000;
  699. lastTime[gun_index] = t;
  700. }
  701. return result;
  702. }
  703. void getNowDatetime(uint8_t *data)
  704. {
  705. time_t t = time(NULL);
  706. struct tm tm = *localtime(&t);
  707. 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);
  708. }
  709. int syncDateTimeRTC(uint8_t *data)
  710. {
  711. struct ParsingResult
  712. {
  713. int result;
  714. int scanedElement;
  715. int year;
  716. int month;
  717. int mday;
  718. int hour;
  719. int min;
  720. int sec;
  721. int tz_hour;
  722. int tz_min;
  723. float minSec;
  724. }result;
  725. struct tm tmOrg;
  726. struct tm *tmTarget;
  727. struct timeb tbTarget;
  728. char buf[128];
  729. memset(&result, 0x00, sizeof(struct ParsingResult));
  730. result.result = PASS;
  731. if(strstr((char*)data, ".") != NULL)
  732. {
  733. // Original data with mini second
  734. if(strstr((char*)data, "Z") != NULL)
  735. {
  736. // Original data with Z
  737. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  738. &result.year,
  739. &result.month,
  740. &result.mday,
  741. &result.hour,
  742. &result.min,
  743. &result.sec,
  744. &result.minSec);
  745. }
  746. else
  747. {
  748. // Original data without Z
  749. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  750. &result.year,
  751. &result.month,
  752. &result.mday,
  753. &result.hour,
  754. &result.min,
  755. &result.sec,
  756. &result.minSec,
  757. &result.tz_hour,
  758. &result.tz_min);
  759. }
  760. }
  761. else
  762. {
  763. // Original data without mini second
  764. if(strstr((char*)data, "Z") != NULL)
  765. {
  766. // Original data with Z
  767. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  768. &result.year,
  769. &result.month,
  770. &result.mday,
  771. &result.hour,
  772. &result.min,
  773. &result.sec);
  774. }
  775. else
  776. {
  777. // Original data without Z
  778. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  779. &result.year,
  780. &result.month,
  781. &result.mday,
  782. &result.hour,
  783. &result.min,
  784. &result.sec,
  785. &result.tz_hour,
  786. &result.tz_min);
  787. }
  788. }
  789. tmOrg.tm_year = result.year - 1900;
  790. tmOrg.tm_mon = result.month - 1;
  791. tmOrg.tm_mday = result.mday;
  792. tmOrg.tm_hour = result.hour;
  793. tmOrg.tm_min = result.min;
  794. tmOrg.tm_sec = result.sec;
  795. tmOrg.tm_gmtoff = 0;
  796. tbTarget.time = mktime(&tmOrg);
  797. tbTarget.timezone = 0;
  798. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  799. tmTarget = gmtime(&tbTarget.time);
  800. 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);
  801. //DEBUG_INFO(" org date time: %s\n", data);
  802. //DEBUG_INFO("parse date time: %s\n", buf);
  803. system(buf);
  804. system("/sbin/hwclock -w --systohc");
  805. if(result.scanedElement < 6)
  806. result.result = FAIL;
  807. return result.result;
  808. }
  809. //==========================================
  810. // GetCompositeSchedule logic related function
  811. //==========================================
  812. int DiffTimebSec(struct timeb ST, struct timeb ET)
  813. {
  814. //return milli-second
  815. unsigned int StartTime,StopTime;
  816. StartTime=(unsigned int)ST.time;
  817. StopTime=(unsigned int)ET.time;
  818. return (StopTime-StartTime);
  819. }
  820. int DiffTimebWithNowSec(struct timeb ST)
  821. {
  822. //return milli-second
  823. struct timeb ET;
  824. unsigned int StartTime,StopTime;
  825. ftime(&ET);
  826. StartTime=(unsigned int)ST.time;
  827. StopTime=(unsigned int)ET.time;
  828. return (StopTime-StartTime);
  829. }
  830. int getStartStop(uint8_t *start, uint8_t *stop)
  831. {
  832. int result = -1;
  833. struct tm tmStart;
  834. struct timeb tbStart;
  835. struct tm tmStop;
  836. struct timeb tbStop;
  837. 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) &&
  838. (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))
  839. {
  840. //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);
  841. //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);
  842. tmStart.tm_year -= 1900;
  843. tmStart.tm_mon -= 1;
  844. tbStart.time = mktime(&tmStart);
  845. tbStart.millitm = 0;
  846. tmStop.tm_year -= 1900;
  847. tmStop.tm_mon -= 1;
  848. tbStop.time = mktime(&tmStop);
  849. tbStop.millitm = 0;
  850. result = DiffTimebSec(tbStart, tbStop);
  851. //DEBUG_INFO("getStartStop(): %d\n", result);
  852. }
  853. else
  854. {
  855. DEBUG_WARN("Start or stop date parsing error.\r\n");
  856. }
  857. return result;
  858. }
  859. int isOvertNow(uint8_t *start)
  860. {
  861. int result = NO;
  862. struct ParsingResult
  863. {
  864. int result;
  865. int scanedElement;
  866. int year;
  867. int month;
  868. int mday;
  869. int hour;
  870. int min;
  871. int sec;
  872. int tz_hour;
  873. int tz_min;
  874. float minSec;
  875. }parsingResult;
  876. struct tm tmStart;
  877. struct timeb tbStart;
  878. if(strstr((char*)start, ".") != NULL)
  879. {
  880. // Original data with mini second
  881. if(strstr((char*)start, "Z") != NULL)
  882. {
  883. // Original data with Z
  884. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  885. &parsingResult.year,
  886. &parsingResult.month,
  887. &parsingResult.mday,
  888. &parsingResult.hour,
  889. &parsingResult.min,
  890. &parsingResult.sec,
  891. &parsingResult.minSec);
  892. }
  893. else
  894. {
  895. // Original data without Z
  896. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  897. &parsingResult.year,
  898. &parsingResult.month,
  899. &parsingResult.mday,
  900. &parsingResult.hour,
  901. &parsingResult.min,
  902. &parsingResult.sec,
  903. &parsingResult.minSec,
  904. &parsingResult.tz_hour,
  905. &parsingResult.tz_min);
  906. }
  907. }
  908. else
  909. {
  910. // Original data without mini second
  911. if(strstr((char*)start, "Z") != NULL)
  912. {
  913. // Original data with Z
  914. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  915. &parsingResult.year,
  916. &parsingResult.month,
  917. &parsingResult.mday,
  918. &parsingResult.hour,
  919. &parsingResult.min,
  920. &parsingResult.sec);
  921. }
  922. else
  923. {
  924. // Original data without Z
  925. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  926. &parsingResult.year,
  927. &parsingResult.month,
  928. &parsingResult.mday,
  929. &parsingResult.hour,
  930. &parsingResult.min,
  931. &parsingResult.sec,
  932. &parsingResult.tz_hour,
  933. &parsingResult.tz_min);
  934. }
  935. }
  936. if(parsingResult.scanedElement >= 6)
  937. {
  938. tmStart.tm_year = parsingResult.year - 1900;
  939. tmStart.tm_mon = parsingResult.month - 1;
  940. tmStart.tm_mday = parsingResult.mday;
  941. tmStart.tm_hour = parsingResult.hour;
  942. tmStart.tm_min = parsingResult.min;
  943. tmStart.tm_sec = parsingResult.sec;
  944. tmStart.tm_gmtoff = 0;
  945. tbStart.time = mktime(&tmStart);
  946. tbStart.timezone = 0;
  947. tbStart.millitm = 0;
  948. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  949. if(DiffTimebWithNowSec(tbStart) <= 0)
  950. result = NO;
  951. else
  952. result = YES;
  953. }
  954. else
  955. {
  956. DEBUG_WARN("Start date parsing error.\n");
  957. }
  958. return result;
  959. }
  960. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  961. {
  962. int result = -1;
  963. struct tm tmStart;
  964. struct timeb tbStart;
  965. struct tm tmStop;
  966. struct timeb tbStop;
  967. 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) &&
  968. (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))
  969. {
  970. tmStart.tm_year -= 1900;
  971. tmStart.tm_mon -= 1;
  972. tbStart.time = mktime(&tmStart);
  973. tbStart.millitm = 0;
  974. tmStop.tm_year -= 1900;
  975. tmStop.tm_mon -= 1;
  976. tbStop.time = mktime(&tmStop);
  977. tbStop.millitm = 0;
  978. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  979. }
  980. return result;
  981. }
  982. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  983. {
  984. FILE *fp;
  985. char profileFileName[128];
  986. char *line = NULL;
  987. size_t len = 0;
  988. time_t CurrentTime;
  989. struct tm *tmComposite;
  990. struct StructChargingProfile maxProfile;
  991. uint8_t limitMax=0;
  992. int compositePeriodIdx = 0;
  993. CurrentTime = time(NULL);
  994. tmComposite=localtime(&CurrentTime);
  995. 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);
  996. if(isUnitA)
  997. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  998. else
  999. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1000. compositeProfile->ChargingSchedule.Duration = durationReq;
  1001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1002. {
  1003. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1004. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1005. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1006. }
  1007. compositeProfile->ChargingProfileId = 0;
  1008. compositeProfile->StackLevel = 99 ;
  1009. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1010. maxProfile.ChargingProfileId = -1;
  1011. maxProfile.ChargingSchedule.Duration = -1;
  1012. system("rm -f /tmp/*.json");
  1013. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1014. // Search max profile
  1015. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1016. if((access(profileFileName, F_OK))!=-1)
  1017. {
  1018. fp = fopen(profileFileName, "r");
  1019. while(getline(&line, &len, fp) != -1)
  1020. {
  1021. json_object *obj = NULL;
  1022. obj = json_tokener_parse(line);
  1023. if(is_error(obj))
  1024. {
  1025. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1026. }
  1027. else
  1028. {
  1029. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1030. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1031. )
  1032. {
  1033. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1034. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1035. )
  1036. {
  1037. struct tm tmFrom, tmTo;
  1038. struct timeb tbFrom, tbTo;
  1039. 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) &&
  1040. (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))
  1041. {
  1042. tmFrom.tm_year -= 1900;
  1043. tmFrom.tm_mon -= 1;
  1044. tbFrom.time = mktime(&tmFrom);
  1045. tmTo.tm_year -= 1900;
  1046. tmTo.tm_mon -= 1;
  1047. tbTo.time = mktime(&tmTo);
  1048. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1049. {
  1050. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1051. {
  1052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1053. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1054. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1055. }
  1056. maxProfile.ChargingProfileId = -1;
  1057. maxProfile.StackLevel = -1;
  1058. if(maxProfile.ChargingProfileId == -1)
  1059. DEBUG_INFO("MaxProfile found.\n");
  1060. else
  1061. DEBUG_INFO("MaxProfile updated.\n");
  1062. // Required item
  1063. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1064. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1065. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1066. if(isUnitA)
  1067. {
  1068. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1069. 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++)
  1070. {
  1071. 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"));
  1072. 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?
  1073. 3:
  1074. 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")));
  1075. 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")));
  1076. }
  1077. }
  1078. else
  1079. {
  1080. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1081. 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++)
  1082. {
  1083. 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"));
  1084. 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?
  1085. 3:
  1086. 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")));
  1087. 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));
  1088. }
  1089. }
  1090. // Optional item
  1091. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1092. {
  1093. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1094. }
  1095. else
  1096. {
  1097. sprintf((char*)maxProfile.ValidFrom, " ");
  1098. }
  1099. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1100. {
  1101. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1102. }
  1103. else
  1104. {
  1105. sprintf((char*)maxProfile.ValidTo, " ");
  1106. }
  1107. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1108. {
  1109. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1110. }
  1111. else
  1112. {
  1113. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1114. }
  1115. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1116. {
  1117. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1118. }
  1119. else
  1120. {
  1121. maxProfile.TransactionId = -1;
  1122. }
  1123. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1124. {
  1125. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1126. }
  1127. else
  1128. {
  1129. maxProfile.ChargingSchedule.Duration = 86400;
  1130. }
  1131. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1132. {
  1133. 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")));
  1134. }
  1135. else
  1136. {
  1137. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1138. }
  1139. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1140. {
  1141. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1142. }
  1143. else
  1144. {
  1145. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1146. }
  1147. }
  1148. }
  1149. }
  1150. else
  1151. {
  1152. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1153. {
  1154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1155. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1156. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1157. }
  1158. maxProfile.ChargingProfileId = -1;
  1159. maxProfile.StackLevel = -1;
  1160. if(maxProfile.ChargingProfileId == -1)
  1161. DEBUG_INFO("MaxProfile found.\n");
  1162. else
  1163. DEBUG_INFO("MaxProfile updated.\n");
  1164. // Required item
  1165. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1166. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1167. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1168. if(isUnitA)
  1169. {
  1170. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1171. 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++)
  1172. {
  1173. 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"));
  1174. 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?
  1175. 3:
  1176. 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")));
  1177. 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")));
  1178. }
  1179. }
  1180. else
  1181. {
  1182. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1183. 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++)
  1184. {
  1185. 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"));
  1186. 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?
  1187. 3:
  1188. 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")));
  1189. 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));
  1190. }
  1191. }
  1192. // Optional item
  1193. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1194. {
  1195. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1196. }
  1197. else
  1198. {
  1199. sprintf((char*)maxProfile.ValidFrom, " ");
  1200. }
  1201. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1202. {
  1203. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1204. }
  1205. else
  1206. {
  1207. sprintf((char*)maxProfile.ValidTo, " ");
  1208. }
  1209. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1210. {
  1211. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1212. }
  1213. else
  1214. {
  1215. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1216. }
  1217. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1218. {
  1219. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1220. }
  1221. else
  1222. {
  1223. maxProfile.TransactionId = -1;
  1224. }
  1225. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1226. {
  1227. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1228. }
  1229. else
  1230. {
  1231. maxProfile.ChargingSchedule.Duration = 86400;
  1232. }
  1233. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1234. {
  1235. 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")));
  1236. }
  1237. else
  1238. {
  1239. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1240. }
  1241. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1242. {
  1243. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1244. }
  1245. else
  1246. {
  1247. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1248. }
  1249. }
  1250. }
  1251. }
  1252. json_object_put(obj);
  1253. }
  1254. fclose(fp);
  1255. /*
  1256. if(maxProfile.ChargingProfileId !=-1)
  1257. {
  1258. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1259. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1260. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1261. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1262. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1263. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1264. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1265. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1266. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1267. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1268. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1269. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1270. {
  1271. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1272. {
  1273. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1274. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1275. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1276. }
  1277. }
  1278. }
  1279. else
  1280. DEBUG_INFO("MaxProfile not found.\n");
  1281. DEBUG_INFO("------------------------------------\n");*/
  1282. }
  1283. if(maxProfile.ChargingProfileId != -1)
  1284. {
  1285. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1286. {
  1287. if(maxProfile.ChargingSchedule.Duration != -1)
  1288. {
  1289. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1290. 0:
  1291. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1292. }
  1293. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1294. {
  1295. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1296. {
  1297. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1298. 0:
  1299. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1300. if(idxPeriod > 0)
  1301. {
  1302. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1303. {
  1304. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1311. {
  1312. if(maxProfile.ChargingSchedule.Duration != -1)
  1313. {
  1314. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1315. }
  1316. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1317. {
  1318. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1319. {
  1320. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1321. if(idxPeriod > 0)
  1322. {
  1323. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1324. {
  1325. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1326. }
  1327. }
  1328. }
  1329. }
  1330. }
  1331. else
  1332. {
  1333. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1334. {
  1335. if(maxProfile.ChargingSchedule.Duration != -1)
  1336. {
  1337. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1338. 0:
  1339. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1340. }
  1341. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1342. {
  1343. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1344. {
  1345. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1346. 0:
  1347. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1348. if(idxPeriod > 0)
  1349. {
  1350. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1351. {
  1352. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1353. }
  1354. }
  1355. }
  1356. }
  1357. }
  1358. else
  1359. {
  1360. if(maxProfile.ChargingSchedule.Duration != -1)
  1361. {
  1362. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1363. 0:
  1364. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1365. }
  1366. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1367. {
  1368. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1369. {
  1370. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1371. 0:
  1372. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1373. if(idxPeriod > 0)
  1374. {
  1375. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1376. {
  1377. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1378. }
  1379. }
  1380. }
  1381. }
  1382. }
  1383. }
  1384. /*
  1385. DEBUG_INFO("MaxProfile after align.\n");
  1386. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1387. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1388. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1389. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1390. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1391. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1392. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1393. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1394. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1395. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1396. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1397. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1398. {
  1399. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1400. {
  1401. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1402. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1403. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1404. }
  1405. }
  1406. DEBUG_INFO("------------------------------------\n");*/
  1407. }
  1408. // Find each profile period quantity
  1409. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1410. {
  1411. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1412. limitMax = idx+1;
  1413. }
  1414. if(maxProfile.ChargingProfileId != -1)
  1415. {
  1416. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1417. {
  1418. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1419. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1420. (maxProfile.ChargingSchedule.Duration > 0))
  1421. {
  1422. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1423. {
  1424. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1425. compositePeriodIdx++;
  1426. }
  1427. else
  1428. {
  1429. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1430. }
  1431. }
  1432. }
  1433. }
  1434. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1435. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1436. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1437. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1438. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1439. {
  1440. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1441. {
  1442. compositeProfile->ChargingProfileId = 1;
  1443. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1444. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1445. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1446. }
  1447. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1448. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1449. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1450. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1451. }
  1452. if(line)
  1453. free(line);
  1454. }
  1455. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1456. {
  1457. FILE *fp;
  1458. char profileFileName[128];
  1459. char *line = NULL;
  1460. size_t len = 0;
  1461. time_t CurrentTime;
  1462. struct tm *tmComposite;
  1463. struct StructChargingProfile maxProfile;
  1464. struct StructChargingProfile defaultTxProfile;
  1465. struct StructChargingProfile txProfile;
  1466. struct StructChargingSchedulePeriod tmpPeriod;
  1467. uint8_t limitMax=0;
  1468. uint8_t limitDef=0;
  1469. uint8_t limitTx=0;
  1470. int compositePeriodIdx = 0;
  1471. CurrentTime = time(NULL);
  1472. tmComposite=localtime(&CurrentTime);
  1473. 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);
  1474. if(isUnitA)
  1475. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1476. else
  1477. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1478. compositeProfile->ChargingSchedule.Duration = durationReq;
  1479. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1480. {
  1481. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1482. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1483. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1484. }
  1485. compositeProfile->ChargingProfileId = 0;
  1486. compositeProfile->StackLevel = 99 ;
  1487. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1488. maxProfile.ChargingProfileId = -1;
  1489. defaultTxProfile.ChargingProfileId = -1;
  1490. txProfile.ChargingProfileId = -1;
  1491. maxProfile.ChargingSchedule.Duration = -1;
  1492. defaultTxProfile.ChargingSchedule.Duration = -1;
  1493. txProfile.ChargingSchedule.Duration = -1;
  1494. system("rm -f /tmp/*.json");
  1495. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1496. /*
  1497. * Search valid charging profile
  1498. */
  1499. //DEBUG_INFO("====================================\n");
  1500. // Search tx profile
  1501. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1502. if((access(profileFileName, F_OK))!=-1)
  1503. {
  1504. fp = fopen(profileFileName, "r");
  1505. while(getline(&line, &len, fp) != -1)
  1506. {
  1507. json_object *obj = NULL;
  1508. obj = json_tokener_parse(line);
  1509. if(is_error(obj))
  1510. {
  1511. DEBUG_ERROR("Parse txProfile from file error.\n");
  1512. }
  1513. else
  1514. {
  1515. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1516. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1517. )
  1518. {
  1519. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1520. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1521. )
  1522. {
  1523. struct tm tmFrom, tmTo;
  1524. struct timeb tbFrom, tbTo;
  1525. 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) &&
  1526. (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))
  1527. {
  1528. tmFrom.tm_year -= 1900;
  1529. tmFrom.tm_mon -= 1;
  1530. tbFrom.time = mktime(&tmFrom);
  1531. tmTo.tm_year -= 1900;
  1532. tmTo.tm_mon -= 1;
  1533. tbTo.time = mktime(&tmTo);
  1534. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1535. {
  1536. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1537. {
  1538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1539. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1540. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1541. }
  1542. txProfile.ChargingProfileId = -1;
  1543. txProfile.StackLevel = -1;
  1544. if(txProfile.ChargingProfileId == -1)
  1545. DEBUG_INFO("TxProfile found.\n");
  1546. else
  1547. DEBUG_INFO("TxProfile updated.\n");
  1548. // Required item
  1549. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1550. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1551. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1552. if(isUnitA)
  1553. {
  1554. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1555. 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++)
  1556. {
  1557. 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"));
  1558. 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?
  1559. 3:
  1560. 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")));
  1561. 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")));
  1562. }
  1563. }
  1564. else
  1565. {
  1566. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1567. 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++)
  1568. {
  1569. 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"));
  1570. 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?
  1571. 3:
  1572. 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")));
  1573. 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));
  1574. }
  1575. }
  1576. // Optional item
  1577. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1578. {
  1579. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1580. }
  1581. else
  1582. {
  1583. sprintf((char*)txProfile.ValidFrom, " ");
  1584. }
  1585. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1586. {
  1587. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1588. }
  1589. else
  1590. {
  1591. sprintf((char*)txProfile.ValidTo, " ");
  1592. }
  1593. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1594. {
  1595. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1596. }
  1597. else
  1598. {
  1599. sprintf((char*)txProfile.RecurrencyKind, " ");
  1600. }
  1601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1602. {
  1603. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1604. }
  1605. else
  1606. {
  1607. txProfile.TransactionId = -1;
  1608. }
  1609. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1610. {
  1611. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1612. }
  1613. else
  1614. {
  1615. txProfile.ChargingSchedule.Duration = 86400;
  1616. }
  1617. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1618. {
  1619. 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")));
  1620. }
  1621. else
  1622. {
  1623. 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));
  1624. }
  1625. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1626. {
  1627. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1628. }
  1629. else
  1630. {
  1631. txProfile.ChargingSchedule.MinChargingRate = -1;
  1632. }
  1633. }
  1634. }
  1635. }
  1636. else
  1637. {
  1638. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1639. {
  1640. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1641. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1642. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1643. }
  1644. txProfile.ChargingProfileId = -1;
  1645. txProfile.StackLevel = -1;
  1646. if(txProfile.ChargingProfileId == -1)
  1647. DEBUG_INFO("TxProfile found.\n");
  1648. else
  1649. DEBUG_INFO("TxProfile updated.\n");
  1650. // Required item
  1651. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1652. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1653. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1654. if(isUnitA)
  1655. {
  1656. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1657. 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++)
  1658. {
  1659. 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"));
  1660. 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?
  1661. 3:
  1662. 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")));
  1663. 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")));
  1664. }
  1665. }
  1666. else
  1667. {
  1668. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1669. 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++)
  1670. {
  1671. 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"));
  1672. 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?
  1673. 3:
  1674. 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")));
  1675. 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));
  1676. }
  1677. }
  1678. // Optional item
  1679. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1680. {
  1681. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1682. }
  1683. else
  1684. {
  1685. sprintf((char*)txProfile.ValidFrom, " ");
  1686. }
  1687. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1688. {
  1689. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1690. }
  1691. else
  1692. {
  1693. sprintf((char*)txProfile.ValidTo, " ");
  1694. }
  1695. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1696. {
  1697. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1698. }
  1699. else
  1700. {
  1701. sprintf((char*)txProfile.RecurrencyKind, " ");
  1702. }
  1703. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1704. {
  1705. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1706. }
  1707. else
  1708. {
  1709. txProfile.TransactionId = -1;
  1710. }
  1711. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1712. {
  1713. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1714. }
  1715. else
  1716. {
  1717. txProfile.ChargingSchedule.Duration = 86400;
  1718. }
  1719. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1720. {
  1721. 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")));
  1722. }
  1723. else
  1724. {
  1725. 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));
  1726. }
  1727. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1728. {
  1729. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1730. }
  1731. else
  1732. {
  1733. txProfile.ChargingSchedule.MinChargingRate = -1;
  1734. }
  1735. }
  1736. }
  1737. }
  1738. json_object_put(obj);
  1739. }
  1740. fclose(fp);
  1741. /*
  1742. if(txProfile.ChargingProfileId != -1)
  1743. {
  1744. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1745. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1746. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1747. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1748. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1749. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1750. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1751. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1752. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1753. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1754. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1755. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1756. {
  1757. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1758. {
  1759. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1760. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1761. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1762. }
  1763. }
  1764. }
  1765. else
  1766. DEBUG_INFO("TxProfile not found.\n");*/
  1767. }
  1768. // Search default tx profile
  1769. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1770. if((access(profileFileName, F_OK))==-1)
  1771. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1772. if((access(profileFileName, F_OK))!=-1)
  1773. {
  1774. fp = fopen(profileFileName, "r");
  1775. while(getline(&line, &len, fp) != -1)
  1776. {
  1777. json_object *obj = NULL;
  1778. obj = json_tokener_parse(line);
  1779. if(is_error(obj))
  1780. {
  1781. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1782. }
  1783. else
  1784. {
  1785. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1786. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1787. )
  1788. {
  1789. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1790. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1791. )
  1792. {
  1793. struct tm tmFrom, tmTo;
  1794. struct timeb tbFrom, tbTo;
  1795. 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) &&
  1796. (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))
  1797. {
  1798. tmFrom.tm_year -= 1900;
  1799. tmFrom.tm_mon -= 1;
  1800. tbFrom.time = mktime(&tmFrom);
  1801. tmTo.tm_year -= 1900;
  1802. tmTo.tm_mon -= 1;
  1803. tbTo.time = mktime(&tmTo);
  1804. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1805. {
  1806. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1807. {
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1809. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1810. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1811. }
  1812. defaultTxProfile.ChargingProfileId = -1;
  1813. defaultTxProfile.StackLevel = -1;
  1814. if(defaultTxProfile.ChargingProfileId == -1)
  1815. DEBUG_INFO("TxDefaultProfile found.\n");
  1816. else
  1817. DEBUG_INFO("TxDefaultProfile updated.\n");
  1818. // Required item
  1819. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1820. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1821. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1822. if(isUnitA)
  1823. {
  1824. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1825. 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++)
  1826. {
  1827. 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"));
  1828. 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?
  1829. 3:
  1830. 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")));
  1831. 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")));
  1832. }
  1833. }
  1834. else
  1835. {
  1836. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1837. 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++)
  1838. {
  1839. 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"));
  1840. 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?
  1841. 3:
  1842. 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")));
  1843. 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));
  1844. }
  1845. }
  1846. // Optional item
  1847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1848. {
  1849. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1850. }
  1851. else
  1852. {
  1853. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1854. }
  1855. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1856. {
  1857. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1858. }
  1859. else
  1860. {
  1861. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1862. }
  1863. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1864. {
  1865. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1866. }
  1867. else
  1868. {
  1869. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1870. }
  1871. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1872. {
  1873. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1874. }
  1875. else
  1876. {
  1877. defaultTxProfile.TransactionId = -1;
  1878. }
  1879. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1880. {
  1881. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1882. }
  1883. else
  1884. {
  1885. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1886. }
  1887. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1888. {
  1889. 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")));
  1890. }
  1891. else
  1892. {
  1893. 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));
  1894. }
  1895. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1896. {
  1897. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1898. }
  1899. else
  1900. {
  1901. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1902. }
  1903. }
  1904. }
  1905. }
  1906. else
  1907. {
  1908. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1909. {
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1912. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1913. }
  1914. defaultTxProfile.ChargingProfileId = -1;
  1915. defaultTxProfile.StackLevel = -1;
  1916. if(defaultTxProfile.ChargingProfileId == -1)
  1917. DEBUG_INFO("TxDefaultProfile found.\n");
  1918. else
  1919. DEBUG_INFO("TxDefaultProfile updated.\n");
  1920. // Required item
  1921. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1922. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1923. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1924. if(isUnitA)
  1925. {
  1926. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1927. 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++)
  1928. {
  1929. 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"));
  1930. 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?
  1931. 3:
  1932. 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")));
  1933. 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")));
  1934. }
  1935. }
  1936. else
  1937. {
  1938. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1939. 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++)
  1940. {
  1941. 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"));
  1942. 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?
  1943. 3:
  1944. 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")));
  1945. 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));
  1946. }
  1947. }
  1948. // Optional item
  1949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1950. {
  1951. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1952. }
  1953. else
  1954. {
  1955. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1956. }
  1957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1958. {
  1959. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1960. }
  1961. else
  1962. {
  1963. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1964. }
  1965. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1966. {
  1967. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1968. }
  1969. else
  1970. {
  1971. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1972. }
  1973. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1974. {
  1975. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1976. }
  1977. else
  1978. {
  1979. defaultTxProfile.TransactionId = -1;
  1980. }
  1981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1982. {
  1983. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1984. }
  1985. else
  1986. {
  1987. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1988. }
  1989. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1990. {
  1991. 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")));
  1992. }
  1993. else
  1994. {
  1995. 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));
  1996. }
  1997. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1998. {
  1999. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2000. }
  2001. else
  2002. {
  2003. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2004. }
  2005. }
  2006. }
  2007. }
  2008. json_object_put(obj);
  2009. }
  2010. fclose(fp);
  2011. /*
  2012. if(defaultTxProfile.ChargingProfileId != -1)
  2013. {
  2014. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2015. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2016. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2017. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2018. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2019. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2020. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2021. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2022. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2023. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2024. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2025. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2026. {
  2027. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2028. {
  2029. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2030. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2031. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2032. }
  2033. }
  2034. }
  2035. else
  2036. DEBUG_INFO("TxDefaultProfile not found.\n");
  2037. DEBUG_INFO("------------------------------------\n");*/
  2038. }
  2039. // Search max profile
  2040. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2041. if((access(profileFileName, F_OK))!=-1)
  2042. {
  2043. fp = fopen(profileFileName, "r");
  2044. while(getline(&line, &len, fp) != -1)
  2045. {
  2046. json_object *obj = NULL;
  2047. obj = json_tokener_parse(line);
  2048. if(is_error(obj))
  2049. {
  2050. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2051. }
  2052. else
  2053. {
  2054. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2055. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2056. )
  2057. {
  2058. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2059. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2060. )
  2061. {
  2062. struct tm tmFrom, tmTo;
  2063. struct timeb tbFrom, tbTo;
  2064. 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) &&
  2065. (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))
  2066. {
  2067. tmFrom.tm_year -= 1900;
  2068. tmFrom.tm_mon -= 1;
  2069. tbFrom.time = mktime(&tmFrom);
  2070. tmTo.tm_year -= 1900;
  2071. tmTo.tm_mon -= 1;
  2072. tbTo.time = mktime(&tmTo);
  2073. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2074. {
  2075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2076. {
  2077. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2078. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2079. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2080. }
  2081. maxProfile.ChargingProfileId = -1;
  2082. maxProfile.StackLevel = -1;
  2083. if(maxProfile.ChargingProfileId == -1)
  2084. DEBUG_INFO("MaxProfile found.\n");
  2085. else
  2086. DEBUG_INFO("MaxProfile updated.\n");
  2087. // Required item
  2088. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2089. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2090. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2091. if(isUnitA)
  2092. {
  2093. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2094. 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++)
  2095. {
  2096. 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"));
  2097. 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?
  2098. 3:
  2099. 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")));
  2100. 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")));
  2101. }
  2102. }
  2103. else
  2104. {
  2105. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2106. 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++)
  2107. {
  2108. 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"));
  2109. 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?
  2110. 3:
  2111. 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")));
  2112. 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));
  2113. }
  2114. }
  2115. // Optional item
  2116. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2117. {
  2118. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2119. }
  2120. else
  2121. {
  2122. sprintf((char*)maxProfile.ValidFrom, " ");
  2123. }
  2124. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2125. {
  2126. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2127. }
  2128. else
  2129. {
  2130. sprintf((char*)maxProfile.ValidTo, " ");
  2131. }
  2132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2133. {
  2134. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2135. }
  2136. else
  2137. {
  2138. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2139. }
  2140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2141. {
  2142. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2143. }
  2144. else
  2145. {
  2146. maxProfile.TransactionId = -1;
  2147. }
  2148. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2149. {
  2150. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2151. }
  2152. else
  2153. {
  2154. maxProfile.ChargingSchedule.Duration = 86400;
  2155. }
  2156. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2157. {
  2158. 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")));
  2159. }
  2160. else
  2161. {
  2162. 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));
  2163. }
  2164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2165. {
  2166. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2167. }
  2168. else
  2169. {
  2170. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2171. }
  2172. }
  2173. }
  2174. }
  2175. else
  2176. {
  2177. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2178. {
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2181. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2182. }
  2183. maxProfile.ChargingProfileId = -1;
  2184. maxProfile.StackLevel = -1;
  2185. if(maxProfile.ChargingProfileId == -1)
  2186. DEBUG_INFO("MaxProfile found.\n");
  2187. else
  2188. DEBUG_INFO("MaxProfile updated.\n");
  2189. // Required item
  2190. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2191. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2192. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2193. if(isUnitA)
  2194. {
  2195. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2196. 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++)
  2197. {
  2198. 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"));
  2199. 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?
  2200. 3:
  2201. 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")));
  2202. 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")));
  2203. }
  2204. }
  2205. else
  2206. {
  2207. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2208. 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++)
  2209. {
  2210. 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"));
  2211. 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?
  2212. 3:
  2213. 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")));
  2214. 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));
  2215. }
  2216. }
  2217. // Optional item
  2218. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2219. {
  2220. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2221. }
  2222. else
  2223. {
  2224. sprintf((char*)maxProfile.ValidFrom, " ");
  2225. }
  2226. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2227. {
  2228. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2229. }
  2230. else
  2231. {
  2232. sprintf((char*)maxProfile.ValidTo, " ");
  2233. }
  2234. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2235. {
  2236. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2237. }
  2238. else
  2239. {
  2240. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2241. }
  2242. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2243. {
  2244. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2245. }
  2246. else
  2247. {
  2248. maxProfile.TransactionId = -1;
  2249. }
  2250. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2251. {
  2252. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2253. }
  2254. else
  2255. {
  2256. maxProfile.ChargingSchedule.Duration = 86400;
  2257. }
  2258. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2259. {
  2260. 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")));
  2261. }
  2262. else
  2263. {
  2264. 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));
  2265. }
  2266. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2267. {
  2268. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2269. }
  2270. else
  2271. {
  2272. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2273. }
  2274. }
  2275. }
  2276. }
  2277. json_object_put(obj);
  2278. }
  2279. fclose(fp);
  2280. /*
  2281. if(maxProfile.ChargingProfileId !=-1)
  2282. {
  2283. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2284. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2285. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2286. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2287. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2288. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2289. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2290. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2291. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2292. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2293. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2295. {
  2296. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2297. {
  2298. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2299. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2300. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2301. }
  2302. }
  2303. }
  2304. else
  2305. DEBUG_INFO("MaxProfile not found.\n");
  2306. DEBUG_INFO("------------------------------------\n");*/
  2307. }
  2308. /*
  2309. * Align found profile start schedule & periods
  2310. */
  2311. //DEBUG_INFO("====================================\n");
  2312. /*
  2313. // For local test usage, force modify found profile start schedule info
  2314. 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);
  2315. 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);
  2316. 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);
  2317. */
  2318. if(txProfile.ChargingProfileId != -1)
  2319. {
  2320. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2321. {
  2322. if(txProfile.ChargingSchedule.Duration != -1)
  2323. {
  2324. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2325. 0:
  2326. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2327. }
  2328. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2329. {
  2330. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2331. {
  2332. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2333. 0:
  2334. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2335. if(idxPeriod > 0)
  2336. {
  2337. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2338. {
  2339. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2346. {
  2347. if(txProfile.ChargingSchedule.Duration != -1)
  2348. {
  2349. 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?
  2350. 0:
  2351. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2352. }
  2353. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2354. {
  2355. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2356. {
  2357. 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?
  2358. 0:
  2359. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2360. if(idxPeriod > 0)
  2361. {
  2362. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2363. {
  2364. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2365. }
  2366. }
  2367. }
  2368. }
  2369. }
  2370. else
  2371. {
  2372. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2373. {
  2374. if(txProfile.ChargingSchedule.Duration != -1)
  2375. {
  2376. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2377. 0:
  2378. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2379. }
  2380. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2381. {
  2382. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2383. {
  2384. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2385. 0:
  2386. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2387. if(idxPeriod > 0)
  2388. {
  2389. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2390. {
  2391. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2392. }
  2393. }
  2394. }
  2395. }
  2396. }
  2397. else
  2398. {
  2399. if(txProfile.ChargingSchedule.Duration != -1)
  2400. {
  2401. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2402. 0:
  2403. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2404. }
  2405. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2406. {
  2407. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2408. {
  2409. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2410. 0:
  2411. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2412. if(idxPeriod > 0)
  2413. {
  2414. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2415. {
  2416. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2417. }
  2418. }
  2419. }
  2420. }
  2421. }
  2422. }
  2423. /*
  2424. DEBUG_INFO("txProfile after align.\n");
  2425. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2426. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2427. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2428. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2429. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2430. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2431. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2432. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2433. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2434. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2435. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2436. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2437. {
  2438. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2439. {
  2440. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2441. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2442. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2443. }
  2444. }*/
  2445. }
  2446. if(defaultTxProfile.ChargingProfileId != -1)
  2447. {
  2448. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2449. {
  2450. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2451. {
  2452. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2453. 0:
  2454. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2455. }
  2456. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2457. {
  2458. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2459. {
  2460. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2461. 0:
  2462. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2463. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2464. {
  2465. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2466. }
  2467. if(idxPeriod > 0)
  2468. {
  2469. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2470. {
  2471. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2472. }
  2473. }
  2474. }
  2475. }
  2476. }
  2477. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2478. {
  2479. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2480. {
  2481. 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?
  2482. 0:
  2483. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2484. }
  2485. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2486. {
  2487. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2488. {
  2489. 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?
  2490. 0:
  2491. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2492. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2493. {
  2494. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2495. }
  2496. if(idxPeriod > 0)
  2497. {
  2498. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2499. {
  2500. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2501. }
  2502. }
  2503. }
  2504. }
  2505. }
  2506. else
  2507. {
  2508. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2509. {
  2510. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2511. {
  2512. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2513. 0:
  2514. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2515. }
  2516. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2517. {
  2518. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2519. {
  2520. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2521. 0:
  2522. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2523. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2524. {
  2525. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2526. }
  2527. if(idxPeriod > 0)
  2528. {
  2529. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2530. {
  2531. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2532. }
  2533. }
  2534. }
  2535. }
  2536. }
  2537. else
  2538. {
  2539. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2540. {
  2541. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2542. 0:
  2543. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2544. }
  2545. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2546. {
  2547. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2548. {
  2549. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2550. 0:
  2551. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2552. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2553. {
  2554. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2555. }
  2556. if(idxPeriod > 0)
  2557. {
  2558. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2559. {
  2560. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2561. }
  2562. }
  2563. }
  2564. }
  2565. }
  2566. }
  2567. /*
  2568. DEBUG_INFO("defaultTxProfile after align.\n");
  2569. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2570. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2571. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2572. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2573. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2574. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2575. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2576. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2577. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2578. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2579. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2580. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2581. {
  2582. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2583. {
  2584. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2585. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2586. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2587. }
  2588. }
  2589. DEBUG_INFO("------------------------------------\n");*/
  2590. }
  2591. if(maxProfile.ChargingProfileId != -1)
  2592. {
  2593. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2594. {
  2595. if(maxProfile.ChargingSchedule.Duration != -1)
  2596. {
  2597. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2598. 0:
  2599. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2600. }
  2601. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2602. {
  2603. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2604. {
  2605. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2606. 0:
  2607. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2608. if(idxPeriod > 0)
  2609. {
  2610. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2611. {
  2612. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2619. {
  2620. if(maxProfile.ChargingSchedule.Duration != -1)
  2621. {
  2622. 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?
  2623. 0:
  2624. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2625. }
  2626. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2627. {
  2628. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2629. {
  2630. 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?
  2631. 0:
  2632. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2633. if(idxPeriod > 0)
  2634. {
  2635. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2636. {
  2637. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2638. }
  2639. }
  2640. }
  2641. }
  2642. }
  2643. else
  2644. {
  2645. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2646. {
  2647. if(maxProfile.ChargingSchedule.Duration != -1)
  2648. {
  2649. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2650. 0:
  2651. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2652. }
  2653. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2654. {
  2655. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2656. {
  2657. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2658. 0:
  2659. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2660. if(idxPeriod > 0)
  2661. {
  2662. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2663. {
  2664. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2665. }
  2666. }
  2667. }
  2668. }
  2669. }
  2670. else
  2671. {
  2672. if(maxProfile.ChargingSchedule.Duration != -1)
  2673. {
  2674. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2675. 0:
  2676. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2677. }
  2678. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2679. {
  2680. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2681. {
  2682. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2683. 0:
  2684. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2685. if(idxPeriod > 0)
  2686. {
  2687. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2688. {
  2689. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2690. }
  2691. }
  2692. }
  2693. }
  2694. }
  2695. }
  2696. /*
  2697. DEBUG_INFO("MaxProfile after align.\n");
  2698. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2699. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2700. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2701. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2702. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2703. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2704. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2705. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2706. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2707. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2708. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2709. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2710. {
  2711. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2712. {
  2713. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2714. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2715. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2716. }
  2717. }
  2718. DEBUG_INFO("------------------------------------\n");*/
  2719. }
  2720. /*
  2721. * Merge to conposite schedule
  2722. */
  2723. //DEBUG_INFO("====================================\n");
  2724. // Find each profile period quantity
  2725. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2726. {
  2727. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2728. limitMax = idx+1;
  2729. }
  2730. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2731. {
  2732. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2733. limitDef = idx+1;
  2734. }
  2735. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2736. {
  2737. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2738. limitTx = idx+1;
  2739. }
  2740. // TxProfile found, composite schedule based on it
  2741. if(txProfile.ChargingProfileId != -1)
  2742. {
  2743. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2744. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2745. {
  2746. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2747. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2748. (txProfile.ChargingSchedule.Duration > 0))
  2749. {
  2750. if(maxProfile.ChargingProfileId != -1)
  2751. {
  2752. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2753. {
  2754. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2755. {
  2756. if((maxProfile.ChargingSchedule.Duration > 0))
  2757. {
  2758. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2759. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2760. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2761. }
  2762. else
  2763. {
  2764. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2765. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2766. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2767. }
  2768. }
  2769. if(idxMaxPeriod == (limitMax-1))
  2770. {
  2771. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2772. {
  2773. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2774. {
  2775. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2776. compositePeriodIdx++;
  2777. }
  2778. else
  2779. {
  2780. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2781. }
  2782. }
  2783. }
  2784. }
  2785. }
  2786. else
  2787. {
  2788. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2789. {
  2790. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2791. compositePeriodIdx++;
  2792. }
  2793. else
  2794. {
  2795. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2796. }
  2797. }
  2798. }
  2799. if(idxTxPeriod == (limitTx-1))
  2800. {
  2801. if(defaultTxProfile.ChargingProfileId != -1)
  2802. {
  2803. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2804. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2805. {
  2806. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2807. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2808. (defaultTxProfile.ChargingSchedule.Duration>0))
  2809. {
  2810. if(maxProfile.ChargingProfileId != -1)
  2811. {
  2812. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2813. {
  2814. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2815. {
  2816. if((maxProfile.ChargingSchedule.Duration > 0))
  2817. {
  2818. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2819. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2820. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2821. }
  2822. else
  2823. {
  2824. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2825. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2826. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2827. }
  2828. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2829. {
  2830. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2831. {
  2832. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2833. compositePeriodIdx++;
  2834. }
  2835. else
  2836. {
  2837. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2838. }
  2839. }
  2840. // Delete duplicate period
  2841. if(compositePeriodIdx > 1)
  2842. {
  2843. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2844. {
  2845. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2846. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2847. compositePeriodIdx -= 1;
  2848. }
  2849. }
  2850. }
  2851. else
  2852. {
  2853. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2854. {
  2855. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2856. compositePeriodIdx++;
  2857. }
  2858. else
  2859. {
  2860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2861. }
  2862. break;
  2863. }
  2864. }
  2865. }
  2866. else
  2867. {
  2868. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2869. {
  2870. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2871. compositePeriodIdx++;
  2872. }
  2873. else
  2874. {
  2875. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. }
  2883. }
  2884. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2885. else if(defaultTxProfile.ChargingProfileId != -1)
  2886. {
  2887. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2888. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2889. {
  2890. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2891. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2892. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2893. {
  2894. if(maxProfile.ChargingProfileId != -1)
  2895. {
  2896. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2897. {
  2898. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2899. {
  2900. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2901. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2902. if((maxProfile.ChargingSchedule.Duration > 0))
  2903. {
  2904. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2905. }
  2906. else
  2907. {
  2908. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2909. }
  2910. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2911. {
  2912. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2913. {
  2914. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2915. compositePeriodIdx++;
  2916. }
  2917. else
  2918. {
  2919. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2920. }
  2921. }
  2922. // Delete duplicate period
  2923. if(compositePeriodIdx > 1)
  2924. {
  2925. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2926. {
  2927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2929. compositePeriodIdx -= 1;
  2930. }
  2931. }
  2932. }
  2933. else
  2934. {
  2935. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2936. {
  2937. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2938. compositePeriodIdx++;
  2939. }
  2940. else
  2941. {
  2942. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2943. }
  2944. break;
  2945. }
  2946. }
  2947. }
  2948. else
  2949. {
  2950. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2951. {
  2952. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2953. compositePeriodIdx++;
  2954. }
  2955. else
  2956. {
  2957. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2958. }
  2959. }
  2960. }
  2961. }
  2962. }
  2963. // Fill other period by MaxProfile
  2964. if(maxProfile.ChargingProfileId != -1)
  2965. {
  2966. if(compositePeriodIdx==0)
  2967. {
  2968. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2969. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2970. {
  2971. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2972. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2973. (maxProfile.ChargingSchedule.Duration > 0))
  2974. {
  2975. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2976. {
  2977. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2978. compositePeriodIdx++;
  2979. }
  2980. else
  2981. {
  2982. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2983. }
  2984. }
  2985. }
  2986. }
  2987. else
  2988. {
  2989. int lastCompositePeriodIdx = compositePeriodIdx;
  2990. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2991. {
  2992. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2993. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2994. (maxProfile.ChargingSchedule.Duration > 0))
  2995. {
  2996. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  2997. {
  2998. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  2999. {
  3000. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3001. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3002. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3003. }
  3004. else
  3005. {
  3006. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3007. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3008. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3009. }
  3010. }
  3011. if(tmpPeriod.Limit != -1)
  3012. {
  3013. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3014. {
  3015. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3016. {
  3017. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3018. compositePeriodIdx++;
  3019. }
  3020. else
  3021. {
  3022. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3023. }
  3024. }
  3025. // Delete duplicate period
  3026. if(compositePeriodIdx > 1)
  3027. {
  3028. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3029. {
  3030. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3031. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3032. compositePeriodIdx -= 1;
  3033. }
  3034. }
  3035. }
  3036. }
  3037. }
  3038. }
  3039. }
  3040. compositeProfile->ChargingSchedule.Duration = durationReq;
  3041. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3042. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3043. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3044. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3045. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3046. {
  3047. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3048. {
  3049. compositeProfile->ChargingProfileId = 1;
  3050. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3051. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3052. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3053. }
  3054. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3055. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3056. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3057. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3058. }
  3059. if(line)
  3060. free(line);
  3061. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3062. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3063. }
  3064. //==========================================
  3065. // Init all share memory
  3066. //==========================================
  3067. int InitShareMemory()
  3068. {
  3069. int result = PASS;
  3070. int MeterSMId;
  3071. //creat ShmSysConfigAndInfo
  3072. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3073. {
  3074. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3075. result = FAIL;
  3076. }
  3077. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3078. {
  3079. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3080. result = FAIL;
  3081. }
  3082. else
  3083. {}
  3084. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3085. {
  3086. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3087. result = FAIL;
  3088. }
  3089. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3090. {
  3091. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3092. result = FAIL;
  3093. }
  3094. else
  3095. {}
  3096. //creat ShmPsuData
  3097. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3098. {
  3099. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3100. result = FAIL;
  3101. }
  3102. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3103. {
  3104. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3105. result = FAIL;
  3106. }
  3107. else
  3108. {}
  3109. //link ShmOCPP16Data
  3110. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3111. {
  3112. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3113. result = FAIL;
  3114. }
  3115. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3116. {
  3117. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3118. result = FAIL;
  3119. }
  3120. else
  3121. {}
  3122. //creat ShmOCPP16DataPH
  3123. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3124. {
  3125. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3126. result = FAIL;
  3127. }
  3128. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3129. {
  3130. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3131. result = FAIL;
  3132. }
  3133. else
  3134. {}
  3135. /****************************** For Initial Settings************************************************/
  3136. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3137. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3138. // allocate Configuration memory address
  3139. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3140. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3141. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3142. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3143. //offline MeterValue Interval
  3144. TempMeterValueInterval = 0;
  3145. return result;
  3146. }
  3147. int ProcessShareMemory()
  3148. {
  3149. int result = PASS;
  3150. if(InitShareMemory() == FAIL)
  3151. {
  3152. DEBUG_ERROR("InitShareMemory NG\n");
  3153. if(ShmStatusCodeData!=NULL)
  3154. {
  3155. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3156. }
  3157. result = FAIL;
  3158. }
  3159. // Model name parsing
  3160. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3161. {
  3162. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3163. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3164. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3165. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3166. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3167. ) // 'D' means DC
  3168. {
  3169. // DO series
  3170. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3171. {
  3172. SystemInitial += 1;
  3173. gunTotalNumber += 1;
  3174. gunType[gun_index] = GUN_TYPE_DO;
  3175. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3176. {
  3177. case Gun_Type_Chademo:
  3178. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3179. break;
  3180. case Gun_Type_CCS_2:
  3181. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3182. break;
  3183. case Gun_Type_GB:
  3184. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3185. break;
  3186. case Gun_Type_AC:
  3187. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3188. break;
  3189. default:
  3190. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3191. break;
  3192. }
  3193. }
  3194. }
  3195. else
  3196. {
  3197. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3198. {
  3199. SystemInitial += 1;
  3200. gunTotalNumber += 1;
  3201. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3202. {
  3203. case Gun_Type_Chademo:
  3204. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3205. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3206. break;
  3207. case Gun_Type_CCS_2:
  3208. gunType[gun_index] = GUN_TYPE_CCS;
  3209. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3210. break;
  3211. case Gun_Type_GB:
  3212. gunType[gun_index] = GUN_TYPE_GBT;
  3213. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3214. break;
  3215. case Gun_Type_AC:
  3216. gunType[gun_index] = GUN_TYPE_AC;
  3217. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3218. break;
  3219. default:
  3220. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3221. break;
  3222. }
  3223. }
  3224. }
  3225. }
  3226. else
  3227. {
  3228. DEBUG_ERROR("Model name parsing fail.\n");
  3229. result = FAIL;
  3230. }
  3231. if(result != PASS)sleep(5);
  3232. return result;
  3233. }
  3234. void checkRemoteStart(uint8_t connectorIdInt)
  3235. {
  3236. uint8_t tempIndex;
  3237. int result = PASS;
  3238. char cmdBuf[512];
  3239. //check Transaction active
  3240. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3241. {
  3242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3243. {
  3244. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3245. }
  3246. else
  3247. {
  3248. tempIndex = connectorIdInt -1;
  3249. }
  3250. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3251. {
  3252. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3253. {
  3254. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3255. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3256. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3257. {
  3258. //Reserved
  3259. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3260. }
  3261. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3262. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3263. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3264. {
  3265. //Reserved
  3266. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3267. result = FAIL;
  3268. goto end;
  3269. }
  3270. else
  3271. {
  3272. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3273. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3274. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3275. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3276. {
  3277. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3278. result = FAIL;
  3279. goto end;
  3280. }
  3281. }//END FOR ELSE
  3282. }
  3283. }// END FOR CHAdeMO_QUANTITY
  3284. }
  3285. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3286. {
  3287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3288. {
  3289. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3290. }
  3291. else
  3292. {
  3293. tempIndex = connectorIdInt -1;
  3294. }
  3295. for (int index = 0; index < CCS_QUANTITY; index++)
  3296. {
  3297. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3298. {
  3299. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3301. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3302. {
  3303. //Reserved
  3304. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3305. }
  3306. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3307. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3308. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3309. {
  3310. //Reserved
  3311. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3312. result = FAIL;
  3313. goto end;
  3314. }
  3315. else
  3316. {
  3317. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3318. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3319. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3320. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3321. {
  3322. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3323. result = FAIL;
  3324. goto end;
  3325. }
  3326. }// END FOR ELSE
  3327. }
  3328. }// END FOR CCS_QUANTITY
  3329. }
  3330. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3331. {
  3332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3333. {
  3334. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3335. }
  3336. else
  3337. {
  3338. tempIndex = connectorIdInt -1;
  3339. }
  3340. for (int index = 0; index < GB_QUANTITY; index++)
  3341. {
  3342. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3343. {
  3344. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3345. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3346. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3347. {
  3348. //Reserved
  3349. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3350. }
  3351. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3352. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3353. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3354. {
  3355. //Reserved
  3356. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3357. result = FAIL;
  3358. goto end;
  3359. }
  3360. else
  3361. {
  3362. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3363. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3364. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3365. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3366. {
  3367. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3368. result = FAIL;
  3369. goto end;
  3370. }
  3371. }// END FOR ELSE
  3372. }
  3373. } // END FOR GB_QUANTITY
  3374. }
  3375. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3376. {
  3377. tempIndex = connectorIdInt -1;
  3378. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3379. {
  3380. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3381. {
  3382. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3383. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3384. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3385. {
  3386. //Reserved
  3387. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3388. }
  3389. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3390. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3391. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3392. {
  3393. //Reserved
  3394. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3395. result = FAIL;
  3396. goto end;
  3397. }
  3398. else
  3399. {
  3400. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3401. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3402. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3403. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3404. {
  3405. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3406. result = FAIL;
  3407. goto end;
  3408. }
  3409. }// END FOR ELSE
  3410. }
  3411. } // END FOR GB_QUANTITY
  3412. }
  3413. else
  3414. {
  3415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3416. {
  3417. tempIndex = 2;
  3418. }
  3419. else
  3420. {
  3421. tempIndex = connectorIdInt -1;
  3422. }
  3423. for (int index = 0; index < AC_QUANTITY; index++)
  3424. {
  3425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3426. {
  3427. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3428. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3429. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3430. {
  3431. //Reserved
  3432. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3433. }
  3434. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3435. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3436. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3437. {
  3438. //Reserved
  3439. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3440. result = FAIL;
  3441. goto end;
  3442. }
  3443. else
  3444. {
  3445. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3446. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3447. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3448. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3449. {
  3450. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3451. result = FAIL;
  3452. goto end;
  3453. }
  3454. }//END FOR ELSE
  3455. }
  3456. }// END FOR AC_QUANTITY
  3457. }
  3458. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3459. {
  3460. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3461. {
  3462. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3463. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3464. {
  3465. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3466. system(cmdBuf);
  3467. }
  3468. }
  3469. else
  3470. {
  3471. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3472. result = FAIL;
  3473. }
  3474. }
  3475. end:
  3476. if(result == PASS)
  3477. {
  3478. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3479. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3480. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3481. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3483. }
  3484. }
  3485. void CheckSystemValue(void)
  3486. {
  3487. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3488. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3489. char filenmae[100]={0};
  3490. char str[100]={0};
  3491. int tempIndex = 0;
  3492. //===============================
  3493. // send Heartbeat
  3494. //===============================
  3495. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3496. {
  3497. //parameter for test
  3498. sendHeartbeatRequest(0);
  3499. //==============================================
  3500. // Reset Waiting Time
  3501. //==============================================
  3502. HeartBeatWithNOResponse += 2;
  3503. }
  3504. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3505. {
  3506. //==========================================
  3507. // Check remote start without connector id
  3508. //==========================================
  3509. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3510. {
  3511. int connectorIdInt = -1;
  3512. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3513. {
  3514. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3515. {
  3516. connectorIdInt = (gun_index+1);
  3517. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3518. checkRemoteStart(connectorIdInt);
  3519. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3520. break;
  3521. }
  3522. }
  3523. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3524. {
  3525. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3526. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3527. }
  3528. }
  3529. //==========================================
  3530. // csu trigger DataTransferReq
  3531. //==========================================
  3532. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3533. {
  3534. sendDataTransferRequest(gun_index);
  3535. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3536. }
  3537. //===============================
  3538. // CSU Trigger Authorize Request
  3539. //===============================
  3540. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3541. {
  3542. sendAuthorizeRequest(0);
  3543. authorizeRetryTimes = authorizeRetryTimes + 1;
  3544. if(authorizeRetryTimes < 3)
  3545. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3546. }
  3547. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3548. {
  3549. authorizeRetryTimes = 0;
  3550. SetOcppConnStatus(FALSE);
  3551. server_sign = FALSE;
  3552. }
  3553. 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))
  3554. {
  3555. sendAuthorizeRequest(0);
  3556. }
  3557. //==============================================
  3558. // Charger start transaction
  3559. //==============================================
  3560. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3561. {
  3562. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3563. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3564. sendStartTransactionRequest(gun_index);
  3565. refreshStartTimer(&clientTime.StartTransaction);
  3566. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3567. storeTempStopTransaction(gun_index);
  3568. }
  3569. //==============================================
  3570. // Charger stop transaction
  3571. //==============================================
  3572. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3573. {
  3574. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3575. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3576. sendStopTransactionRequest(gun_index);
  3577. refreshStartTimer(&clientTime.StopTransaction);
  3578. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3579. }
  3580. //==============================================
  3581. // Charger status report
  3582. //==============================================
  3583. //--- Check Mode Change ---//
  3584. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3585. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3586. {
  3587. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3588. {
  3589. tempIndex = ((gun_index==2) ? 1: 0);
  3590. }
  3591. else
  3592. {
  3593. tempIndex = gun_index;
  3594. }
  3595. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3596. {
  3597. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3598. {
  3599. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3600. {
  3601. // Sent unplug message for California pricing logic
  3602. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3603. {
  3604. uint8_t ts[20];
  3605. getNowDatetime(ts);
  3606. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3607. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3608. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3609. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3610. }
  3611. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3612. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3613. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3614. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3615. {
  3616. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3617. if((access(filenmae,F_OK))!=-1)
  3618. {
  3619. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3620. sprintf(str,"rm -f %s",filenmae);
  3621. system(str);
  3622. }
  3623. }
  3624. }
  3625. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3626. #if 1 // for TempStopTransaction
  3627. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3628. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3629. {
  3630. checkTempStopTransaction(gun_index);
  3631. }
  3632. #endif
  3633. }
  3634. }
  3635. }
  3636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3637. {
  3638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3639. {
  3640. tempIndex = ((gun_index==2) ? 1: 0);
  3641. }
  3642. else
  3643. {
  3644. tempIndex = gun_index;
  3645. }
  3646. for (int index = 0; index < CCS_QUANTITY; index++)
  3647. {
  3648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3649. {
  3650. 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]*/ )
  3651. {
  3652. // Sent unplug message for California pricing logic
  3653. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3654. {
  3655. uint8_t ts[20];
  3656. getNowDatetime(ts);
  3657. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3658. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3659. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3660. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3661. }
  3662. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3663. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3664. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3665. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3666. {
  3667. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3668. if((access(filenmae,F_OK))!=-1)
  3669. {
  3670. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3671. sprintf(str,"rm -f %s",filenmae);
  3672. system(str);
  3673. }
  3674. }
  3675. }
  3676. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3677. #if 1 // for TempStopTransaction
  3678. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3679. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3680. {
  3681. checkTempStopTransaction(gun_index);
  3682. }
  3683. #endif
  3684. }
  3685. }
  3686. }
  3687. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3688. {
  3689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3690. {
  3691. tempIndex = ((gun_index==2) ? 1: 0);
  3692. }
  3693. else
  3694. {
  3695. tempIndex = gun_index;
  3696. }
  3697. for (int index = 0; index < GB_QUANTITY; index++)
  3698. {
  3699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3700. {
  3701. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3702. {
  3703. // Sent unplug message for California pricing logic
  3704. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3705. {
  3706. uint8_t ts[20];
  3707. getNowDatetime(ts);
  3708. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3711. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3712. }
  3713. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3714. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3715. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3716. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3717. {
  3718. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3719. if((access(filenmae,F_OK))!=-1)
  3720. {
  3721. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3722. sprintf(str,"rm -f %s",filenmae);
  3723. system(str);
  3724. }
  3725. }
  3726. }
  3727. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3728. #if 1 // for TempStopTransaction
  3729. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3730. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3731. {
  3732. checkTempStopTransaction(gun_index);
  3733. }
  3734. #endif
  3735. }
  3736. }
  3737. }
  3738. else if(gunType[gun_index] == GUN_TYPE_DO)
  3739. {
  3740. tempIndex = gun_index;
  3741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3742. {
  3743. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3744. {
  3745. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3746. {
  3747. // Sent unplug message for California pricing logic
  3748. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3749. {
  3750. uint8_t ts[20];
  3751. getNowDatetime(ts);
  3752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3754. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3755. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3756. }
  3757. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3758. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3759. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3760. 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
  3761. {
  3762. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3763. if((access(filenmae,F_OK))!=-1)
  3764. {
  3765. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3766. sprintf(str,"rm -f %s",filenmae);
  3767. system(str);
  3768. }
  3769. }
  3770. }
  3771. 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);
  3772. #if 1 // for TempStopTransaction
  3773. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3774. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3775. {
  3776. checkTempStopTransaction(gun_index);
  3777. }
  3778. #endif
  3779. }
  3780. }
  3781. }
  3782. else
  3783. {
  3784. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3785. {
  3786. tempIndex = 2;
  3787. }
  3788. else
  3789. {
  3790. tempIndex = gun_index;
  3791. }
  3792. for (int index = 0; index < AC_QUANTITY; index++)
  3793. {
  3794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3795. {
  3796. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3797. {
  3798. // Sent unplug message for California pricing logic
  3799. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3800. {
  3801. uint8_t ts[20];
  3802. getNowDatetime(ts);
  3803. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3804. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3805. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3806. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3807. }
  3808. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3809. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3810. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3811. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3812. {
  3813. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3814. if((access(filenmae,F_OK))!=-1)
  3815. {
  3816. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3817. sprintf(str,"rm -f %s",filenmae);
  3818. system(str);
  3819. }
  3820. }
  3821. }
  3822. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3823. #if 1 // for TempStopTransaction
  3824. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3825. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3826. {
  3827. checkTempStopTransaction(gun_index);
  3828. }
  3829. #endif
  3830. }
  3831. }// END
  3832. }
  3833. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  3834. (
  3835. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3836. )
  3837. )
  3838. {
  3839. if(SystemInitial > 0)
  3840. SystemInitial -= 1;
  3841. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3842. sendStatusNotificationRequest(gun_index);
  3843. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  3844. }
  3845. //==============================================
  3846. // CSU Trigger Smart Charging Profilw
  3847. //==============================================
  3848. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3849. {
  3850. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3851. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3852. }
  3853. //==============================================
  3854. // Meter report
  3855. //==============================================
  3856. // Trigger MeterValue
  3857. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3858. {
  3859. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3860. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3861. }
  3862. // ClockAlign MeterValue
  3863. 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))
  3864. {
  3865. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3866. {
  3867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3868. {
  3869. tempIndex = ((gun_index==2) ? 1: 0);
  3870. }
  3871. else
  3872. {
  3873. tempIndex = gun_index;
  3874. }
  3875. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3876. {
  3877. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3878. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3879. {
  3880. reqClockAlignMeter[gun_index] = 1;
  3881. }
  3882. }// End for CHAdeMO
  3883. }
  3884. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3885. {
  3886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3887. {
  3888. tempIndex = ((gun_index==2) ? 1: 0);
  3889. }
  3890. else
  3891. {
  3892. tempIndex = gun_index;
  3893. }
  3894. for (int index = 0; index < CCS_QUANTITY; index++)
  3895. {
  3896. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3897. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3898. {
  3899. reqClockAlignMeter[gun_index] = 1;
  3900. }
  3901. } // End for CCS
  3902. }
  3903. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3904. {
  3905. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3906. {
  3907. tempIndex = ((gun_index==2) ? 1: 0);
  3908. }
  3909. else
  3910. {
  3911. tempIndex = gun_index;
  3912. }
  3913. for (int index = 0; index < GB_QUANTITY; index++)
  3914. {
  3915. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3916. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3917. {
  3918. reqClockAlignMeter[gun_index] = 1;
  3919. }
  3920. }// End for GB
  3921. }
  3922. else if(gunType[gun_index] == GUN_TYPE_DO)
  3923. {
  3924. tempIndex = gun_index;
  3925. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3926. {
  3927. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3928. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3929. {
  3930. reqClockAlignMeter[gun_index] = 1;
  3931. }
  3932. }
  3933. }
  3934. else
  3935. {
  3936. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3937. {
  3938. tempIndex = 2;
  3939. }
  3940. else
  3941. {
  3942. tempIndex = gun_index;
  3943. }
  3944. for (int index = 0; index < AC_QUANTITY; index++)
  3945. {
  3946. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3947. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3948. {
  3949. reqClockAlignMeter[gun_index] = 1;
  3950. }
  3951. }//End for AC
  3952. }
  3953. if(reqClockAlignMeter[gun_index] == 1)
  3954. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3955. }
  3956. // Sample period MeterValue
  3957. 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))))
  3958. {
  3959. //check Transaction active
  3960. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3961. {
  3962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3963. {
  3964. tempIndex = ((gun_index==2) ? 1: 0);
  3965. }
  3966. else
  3967. {
  3968. tempIndex = gun_index;
  3969. }
  3970. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3971. {
  3972. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3973. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3974. {
  3975. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3976. {
  3977. reqSampleMeter[gun_index] = 1;
  3978. }
  3979. }
  3980. }// End for CHAdeMO
  3981. }
  3982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3983. {
  3984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3985. {
  3986. tempIndex = ((gun_index==2) ? 1: 0);
  3987. }
  3988. else
  3989. {
  3990. tempIndex = gun_index;
  3991. }
  3992. for (int index = 0; index < CCS_QUANTITY; index++)
  3993. {
  3994. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3995. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3996. {
  3997. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3998. {
  3999. reqSampleMeter[gun_index] = 1;
  4000. }
  4001. }
  4002. } // End for CCS
  4003. }
  4004. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4005. {
  4006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4007. {
  4008. tempIndex = ((gun_index==2) ? 1: 0);
  4009. }
  4010. else
  4011. {
  4012. tempIndex = gun_index;
  4013. }
  4014. for (int index = 0; index < GB_QUANTITY; index++)
  4015. {
  4016. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4017. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4018. {
  4019. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4020. {
  4021. reqSampleMeter[gun_index] = 1;
  4022. }
  4023. }
  4024. }// End for GB
  4025. }
  4026. else if(gunType[gun_index] == GUN_TYPE_DO)
  4027. {
  4028. tempIndex = gun_index;
  4029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4030. {
  4031. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4032. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4033. {
  4034. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4035. {
  4036. reqSampleMeter[gun_index] = 1;
  4037. }
  4038. }
  4039. }
  4040. }
  4041. else
  4042. {
  4043. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4044. {
  4045. tempIndex = 2;
  4046. }
  4047. else
  4048. {
  4049. tempIndex = gun_index;
  4050. }
  4051. for (int index = 0; index < AC_QUANTITY; index++)
  4052. {
  4053. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4054. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4055. {
  4056. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4057. {
  4058. reqSampleMeter[gun_index] = 1;
  4059. }
  4060. }
  4061. }//End for AC
  4062. }
  4063. if(reqSampleMeter[gun_index] == 1)
  4064. {
  4065. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4066. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4067. storeTempStopTransaction(gun_index);
  4068. }
  4069. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4070. }
  4071. //==============================================
  4072. // Check Connector reserved
  4073. //==============================================
  4074. //===============================
  4075. // Check if Reserve is expired
  4076. //===============================
  4077. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4078. {
  4079. double diff_t;
  4080. struct tm tp;
  4081. // current time
  4082. time_t t = time(NULL);
  4083. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4084. tp.tm_isdst = -1;
  4085. time_t utc = mktime(&tp);
  4086. diff_t = difftime(utc, t);
  4087. if(diff_t <= 0)
  4088. {
  4089. DEBUG_INFO("reserve expired.\n");
  4090. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4091. }
  4092. }//END OF Check if Reserve is expired
  4093. //==========================================
  4094. // csu trigger FirmwareStatusNotificationReq
  4095. //==========================================
  4096. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4097. {
  4098. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4099. }
  4100. //==========================================
  4101. // csu trigger DiagnosticsStatusNotificationReq
  4102. //==========================================
  4103. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4104. {
  4105. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4106. }
  4107. //==========================================
  4108. // csu trigger CancelReservationConf
  4109. //==========================================
  4110. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4111. {
  4112. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4113. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4114. }
  4115. //==========================================
  4116. // csu trigger ChangeAvailabilityConf
  4117. //==========================================
  4118. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4119. {
  4120. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4121. }
  4122. //==========================================
  4123. // csu trigger UnlockConnectorConf
  4124. //==========================================
  4125. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4126. {
  4127. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4128. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4129. }
  4130. //==========================================
  4131. // csu trigger ReserveNowConf
  4132. //==========================================
  4133. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4134. {
  4135. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4136. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4137. }
  4138. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4139. {
  4140. sendSignCertificateRequest();
  4141. }
  4142. }
  4143. }
  4144. //==========================================
  4145. // send request routine
  4146. //==========================================
  4147. int sendAuthorizeRequest(int gun_index)
  4148. {
  4149. mtrace();
  4150. int result = FAIL;
  4151. char message[100]={0};
  4152. char guid[37];
  4153. char tempdata[65]={0};
  4154. DEBUG_INFO("sendAuthorizeRequest...\n");
  4155. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4156. //Local Authorize
  4157. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4158. {
  4159. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4160. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4161. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4162. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4163. result = PASS;
  4164. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4165. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4166. authorizeRetryTimes = 0;
  4167. return result;
  4168. }
  4169. 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))||
  4170. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4171. {
  4172. // Query from cache
  4173. DEBUG_INFO("Authorize from cache.\n");
  4174. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4175. // Query from list
  4176. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4177. {
  4178. DEBUG_INFO("Authorize from list.\n");
  4179. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4180. }
  4181. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4182. {
  4183. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4184. {
  4185. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4186. }
  4187. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4188. {
  4189. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4190. }
  4191. if(!GetOcppConnStatus())
  4192. {
  4193. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4194. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4195. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4196. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4197. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4198. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4199. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4200. authorizeRetryTimes = 0;
  4201. return result;
  4202. }
  4203. }
  4204. else
  4205. {
  4206. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4207. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4208. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4209. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4210. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4211. else
  4212. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4213. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4214. result = PASS;
  4215. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4216. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4217. authorizeRetryTimes = 0;
  4218. return result;
  4219. }
  4220. }
  4221. //initialize struct Authorize
  4222. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4223. //get data from shared memory
  4224. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4225. random_uuid(guid);
  4226. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4227. LWS_Send(message);
  4228. sprintf(tempdata, "Authorize,%d", gun_index);
  4229. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4230. {
  4231. result = PASS;
  4232. DEBUG_INFO("Authorize mapItem pass\n");
  4233. }
  4234. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4235. return result;
  4236. }
  4237. int sendBootNotificationRequest(void)
  4238. {
  4239. mtrace();
  4240. int result = FAIL;
  4241. char message[500]={0}, payload[700]={0};
  4242. char guid[37]={0};
  4243. char tempdata[65]={0};
  4244. // Fill BootNotification fields
  4245. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4246. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4247. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4248. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4249. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4250. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4251. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4252. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4253. ShmOCPP16DataPH->ChargeBoxId
  4254. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4255. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4256. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4257. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4258. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4259. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4260. random_uuid(guid);
  4261. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4262. LWS_Send(message);
  4263. sprintf(tempdata, "BootNotification,0");
  4264. 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*/)
  4265. {
  4266. result = PASS;
  4267. }
  4268. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4269. strcpy(queuedata,message);
  4270. return result;
  4271. }
  4272. int sendDataTransferRequest(int gun_index)
  4273. {
  4274. mtrace();
  4275. char message[1000]={0};
  4276. char guid[37]={0};
  4277. char tempdata[65]={0};
  4278. int result = FAIL;
  4279. random_uuid(guid);
  4280. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4281. MESSAGE_TYPE_CALL,
  4282. guid,
  4283. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4284. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4285. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4286. LWS_Send(message);
  4287. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4288. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4289. {
  4290. result = PASS;
  4291. DEBUG_INFO("DataTransfer mapItem pass\n");
  4292. }
  4293. return result;
  4294. }
  4295. int sendDiagnosticsStatusNotificationRequest(char *status)
  4296. {
  4297. mtrace();
  4298. int result = FAIL;
  4299. char message[110]={0};
  4300. char guid[37]={0};
  4301. char tempdata[65]={0};
  4302. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4303. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4304. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4305. random_uuid(guid);
  4306. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4307. LWS_SendNow(message);
  4308. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4309. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4310. {
  4311. result = PASS;
  4312. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4313. }
  4314. //#ifdef SystemLogMessage
  4315. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4316. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4317. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4318. //#endif
  4319. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4320. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4321. //record status
  4322. if(strcmp(status,"Idle")==0)
  4323. {
  4324. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4325. }
  4326. else if(strcmp(status,"Uploaded")==0)
  4327. {
  4328. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4329. }
  4330. else if(strcmp(status,"UploadFailed")==0)
  4331. {
  4332. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4333. }
  4334. else if(strcmp(status,"Uploading")==0)
  4335. {
  4336. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4337. }
  4338. return result;
  4339. }
  4340. int sendFirmwareStatusNotificationRequest(char *status)
  4341. {
  4342. mtrace();
  4343. int result = FAIL;
  4344. char message[110]={0};
  4345. char guid[37]={0};
  4346. char tempdata[65]={0};
  4347. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4348. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4349. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4350. random_uuid(guid);
  4351. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4352. LWS_SendNow(message);
  4353. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4354. 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*/)
  4355. {
  4356. result = PASS;
  4357. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4358. }
  4359. //#ifdef SystemLogMessage
  4360. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4361. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4362. //#endif
  4363. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4364. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4365. //record status
  4366. if(strcmp(status,"Downloaded")==0)
  4367. {
  4368. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4369. }
  4370. else if(strcmp(status,"DownloadFailed")==0)
  4371. {
  4372. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4373. }
  4374. else if(strcmp(status,"Downloading")==0)
  4375. {
  4376. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4377. }
  4378. else if(strcmp(status,"Idle")==0)
  4379. {
  4380. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4381. }
  4382. else if(strcmp(status,"InstallationFailed")==0)
  4383. {
  4384. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4385. }
  4386. else if(strcmp(status,"Installing")==0)
  4387. {
  4388. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4389. }
  4390. else if(strcmp(status,"Installed")==0)
  4391. {
  4392. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4393. }
  4394. return result;
  4395. }
  4396. int sendHeartbeatRequest(int gun_index)
  4397. {
  4398. mtrace();
  4399. int result = FAIL;
  4400. char message[80]={0};
  4401. char guid[37]={0};
  4402. char tempdata[65]={0};
  4403. random_uuid(guid);
  4404. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4405. , MESSAGE_TYPE_CALL
  4406. , guid );
  4407. LWS_Send(message);
  4408. sprintf(tempdata, "Heartbeat,%d", 0);
  4409. 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*/)
  4410. {
  4411. result = PASS;
  4412. }
  4413. return result;
  4414. }
  4415. int sendStartTransactionRequest(int gun_index)
  4416. {
  4417. mtrace();
  4418. int result = FAIL;
  4419. char message[250]={0};
  4420. char guid[37]={0};
  4421. struct timeval tmnow;
  4422. struct tm *tm;
  4423. char buf[28];//, usec_buf[6];
  4424. char tempdata[65]={0};
  4425. int tempIndex = 0;
  4426. DEBUG_INFO("sendStartTransactionRequest...\n");
  4427. gettimeofday(&tmnow, NULL);
  4428. time_t t;
  4429. t = time(NULL);
  4430. /*UTC time and date*/
  4431. tm = gmtime(&t);
  4432. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4433. #if 0 // remove temporally
  4434. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4435. strcat(buf,".");
  4436. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4437. strcat(buf,usec_buf);
  4438. #endif
  4439. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4440. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4441. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4442. // clear StartTransaction Response
  4443. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4444. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4445. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4446. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4447. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4448. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4449. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4450. {
  4451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4452. {
  4453. tempIndex = ((gun_index==2) ? 1: 0);
  4454. }
  4455. else
  4456. {
  4457. tempIndex = gun_index;
  4458. }
  4459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4460. {
  4461. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4462. {
  4463. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4464. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4465. }
  4466. }
  4467. }
  4468. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4469. {
  4470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4471. {
  4472. tempIndex = ((gun_index==2) ? 1: 0);
  4473. }
  4474. else
  4475. {
  4476. tempIndex = gun_index;
  4477. }
  4478. for (int index = 0; index < CCS_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4481. {
  4482. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4483. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4484. }
  4485. }
  4486. }
  4487. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4488. {
  4489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4490. {
  4491. tempIndex = ((gun_index==2) ? 1: 0);
  4492. }
  4493. else
  4494. {
  4495. tempIndex = gun_index;
  4496. }
  4497. for (int index = 0; index < GB_QUANTITY; index++)
  4498. {
  4499. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4500. {
  4501. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4502. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4503. }
  4504. }
  4505. }
  4506. else if(gunType[gun_index] == GUN_TYPE_DO)
  4507. {
  4508. tempIndex = gun_index;
  4509. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4510. {
  4511. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4512. {
  4513. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4514. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4515. }
  4516. }
  4517. }
  4518. else
  4519. {
  4520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4521. {
  4522. tempIndex = 2;
  4523. }
  4524. else
  4525. {
  4526. tempIndex = gun_index;
  4527. }
  4528. for (int index = 0; index < AC_QUANTITY; index++)
  4529. {
  4530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4531. {
  4532. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4533. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4534. }
  4535. }
  4536. }
  4537. random_uuid(guid);
  4538. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4539. {
  4540. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4541. , gun_index +1
  4542. , MESSAGE_TYPE_CALL
  4543. , guid
  4544. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4545. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4546. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4547. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4548. }
  4549. else
  4550. {
  4551. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4552. , gun_index +1
  4553. , MESSAGE_TYPE_CALL
  4554. , guid
  4555. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4556. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4557. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4558. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4559. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4560. }
  4561. #if 1
  4562. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4563. 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*/)
  4564. {
  4565. result = PASS;
  4566. }
  4567. #endif
  4568. strcpy(queuedata, message);
  4569. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4570. OCPP_insert_transaction_msg(YES, queuedata);
  4571. return result;
  4572. }
  4573. int sendStatusNotificationRequest(int gun_index)
  4574. {
  4575. mtrace();
  4576. int result = FAIL;
  4577. char message[600]={0};
  4578. char guid[37];
  4579. int currentStatus = 0;
  4580. struct timeval tmnow;
  4581. struct tm *tm;
  4582. char buf[28];//, usec_buf[6];
  4583. char tempdata[65]={0};
  4584. int tempIndex = 0;
  4585. uint8_t isStateChanged = TRUE;
  4586. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4587. gettimeofday(&tmnow, NULL);
  4588. time_t t;
  4589. t = time(NULL);
  4590. /*UTC time and date*/
  4591. tm = gmtime(&t);
  4592. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4593. #if 0 // remove temporally
  4594. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4595. strcat(buf,".");
  4596. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4597. strcat(buf,usec_buf);
  4598. #endif
  4599. //printf("%s",buf);
  4600. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4601. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4602. // it's option
  4603. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4604. /*
  4605. enum _SYSTEM_STATUS
  4606. {
  4607. S_BOOTING = 0,
  4608. S_IDLE, = 1
  4609. S_AUTHORIZING, =2
  4610. S_REASSIGN_CHECK, =3
  4611. S_REASSIGN, =4
  4612. S_PRECHARGE, =5
  4613. S_PREPARING_FOR_EV, =6
  4614. S_PREPARING_FOR_EVSE, =7
  4615. S_CHARGING, =8
  4616. S_TERMINATING, =9
  4617. S_COMPLETE, =10
  4618. S_ALARM, =11
  4619. S_FAULT =12
  4620. }
  4621. */
  4622. //check Transaction active
  4623. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4624. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4625. {
  4626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4627. {
  4628. tempIndex = ((gun_index==2) ? 1: 0);
  4629. }
  4630. else
  4631. {
  4632. tempIndex = gun_index;
  4633. }
  4634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4635. {
  4636. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4637. {
  4638. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4639. {
  4640. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4641. {
  4642. currentStatus = Preparing; //OCPP Status: Preparing
  4643. }
  4644. else
  4645. {
  4646. currentStatus = Available; //OCPP Status: Available
  4647. }
  4648. }
  4649. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4650. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4651. ) //S_PRECHARGE
  4652. {
  4653. currentStatus = Preparing; //OCPP Status: Preparing
  4654. }
  4655. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4656. {
  4657. currentStatus = Charging; //OCPP Status: Charging
  4658. }
  4659. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4660. {
  4661. currentStatus = Finishing; //OCPP Status: Finishing
  4662. }
  4663. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4664. {
  4665. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4666. }
  4667. 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
  4668. {
  4669. currentStatus = Unavailable; //OCPP Status: Unavailable
  4670. }
  4671. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4672. {
  4673. currentStatus = Faulted; //OCPP Status: Faulted
  4674. }
  4675. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4676. {
  4677. currentStatus = Reserved; //OCPP Status: Reserved
  4678. }
  4679. } //end of the same index
  4680. }//end of for CHAdeMO_QUANTITY
  4681. }
  4682. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4683. {
  4684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4685. {
  4686. tempIndex = ((gun_index==2) ? 1: 0);
  4687. }
  4688. else
  4689. {
  4690. tempIndex = gun_index;
  4691. }
  4692. for (int index = 0; index < CCS_QUANTITY; index++)
  4693. {
  4694. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4695. {
  4696. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4697. {
  4698. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4699. {
  4700. currentStatus = Preparing; //OCPP Status: Preparing
  4701. }
  4702. else
  4703. {
  4704. currentStatus = Available; //OCPP Status: Available
  4705. }
  4706. }
  4707. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4708. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4709. ) //S_PRECHARGE
  4710. {
  4711. currentStatus = Preparing; //OCPP Status: Preparing
  4712. }
  4713. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4714. {
  4715. currentStatus = Charging; //OCPP Status: Charging
  4716. }
  4717. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4718. {
  4719. currentStatus = Finishing; //OCPP Status: Finishing
  4720. }
  4721. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4722. {
  4723. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4724. }
  4725. 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
  4726. {
  4727. currentStatus = Unavailable; //OCPP Status : Unavailable
  4728. }
  4729. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4730. {
  4731. currentStatus = Faulted; //OCPP Status: Faulted
  4732. }
  4733. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4734. {
  4735. currentStatus = Reserved; //OCPP Status: Reserved
  4736. }
  4737. } //end of the same index
  4738. } // end of for CCS_QUANTITY
  4739. }
  4740. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4741. {
  4742. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4743. {
  4744. tempIndex = ((gun_index==2) ? 1: 0);
  4745. }
  4746. else
  4747. {
  4748. tempIndex = gun_index;
  4749. }
  4750. for (int index = 0; index < GB_QUANTITY; index++)
  4751. {
  4752. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4753. {
  4754. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4755. {
  4756. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4757. {
  4758. currentStatus = Preparing; //OCPP Status: Preparing
  4759. }
  4760. else
  4761. {
  4762. currentStatus = Available; //OCPP Status: Available
  4763. }
  4764. }
  4765. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4766. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4767. ) //S_PRECHARGE
  4768. {
  4769. currentStatus = Preparing; //OCPP Status: Preparing
  4770. }
  4771. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4772. {
  4773. currentStatus = Charging; //OCPP Status: Charging
  4774. }
  4775. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4776. {
  4777. currentStatus = Finishing; //OCPP Status: Finishing
  4778. }
  4779. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4780. {
  4781. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4782. }
  4783. 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
  4784. {
  4785. currentStatus = Unavailable; //OCPP Status: Unavailable
  4786. }
  4787. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4788. {
  4789. currentStatus = Faulted; //OCPP Status: Faulted
  4790. }
  4791. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4792. {
  4793. currentStatus = Reserved; //OCPP Status: Reserved
  4794. }
  4795. } //end of the same index
  4796. } // end of for GB_QUANTITY
  4797. }
  4798. else if(gunType[gun_index] == GUN_TYPE_DO)
  4799. {
  4800. tempIndex = gun_index;
  4801. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4802. {
  4803. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4804. {
  4805. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4806. {
  4807. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4808. {
  4809. currentStatus = Preparing; //OCPP Status: Preparing
  4810. }
  4811. else
  4812. {
  4813. currentStatus = Available; //OCPP Status: Available
  4814. }
  4815. }
  4816. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4817. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4818. ) //S_PRECHARGE
  4819. {
  4820. currentStatus = Preparing; //OCPP Status: Preparing
  4821. }
  4822. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4823. {
  4824. currentStatus = Charging; //OCPP Status: Charging
  4825. }
  4826. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4827. {
  4828. currentStatus = Finishing; //OCPP Status: Finishing
  4829. }
  4830. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4831. {
  4832. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4833. }
  4834. 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
  4835. {
  4836. currentStatus = Unavailable; //OCPP Status: Unavailable
  4837. }
  4838. 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
  4839. {
  4840. currentStatus = Faulted; //OCPP Status: Faulted
  4841. }
  4842. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4843. {
  4844. currentStatus = Reserved; //OCPP Status: Reserved
  4845. }
  4846. } //end of the same index
  4847. }
  4848. }
  4849. else
  4850. {
  4851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4852. {
  4853. tempIndex = 2;
  4854. }
  4855. else
  4856. {
  4857. tempIndex = gun_index;
  4858. }
  4859. for (int index = 0; index < AC_QUANTITY; index++)
  4860. {
  4861. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4862. {
  4863. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4864. {
  4865. 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))
  4866. {
  4867. currentStatus = Preparing; //OCPP Status: Preparing
  4868. }
  4869. else
  4870. {
  4871. currentStatus = Available; //OCPP Status: Available
  4872. }
  4873. }
  4874. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4875. {
  4876. currentStatus = Preparing; //OCPP Status: Preparing
  4877. }
  4878. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4879. {
  4880. currentStatus = Charging; //OCPP Status: Charging
  4881. }
  4882. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4883. {
  4884. currentStatus = Finishing; //OCPP Status: Finishing
  4885. }
  4886. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4887. {
  4888. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4889. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4890. else
  4891. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4892. }
  4893. 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
  4894. {
  4895. currentStatus = Unavailable; //OCPP Status: Unavailable
  4896. }
  4897. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4898. {
  4899. currentStatus = Faulted; //OCPP Status: Faulted
  4900. }
  4901. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4902. {
  4903. currentStatus = Reserved; //OCPP Status: Reserved
  4904. }
  4905. }//end of the same index
  4906. }//end of for AC_QUANTITY
  4907. }
  4908. //it's option
  4909. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4910. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4911. {
  4912. isStateChanged = FALSE;
  4913. }
  4914. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4915. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4916. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4917. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4918. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4919. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4920. random_uuid(guid);
  4921. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4922. , MESSAGE_TYPE_CALL
  4923. , guid
  4924. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4925. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4926. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4927. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4928. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4929. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4930. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4931. if((server_sign == TRUE) && isStateChanged)
  4932. {
  4933. LWS_Send(message);
  4934. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4935. 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*/)
  4936. {
  4937. //DEBUG_ERROR("statusNotification mapitem pass");
  4938. result = PASS;
  4939. }
  4940. }
  4941. else
  4942. {
  4943. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4944. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4945. result = PASS;
  4946. }
  4947. return result;
  4948. }
  4949. int sendStopTransactionRequest(int gun_index)
  4950. {
  4951. mtrace();
  4952. int result = FAIL;
  4953. //char message[1500]={0};
  4954. char guid[37]={0};
  4955. char tempdata[65]={0};
  4956. int tempIndex = 0;
  4957. char TempStopTransaction[256];
  4958. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4959. //int idx_sample=0;
  4960. DEBUG_INFO("sendStopTransactionRequest \n");
  4961. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4962. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4963. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4964. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4965. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4966. {
  4967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4968. {
  4969. tempIndex = ((gun_index==2) ? 1: 0);
  4970. }
  4971. else
  4972. {
  4973. tempIndex = gun_index;
  4974. }
  4975. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4976. {
  4977. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4978. {
  4979. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4980. }
  4981. }// END OF CHAdeMO_QUANTITY
  4982. }
  4983. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4984. {
  4985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4986. {
  4987. tempIndex = ((gun_index==2) ? 1: 0);
  4988. }
  4989. else
  4990. {
  4991. tempIndex = gun_index;
  4992. }
  4993. for (int index = 0; index < CCS_QUANTITY; index++)
  4994. {
  4995. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4996. {
  4997. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4998. }
  4999. }// END OF CCS_QUANTITY
  5000. }
  5001. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5002. {
  5003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5004. {
  5005. tempIndex = ((gun_index==2) ? 1: 0);
  5006. }
  5007. else
  5008. {
  5009. tempIndex = gun_index;
  5010. }
  5011. for (int index = 0; index < GB_QUANTITY; index++)
  5012. {
  5013. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5014. {
  5015. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5016. }
  5017. }// END OF GB_QUANTITY
  5018. }
  5019. else if(gunType[gun_index] == GUN_TYPE_DO)
  5020. {
  5021. tempIndex = gun_index;
  5022. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5023. {
  5024. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5025. {
  5026. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5027. }
  5028. }// END OF GB_QUANTITY
  5029. }
  5030. else
  5031. {
  5032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5033. {
  5034. tempIndex = 2;
  5035. }
  5036. else
  5037. {
  5038. tempIndex = gun_index;
  5039. }
  5040. for (int index = 0; index < AC_QUANTITY; index++)
  5041. {
  5042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5043. {
  5044. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5045. }
  5046. }// END OF AC_QUANTITY
  5047. }
  5048. //====================================== Stop Transaction Time =====================================================
  5049. struct timeval tmnow;
  5050. struct tm *tm;
  5051. char buf[28];//, usec_buf[6];
  5052. gettimeofday(&tmnow, NULL);
  5053. time_t t;
  5054. t = time(NULL);
  5055. /*UTC time and date*/
  5056. tm = gmtime(&t);
  5057. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5059. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5060. random_uuid(guid);
  5061. /***********************************transactionData******************************************************/
  5062. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5063. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5064. //=================================
  5065. // Transaction_Begin
  5066. //=================================
  5067. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5068. {
  5069. //============================================ Energy.Active.Import.Interval ================================
  5070. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5073. 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*/]);
  5074. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5075. 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))
  5076. {
  5077. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5078. }
  5079. else
  5080. {
  5081. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5082. }
  5083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5084. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5085. }
  5086. //=================================
  5087. // Transaction_End
  5088. //=================================
  5089. // ================================= Current.Import L1 ===============================================
  5090. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5091. {
  5092. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5093. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5094. {
  5095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5096. {
  5097. tempIndex = ((gun_index==2) ? 1: 0);
  5098. }
  5099. else
  5100. {
  5101. tempIndex = gun_index;
  5102. }
  5103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5104. {
  5105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5106. {
  5107. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5108. }
  5109. }// End of for CHAdeMO_QUANTITY
  5110. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5111. }
  5112. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5113. {
  5114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5115. {
  5116. tempIndex = ((gun_index==2) ? 1: 0);
  5117. }
  5118. else
  5119. {
  5120. tempIndex = gun_index;
  5121. }
  5122. for (int index = 0; index < CCS_QUANTITY; index++)
  5123. {
  5124. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5125. {
  5126. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5127. }
  5128. }// End of for CCS_QUANTITY
  5129. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5130. }
  5131. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5132. {
  5133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5134. {
  5135. tempIndex = ((gun_index==2) ? 1: 0);
  5136. }
  5137. else
  5138. {
  5139. tempIndex = gun_index;
  5140. }
  5141. for (int index = 0; index < GB_QUANTITY; index++)
  5142. {
  5143. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5144. {
  5145. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5146. }
  5147. }// End of for GB_QUANTITY
  5148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5149. }
  5150. else if(gunType[gun_index] == GUN_TYPE_DO)
  5151. {
  5152. tempIndex = gun_index;
  5153. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5154. {
  5155. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5156. {
  5157. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5158. }
  5159. }
  5160. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5161. }
  5162. else
  5163. {
  5164. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5165. {
  5166. tempIndex = 2;
  5167. }
  5168. else
  5169. {
  5170. tempIndex = gun_index;
  5171. }
  5172. for (int index = 0; index < AC_QUANTITY; index++)
  5173. {
  5174. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5175. {
  5176. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5177. }
  5178. }// End of for AC_QUANTITY
  5179. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5180. }
  5181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5182. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5183. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5185. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5186. }
  5187. // ================================= Energy.Active.Import.Interval ==============================================
  5188. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5189. {
  5190. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5191. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5192. {
  5193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5194. {
  5195. tempIndex = ((gun_index==2) ? 1: 0);
  5196. }
  5197. else
  5198. {
  5199. tempIndex = gun_index;
  5200. }
  5201. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5202. {
  5203. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5204. {
  5205. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5206. }
  5207. }// END OF CHAdeMO_QUANTITY
  5208. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5209. }
  5210. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5211. {
  5212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5213. {
  5214. tempIndex = ((gun_index==2) ? 1: 0);
  5215. }
  5216. else
  5217. {
  5218. tempIndex = gun_index;
  5219. }
  5220. for (int index = 0; index < CCS_QUANTITY; index++)
  5221. {
  5222. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5223. {
  5224. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5225. }
  5226. }// END OF CCS_QUANTITY
  5227. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5228. }
  5229. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5230. {
  5231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5232. {
  5233. tempIndex = ((gun_index==2) ? 1: 0);
  5234. }
  5235. else
  5236. {
  5237. tempIndex = gun_index;
  5238. }
  5239. for (int index = 0; index < GB_QUANTITY; index++)
  5240. {
  5241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5242. {
  5243. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5244. }
  5245. }// END OF GB_QUANTITY
  5246. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5247. }
  5248. else if(gunType[gun_index] == GUN_TYPE_DO)
  5249. {
  5250. tempIndex = gun_index;
  5251. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5252. {
  5253. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5254. {
  5255. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5256. }
  5257. }
  5258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5259. }
  5260. else
  5261. {
  5262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5263. {
  5264. tempIndex = 2;
  5265. }
  5266. else
  5267. {
  5268. tempIndex = gun_index;
  5269. }
  5270. for (int index = 0; index < AC_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5273. {
  5274. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5275. }
  5276. }// END OF AC_QUANTITY
  5277. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5278. }
  5279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5283. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5284. }
  5285. //=================================== Power.Active.Import ==================================================
  5286. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5287. {
  5288. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5289. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5290. {
  5291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5292. {
  5293. tempIndex = ((gun_index==2) ? 1: 0);
  5294. }
  5295. else
  5296. {
  5297. tempIndex = gun_index;
  5298. }
  5299. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5300. {
  5301. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5302. {
  5303. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5304. }
  5305. } // End for CHAdeMO_QUANTITY
  5306. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5307. }
  5308. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5309. {
  5310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5311. {
  5312. tempIndex = ((gun_index==2) ? 1: 0);
  5313. }
  5314. else
  5315. {
  5316. tempIndex = gun_index;
  5317. }
  5318. for (int index = 0; index < CCS_QUANTITY; index++)
  5319. {
  5320. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5321. {
  5322. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5323. }
  5324. } // END for CCS_QUANTITY
  5325. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5326. }
  5327. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5328. {
  5329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5330. {
  5331. tempIndex = ((gun_index==2) ? 1: 0);
  5332. }
  5333. else
  5334. {
  5335. tempIndex = gun_index;
  5336. }
  5337. for (int index = 0; index < GB_QUANTITY; index++)
  5338. {
  5339. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5340. {
  5341. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5342. }
  5343. }// END for GB_QUANTITY
  5344. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5345. }
  5346. else if(gunType[gun_index] == GUN_TYPE_DO)
  5347. {
  5348. tempIndex = gun_index;
  5349. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5350. {
  5351. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5352. {
  5353. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5354. }
  5355. }
  5356. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5357. }
  5358. else
  5359. {
  5360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5361. {
  5362. tempIndex = 2;
  5363. }
  5364. else
  5365. {
  5366. tempIndex = gun_index;
  5367. }
  5368. for (int index = 0; index < AC_QUANTITY; index++)
  5369. {
  5370. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5371. {
  5372. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5373. }
  5374. } // END for AC_QUANTITY
  5375. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5376. }
  5377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5378. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5382. }
  5383. //============================ Voltage L1 ====================================
  5384. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5385. {
  5386. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5387. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5388. {
  5389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5390. {
  5391. tempIndex = ((gun_index==2) ? 1: 0);
  5392. }
  5393. else
  5394. {
  5395. tempIndex = gun_index;
  5396. }
  5397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5400. {
  5401. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5402. }
  5403. } // END OF FOR CHAdeMO_QUANTITY
  5404. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5405. }
  5406. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5407. {
  5408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5409. {
  5410. tempIndex = ((gun_index==2) ? 1: 0);
  5411. }
  5412. else
  5413. {
  5414. tempIndex = gun_index;
  5415. }
  5416. for (int index = 0; index < CCS_QUANTITY; index++)
  5417. {
  5418. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5419. {
  5420. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5421. }
  5422. } // END OF FOR CCS_QUANTITY
  5423. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5424. }
  5425. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5426. {
  5427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5428. {
  5429. tempIndex = ((gun_index==2) ? 1: 0);
  5430. }
  5431. else
  5432. {
  5433. tempIndex = gun_index;
  5434. }
  5435. for (int index = 0; index < GB_QUANTITY; index++)
  5436. {
  5437. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5438. {
  5439. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5440. }
  5441. } // END OF FOR GB_QUANTITY
  5442. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5443. }
  5444. else if(gunType[gun_index] == GUN_TYPE_DO)
  5445. {
  5446. tempIndex = gun_index;
  5447. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5448. {
  5449. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5450. {
  5451. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5452. }
  5453. }
  5454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5455. }
  5456. else
  5457. {
  5458. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5459. {
  5460. tempIndex = 2;
  5461. }
  5462. else
  5463. {
  5464. tempIndex = gun_index;
  5465. }
  5466. for (int index = 0; index < AC_QUANTITY; index++)
  5467. {
  5468. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5469. {
  5470. 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
  5471. }
  5472. } // END OF FOR AC_QUANTITY
  5473. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5474. }
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5476. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5480. }
  5481. //====================== End SoC ================================
  5482. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5483. {
  5484. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5485. 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))
  5486. {
  5487. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5488. {
  5489. tempIndex = ((gun_index==2) ? 1: 0);
  5490. }
  5491. else
  5492. {
  5493. tempIndex = gun_index;
  5494. }
  5495. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5496. {
  5497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5498. {
  5499. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5500. {
  5501. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5502. }
  5503. }
  5504. }
  5505. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5506. {
  5507. for (int index = 0; index < CCS_QUANTITY; index++)
  5508. {
  5509. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5510. {
  5511. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5512. }
  5513. }
  5514. }
  5515. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5516. {
  5517. for (int index = 0; index < GB_QUANTITY; index++)
  5518. {
  5519. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5520. {
  5521. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5522. }
  5523. }
  5524. }
  5525. else if(gunType[gun_index] == GUN_TYPE_DO)
  5526. {
  5527. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5528. {
  5529. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5530. {
  5531. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5532. }
  5533. }
  5534. }
  5535. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5536. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5537. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5539. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5540. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5541. } // END FOR DC CASE
  5542. }
  5543. // ================================= Current.Import L2 ===============================================
  5544. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5545. {
  5546. // AC 3 phse L2 current
  5547. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5548. {
  5549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5550. {
  5551. tempIndex = 2;
  5552. }
  5553. else
  5554. {
  5555. tempIndex = gun_index;
  5556. }
  5557. for (int index = 0; index < AC_QUANTITY; index++)
  5558. {
  5559. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5560. {
  5561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5562. }
  5563. }// End of for AC_QUANTITY
  5564. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5565. }
  5566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5567. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5571. }
  5572. // ================================= Current.Import L3 ===============================================
  5573. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5574. {
  5575. // AC 3 phse L3 current
  5576. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5577. {
  5578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5579. {
  5580. tempIndex = 2;
  5581. }
  5582. else
  5583. {
  5584. tempIndex = gun_index;
  5585. }
  5586. for (int index = 0; index < AC_QUANTITY; index++)
  5587. {
  5588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5589. {
  5590. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5591. }
  5592. }// End of for AC_QUANTITY
  5593. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5594. }
  5595. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5596. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5600. }
  5601. //============================ Voltage L2 ====================================
  5602. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5603. {
  5604. // AC 3 phse L2 voltage
  5605. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5606. {
  5607. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5608. {
  5609. tempIndex = 2;
  5610. }
  5611. else
  5612. {
  5613. tempIndex = gun_index;
  5614. }
  5615. for (int index = 0; index < AC_QUANTITY; index++)
  5616. {
  5617. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5618. {
  5619. 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
  5620. }
  5621. } // END OF FOR AC_QUANTITY
  5622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5623. }
  5624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5629. }
  5630. //============================ Voltage L3 ====================================
  5631. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5632. {
  5633. // AC 3 phse L3 voltage
  5634. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5635. {
  5636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5637. {
  5638. tempIndex = 2;
  5639. }
  5640. else
  5641. {
  5642. tempIndex = gun_index;
  5643. }
  5644. for (int index = 0; index < AC_QUANTITY; index++)
  5645. {
  5646. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5647. {
  5648. 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
  5649. }
  5650. } // END OF FOR AC_QUANTITY
  5651. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5652. }
  5653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5658. }
  5659. //====================== Start SoC ================================
  5660. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5661. {
  5662. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5663. 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))
  5664. {
  5665. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5666. {
  5667. tempIndex = ((gun_index==2) ? 1: 0);
  5668. }
  5669. else
  5670. {
  5671. tempIndex = gun_index;
  5672. }
  5673. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5674. {
  5675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5676. {
  5677. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5678. {
  5679. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5680. }
  5681. }
  5682. }
  5683. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5684. {
  5685. for (int index = 0; index < CCS_QUANTITY; index++)
  5686. {
  5687. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5688. {
  5689. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5690. }
  5691. }
  5692. }
  5693. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5694. {
  5695. for (int index = 0; index < GB_QUANTITY; index++)
  5696. {
  5697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5698. {
  5699. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5700. }
  5701. }
  5702. }
  5703. else if(gunType[gun_index] == GUN_TYPE_DO)
  5704. {
  5705. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5706. {
  5707. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5708. {
  5709. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5710. }
  5711. }
  5712. }
  5713. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5714. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5718. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5719. } // END FOR DC CASE
  5720. }
  5721. //================================================ Message create ====================================================
  5722. json_object *StopTransaction = json_object_new_object();
  5723. json_object *transactionDatas = json_object_new_array();
  5724. json_object *sampledValues = json_object_new_array();
  5725. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5726. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5727. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5728. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5729. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5730. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5731. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5732. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5733. {
  5734. json_object *transactionData = json_object_new_object();
  5735. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5736. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5737. {
  5738. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5739. {
  5740. json_object *sampledValue = json_object_new_object();
  5741. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5742. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5743. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5744. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5745. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5746. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5747. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5748. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5749. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5750. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5751. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5752. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5753. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5754. json_object_array_add(sampledValues, sampledValue);
  5755. }
  5756. }
  5757. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5758. json_object_array_add(transactionDatas, transactionData);
  5759. }
  5760. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5761. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5762. ,MESSAGE_TYPE_CALL
  5763. ,guid
  5764. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5765. json_object_put(StopTransaction);
  5766. #if 1 // for TempStopTransaction
  5767. //Delete TempStopTransaction
  5768. if((access(TempStopTransaction,F_OK))!=-1)
  5769. {
  5770. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5771. }
  5772. #endif
  5773. #if 1
  5774. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5775. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5776. {
  5777. result = PASS;
  5778. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5779. }
  5780. #endif
  5781. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5782. OCPP_insert_transaction_msg(NO, queuedata);
  5783. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5784. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5785. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5786. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5787. {
  5788. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5789. }
  5790. //for test
  5791. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5792. return result;
  5793. }
  5794. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5795. {
  5796. mtrace();
  5797. int result = FAIL;
  5798. char guid[37]={0};
  5799. char tempdata[65]={0};
  5800. int tempIndex = 0;
  5801. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5802. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5803. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5804. //set value
  5805. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5806. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  5807. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5808. -1);
  5809. random_uuid(guid);
  5810. //UTC Date time
  5811. struct timeval tmnow;
  5812. struct tm *tm;
  5813. char buf[28];//, usec_buf[6];
  5814. gettimeofday(&tmnow, NULL);
  5815. time_t t;
  5816. t = time(NULL);
  5817. /*UTC time and date*/
  5818. tm = gmtime(&t);
  5819. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5820. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5821. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5822. //********************************(1)Current.Import L1************************************************/
  5823. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5824. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5825. (dataType == ReadingContext_Trigger))
  5826. {
  5827. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5828. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5829. {
  5830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5831. {
  5832. tempIndex = ((gun_index==2) ? 1: 0);
  5833. }
  5834. else
  5835. {
  5836. tempIndex = gun_index;
  5837. }
  5838. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5839. {
  5840. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5841. {
  5842. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5843. }
  5844. }
  5845. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5846. }
  5847. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5848. {
  5849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5850. {
  5851. tempIndex = ((gun_index==2) ? 1: 0);
  5852. }
  5853. else
  5854. {
  5855. tempIndex = gun_index;
  5856. }
  5857. for (int index = 0; index < CCS_QUANTITY; index++)
  5858. {
  5859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5860. {
  5861. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5862. }
  5863. }
  5864. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5865. }
  5866. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5867. {
  5868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5869. {
  5870. tempIndex = ((gun_index==2) ? 1: 0);
  5871. }
  5872. else
  5873. {
  5874. tempIndex = gun_index;
  5875. }
  5876. for (int index = 0; index < GB_QUANTITY; index++)
  5877. {
  5878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5879. {
  5880. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5881. }
  5882. }
  5883. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5884. }
  5885. else if(gunType[gun_index] == GUN_TYPE_DO)
  5886. {
  5887. tempIndex = gun_index;
  5888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5889. {
  5890. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5891. {
  5892. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5893. }
  5894. }
  5895. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5896. }
  5897. else
  5898. {
  5899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5900. {
  5901. tempIndex = 2;
  5902. }
  5903. else
  5904. {
  5905. tempIndex = gun_index;
  5906. }
  5907. for (int index = 0; index < AC_QUANTITY; index++)
  5908. {
  5909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5910. {
  5911. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5912. }
  5913. }
  5914. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5915. }
  5916. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5917. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5919. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5921. }
  5922. //********************************(2)Energy.Active.Import.Register ************************************************/
  5923. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5924. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5925. (dataType == ReadingContext_Trigger))
  5926. {
  5927. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5928. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5929. {
  5930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5931. {
  5932. tempIndex = ((gun_index==2) ? 1: 0);
  5933. }
  5934. else
  5935. {
  5936. tempIndex = gun_index;
  5937. }
  5938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5939. {
  5940. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5941. {
  5942. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5943. }
  5944. }
  5945. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5946. }
  5947. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5948. {
  5949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5950. {
  5951. tempIndex = ((gun_index==2) ? 1: 0);
  5952. }
  5953. else
  5954. {
  5955. tempIndex = gun_index;
  5956. }
  5957. for (int index = 0; index < CCS_QUANTITY; index++)
  5958. {
  5959. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5960. {
  5961. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5962. }
  5963. }
  5964. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5965. }
  5966. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5967. {
  5968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5969. {
  5970. tempIndex = ((gun_index==2) ? 1: 0);
  5971. }
  5972. else
  5973. {
  5974. tempIndex = gun_index;
  5975. }
  5976. for (int index = 0; index < GB_QUANTITY; index++)
  5977. {
  5978. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5979. {
  5980. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5981. }
  5982. }
  5983. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5984. }
  5985. else if(gunType[gun_index] == GUN_TYPE_DO)
  5986. {
  5987. tempIndex = gun_index;
  5988. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5989. {
  5990. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5991. {
  5992. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5993. }
  5994. }
  5995. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5996. }
  5997. else
  5998. {
  5999. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6000. {
  6001. tempIndex = 2;
  6002. }
  6003. else
  6004. {
  6005. tempIndex = gun_index;
  6006. }
  6007. for (int index = 0; index < AC_QUANTITY; index++)
  6008. {
  6009. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6010. {
  6011. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6012. }
  6013. }
  6014. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6015. }
  6016. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6017. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6021. }
  6022. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6023. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6024. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6025. (dataType == ReadingContext_Trigger))
  6026. {
  6027. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6028. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6029. {
  6030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6031. {
  6032. tempIndex = ((gun_index==2) ? 1: 0);
  6033. }
  6034. else
  6035. {
  6036. tempIndex = gun_index;
  6037. }
  6038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6039. {
  6040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6041. {
  6042. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6043. }
  6044. } // END OF FOR CHAdeMO_QUANTITY
  6045. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6046. }
  6047. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6048. {
  6049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6050. {
  6051. tempIndex = ((gun_index==2) ? 1: 0);
  6052. }
  6053. else
  6054. {
  6055. tempIndex = gun_index;
  6056. }
  6057. for (int index = 0; index < CCS_QUANTITY; index++)
  6058. {
  6059. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6060. {
  6061. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6062. }
  6063. } // END OF CCS_QUANTITY
  6064. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6065. }
  6066. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6067. {
  6068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6069. {
  6070. tempIndex = ((gun_index==2) ? 1: 0);
  6071. }
  6072. else
  6073. {
  6074. tempIndex = gun_index;
  6075. }
  6076. for (int index = 0; index < GB_QUANTITY; index++)
  6077. {
  6078. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6079. {
  6080. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6081. }
  6082. } // END OF GB_QUANTITY
  6083. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6084. }
  6085. else if(gunType[gun_index] == GUN_TYPE_DO)
  6086. {
  6087. tempIndex = gun_index;
  6088. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6089. {
  6090. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6091. {
  6092. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6093. }
  6094. }
  6095. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6096. }
  6097. else
  6098. {
  6099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6100. {
  6101. tempIndex = 2;
  6102. }
  6103. else
  6104. {
  6105. tempIndex = gun_index;
  6106. }
  6107. for (int index = 0; index < AC_QUANTITY; index++)
  6108. {
  6109. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6110. {
  6111. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6112. }
  6113. }
  6114. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6115. }
  6116. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6117. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6118. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6119. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6120. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6121. }
  6122. //********************************(4)Power.Active.Import************************************************/
  6123. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6124. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6125. (dataType == ReadingContext_Trigger))
  6126. {
  6127. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6128. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6129. {
  6130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6131. {
  6132. tempIndex = ((gun_index==2) ? 1: 0);
  6133. }
  6134. else
  6135. {
  6136. tempIndex = gun_index;
  6137. }
  6138. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6139. {
  6140. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6141. {
  6142. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6143. }
  6144. } // END OF FOR
  6145. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6146. }
  6147. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6148. {
  6149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6150. {
  6151. tempIndex = ((gun_index==2) ? 1: 0);
  6152. }
  6153. else
  6154. {
  6155. tempIndex = gun_index;
  6156. }
  6157. for (int index = 0; index < CCS_QUANTITY; index++)
  6158. {
  6159. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6160. {
  6161. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6162. }
  6163. }
  6164. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6165. }
  6166. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6167. {
  6168. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6169. {
  6170. tempIndex = ((gun_index==2) ? 1: 0);
  6171. }
  6172. else
  6173. {
  6174. tempIndex = gun_index;
  6175. }
  6176. for (int index = 0; index < GB_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6179. {
  6180. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6181. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6182. }
  6183. }
  6184. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6185. }
  6186. else if(gunType[gun_index] == GUN_TYPE_DO)
  6187. {
  6188. tempIndex = gun_index;
  6189. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6190. {
  6191. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6192. {
  6193. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6194. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6195. }
  6196. }
  6197. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6198. }
  6199. else
  6200. {
  6201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6202. {
  6203. tempIndex = 2;
  6204. }
  6205. else
  6206. {
  6207. tempIndex = gun_index;
  6208. }
  6209. for (int index = 0; index < AC_QUANTITY; index++)
  6210. {
  6211. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6212. {
  6213. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6214. }
  6215. }
  6216. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6217. }
  6218. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6219. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6221. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6222. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6223. }
  6224. //***********************************************(5)VOLTAGE L1******************************************************/
  6225. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6226. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6227. (dataType == ReadingContext_Trigger))
  6228. {
  6229. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6230. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6231. {
  6232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6233. {
  6234. tempIndex = ((gun_index==2) ? 1: 0);
  6235. }
  6236. else
  6237. {
  6238. tempIndex = gun_index;
  6239. }
  6240. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6241. {
  6242. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6243. {
  6244. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6245. }
  6246. }
  6247. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6248. }
  6249. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6250. {
  6251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6252. {
  6253. tempIndex = ((gun_index==2) ? 1: 0);
  6254. }
  6255. else
  6256. {
  6257. tempIndex = gun_index;
  6258. }
  6259. for (int index = 0; index < CCS_QUANTITY; index++)
  6260. {
  6261. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6262. {
  6263. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6264. }
  6265. }
  6266. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6267. }
  6268. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6269. {
  6270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6271. {
  6272. tempIndex = ((gun_index==2) ? 1: 0);
  6273. }
  6274. else
  6275. {
  6276. tempIndex = gun_index;
  6277. }
  6278. for (int index = 0; index < GB_QUANTITY; index++)
  6279. {
  6280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6281. {
  6282. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6283. }
  6284. }
  6285. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6286. }
  6287. else if(gunType[gun_index] == GUN_TYPE_DO)
  6288. {
  6289. tempIndex = gun_index;
  6290. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6291. {
  6292. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6293. {
  6294. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6295. }
  6296. }
  6297. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6298. }
  6299. else
  6300. {
  6301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6302. {
  6303. tempIndex = 2;
  6304. }
  6305. else
  6306. {
  6307. tempIndex = gun_index;
  6308. }
  6309. for (int index = 0; index < AC_QUANTITY; index++)
  6310. {
  6311. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6312. {
  6313. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6314. }
  6315. }
  6316. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6317. }
  6318. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6319. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6320. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6321. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6322. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6323. }
  6324. //***********************************************(6)SOC******************************************************/
  6325. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6326. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6327. (dataType == ReadingContext_Trigger))
  6328. {
  6329. 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))
  6330. {
  6331. //idx_sample=5;
  6332. //sampledValue = NULL;
  6333. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6334. {
  6335. tempIndex = ((gun_index==2) ? 1: 0);
  6336. }
  6337. else
  6338. {
  6339. tempIndex = gun_index;
  6340. }
  6341. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6342. {
  6343. //tempIndex = ((gun_index==2) ? 1: 0);
  6344. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6345. {
  6346. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6347. {
  6348. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6349. }
  6350. }
  6351. }
  6352. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6353. {
  6354. //tempIndex = ((gun_index==2) ? 1: 0);
  6355. for (int index = 0; index < CCS_QUANTITY; index++)
  6356. {
  6357. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6358. {
  6359. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6360. }
  6361. }
  6362. }
  6363. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6364. {
  6365. //tempIndex = ((gun_index==2) ? 1: 0);
  6366. for (int index = 0; index < GB_QUANTITY; index++)
  6367. {
  6368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6369. {
  6370. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6371. }
  6372. }
  6373. }
  6374. else if(gunType[gun_index] == GUN_TYPE_DO)
  6375. {
  6376. //tempIndex = ((gun_index==2) ? 1: 0);
  6377. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6378. {
  6379. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6380. {
  6381. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6382. }
  6383. }
  6384. }
  6385. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6386. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6387. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6388. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6389. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6390. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6391. }
  6392. }
  6393. //********************************(7)Current.Import L2************************************************/
  6394. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6395. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6396. (dataType == ReadingContext_Trigger))
  6397. {
  6398. // Only for AC 3 phase
  6399. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6400. {
  6401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6402. {
  6403. tempIndex = 2;
  6404. }
  6405. else
  6406. {
  6407. tempIndex = gun_index;
  6408. }
  6409. for (int index = 0; index < AC_QUANTITY; index++)
  6410. {
  6411. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6412. {
  6413. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6414. }
  6415. }
  6416. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6417. }
  6418. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6419. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6422. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6423. }
  6424. //********************************(8)Current.Import L3************************************************/
  6425. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6426. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6427. (dataType == ReadingContext_Trigger))
  6428. {
  6429. // Only for AC 3 phase
  6430. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6431. {
  6432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6433. {
  6434. tempIndex = 2;
  6435. }
  6436. else
  6437. {
  6438. tempIndex = gun_index;
  6439. }
  6440. for (int index = 0; index < AC_QUANTITY; index++)
  6441. {
  6442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6443. {
  6444. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6445. }
  6446. }
  6447. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6448. }
  6449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6450. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6454. }
  6455. //***********************************************(9)VOLTAGE L2******************************************************/
  6456. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6457. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6458. (dataType == ReadingContext_Trigger))
  6459. {
  6460. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6461. {
  6462. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6463. {
  6464. tempIndex = 2;
  6465. }
  6466. else
  6467. {
  6468. tempIndex = gun_index;
  6469. }
  6470. for (int index = 0; index < AC_QUANTITY; index++)
  6471. {
  6472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6473. {
  6474. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6475. }
  6476. }
  6477. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6478. }
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6481. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6483. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6484. }
  6485. //***********************************************(10)VOLTAGE L3******************************************************/
  6486. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6487. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6488. (dataType == ReadingContext_Trigger))
  6489. {
  6490. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6491. {
  6492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6493. {
  6494. tempIndex = 2;
  6495. }
  6496. else
  6497. {
  6498. tempIndex = gun_index;
  6499. }
  6500. for (int index = 0; index < AC_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6503. {
  6504. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6505. }
  6506. }
  6507. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6508. }
  6509. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6510. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6513. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6514. }
  6515. //***********************************************(11)Current.Offered******************************************************/
  6516. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6517. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6518. (dataType == ReadingContext_Trigger))
  6519. {
  6520. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6521. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6522. {
  6523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6524. {
  6525. tempIndex = ((gun_index==2) ? 1: 0);
  6526. }
  6527. else
  6528. {
  6529. tempIndex = gun_index;
  6530. }
  6531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6532. {
  6533. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6534. {
  6535. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6536. }
  6537. } // END OF FOR CHAdeMO_QUANTITY
  6538. }
  6539. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6540. {
  6541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6542. {
  6543. tempIndex = ((gun_index==2) ? 1: 0);
  6544. }
  6545. else
  6546. {
  6547. tempIndex = gun_index;
  6548. }
  6549. for (int index = 0; index < CCS_QUANTITY; index++)
  6550. {
  6551. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6552. {
  6553. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6554. }
  6555. } // END OF CCS_QUANTITY
  6556. }
  6557. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6558. {
  6559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6560. {
  6561. tempIndex = ((gun_index==2) ? 1: 0);
  6562. }
  6563. else
  6564. {
  6565. tempIndex = gun_index;
  6566. }
  6567. for (int index = 0; index < GB_QUANTITY; index++)
  6568. {
  6569. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6570. {
  6571. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6572. }
  6573. } // END OF GB_QUANTITY
  6574. }
  6575. else if(gunType[gun_index] == GUN_TYPE_DO)
  6576. {
  6577. tempIndex = gun_index;
  6578. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6579. {
  6580. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6581. {
  6582. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6583. }
  6584. }
  6585. }
  6586. else
  6587. {
  6588. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6589. {
  6590. tempIndex = 2;
  6591. }
  6592. else
  6593. {
  6594. tempIndex = gun_index;
  6595. }
  6596. for (int index = 0; index < AC_QUANTITY; index++)
  6597. {
  6598. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6599. {
  6600. uint16_t currentOffer;
  6601. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6602. {
  6603. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6604. }
  6605. else
  6606. {
  6607. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6608. }
  6609. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6610. }
  6611. }
  6612. }
  6613. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6614. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6615. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6616. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6617. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6618. }
  6619. //***********************************************(12)Power.Offered******************************************************/
  6620. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6621. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6622. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6623. {
  6624. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6625. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6626. {
  6627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6628. {
  6629. tempIndex = ((gun_index==2) ? 1: 0);
  6630. }
  6631. else
  6632. {
  6633. tempIndex = gun_index;
  6634. }
  6635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6636. {
  6637. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6638. {
  6639. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6640. }
  6641. } // END OF FOR CHAdeMO_QUANTITY
  6642. }
  6643. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6644. {
  6645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6646. {
  6647. tempIndex = ((gun_index==2) ? 1: 0);
  6648. }
  6649. else
  6650. {
  6651. tempIndex = gun_index;
  6652. }
  6653. for (int index = 0; index < CCS_QUANTITY; index++)
  6654. {
  6655. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6656. {
  6657. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6658. }
  6659. } // END OF CCS_QUANTITY
  6660. }
  6661. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6662. {
  6663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6664. {
  6665. tempIndex = ((gun_index==2) ? 1: 0);
  6666. }
  6667. else
  6668. {
  6669. tempIndex = gun_index;
  6670. }
  6671. for (int index = 0; index < GB_QUANTITY; index++)
  6672. {
  6673. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6674. {
  6675. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6676. }
  6677. } // END OF GB_QUANTITY
  6678. }
  6679. else if(gunType[gun_index] == GUN_TYPE_DO)
  6680. {
  6681. tempIndex = gun_index;
  6682. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6683. {
  6684. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6685. {
  6686. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6687. }
  6688. }
  6689. }
  6690. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6691. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6692. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6693. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6694. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6695. }
  6696. // Message create ====================================================================================================
  6697. if(TRUE)
  6698. {
  6699. json_object *MeterValueReq = json_object_new_object();
  6700. json_object *MeterValues = json_object_new_array();
  6701. json_object *sampledValues = json_object_new_array();
  6702. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6703. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6704. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6705. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6706. {
  6707. json_object *MeterValue = json_object_new_object();
  6708. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6709. {
  6710. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6711. {
  6712. json_object *sampledValue = json_object_new_object();
  6713. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6714. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6715. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6716. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6717. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6718. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6719. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6720. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6721. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6722. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6723. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6724. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6725. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6726. json_object_array_add(sampledValues, sampledValue);
  6727. }
  6728. }
  6729. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6730. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6731. json_object_array_add(MeterValues, MeterValue);
  6732. }
  6733. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6734. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6735. ,gun_index + 1
  6736. ,MESSAGE_TYPE_CALL
  6737. ,guid
  6738. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6739. json_object_put(MeterValueReq);
  6740. }
  6741. // Put request guid to hash map
  6742. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6743. 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*/)
  6744. {
  6745. result = PASS;
  6746. //DEBUG_INFO("MeterValues mapitem pass\n");
  6747. }
  6748. if((dataType != ReadingContext_Trigger) &&
  6749. (dataType != ReadingContext_Sample_Clock) &&
  6750. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6751. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6752. else
  6753. {
  6754. if(FirstHeartBeat)
  6755. LWS_Send(queuedata +2);
  6756. }
  6757. return result;
  6758. }
  6759. int sendLogStatusNotificationRequest(char *status)
  6760. {
  6761. mtrace();
  6762. int result = PASS;
  6763. char message[4096]={0};
  6764. char guid[37]={0};
  6765. char tempdata[128]={0};
  6766. json_object *LogStatusNotification = json_object_new_object();
  6767. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6768. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6769. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6770. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6771. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6772. random_uuid(guid);
  6773. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6774. json_object_put(LogStatusNotification);
  6775. LWS_Send(message);
  6776. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6777. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6778. {
  6779. result = PASS;
  6780. }
  6781. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6782. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6783. return result;
  6784. }
  6785. int sendSecurityEventNotificationRequest()
  6786. {
  6787. mtrace();
  6788. int result = PASS;
  6789. char message[4096]={0};
  6790. char guid[37]={0};
  6791. char tempdata[128]={0};
  6792. json_object *SecurityEventNotification = json_object_new_object();
  6793. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6794. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6795. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6796. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6797. random_uuid(guid);
  6798. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6799. json_object_put(SecurityEventNotification);
  6800. LWS_Send(message);
  6801. sprintf(tempdata, "SecurityEventNotification,0");
  6802. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6803. {
  6804. result = PASS;
  6805. }
  6806. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6807. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6808. return result;
  6809. }
  6810. int sendSignCertificateRequest()
  6811. {
  6812. mtrace();
  6813. int result = PASS;
  6814. char message[4096]={0};
  6815. char guid[37]={0};
  6816. char tempdata[128]={0};
  6817. json_object *SignCertificate = json_object_new_object();
  6818. DEBUG_INFO("sendSignCertificateRequest...\n");
  6819. // Read csr file content
  6820. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6821. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6822. char *line = NULL;
  6823. size_t len = 0;
  6824. while(getline(&line, &len, fp) != -1)
  6825. {
  6826. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6827. {
  6828. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6829. }
  6830. }
  6831. fclose(fp);
  6832. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6833. random_uuid(guid);
  6834. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6835. json_object_put(SignCertificate);
  6836. LWS_Send(message);
  6837. sprintf(tempdata, "SignCertificate,0");
  6838. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6839. {
  6840. result = PASS;
  6841. }
  6842. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6843. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6844. return result;
  6845. }
  6846. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6847. {
  6848. mtrace();
  6849. int result = PASS;
  6850. char message[110]={0};
  6851. char guid[37]={0};
  6852. char tempdata[65]={0};
  6853. json_object *FirmwareStatusNotification = json_object_new_object();
  6854. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6855. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6856. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6857. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6858. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6859. random_uuid(guid);
  6860. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6861. json_object_put(FirmwareStatusNotification);
  6862. LWS_Send(message);
  6863. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6864. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6865. {
  6866. result = PASS;
  6867. }
  6868. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6869. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6870. return result;
  6871. }
  6872. //==========================================
  6873. // send confirm routine
  6874. //==========================================
  6875. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6876. {
  6877. mtrace();
  6878. int result = FAIL;
  6879. char message[100]={0};
  6880. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6881. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6882. LWS_Send(message);
  6883. result = TRUE;
  6884. return result;
  6885. }
  6886. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6887. {
  6888. mtrace();
  6889. int result = FAIL;
  6890. char message[100]={0};
  6891. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6892. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6893. LWS_Send(message);
  6894. result = TRUE;
  6895. return result;
  6896. }
  6897. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6898. {
  6899. mtrace();
  6900. int result = FAIL;
  6901. char message[100]={0};
  6902. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6903. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6904. LWS_Send(message);
  6905. result = TRUE;
  6906. return result;
  6907. }
  6908. int sendClearCacheConfirmation(char *uuid,char *payload)
  6909. {
  6910. mtrace();
  6911. int result = FAIL;
  6912. char message[500]={0};
  6913. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6914. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6915. LWS_Send(message);
  6916. return result;
  6917. }
  6918. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6919. {
  6920. mtrace();
  6921. int result = FAIL;
  6922. char message[500]={0};
  6923. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6924. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6925. LWS_Send(message);
  6926. return result;
  6927. }
  6928. int sendDataTransferConfirmation(char *uuid,char *payload)
  6929. {
  6930. mtrace();
  6931. char statusStr[20]={0};
  6932. char dataStr[10]={0};
  6933. char sstr[20]={0};
  6934. int c = 0;
  6935. char *loc;
  6936. int result = FAIL;
  6937. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6938. /**********************status**************************/
  6939. loc = strstr(payload, "status");
  6940. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6941. c = 0;
  6942. while (loc[3+strlen("status")+c] != '\"')
  6943. {
  6944. sstr[c] = loc[3+strlen("status")+c];
  6945. c++;
  6946. }
  6947. sstr[c] = '\0';
  6948. strcpy(statusStr, sstr);
  6949. /**********************data**************************/
  6950. loc = strstr(payload, "data");
  6951. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6952. c = 0;
  6953. while (loc[3+strlen("data")+c] != '\"')
  6954. {
  6955. sstr[c] = loc[3+strlen("data")+c];
  6956. c++;
  6957. }
  6958. sstr[c] = '\0';
  6959. strcpy(dataStr, sstr);
  6960. return result;
  6961. }
  6962. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6963. {
  6964. mtrace();
  6965. int result = FAIL;
  6966. char message[1000]={0};
  6967. int CompositeScheduleIndex = 0;
  6968. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6969. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6970. if(nPeriod == 0)
  6971. {
  6972. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6973. {
  6974. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6975. ,MESSAGE_TYPE_CALLRESULT
  6976. ,uuid
  6977. ,payload
  6978. ,connectorIdInt);
  6979. }
  6980. else
  6981. {
  6982. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6983. ,MESSAGE_TYPE_CALLRESULT
  6984. ,uuid
  6985. ,payload
  6986. ,connectorIdInt
  6987. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6988. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6989. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6990. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6991. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6992. }
  6993. }
  6994. else
  6995. {
  6996. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6997. ,MESSAGE_TYPE_CALLRESULT
  6998. ,uuid
  6999. ,payload
  7000. ,connectorIdInt
  7001. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7002. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7003. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7004. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7005. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7006. {
  7007. if (idx_sample == 0)
  7008. {
  7009. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7010. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7011. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7012. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7013. }
  7014. else
  7015. {
  7016. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7017. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7018. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7019. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7020. }
  7021. }
  7022. sprintf(message + strlen(message), "]}}]");
  7023. }
  7024. LWS_Send(message);
  7025. result = TRUE;
  7026. return result;
  7027. }
  7028. int sendGetConfigurationConfirmation(char *uuid)
  7029. {
  7030. mtrace();
  7031. int result = FAIL;
  7032. int MaxKeySupported = 0;
  7033. int sentConfigurationNumber= 0;
  7034. int sentunConfigurationNumber= 0;
  7035. char message[1024*10]={0};
  7036. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7037. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7038. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7039. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7040. ,MESSAGE_TYPE_CALLRESULT
  7041. ,uuid );
  7042. //configuration key
  7043. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7044. {
  7045. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7046. {
  7047. if (sentConfigurationNumber == 0)
  7048. {
  7049. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7050. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7051. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7052. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7053. }
  7054. else
  7055. {
  7056. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7057. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7058. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7059. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7060. }
  7061. sentConfigurationNumber = sentConfigurationNumber + 1;
  7062. }
  7063. }
  7064. sprintf(message + strlen(message), "]");
  7065. if(UnknownKeynum != 0)
  7066. {
  7067. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7068. //unkown key
  7069. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7070. {
  7071. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7072. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7073. if(sentunConfigurationNumber == 0)
  7074. {
  7075. sprintf(message + strlen(message), "\"%s\""
  7076. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7077. }
  7078. else
  7079. {
  7080. sprintf(message + strlen(message), ",\"%s\""
  7081. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7082. }
  7083. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7084. }
  7085. sprintf(message + strlen(message), "]");
  7086. }
  7087. sprintf(message + strlen(message), "}]");
  7088. LWS_Send(message);
  7089. return result;
  7090. }
  7091. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7092. {
  7093. mtrace();
  7094. int result = FAIL;
  7095. char message[400]={0};
  7096. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7097. if(strcmp(payload,"")==0)
  7098. {
  7099. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7100. }
  7101. else
  7102. {
  7103. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7104. }
  7105. LWS_Send(message);
  7106. result = TRUE;
  7107. return result;
  7108. }
  7109. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7110. {
  7111. mtrace();
  7112. int result = FAIL;
  7113. char message[80]={0};
  7114. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7115. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7116. LWS_Send(message);
  7117. result = TRUE;
  7118. return result;
  7119. }
  7120. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7121. {
  7122. mtrace();
  7123. int result = FAIL;
  7124. char message[80]={0};
  7125. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7126. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7127. LWS_Send(message);
  7128. result = TRUE;
  7129. return result;
  7130. }
  7131. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7132. {
  7133. mtrace();
  7134. int result = FAIL;
  7135. char message[80]={0};
  7136. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7137. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7138. LWS_Send(message);
  7139. result = TRUE;
  7140. return result;
  7141. }
  7142. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7143. {
  7144. mtrace();
  7145. int result = FAIL;
  7146. char message[80]={0};
  7147. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7148. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7149. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7150. LWS_Send(message);
  7151. result = TRUE;
  7152. return result;
  7153. }
  7154. int sendResetConfirmation(char *uuid,char *payload)
  7155. {
  7156. mtrace();
  7157. int result = FAIL;
  7158. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7159. char message[80]={0};
  7160. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7161. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7162. LWS_Send(message);
  7163. result = TRUE;
  7164. return result;
  7165. }
  7166. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7167. {
  7168. mtrace();
  7169. int result = FAIL;
  7170. char message[500]={0};
  7171. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7172. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7173. LWS_Send(message);
  7174. result = TRUE;
  7175. return result;
  7176. }
  7177. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7178. {
  7179. mtrace();
  7180. int result = FAIL;
  7181. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7182. char message[80]={0};
  7183. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7184. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7185. LWS_Send(message);
  7186. result = TRUE;
  7187. return result;
  7188. }
  7189. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7190. {
  7191. mtrace();
  7192. int result = FAIL;
  7193. char message[80]={0};
  7194. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7195. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7196. LWS_Send(message);
  7197. result = TRUE;
  7198. return result;
  7199. }
  7200. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7201. {
  7202. mtrace();
  7203. int result = FAIL;
  7204. char message[80]={0};
  7205. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7206. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7207. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7208. LWS_Send(message);
  7209. result = TRUE;
  7210. return result;
  7211. }
  7212. int sendUpdateFirmwareConfirmation(char *uuid)
  7213. {
  7214. mtrace();
  7215. int result = FAIL;
  7216. char message[60]={0};
  7217. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7218. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7219. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7220. LWS_Send(message);
  7221. result = TRUE;
  7222. return result;
  7223. }
  7224. int sendCertificateSignedConfirmation(char *uuid)
  7225. {
  7226. mtrace();
  7227. int result = PASS;
  7228. char message[4096]={0};
  7229. json_object *CertificateSigned = json_object_new_object();
  7230. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7231. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7232. sprintf(message,"[%d,\"%s\",%s]"
  7233. ,MESSAGE_TYPE_CALLRESULT
  7234. ,uuid
  7235. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7236. json_object_put(CertificateSigned);
  7237. LWS_Send(message);
  7238. return result;
  7239. }
  7240. int sendDeleteCertificateConfirmation(char *uuid)
  7241. {
  7242. mtrace();
  7243. int result = PASS;
  7244. char message[4096]={0};
  7245. json_object *DeleteCertificate = json_object_new_object();
  7246. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7247. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7248. sprintf(message,"[%d,\"%s\",%s]"
  7249. ,MESSAGE_TYPE_CALLRESULT
  7250. ,uuid
  7251. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7252. json_object_put(DeleteCertificate);
  7253. LWS_Send(message);
  7254. return result;
  7255. }
  7256. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7257. {
  7258. mtrace();
  7259. int result = PASS;
  7260. char message[4096]={0};
  7261. json_object *ExtendedTriggerMessage = json_object_new_object();
  7262. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7263. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7264. sprintf(message,"[%d,\"%s\",%s]"
  7265. ,MESSAGE_TYPE_CALLRESULT
  7266. ,uuid
  7267. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7268. json_object_put(ExtendedTriggerMessage);
  7269. LWS_Send(message);
  7270. return result;
  7271. }
  7272. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7273. {
  7274. mtrace();
  7275. int result = PASS;
  7276. char message[4096]={0};
  7277. json_object *GetInstalledCertificateIds = json_object_new_object();
  7278. json_object *certificateHashDataDatas = json_object_new_array();
  7279. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7280. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7281. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7282. {
  7283. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7284. {
  7285. json_object *certificateHashData = json_object_new_object();
  7286. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7287. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7288. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7289. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7290. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7291. }
  7292. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7293. }
  7294. else
  7295. {
  7296. json_object_put(certificateHashDataDatas);
  7297. }
  7298. sprintf(message,"[%d,\"%s\",%s]"
  7299. ,MESSAGE_TYPE_CALLRESULT
  7300. ,uuid
  7301. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7302. json_object_put(GetInstalledCertificateIds);
  7303. LWS_Send(message);
  7304. return result;
  7305. }
  7306. int sendGetLogConfirmation(char *uuid)
  7307. {
  7308. mtrace();
  7309. int result = PASS;
  7310. char message[4096]={0};
  7311. json_object *GetLog = json_object_new_object();
  7312. DEBUG_INFO("sendGetLogConfirmation...\n");
  7313. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7314. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7315. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7316. sprintf(message,"[%d,\"%s\",%s]"
  7317. ,MESSAGE_TYPE_CALLRESULT
  7318. ,uuid
  7319. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7320. json_object_put(GetLog);
  7321. LWS_Send(message);
  7322. return result;
  7323. }
  7324. int sendInstallCertificateConfirmation(char *uuid)
  7325. {
  7326. mtrace();
  7327. int result = PASS;
  7328. char message[4096]={0};
  7329. json_object *InstallCertificate = json_object_new_object();
  7330. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7331. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7332. sprintf(message,"[%d,\"%s\",%s]"
  7333. ,MESSAGE_TYPE_CALLRESULT
  7334. ,uuid
  7335. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7336. json_object_put(InstallCertificate);
  7337. LWS_Send(message);
  7338. return result;
  7339. }
  7340. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7341. {
  7342. mtrace();
  7343. int result = PASS;
  7344. char message[4096]={0};
  7345. json_object *SignedUpdateFirmware = json_object_new_object();
  7346. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7347. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7348. sprintf(message,"[%d,\"%s\",%s]"
  7349. ,MESSAGE_TYPE_CALLRESULT
  7350. ,uuid
  7351. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7352. json_object_put(SignedUpdateFirmware);
  7353. LWS_Send(message);
  7354. return result;
  7355. }
  7356. int sendUnknownConfirmation(char *uuid)
  7357. {
  7358. mtrace();
  7359. int result = PASS;
  7360. char message[256]={0};
  7361. DEBUG_INFO("sendUnknownConfirmation...\n");
  7362. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7363. LWS_Send(message);
  7364. return result;
  7365. }
  7366. //==========================================
  7367. // Handle server request routine Start
  7368. //==========================================
  7369. int handleCancelReservationRequest(char *uuid, char *payload)
  7370. {
  7371. mtrace();
  7372. int result = FAIL;
  7373. int gunNO = 0;
  7374. int reservationIdInt = -1;
  7375. char comfirmstr[20];
  7376. DEBUG_INFO("handleCancelReservationRequest...\n");
  7377. json_object *CancelReservation;
  7378. CancelReservation = json_tokener_parse(payload);
  7379. if(!is_error(CancelReservation))
  7380. {
  7381. // Required data
  7382. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7383. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7384. }
  7385. json_object_put(CancelReservation);
  7386. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7387. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7388. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7389. if(reservationIdInt != -1)
  7390. {
  7391. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7392. //check Transaction active
  7393. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7395. {
  7396. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7397. {
  7398. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7399. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7400. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7401. {
  7402. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7403. }
  7404. else
  7405. {
  7406. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7407. }
  7408. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7409. goto end;
  7410. }
  7411. }
  7412. for (int index = 0; index < CCS_QUANTITY; index++)
  7413. {
  7414. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7415. {
  7416. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7417. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7418. if(gunType[2] == GUN_TYPE_CCS)
  7419. {
  7420. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7421. }
  7422. else
  7423. {
  7424. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7425. }
  7426. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7427. goto end;
  7428. }
  7429. }
  7430. for (int index = 0; index < GB_QUANTITY; index++)
  7431. {
  7432. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7433. {
  7434. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7435. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7436. if(gunType[2] == GUN_TYPE_GBT)
  7437. {
  7438. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7439. }
  7440. else
  7441. {
  7442. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7443. }
  7444. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7445. goto end;
  7446. }
  7447. }
  7448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7449. {
  7450. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7451. {
  7452. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7453. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7454. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7455. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7456. goto end;
  7457. }
  7458. }
  7459. for (int index = 0; index < AC_QUANTITY; index++)
  7460. {
  7461. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7462. {
  7463. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7464. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7466. {
  7467. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7468. }
  7469. else
  7470. {
  7471. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7472. }
  7473. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7474. goto end;
  7475. }
  7476. }
  7477. }
  7478. //The reservationId does NOT match the reservationId
  7479. sendCancelReservationConfirmation(uuid, comfirmstr);
  7480. end:
  7481. // Fill in ocpp packet uuid
  7482. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7483. return result;
  7484. }
  7485. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7486. {
  7487. mtrace();
  7488. int result = FAIL;
  7489. int gunIndex = -1;
  7490. char typeStr[16]={0};
  7491. char comfirmstr[20];
  7492. int specificId = FALSE;
  7493. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7494. json_object *ChangeAvailability;
  7495. ChangeAvailability = json_tokener_parse(payload);
  7496. if(!is_error(ChangeAvailability))
  7497. {
  7498. // Required data
  7499. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7500. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7501. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7502. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7503. }
  7504. json_object_put(ChangeAvailability);
  7505. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7506. {
  7507. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7508. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7509. }
  7510. else if(gunIndex == 0)
  7511. {
  7512. for(int i=0; i < gunTotalNumber; i++)
  7513. {
  7514. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7515. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7516. }
  7517. }
  7518. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7519. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7520. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7521. {
  7522. specificId = TRUE;
  7523. }
  7524. if(specificId == FALSE)
  7525. goto end;
  7526. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7527. {
  7528. //----------------------gunIndex is 0 ------------------------------------------------//
  7529. if(gunIndex == 0)
  7530. {
  7531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7532. {
  7533. for(int i=0; i < gunTotalNumber; i++)
  7534. {
  7535. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7536. {
  7537. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7538. {
  7539. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7540. {
  7541. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7542. goto end;
  7543. }
  7544. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7545. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7546. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7547. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7548. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7549. {
  7550. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7551. goto end;
  7552. }
  7553. }
  7554. }//END FOR CHAdeMO_QUANTITY
  7555. for (int index = 0; index < CCS_QUANTITY; index++)
  7556. {
  7557. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7558. {
  7559. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7560. {
  7561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7562. goto end;
  7563. }
  7564. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7565. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7566. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7567. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7568. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7569. {
  7570. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7571. goto end;
  7572. }
  7573. }
  7574. }//END FOR CCS_QUANTITY
  7575. for (int index = 0; index < GB_QUANTITY; index++)
  7576. {
  7577. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7578. {
  7579. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7580. {
  7581. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7582. goto end;
  7583. }
  7584. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7585. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7586. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7589. {
  7590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7591. goto end;
  7592. }
  7593. }
  7594. }// END FOR GB_QUANTITY
  7595. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7596. {
  7597. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7598. {
  7599. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7600. {
  7601. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7602. goto end;
  7603. }
  7604. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7605. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7606. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7608. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7609. {
  7610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7611. goto end;
  7612. }
  7613. }
  7614. }// END FOR GENERAL_GUN_QUANTITY
  7615. for (int index = 0; index < AC_QUANTITY; index++)
  7616. {
  7617. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7618. {
  7619. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7620. {
  7621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7622. goto end;
  7623. }
  7624. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7625. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7626. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7628. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7629. {
  7630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7631. goto end;
  7632. }
  7633. }
  7634. }//END FOR AC_QUANTITY
  7635. }// END FOR gunTotalNumber
  7636. }
  7637. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7638. {
  7639. for(int i=0; i < gunTotalNumber; i++)
  7640. {
  7641. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7642. {
  7643. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7644. goto end;
  7645. }
  7646. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7647. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7648. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7649. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7650. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7651. {
  7652. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7653. goto end;
  7654. }
  7655. }
  7656. }
  7657. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7658. goto end;
  7659. }
  7660. //----------------------gunIndex is not 0 ------------------------------------------------//
  7661. //check Transaction active
  7662. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7663. {
  7664. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7665. {
  7666. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7667. {
  7668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7669. goto end;
  7670. }
  7671. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7672. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7673. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7676. {
  7677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7678. goto end;
  7679. }
  7680. else
  7681. {
  7682. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7684. goto end;
  7685. }
  7686. }
  7687. }//END FOR CHAdeMO_QUANTITY
  7688. for (int index = 0; index < CCS_QUANTITY; index++)
  7689. {
  7690. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7691. {
  7692. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7693. {
  7694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7695. goto end;
  7696. }
  7697. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7698. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7699. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7700. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7701. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7702. {
  7703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7704. goto end;
  7705. }
  7706. else
  7707. {
  7708. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7710. goto end;
  7711. }
  7712. }
  7713. }//END FOR CCS_QUANTITY
  7714. for (int index = 0; index < GB_QUANTITY; index++)
  7715. {
  7716. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7717. {
  7718. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7719. {
  7720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7721. goto end;
  7722. }
  7723. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7724. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7725. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7726. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7727. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7728. {
  7729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7730. goto end;
  7731. }
  7732. else
  7733. {
  7734. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7735. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7736. goto end;
  7737. }
  7738. }
  7739. }// END FOR GB_QUANTITY
  7740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7741. {
  7742. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7743. {
  7744. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7745. {
  7746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7747. goto end;
  7748. }
  7749. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7750. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7751. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7754. {
  7755. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7756. goto end;
  7757. }
  7758. else
  7759. {
  7760. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7761. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7762. goto end;
  7763. }
  7764. }
  7765. }// END FOR GENERAL_GUN_QUANTITY
  7766. for (int index = 0; index < AC_QUANTITY; index++)
  7767. {
  7768. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7769. {
  7770. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7771. {
  7772. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7773. goto end;
  7774. }
  7775. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7776. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7777. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7779. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7780. {
  7781. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7782. goto end;
  7783. }
  7784. else
  7785. {
  7786. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7787. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7788. goto end;
  7789. }
  7790. }
  7791. }//END FOR AC_QUANTITY
  7792. }//END FOR AvailabilityTypeStr[Inoperative]
  7793. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7794. {
  7795. //----------------------gunIndex is 0 ------------------------------------------------//
  7796. if(gunIndex == 0)
  7797. {
  7798. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7799. {
  7800. for(int i=0; i < gunTotalNumber; i++)
  7801. {
  7802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7803. {
  7804. 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
  7805. {
  7806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7807. goto end;
  7808. }
  7809. }//END FOR CHAdeMO_QUANTITY
  7810. for (int index = 0; index < CCS_QUANTITY; index++)
  7811. {
  7812. 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
  7813. {
  7814. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7815. goto end;
  7816. }
  7817. }//END FOR CCS_QUANTITY
  7818. for (int index = 0; index < GB_QUANTITY; index++)
  7819. {
  7820. 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
  7821. {
  7822. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7823. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7824. goto end;
  7825. }
  7826. }// END FOR GB_QUANTITY
  7827. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7828. {
  7829. 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
  7830. {
  7831. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7832. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7833. goto end;
  7834. }
  7835. }// END FOR GENERAL_GUN_QUANTITY
  7836. for (int index = 0; index < AC_QUANTITY; index++)
  7837. {
  7838. 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
  7839. {
  7840. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7841. goto end;
  7842. }
  7843. }//END FOR CHAdeMO_QUANTITY
  7844. }// END FOR gunTotalNumber
  7845. }
  7846. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7847. {
  7848. for(int i=0; i < gunTotalNumber; i++)
  7849. {
  7850. for (int index = 0; index < AC_QUANTITY; index++)
  7851. {
  7852. 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
  7853. {
  7854. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7855. goto end;
  7856. }
  7857. }//END FOR CHAdeMO_QUANTITY
  7858. } // END FOR gunTotalNumber
  7859. }
  7860. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7861. goto end;
  7862. }
  7863. //----------------------gunIndex is not 0 ------------------------------------------------//
  7864. //check Transaction active
  7865. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7866. {
  7867. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7868. {
  7869. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7870. goto end;
  7871. }
  7872. }//END FOR CHAdeMO_QUANTITY
  7873. for (int index = 0; index < CCS_QUANTITY; index++)
  7874. {
  7875. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7876. {
  7877. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7878. goto end;
  7879. }
  7880. }//END FOR CCS_QUANTITY
  7881. for (int index = 0; index < GB_QUANTITY; index++)
  7882. {
  7883. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7884. {
  7885. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7886. goto end;
  7887. }
  7888. }// END FOR GB_QUANTITY
  7889. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7890. {
  7891. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7892. {
  7893. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7894. goto end;
  7895. }
  7896. }// END FOR GENERAL_GUN_QUANTITY
  7897. for (int index = 0; index < AC_QUANTITY; index++)
  7898. {
  7899. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7900. {
  7901. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7902. goto end;
  7903. }
  7904. }//END FOR AC_QUANTITY
  7905. }//END FOR AvailabilityTypeStr[Operative]
  7906. end:
  7907. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7908. {
  7909. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7910. }
  7911. else
  7912. {
  7913. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7914. }
  7915. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7916. {
  7917. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7918. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7919. }
  7920. else if(gunIndex == 0)
  7921. {
  7922. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7923. {
  7924. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7925. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7926. }
  7927. }
  7928. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7929. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7930. return result;
  7931. }
  7932. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7933. {
  7934. mtrace();
  7935. int result = FAIL;
  7936. char keystr[40]={0};
  7937. char valuestr[256]={0};
  7938. char comfirmstr[20]={0};
  7939. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7940. json_object *ChangeConfiguration;
  7941. ChangeConfiguration = json_tokener_parse(payload);
  7942. if(!is_error(ChangeConfiguration))
  7943. {
  7944. // Required data
  7945. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7946. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7947. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7948. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7949. }
  7950. json_object_put(ChangeConfiguration);
  7951. if((uuid==NULL) || (payload ==NULL) )
  7952. {
  7953. DEBUG_ERROR("Payload is null\n");
  7954. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7955. }
  7956. else
  7957. {
  7958. int status = setKeyValue(keystr, valuestr);
  7959. switch(status)
  7960. {
  7961. case ConfigurationStatus_Accepted:
  7962. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7963. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7964. StoreConfigurationTable();
  7965. break;
  7966. case RebootRequired:
  7967. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7968. StoreConfigurationTable();
  7969. break;
  7970. case NotSupported:
  7971. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7972. break;
  7973. case ConfigurationStatus_Rejected:
  7974. default:
  7975. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7976. break;
  7977. }
  7978. }
  7979. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7980. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7981. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  7982. {
  7983. ChageWebSocketPingInterval(atoi(valuestr));
  7984. }
  7985. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7986. {
  7987. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7988. SetOcppConnStatus(FALSE);
  7989. }
  7990. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7991. {
  7992. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7993. }
  7994. return result;
  7995. }
  7996. int handleClearCacheRequest(char *uuid, char *payload)
  7997. {
  7998. mtrace();
  7999. int result = FAIL;
  8000. char comfirmstr[20];
  8001. char rmFileCmd[100]={0};
  8002. struct stat stats;
  8003. DEBUG_INFO("handleClearCacheRequest...\n");
  8004. stat("/Storage/OCPP_PH", &stats);
  8005. // Check for directory existence
  8006. if (S_ISDIR(stats.st_mode) == 1)
  8007. {}
  8008. else
  8009. {
  8010. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8011. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8012. system(rmFileCmd);
  8013. }
  8014. if(OCPP_cleanLocalCache())
  8015. {
  8016. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8017. }
  8018. else
  8019. {
  8020. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8021. }
  8022. sendClearCacheConfirmation(uuid, comfirmstr);
  8023. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8024. return result;
  8025. }
  8026. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8027. {
  8028. mtrace();
  8029. int result = FAIL;
  8030. int resultRename;
  8031. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8032. char chargingProfilePurposeStr[26]={0};
  8033. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8034. char tempchargingProfilePurposeStr[26]={0};
  8035. char str[100]={0};
  8036. char fname[200]={0};
  8037. char comfirmstr[20]={0};
  8038. char word[1600]={0};
  8039. int clearflag = FALSE;
  8040. int chargingProfileIdIsNULL = FALSE;
  8041. int connectorIsNULL = FALSE;
  8042. int chargingProfilePurposeIsNULL = FALSE;
  8043. int stackLevelIsNULL = FALSE;
  8044. //int GotoEnd = FALSE;
  8045. FILE *fptr1, *fptr2;
  8046. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8047. int n_chargingProfile=0;
  8048. int isEmptyFile = FALSE;
  8049. char sLineWord[1600]={0};
  8050. char chargingProfiles[10][100]={0};
  8051. int ChargeProfileCount = 0;
  8052. int ch;
  8053. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8054. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8055. json_object *ClearChargingProfile;
  8056. ClearChargingProfile = json_tokener_parse(payload);
  8057. if(!is_error(ClearChargingProfile))
  8058. {
  8059. // Optional data
  8060. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8061. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8062. else
  8063. chargingProfileIdIsNULL = TRUE;
  8064. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8065. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8066. else
  8067. connectorIsNULL = TRUE;
  8068. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8069. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8070. else
  8071. chargingProfilePurposeIsNULL = TRUE;
  8072. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8073. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8074. else
  8075. stackLevelIsNULL = TRUE;
  8076. }
  8077. json_object_put(ClearChargingProfile);
  8078. if(connectorIsNULL == FALSE)
  8079. {
  8080. switch(connectorIdInt)
  8081. {
  8082. case 0:
  8083. if(chargingProfilePurposeIsNULL == TRUE)
  8084. {
  8085. int l = 0;
  8086. strcpy(fname, ChargePointMaxProfile_JSON);
  8087. if((access(fname,F_OK))!=-1)
  8088. {
  8089. strcpy(chargingProfiles[l], fname);
  8090. l = l + 1;
  8091. }
  8092. strcpy(fname, TxDefaultProfile_0_JSON);
  8093. if((access(fname,F_OK))!=-1)
  8094. {
  8095. strcpy(chargingProfiles[l], fname);
  8096. l = l + 1;
  8097. }
  8098. ChargeProfileCount = l;
  8099. }
  8100. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8101. {
  8102. strcpy(fname, ChargePointMaxProfile_JSON);
  8103. if((access(fname,F_OK))!=-1)
  8104. {
  8105. strcpy(chargingProfiles[0], fname);
  8106. ChargeProfileCount = 1;
  8107. }
  8108. }
  8109. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8110. {
  8111. strcpy(fname, TxDefaultProfile_0_JSON);
  8112. if((access(fname,F_OK))!=-1)
  8113. {
  8114. strcpy(chargingProfiles[0], fname);
  8115. ChargeProfileCount = 1;
  8116. }
  8117. }
  8118. break;
  8119. default:
  8120. if(chargingProfilePurposeIsNULL == TRUE)
  8121. {
  8122. int m = 0;
  8123. memset(fname, 0, ARRAY_SIZE(fname));
  8124. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8125. if((access(fname,F_OK))!=-1)
  8126. {
  8127. strcpy(chargingProfiles[m], fname);
  8128. m = m + 1;
  8129. }
  8130. memset(fname, 0, ARRAY_SIZE(fname));
  8131. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8132. if((access(fname,F_OK))!=-1)
  8133. {
  8134. strcpy(chargingProfiles[m], fname);
  8135. m = m + 1;
  8136. }
  8137. ChargeProfileCount = m;
  8138. }
  8139. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8140. {
  8141. //strcpy(fname, TxDefaultProfile_1_JSON);
  8142. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8143. if((access(fname,F_OK))!=-1)
  8144. {
  8145. strcpy(chargingProfiles[0], fname);
  8146. ChargeProfileCount = 1;
  8147. }
  8148. }
  8149. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8150. {
  8151. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8152. if((access(fname,F_OK))!=-1)
  8153. {
  8154. strcpy(chargingProfiles[0], fname);
  8155. ChargeProfileCount = 1;
  8156. }
  8157. //strcpy(fname, TxProfile_1_JSON);
  8158. }
  8159. //strcpy(fname, ChargePointMaxProfile_JSON );
  8160. break;
  8161. }
  8162. }
  8163. else // Check all Charging Profiles
  8164. {
  8165. int i = 0;
  8166. char fnametemp[200]={0};
  8167. ChargeProfileCount = 0;
  8168. //Check ChargePointMaxProfile.json exit
  8169. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8170. {
  8171. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8172. i = i + 1;
  8173. }
  8174. //Check TxDefaultProfile_0.json exit
  8175. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8176. {
  8177. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8178. i = i + 1;
  8179. }
  8180. //Check TxDefaultProfile_%d.json
  8181. for(int j=1; j <= gunTotalNumber; j++)
  8182. {
  8183. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8184. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8185. if((access(fnametemp,F_OK))!=-1)
  8186. {
  8187. strcpy(chargingProfiles[i], fnametemp);
  8188. i = i + 1;
  8189. }
  8190. }
  8191. //Check TxProfile_%d.json
  8192. for(int j=1; j <= gunTotalNumber; j++)
  8193. {
  8194. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8195. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8196. if((access(fnametemp,F_OK))!=-1)
  8197. {
  8198. strcpy(chargingProfiles[i], fnametemp);
  8199. i = i + 1;
  8200. }
  8201. }
  8202. ChargeProfileCount = i;
  8203. }// End connectorIsNULL is TRUE
  8204. if(ChargeProfileCount == 0)
  8205. {
  8206. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8207. goto end;
  8208. }
  8209. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8210. {
  8211. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8212. goto end;
  8213. }
  8214. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8215. {
  8216. memset(str, 0, ARRAY_SIZE(str));
  8217. // clear temp file
  8218. sprintf(str,"rm -f %s",temp);
  8219. system(str);
  8220. for(int k=0; k < ChargeProfileCount; k++)
  8221. {
  8222. memset(str, 0, ARRAY_SIZE(str));
  8223. //clear file in C
  8224. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8225. system(str);
  8226. }
  8227. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8228. goto end;
  8229. }
  8230. else if(connectorIsNULL == TRUE)
  8231. {
  8232. for(int k=0; k < ChargeProfileCount; k++)
  8233. {
  8234. fptr1 = fopen(chargingProfiles[k], "r");
  8235. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8236. //Check Charging Profile Count
  8237. while(fscanf(fptr1, "%s", word) != EOF)
  8238. {
  8239. //DEBUG_INFO("word=%s\n",word);
  8240. if(strstr(word, "chargingProfileId")!= NULL)
  8241. {
  8242. //DEBUG_INFO("test chargingProfileId \n");
  8243. n_chargingProfile = n_chargingProfile + 1;
  8244. //DEBUG_INFO("chargingProfileId Found\n");
  8245. }
  8246. }
  8247. rewind(fptr1);
  8248. //search Charging Profile Element
  8249. //int i= 0;
  8250. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8251. {
  8252. json_object *tmpProfilee;
  8253. tmpProfilee = json_tokener_parse(sLineWord);
  8254. if(!is_error(tmpProfilee))
  8255. {
  8256. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8257. {
  8258. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8259. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8260. }
  8261. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8262. {
  8263. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8264. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8265. }
  8266. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8267. {
  8268. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8269. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8270. }
  8271. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8272. {
  8273. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8274. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8275. }
  8276. }
  8277. json_object_put(tmpProfilee);
  8278. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8279. {
  8280. //------- not write to fptr2-------//
  8281. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8282. //clearflag = TRUE;
  8283. }
  8284. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8285. {
  8286. //------- not write to fptr2-------//
  8287. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8288. }
  8289. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8290. {
  8291. //------- not write to fptr2-------//
  8292. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8293. }
  8294. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8295. {
  8296. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8297. }
  8298. else
  8299. {
  8300. fprintf(fptr2, sLineWord);//writing data into file
  8301. }
  8302. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8303. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8304. if(clearflag == TRUE)
  8305. {
  8306. fclose(fptr1);
  8307. fclose(fptr2);
  8308. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8309. system(str);
  8310. // clear temp file
  8311. sprintf(str,"rm -f %s",temp);
  8312. system(str);
  8313. }
  8314. else
  8315. {
  8316. fclose(fptr1);
  8317. fclose(fptr2);
  8318. memset(str, 0, ARRAY_SIZE(str));
  8319. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8320. system(str);
  8321. resultRename = rename(temp, chargingProfiles[k]);
  8322. if(resultRename == 0)
  8323. {
  8324. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8325. }
  8326. else
  8327. {
  8328. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8329. }
  8330. if(comfirmstr[0]== 0)
  8331. {
  8332. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8333. }
  8334. //Check chargingProfile is empty file
  8335. /*------ Read the file ----------------*/
  8336. fptr1=fopen(chargingProfiles[k],"r");
  8337. ch=fgetc(fptr1);
  8338. rewind(fptr1);
  8339. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8340. if(ch!=EOF)
  8341. {
  8342. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8343. {
  8344. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8345. if(sLineWord[0]=='\0')
  8346. {
  8347. isEmptyFile = TRUE;
  8348. break;
  8349. }
  8350. else
  8351. {
  8352. isEmptyFile = FALSE;
  8353. break;
  8354. }
  8355. }
  8356. }
  8357. else
  8358. isEmptyFile = TRUE;
  8359. fclose(fptr1);
  8360. if(isEmptyFile == TRUE)
  8361. {
  8362. memset(str, 0, ARRAY_SIZE(str));
  8363. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8364. system(str);
  8365. }
  8366. }
  8367. }// End of while(int k=0; k < ChargePointCount; k++)
  8368. }
  8369. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8370. {
  8371. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8372. for(int k=0; k < ChargeProfileCount; k++)
  8373. {
  8374. fptr1 = fopen(chargingProfiles[k], "r");
  8375. fptr2 = fopen(temp, "w+");
  8376. //Check Charging Profile Count
  8377. while(fscanf(fptr1, "%s", word) != EOF)
  8378. {
  8379. //DEBUG_INFO("word=%s\n",word);
  8380. if(strstr(word, "chargingProfileId")!= NULL)
  8381. {
  8382. n_chargingProfile = n_chargingProfile + 1;
  8383. }
  8384. }
  8385. rewind(fptr1);
  8386. //search Charging Profile Element
  8387. //int i= 0;
  8388. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8389. {
  8390. json_object *tmpProfilee;
  8391. tmpProfilee = json_tokener_parse(sLineWord);
  8392. if(!is_error(tmpProfilee))
  8393. {
  8394. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8395. {
  8396. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8397. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8398. }
  8399. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8400. {
  8401. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8402. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8403. }
  8404. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8405. {
  8406. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8407. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8408. }
  8409. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8410. {
  8411. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8412. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8413. }
  8414. }
  8415. json_object_put(tmpProfilee);
  8416. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8417. {
  8418. //------- not write to fptr2-------//
  8419. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8420. //clearflag = TRUE;
  8421. }
  8422. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8423. {
  8424. //------- not write to fptr2-------//
  8425. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8426. }
  8427. else if(stackLevelIsNULL == TRUE)
  8428. {
  8429. //Clear Whole File
  8430. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8431. clearflag = TRUE;
  8432. break;
  8433. }
  8434. else
  8435. {
  8436. fprintf(fptr2, sLineWord);//writing data into file
  8437. }
  8438. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8439. }
  8440. if(clearflag == TRUE)
  8441. {
  8442. fclose(fptr1);
  8443. fclose(fptr2);
  8444. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8445. system(str);
  8446. // clear temp file
  8447. sprintf(str,"rm -f %s",temp);
  8448. system(str);
  8449. }
  8450. else
  8451. {
  8452. fclose(fptr1);
  8453. fclose(fptr2);
  8454. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8455. system(str);
  8456. resultRename = rename(temp, chargingProfiles[k]);
  8457. if(resultRename == 0)
  8458. {
  8459. DEBUG_INFO("File ChargingProfile renamed successfully");
  8460. }
  8461. else
  8462. {
  8463. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8464. }
  8465. if(comfirmstr[0]== 0)
  8466. {
  8467. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8468. }
  8469. //Check chargingProfile is empty file
  8470. /*------ Read the file ----------------*/
  8471. fptr1=fopen(chargingProfiles[k],"r");
  8472. ch=fgetc(fptr1);
  8473. rewind(fptr1);
  8474. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8475. if(ch!=EOF)
  8476. {
  8477. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8478. {
  8479. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8480. if(sLineWord[0]=='\0')
  8481. {
  8482. isEmptyFile = TRUE;
  8483. break;
  8484. }
  8485. else
  8486. {
  8487. isEmptyFile = FALSE;
  8488. break;
  8489. }
  8490. }
  8491. }
  8492. else
  8493. isEmptyFile = TRUE;
  8494. fclose(fptr1);
  8495. if(isEmptyFile == TRUE)
  8496. {
  8497. memset(str, 0, ARRAY_SIZE(str));
  8498. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8499. system(str);
  8500. }
  8501. /*------- End of reading ---------------*/
  8502. }
  8503. } // while(int k=0; k < ChargeProfileCount; k++)
  8504. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8505. end:
  8506. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8507. {
  8508. if(connectorIdInt == 0)
  8509. {
  8510. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8511. {
  8512. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8513. }
  8514. }
  8515. else
  8516. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8517. }
  8518. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8519. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8520. return result;
  8521. }
  8522. void createFirmwareVersionByDataTransfer(void)
  8523. {
  8524. json_object *FirmwareDataTransfer = json_object_new_object();
  8525. // AC & DC model
  8526. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8527. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8528. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8529. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8530. // DC model
  8531. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8532. {
  8533. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8534. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8535. (gunType[3] != GUN_TYPE_UNKNOWN))
  8536. {
  8537. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8538. }
  8539. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8540. {
  8541. // DS DM DW
  8542. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8543. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8544. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8545. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8546. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8547. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8548. }
  8549. else
  8550. {
  8551. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8552. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8553. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8554. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8555. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8556. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8557. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8558. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8559. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8560. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8561. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8562. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8563. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8564. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8565. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8566. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8567. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8568. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8569. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8570. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8571. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8572. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8573. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8574. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8575. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8576. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8577. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8578. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8579. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8580. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8581. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8582. }
  8583. }
  8584. // 4G model
  8585. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8586. {
  8587. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8588. }
  8589. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8590. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8591. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8592. json_object_put(FirmwareDataTransfer);
  8593. }
  8594. int handleDataTransferRequest(char *uuid, char *payload)
  8595. {
  8596. mtrace();
  8597. json_object *response = json_object_new_object();
  8598. int result = FAIL;
  8599. char tempvendorId[255]={0};
  8600. char tempmessageId[50]={0};
  8601. char tempdata[512]={0};
  8602. char message[2048]={0};
  8603. DEBUG_INFO("handleDataTransferRequest...\n");
  8604. if((uuid != NULL) && (payload != NULL))
  8605. {
  8606. json_object *DataTransfer;
  8607. DataTransfer = json_tokener_parse(payload);
  8608. if(!is_error(DataTransfer))
  8609. {
  8610. // Required data
  8611. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8612. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8613. // Optional data
  8614. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8615. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8616. if(json_object_object_get(DataTransfer, "data") != NULL)
  8617. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8618. result = PASS;
  8619. }
  8620. json_object_put(DataTransfer);
  8621. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8622. {
  8623. // Send all moudle firmware version on EVSE
  8624. createFirmwareVersionByDataTransfer();
  8625. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8626. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  8627. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8628. json_object_put(response);
  8629. }
  8630. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8631. {
  8632. system("/usr/bin/run_tmate_restart.sh &");
  8633. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8634. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8635. json_object_put(response);
  8636. }
  8637. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8638. {
  8639. json_object *data;
  8640. data = json_tokener_parse(tempdata);
  8641. if(!is_error(data))
  8642. {
  8643. 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))
  8644. {
  8645. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8646. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8647. if(json_object_object_get(data, "SOC") != NULL)
  8648. {
  8649. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8650. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8651. }
  8652. if(json_object_object_get(data, "Energy") != NULL)
  8653. {
  8654. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8655. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8656. }
  8657. if(json_object_object_get(data, "Duration") != NULL)
  8658. {
  8659. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8660. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8661. }
  8662. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8663. }
  8664. else
  8665. {
  8666. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8667. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8668. }
  8669. }
  8670. else
  8671. {
  8672. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8673. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8674. }
  8675. json_object_put(data);
  8676. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8677. json_object_put(response);
  8678. }
  8679. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8680. {
  8681. json_object *data;
  8682. data = json_tokener_parse(tempdata);
  8683. if(!is_error(data))
  8684. {
  8685. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8686. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8687. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8688. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8689. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8690. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8691. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8692. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8693. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8694. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8695. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8696. }
  8697. else
  8698. {
  8699. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8700. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8701. }
  8702. json_object_put(data);
  8703. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8704. json_object_put(response);
  8705. }
  8706. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8707. {
  8708. json_object *data;
  8709. data = json_tokener_parse(tempdata);
  8710. if(!is_error(data))
  8711. {
  8712. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8713. if(json_object_object_get(data, "idToken") != NULL)
  8714. {
  8715. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8716. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8717. }
  8718. if(json_object_object_get(data, "price") != NULL)
  8719. {
  8720. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8721. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8722. }
  8723. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8724. }
  8725. else
  8726. {
  8727. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8728. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8729. }
  8730. json_object_put(data);
  8731. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8732. json_object_put(response);
  8733. }
  8734. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8735. {
  8736. json_object *data;
  8737. data = json_tokener_parse(tempdata);
  8738. if(!is_error(data))
  8739. {
  8740. if(json_object_object_get(data, "txId") != NULL)
  8741. {
  8742. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8743. for(int idx = 0;idx<gunTotalNumber;idx++)
  8744. {
  8745. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8746. {
  8747. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8748. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8749. if(json_object_object_get(data, "description") != NULL)
  8750. {
  8751. // California pricing V1.0
  8752. DEBUG_INFO("California pricing V1.0\n");
  8753. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8754. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8755. }
  8756. else
  8757. {
  8758. // California pricing V1.1
  8759. DEBUG_INFO("California pricing V1.1\n");
  8760. if(json_object_object_get(data, "timestamp") != NULL)
  8761. {
  8762. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8763. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8764. }
  8765. if(json_object_object_get(data, "meterValue") != NULL)
  8766. {
  8767. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8768. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8769. }
  8770. if(json_object_object_get(data, "cost") != NULL)
  8771. {
  8772. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8773. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8774. }
  8775. if(json_object_object_get(data, "state") != NULL)
  8776. {
  8777. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8778. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8779. }
  8780. if(json_object_object_get(data, "chargingPrice") != NULL)
  8781. {
  8782. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8783. {
  8784. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8785. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8786. }
  8787. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8788. {
  8789. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8790. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8791. }
  8792. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8793. {
  8794. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8795. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8796. }
  8797. }
  8798. if(json_object_object_get(data, "idlePrice") != NULL)
  8799. {
  8800. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8801. {
  8802. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8803. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8804. }
  8805. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8806. {
  8807. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8808. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8809. }
  8810. }
  8811. if(json_object_object_get(data, "nextPeriod") != NULL)
  8812. {
  8813. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8814. {
  8815. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8816. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8817. }
  8818. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8819. {
  8820. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8821. {
  8822. 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")));
  8823. 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"));
  8824. }
  8825. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8826. {
  8827. 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")));
  8828. 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"));
  8829. }
  8830. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8831. {
  8832. 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")));
  8833. 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"));
  8834. }
  8835. }
  8836. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8837. {
  8838. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8839. {
  8840. 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")));
  8841. 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"));
  8842. }
  8843. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8844. {
  8845. 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")));
  8846. 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"));
  8847. }
  8848. }
  8849. }
  8850. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8851. {
  8852. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8853. {
  8854. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8855. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8856. }
  8857. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8858. {
  8859. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8860. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8861. }
  8862. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8863. {
  8864. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8865. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8866. }
  8867. }
  8868. }
  8869. }
  8870. }
  8871. }
  8872. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8873. }
  8874. else
  8875. {
  8876. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8877. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8878. }
  8879. json_object_put(data);
  8880. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8881. json_object_put(response);
  8882. }
  8883. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8884. {
  8885. json_object *data;
  8886. data = json_tokener_parse(tempdata);
  8887. if(!is_error(data))
  8888. {
  8889. if(json_object_object_get(data, "txId") != NULL)
  8890. {
  8891. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8892. for(int idx = 0;idx<gunTotalNumber;idx++)
  8893. {
  8894. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8895. {
  8896. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8897. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8898. if(json_object_object_get(data, "description") != NULL)
  8899. {
  8900. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8901. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8902. }
  8903. }
  8904. }
  8905. }
  8906. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8907. }
  8908. else
  8909. {
  8910. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8911. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8912. }
  8913. json_object_put(data);
  8914. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8915. json_object_put(response);
  8916. }
  8917. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8918. {
  8919. json_object *data;
  8920. data = json_tokener_parse(tempdata);
  8921. if(!is_error(data))
  8922. {
  8923. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8924. if(json_object_object_get(data, "Content_Type") != NULL)
  8925. {
  8926. 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))
  8927. {
  8928. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8929. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8930. {
  8931. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8932. }
  8933. }
  8934. else
  8935. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8936. }
  8937. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8938. }
  8939. else
  8940. {
  8941. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8942. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8943. }
  8944. json_object_put(data);
  8945. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8946. json_object_put(response);
  8947. }
  8948. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8949. {
  8950. json_object *data;
  8951. data = json_tokener_parse(tempdata);
  8952. if(!is_error(data))
  8953. {
  8954. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8955. if(json_object_object_get(data, "Page_Index") != NULL)
  8956. {
  8957. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8958. }
  8959. if(json_object_object_get(data, "Duration") != NULL)
  8960. {
  8961. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8962. }
  8963. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8964. }
  8965. else
  8966. {
  8967. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8968. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8969. }
  8970. json_object_put(data);
  8971. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8972. json_object_put(response);
  8973. }
  8974. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8975. {
  8976. json_object *data;
  8977. data = json_tokener_parse(tempdata);
  8978. if(!is_error(data))
  8979. {
  8980. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8981. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8982. {
  8983. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8984. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8985. else
  8986. {
  8987. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8988. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8989. }
  8990. }
  8991. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8992. {
  8993. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8994. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8995. else
  8996. {
  8997. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8998. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8999. }
  9000. }
  9001. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9002. {
  9003. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9004. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9005. else
  9006. {
  9007. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9008. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9009. }
  9010. }
  9011. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9012. {
  9013. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9014. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9015. else
  9016. {
  9017. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9018. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9019. }
  9020. }
  9021. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9022. {
  9023. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9024. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9025. else
  9026. {
  9027. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9028. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9029. }
  9030. }
  9031. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9032. {
  9033. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9034. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9035. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9036. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9037. else
  9038. {
  9039. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9040. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9041. }
  9042. }
  9043. if(json_object_object_get(data, "isAuthentication") != NULL)
  9044. {
  9045. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9046. {
  9047. case 0:
  9048. case 1:
  9049. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9050. break;
  9051. default:
  9052. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9053. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9054. break;
  9055. }
  9056. }
  9057. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9058. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9059. }
  9060. else
  9061. {
  9062. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9063. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9064. }
  9065. json_object_put(data);
  9066. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9067. json_object_put(response);
  9068. }
  9069. else
  9070. {
  9071. // Can not find valid message id
  9072. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9073. }
  9074. }
  9075. else
  9076. {
  9077. // Payload is null
  9078. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9079. }
  9080. LWS_Send(message);
  9081. return result;
  9082. }
  9083. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9084. {
  9085. mtrace();
  9086. int result = FAIL;
  9087. int connectorIdInt, durationInt;
  9088. char chargingRateUnitStr[4]={0};
  9089. char comfirmstr[20];
  9090. int confirmPeriods = 0;
  9091. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9092. json_object *GetCompositeSchedule;
  9093. GetCompositeSchedule = json_tokener_parse(payload);
  9094. if(!is_error(GetCompositeSchedule))
  9095. {
  9096. // Required data
  9097. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9098. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9099. else
  9100. connectorIdInt = -1;
  9101. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9102. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9103. else
  9104. durationInt = 86400;
  9105. // Optional data
  9106. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9107. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9108. }
  9109. json_object_put(GetCompositeSchedule);
  9110. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9111. if((connectorIdInt == 0) ||
  9112. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9113. {
  9114. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9115. struct StructChargingProfile tmpProfile[1];
  9116. if(strstr(chargingRateUnitStr, "W") != NULL)
  9117. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9118. else
  9119. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9120. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9121. {
  9122. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9123. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9124. }
  9125. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9126. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9127. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9128. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9129. {
  9130. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9131. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9132. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9133. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9134. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9135. {
  9136. confirmPeriods = idx;
  9137. break;
  9138. }
  9139. }
  9140. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9141. {
  9142. confirmPeriods += 1;
  9143. }
  9144. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9145. }
  9146. else
  9147. {
  9148. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9149. }
  9150. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9151. return result;
  9152. }
  9153. int handleGetConfigurationRequest(char *uuid, char *payload)
  9154. {
  9155. mtrace();
  9156. int result = FAIL;
  9157. int MaxKeySupported = 0;
  9158. int n_keys = 0;
  9159. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9160. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9161. json_object *GetConfiguration;
  9162. GetConfiguration = json_tokener_parse(payload);
  9163. if(!is_error(GetConfiguration))
  9164. {
  9165. // Optional data
  9166. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9167. {
  9168. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9169. {
  9170. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9171. n_keys = idx + 1;
  9172. }
  9173. }
  9174. }
  9175. json_object_put(GetConfiguration);
  9176. UnknownKeynum = 0;
  9177. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9178. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9179. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9180. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9181. if(n_keys != 0)
  9182. {
  9183. for(int i=0;i<n_keys;i++)
  9184. {
  9185. getKeyValue(requestKey[i]);
  9186. }
  9187. }
  9188. else
  9189. {
  9190. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9191. getKeyValue("");
  9192. }
  9193. processUnkownKey();
  9194. sendGetConfigurationConfirmation(uuid);
  9195. return result;
  9196. }
  9197. static char fnamePlusPath[100]={0};
  9198. static char fnamePWithNoPath[60]={0};
  9199. void checkUploadLog(void)
  9200. {
  9201. FILE *fp;
  9202. /* Open the command for reading. */
  9203. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9204. if (fp == NULL) {
  9205. DEBUG_WARN("Failed to run command\n" );
  9206. exit(1);
  9207. }
  9208. int ftppathlen = 0;
  9209. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9210. int i = 0;
  9211. /* Read the output a line at a time - output it. */
  9212. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9213. if(i==0)
  9214. {
  9215. ftppathlen = strlen(fnamePlusPath);
  9216. DEBUG_INFO("%s\n", fnamePlusPath);
  9217. fnamePlusPath[ftppathlen]='\0';
  9218. break;
  9219. }
  9220. i= i+1;
  9221. }
  9222. /* close */
  9223. pclose(fp);
  9224. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9225. {
  9226. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9227. {
  9228. fnamePlusPath[k]='\0';
  9229. }
  9230. }
  9231. i=1;
  9232. //char fname[60]={0};
  9233. while(i < ftppathlen)
  9234. {
  9235. int len=ftppathlen-i;
  9236. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9237. {
  9238. DEBUG_INFO("compare '/' all right\n");
  9239. break;
  9240. }
  9241. i=i+1;
  9242. }
  9243. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9244. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9245. fnamePWithNoPath[i+1] = '\0';
  9246. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9247. {
  9248. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9249. {
  9250. fnamePWithNoPath[j]='\0';
  9251. }
  9252. }
  9253. FILE* fp1 = fopen(fnamePlusPath, "r");
  9254. if (fp1)
  9255. {
  9256. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9257. // file exists
  9258. fclose(fp1);
  9259. }
  9260. else
  9261. {
  9262. // file doesn't exist
  9263. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9264. }
  9265. }
  9266. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9267. {
  9268. mtrace();
  9269. int result = FAIL;
  9270. time_t CurrentTime;
  9271. struct tm *tm;
  9272. pthread_t th_Status;
  9273. CurrentTime = time(NULL);
  9274. tm = localtime(&CurrentTime);
  9275. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9276. 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);
  9277. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9278. if(!interLock.isGetDiagnosticGoing)
  9279. {
  9280. interLock.isGetDiagnosticGoing = 1;
  9281. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9282. sleep(1);
  9283. }
  9284. else
  9285. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9286. return result;
  9287. }
  9288. void* GetDiagnosticsProcess(void* data)
  9289. {
  9290. pthread_detach(pthread_self());
  9291. mtrace();
  9292. int retriesInt=0, retryIntervalInt=0;
  9293. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9294. 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};
  9295. int port=0;
  9296. int isSuccess = FALSE;
  9297. char ftpbuf[200]={0};
  9298. char cmdBuf[2048];
  9299. struct tm *tmNow;
  9300. time_t CurrentTime;
  9301. struct tm tmStart;
  9302. struct tm tmStop;
  9303. CurrentTime = time(NULL);
  9304. tmNow=localtime(&CurrentTime);
  9305. uint16_t targetYear, targetMonth;
  9306. json_object *GetDiagnostics;
  9307. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9308. GetDiagnostics = json_tokener_parse(data);
  9309. if(!is_error(GetDiagnostics))
  9310. {
  9311. // Required data
  9312. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9313. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9314. // Optional data
  9315. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9316. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9317. else
  9318. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9319. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9320. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9321. else
  9322. retryIntervalInt = 30;
  9323. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9324. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9325. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9326. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9327. }
  9328. json_object_put(GetDiagnostics);
  9329. // Pack log to compress file
  9330. 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) &&
  9331. (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))
  9332. {
  9333. // Pack system log
  9334. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9335. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9336. targetYear = tmStart.tm_year;
  9337. targetMonth = tmStart.tm_mon;
  9338. do
  9339. {
  9340. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9341. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9342. if(targetMonth+1>=13)
  9343. {
  9344. targetYear += 1;
  9345. targetMonth = 1;
  9346. }
  9347. else
  9348. {
  9349. targetMonth += 1;
  9350. }
  9351. }while((targetYear < (tmNow->tm_year+1900)) ||
  9352. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9353. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9354. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9355. system(cmdBuf);
  9356. // Pack charging & event log
  9357. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9358. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9359. targetYear = tmStart.tm_year;
  9360. targetMonth = tmStart.tm_mon;
  9361. do
  9362. {
  9363. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9364. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9365. if(targetMonth+1>=13)
  9366. {
  9367. targetYear += 1;
  9368. targetMonth = 1;
  9369. }
  9370. else
  9371. {
  9372. targetMonth += 1;
  9373. }
  9374. }while((targetYear < (tmNow->tm_year+1900)) ||
  9375. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9376. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9377. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9378. system(cmdBuf);
  9379. // Combine log file
  9380. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9381. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9382. }
  9383. else
  9384. {
  9385. system("exec /root/logPackTools 'log' 6");
  9386. }
  9387. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9388. system(cmdBuf);
  9389. checkUploadLog();
  9390. //****************location*******************/
  9391. if(strcmp(locationstr,"")==0)
  9392. {
  9393. DEBUG_INFO("location is <Empty>!\n");
  9394. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9395. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9396. goto end;
  9397. }
  9398. memset(protocol, 0, ARRAY_SIZE(protocol));
  9399. memset(user, 0, ARRAY_SIZE(user) );
  9400. memset(password, 0, ARRAY_SIZE(password));
  9401. memset(host, 0, ARRAY_SIZE(host));
  9402. memset(path, 0, ARRAY_SIZE(path));
  9403. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9404. memset(host1, 0, ARRAY_SIZE(host1));
  9405. memset(path1, 0, ARRAY_SIZE(path1));
  9406. /*location: ftp://user:password@host:port/path*/
  9407. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9408. if((access(fnamePlusPath,F_OK))!=-1)
  9409. {
  9410. DEBUG_INFO("fnamePlusPath exist.\n");
  9411. }
  9412. else
  9413. {
  9414. DEBUG_INFO("fnamePlusPath not exist!\n");
  9415. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9416. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9417. goto end;
  9418. }
  9419. if(strchr(locationstr,'@')==NULL)
  9420. {
  9421. sscanf(locationstr,
  9422. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9423. protocol, host, &port, path);
  9424. strcpy(user,"anonymous");
  9425. strcpy(password,"");
  9426. }
  9427. else
  9428. {
  9429. //DEBUG_INFO("pch=%s\n", pch);
  9430. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9431. protocol, user, password, host, &port, path);
  9432. }
  9433. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9434. {
  9435. DEBUG_INFO("protocol is not ftp/http ! \n");
  9436. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9437. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9438. goto end;
  9439. }
  9440. if(strncmp(locationstr,"http", 4) == 0)
  9441. {
  9442. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9443. sprintf(ftppath,"/%s", path);
  9444. do
  9445. {
  9446. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9447. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9448. sleep(3);
  9449. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9450. if(!isSuccess)
  9451. {
  9452. DEBUG_INFO("Diagnostics fail.\n");
  9453. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9454. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9455. sleep(retryIntervalInt);
  9456. }
  9457. else
  9458. {
  9459. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9460. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9461. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9462. }
  9463. retriesInt--;
  9464. }while((isSuccess == 0)&&(retriesInt >= 0));
  9465. }
  9466. else
  9467. {
  9468. sscanf(host,"%[^/]%s",host1, path1);
  9469. if(strlen(path) > 0)
  9470. sprintf(ftppath,"/%s", path);
  9471. else
  9472. sprintf(ftppath,"/%s", path1);
  9473. int ftppathlen=strlen(ftppath);
  9474. int i=1;
  9475. char filenametemp[50];
  9476. while(i < ftppathlen)
  9477. {
  9478. int len=ftppathlen-i;
  9479. if(ftppath[len]== 47) // '/' ascll code: 47
  9480. {
  9481. DEBUG_INFO("find '/' all right\n");
  9482. break;
  9483. }
  9484. i=i+1;
  9485. }
  9486. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9487. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9488. filenametemp[i+1] = 0;
  9489. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9490. if(port == 0)
  9491. port = 21;
  9492. do
  9493. {
  9494. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9495. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9496. sleep(3);
  9497. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9498. if(!isSuccess)
  9499. {
  9500. DEBUG_INFO("Diagnostics fail.\n");
  9501. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9502. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9503. sleep(retryIntervalInt);
  9504. }
  9505. else
  9506. {
  9507. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9508. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9509. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9510. }
  9511. retriesInt--;
  9512. }while((!isSuccess)&&(retriesInt >= 0));
  9513. }
  9514. end:
  9515. system("rm -f /mnt/*");
  9516. sleep(5);
  9517. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9518. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9519. interLock.isGetDiagnosticGoing = 0;
  9520. pthread_exit(NULL);
  9521. }
  9522. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9523. {
  9524. mtrace();
  9525. int result = FAIL;
  9526. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9527. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9528. {
  9529. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9530. locallistVersion = -1;
  9531. }
  9532. else
  9533. {
  9534. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9535. OCPP_getListVerion();
  9536. }
  9537. //from db.OCPP_getListVerion
  9538. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9539. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9540. sendGetLocalListVersionConfirmation(uuid,"");
  9541. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9542. return result;
  9543. }
  9544. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9545. {
  9546. mtrace();
  9547. int result = FAIL;
  9548. int connectorIdInt=-1;
  9549. int tempIndex = 0;
  9550. int connectorIdIsNULL, chargingProfileIsNULL;
  9551. char comfirmstr[20]={0};
  9552. char cmdBuf[512];
  9553. json_object *RemoteStartTransaction;
  9554. FILE *fp;
  9555. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9556. if(server_pending == TRUE)
  9557. {
  9558. return 0;
  9559. }
  9560. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9561. RemoteStartTransaction = json_tokener_parse(payload);
  9562. if(!is_error(RemoteStartTransaction))
  9563. {
  9564. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9565. {
  9566. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9567. }
  9568. else
  9569. {
  9570. connectorIdIsNULL = TRUE;
  9571. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9572. {
  9573. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9574. {
  9575. connectorIdIsNULL = FALSE;
  9576. connectorIdInt = (gun_index+1);
  9577. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9578. break;
  9579. }
  9580. }
  9581. }
  9582. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9583. {
  9584. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9585. // Required data
  9586. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9587. // Optional data
  9588. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9589. {
  9590. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9591. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9592. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9593. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9594. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9595. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9596. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9597. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9598. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9599. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9600. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9601. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9602. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9603. {
  9604. 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")));
  9605. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9606. 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"));
  9607. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9608. 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"));
  9609. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9610. 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")));
  9611. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9612. {
  9613. 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++)
  9614. {
  9615. 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"));
  9616. 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"));
  9617. 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)
  9618. 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"));
  9619. }
  9620. }
  9621. }
  9622. }
  9623. else
  9624. {
  9625. chargingProfileIsNULL = TRUE;
  9626. }
  9627. }
  9628. }
  9629. else
  9630. {
  9631. connectorIdIsNULL = TRUE;
  9632. }
  9633. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9634. {
  9635. DEBUG_WARN("Connector id is NULL\n.");
  9636. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9637. goto end;
  9638. }
  9639. /*
  9640. enum _SYSTEM_STATUS
  9641. {
  9642. S_BOOTING = 0,
  9643. S_IDLE, = 1
  9644. S_AUTHORIZING, = 2
  9645. S_REASSIGN_CHECK, = 3
  9646. S_REASSIGN, = 4
  9647. S_PRECHARGE, = 5
  9648. S_PREPARING_FOR_EV, = 6
  9649. S_PREPARING_FOR_EVSE, = 7
  9650. S_CHARGING, = 8
  9651. S_TERMINATING, = 9
  9652. S_COMPLETE, = 10
  9653. S_ALARM, = 11
  9654. S_FAULT = 12
  9655. }
  9656. */
  9657. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9658. {
  9659. //check Transaction active
  9660. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9661. {
  9662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9663. {
  9664. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9665. }
  9666. else
  9667. {
  9668. tempIndex = connectorIdInt -1;
  9669. }
  9670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9671. {
  9672. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9673. {
  9674. 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))
  9675. {
  9676. //Reserved
  9677. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9678. }
  9679. 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))
  9680. {
  9681. //Reserved
  9682. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9683. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9684. goto end;
  9685. }
  9686. else
  9687. {
  9688. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9689. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9690. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9691. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9692. {
  9693. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9694. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9695. goto end;
  9696. }
  9697. }//END FOR ELSE
  9698. }
  9699. }// END FOR CHAdeMO_QUANTITY
  9700. }
  9701. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9702. {
  9703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9704. {
  9705. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9706. }
  9707. else
  9708. {
  9709. tempIndex = connectorIdInt -1;
  9710. }
  9711. for (int index = 0; index < CCS_QUANTITY; index++)
  9712. {
  9713. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9714. {
  9715. 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))
  9716. {
  9717. //Reserved
  9718. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9719. }
  9720. 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))
  9721. {
  9722. //Reserved
  9723. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9724. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9725. goto end;
  9726. }
  9727. else
  9728. {
  9729. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9730. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9731. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9732. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9733. {
  9734. DEBUG_WARN("CCS connector not allow start\n.");
  9735. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9736. goto end;
  9737. }
  9738. }// END FOR ELSE
  9739. }
  9740. }// END FOR CCS_QUANTITY
  9741. }
  9742. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9743. {
  9744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9745. {
  9746. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9747. }
  9748. else
  9749. {
  9750. tempIndex = connectorIdInt -1;
  9751. }
  9752. for (int index = 0; index < GB_QUANTITY; index++)
  9753. {
  9754. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9755. {
  9756. 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))
  9757. {
  9758. //Reserved
  9759. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9760. }
  9761. 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))
  9762. {
  9763. //Reserved
  9764. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9765. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9766. goto end;
  9767. }
  9768. else
  9769. {
  9770. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9771. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9772. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9773. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9774. {
  9775. DEBUG_WARN("GB connector not allow start\n.");
  9776. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9777. goto end;
  9778. }
  9779. }// END FOR ELSE
  9780. }
  9781. } // END FOR GB_QUANTITY
  9782. }
  9783. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9784. {
  9785. tempIndex = connectorIdInt -1;
  9786. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9787. {
  9788. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9789. {
  9790. 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))
  9791. {
  9792. //Reserved
  9793. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9794. }
  9795. 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))
  9796. {
  9797. //Reserved
  9798. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9799. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9800. goto end;
  9801. }
  9802. else
  9803. {
  9804. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9805. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9806. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9807. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9808. {
  9809. DEBUG_WARN("GB connector not allow start\n.");
  9810. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9811. goto end;
  9812. }
  9813. }// END FOR ELSE
  9814. }
  9815. } // END FOR GB_QUANTITY
  9816. }
  9817. else
  9818. {
  9819. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9820. {
  9821. tempIndex = 2;
  9822. }
  9823. else
  9824. {
  9825. tempIndex = connectorIdInt -1;
  9826. }
  9827. for (int index = 0; index < AC_QUANTITY; index++)
  9828. {
  9829. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9830. {
  9831. 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))
  9832. {
  9833. //Reserved
  9834. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9835. }
  9836. 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))
  9837. {
  9838. //Reserved
  9839. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9840. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9841. goto end;
  9842. }
  9843. else
  9844. {
  9845. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9846. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9847. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9848. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9849. {
  9850. DEBUG_WARN("AC connector not allow start\n.");
  9851. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9852. goto end;
  9853. }
  9854. }//END FOR ELSE
  9855. }
  9856. }// END FOR AC_QUANTITY
  9857. }
  9858. if(chargingProfileIsNULL == FALSE)
  9859. {
  9860. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9861. {
  9862. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9863. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9864. //memset idTag
  9865. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9866. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9867. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9868. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9869. // Save profile to file
  9870. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9871. system(cmdBuf);
  9872. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9873. fp = fopen(cmdBuf, "w");
  9874. 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));
  9875. fclose(fp);
  9876. }
  9877. else
  9878. {
  9879. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9880. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9881. }
  9882. }
  9883. else
  9884. {
  9885. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9886. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9887. //memset idTag
  9888. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9889. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9890. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9891. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9892. }
  9893. }
  9894. else
  9895. {
  9896. DEBUG_WARN("Connector id over\n.");
  9897. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9898. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9899. }
  9900. end:
  9901. json_object_put(RemoteStartTransaction);
  9902. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9903. {
  9904. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9905. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9906. }
  9907. //OCPP send RemoteStartConfirmation by first.
  9908. sendRemoteStartConfirmation(uuid, comfirmstr);
  9909. return result;
  9910. }
  9911. int handleRemoteStartRequest(char *uuid, char *payload)
  9912. {
  9913. mtrace();
  9914. int result = PASS;
  9915. int connectorIdInt=-1;
  9916. int tempIndex = 0;
  9917. char comfirmstr[20]={0};
  9918. char cmdBuf[512];
  9919. json_object *RemoteStartTransaction;
  9920. FILE *fp;
  9921. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9922. if(server_pending == TRUE)
  9923. {
  9924. result = FAIL;
  9925. }
  9926. RemoteStartTransaction = json_tokener_parse(payload);
  9927. if(!is_error(RemoteStartTransaction))
  9928. {
  9929. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9930. {
  9931. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9932. }
  9933. else
  9934. {
  9935. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9936. {
  9937. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9938. {
  9939. connectorIdInt = (gun_index+1);
  9940. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9941. break;
  9942. }
  9943. }
  9944. }
  9945. if(connectorIdInt == 0)
  9946. {
  9947. DEBUG_WARN("Connector id shall not equal 0.\n");
  9948. result = FAIL;
  9949. }
  9950. else if(connectorIdInt == -1)
  9951. {
  9952. DEBUG_INFO("Connector id does not specific.\n");
  9953. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9954. {
  9955. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  9956. // Required data
  9957. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9958. // Optional data
  9959. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9960. {
  9961. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9962. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9963. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9964. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9965. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9966. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9967. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9968. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9969. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9970. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9971. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9972. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9973. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9974. {
  9975. 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")));
  9976. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9977. 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"));
  9978. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9979. 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"));
  9980. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9981. 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")));
  9982. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9983. {
  9984. 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++)
  9985. {
  9986. 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"));
  9987. 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"));
  9988. 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)
  9989. 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"));
  9990. }
  9991. }
  9992. }
  9993. }
  9994. else
  9995. {
  9996. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  9997. }
  9998. }
  9999. }
  10000. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10001. {
  10002. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10003. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10004. // Required data
  10005. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10006. // Optional data
  10007. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10008. {
  10009. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10010. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10011. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10012. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10013. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10014. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10015. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10016. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10017. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10018. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10019. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10020. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10021. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10022. {
  10023. 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")));
  10024. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10025. 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"));
  10026. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10027. 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"));
  10028. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10029. 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")));
  10030. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10031. {
  10032. 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++)
  10033. {
  10034. 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"));
  10035. 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"));
  10036. 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)
  10037. 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"));
  10038. }
  10039. }
  10040. }
  10041. }
  10042. else
  10043. {
  10044. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10045. }
  10046. }
  10047. else
  10048. {
  10049. DEBUG_WARN("Connector id is over maximun value.\n");
  10050. result = FAIL;
  10051. }
  10052. }
  10053. if(result == PASS)
  10054. {
  10055. if(connectorIdInt > 0)
  10056. {
  10057. //check Transaction active
  10058. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10059. {
  10060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10061. {
  10062. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10063. }
  10064. else
  10065. {
  10066. tempIndex = connectorIdInt -1;
  10067. }
  10068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10069. {
  10070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10071. {
  10072. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10073. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10074. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10075. {
  10076. //Reserved
  10077. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10078. }
  10079. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10080. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10081. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10082. {
  10083. //Reserved
  10084. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10086. goto end;
  10087. }
  10088. else
  10089. {
  10090. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10091. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10092. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10093. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10094. {
  10095. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10096. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10097. goto end;
  10098. }
  10099. }//END FOR ELSE
  10100. }
  10101. }// END FOR CHAdeMO_QUANTITY
  10102. }
  10103. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10104. {
  10105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10106. {
  10107. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10108. }
  10109. else
  10110. {
  10111. tempIndex = connectorIdInt -1;
  10112. }
  10113. for (int index = 0; index < CCS_QUANTITY; index++)
  10114. {
  10115. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10116. {
  10117. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10118. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10119. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10120. {
  10121. //Reserved
  10122. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10123. }
  10124. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10125. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10126. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10127. {
  10128. //Reserved
  10129. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10130. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10131. goto end;
  10132. }
  10133. else
  10134. {
  10135. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10136. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10137. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10138. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10139. {
  10140. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10141. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10142. goto end;
  10143. }
  10144. }// END FOR ELSE
  10145. }
  10146. }// END FOR CCS_QUANTITY
  10147. }
  10148. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10149. {
  10150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10151. {
  10152. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10153. }
  10154. else
  10155. {
  10156. tempIndex = connectorIdInt -1;
  10157. }
  10158. for (int index = 0; index < GB_QUANTITY; index++)
  10159. {
  10160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10161. {
  10162. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10163. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10164. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10165. {
  10166. //Reserved
  10167. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10168. }
  10169. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10170. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10171. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10172. {
  10173. //Reserved
  10174. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10175. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10176. goto end;
  10177. }
  10178. else
  10179. {
  10180. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10181. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10182. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10183. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10184. {
  10185. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10186. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10187. goto end;
  10188. }
  10189. }// END FOR ELSE
  10190. }
  10191. } // END FOR GB_QUANTITY
  10192. }
  10193. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10194. {
  10195. tempIndex = connectorIdInt -1;
  10196. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10197. {
  10198. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10199. {
  10200. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10201. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10202. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10203. {
  10204. //Reserved
  10205. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10206. }
  10207. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10208. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10209. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10210. {
  10211. //Reserved
  10212. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10213. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10214. goto end;
  10215. }
  10216. else
  10217. {
  10218. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10219. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10220. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10221. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10222. {
  10223. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10224. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10225. goto end;
  10226. }
  10227. }// END FOR ELSE
  10228. }
  10229. } // END FOR GB_QUANTITY
  10230. }
  10231. else
  10232. {
  10233. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10234. {
  10235. tempIndex = 2;
  10236. }
  10237. else
  10238. {
  10239. tempIndex = connectorIdInt -1;
  10240. }
  10241. for (int index = 0; index < AC_QUANTITY; index++)
  10242. {
  10243. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10244. {
  10245. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10246. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10247. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10248. {
  10249. //Reserved
  10250. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10251. }
  10252. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10253. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10254. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10255. {
  10256. //Reserved
  10257. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10258. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10259. goto end;
  10260. }
  10261. else
  10262. {
  10263. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10264. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10265. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10266. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10267. {
  10268. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10269. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10270. goto end;
  10271. }
  10272. }//END FOR ELSE
  10273. }
  10274. }// END FOR AC_QUANTITY
  10275. }
  10276. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10277. {
  10278. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10279. {
  10280. // Save profile to file
  10281. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10282. system(cmdBuf);
  10283. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10284. fp = fopen(cmdBuf, "w");
  10285. 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));
  10286. fclose(fp);
  10287. }
  10288. else
  10289. {
  10290. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10291. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10292. goto end;
  10293. }
  10294. }
  10295. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10296. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10297. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10298. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10299. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10300. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10301. }
  10302. else
  10303. {
  10304. uint8_t isHasIdleConnector = FALSE;
  10305. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10306. {
  10307. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10308. {
  10309. isHasIdleConnector = TRUE;
  10310. break;
  10311. }
  10312. }
  10313. if(isHasIdleConnector == TRUE)
  10314. {
  10315. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10316. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10317. {
  10318. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10319. {
  10320. // Save profile to file
  10321. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10322. system(cmdBuf);
  10323. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10324. fp = fopen(cmdBuf, "w");
  10325. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10326. fclose(fp);
  10327. refreshStartTimer(&clientTime.RemoteStartWait);
  10328. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10329. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10330. }
  10331. else
  10332. {
  10333. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10335. }
  10336. }
  10337. }
  10338. else
  10339. {
  10340. DEBUG_INFO("There is not any connector is idle.\n");
  10341. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10342. }
  10343. }
  10344. }
  10345. else
  10346. {
  10347. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10348. }
  10349. end:
  10350. json_object_put(RemoteStartTransaction);
  10351. sendRemoteStartConfirmation(uuid, comfirmstr);
  10352. return result;
  10353. }
  10354. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10355. {
  10356. mtrace();
  10357. int result = FAIL;
  10358. int match = FALSE;
  10359. int GunNO = 0;
  10360. int tempIndex = 0;
  10361. int transactionIdInt=0;
  10362. int transactionIdIsNULL= TRUE;
  10363. char comfirmstr[20];
  10364. json_object *RemoteStopTransaction;
  10365. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10366. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10367. if(server_pending == TRUE)
  10368. {
  10369. return 0;
  10370. }
  10371. RemoteStopTransaction = json_tokener_parse(payload);
  10372. if(!is_error(RemoteStopTransaction))
  10373. {
  10374. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10375. {
  10376. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10377. transactionIdIsNULL = FALSE;
  10378. }
  10379. }
  10380. json_object_put(RemoteStopTransaction);
  10381. if(transactionIdIsNULL == FALSE)
  10382. {
  10383. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10384. {
  10385. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10386. {
  10387. //check Transaction active
  10388. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10389. {
  10390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10391. {
  10392. tempIndex = ((gun_index==2) ? 1: 0);
  10393. }
  10394. else
  10395. {
  10396. tempIndex = gun_index;
  10397. }
  10398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10399. {
  10400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10401. {
  10402. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10403. {
  10404. match = TRUE;
  10405. GunNO = gun_index;
  10406. }
  10407. }
  10408. }// END FOR CHAdeMO_QUANTITY
  10409. }
  10410. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10411. {
  10412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10413. {
  10414. tempIndex = ((gun_index==2) ? 1: 0);
  10415. }
  10416. else
  10417. {
  10418. tempIndex = gun_index;
  10419. }
  10420. for (int index = 0; index < CCS_QUANTITY; index++)
  10421. {
  10422. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10423. {
  10424. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10425. {
  10426. match = TRUE;
  10427. GunNO = gun_index;
  10428. }
  10429. }
  10430. }// END FOR CCS_QUANTITY
  10431. }
  10432. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10433. {
  10434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10435. {
  10436. tempIndex = ((gun_index==2) ? 1: 0);
  10437. }
  10438. else
  10439. {
  10440. tempIndex = gun_index;
  10441. }
  10442. for (int index = 0; index < GB_QUANTITY; index++)
  10443. {
  10444. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10445. {
  10446. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10447. {
  10448. match = TRUE;
  10449. GunNO = gun_index;
  10450. }
  10451. }
  10452. }// END FOR GB_QUANTITY
  10453. }
  10454. else if(gunType[gun_index] == GUN_TYPE_DO)
  10455. {
  10456. tempIndex = gun_index;
  10457. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10458. {
  10459. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10460. {
  10461. 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
  10462. {
  10463. match = TRUE;
  10464. GunNO = gun_index;
  10465. }
  10466. }
  10467. }// END FOR GB_QUANTITY
  10468. }
  10469. else
  10470. {
  10471. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10472. {
  10473. tempIndex = 2;
  10474. }
  10475. else
  10476. {
  10477. tempIndex = gun_index;
  10478. }
  10479. for (int index = 0; index < AC_QUANTITY; index++)
  10480. {
  10481. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10482. {
  10483. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10484. {
  10485. match = TRUE;
  10486. GunNO = gun_index;
  10487. }
  10488. }
  10489. }// END FOR CHAdeMO_QUANTITY
  10490. } // END FOR AC ELSE
  10491. }// CHECK IF ResponseTransactionId == transactionIdInt
  10492. }//END FOR
  10493. if( match == TRUE)
  10494. {
  10495. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10496. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10497. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10498. }
  10499. else
  10500. {
  10501. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10502. }
  10503. }
  10504. else
  10505. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10506. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10507. return result;
  10508. }
  10509. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10510. {
  10511. mtrace();
  10512. int result = FAIL;
  10513. int connectorIdInt=0, reservationIdInt=0;
  10514. int tempIndex = 0;
  10515. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10516. char comfirmstr[20]={0};
  10517. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10518. int c = 0;
  10519. char *loc;
  10520. //char *ptr;
  10521. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10522. strcpy(sstrtemp, stringtrimspace(payload));
  10523. //***(1)connectorId ****/
  10524. c=0;
  10525. loc = strstr(sstrtemp, "connectorId");
  10526. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10527. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10528. {
  10529. sstr[c] = loc[strlen("connectorId")+2+c];
  10530. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10531. c++;
  10532. }
  10533. sstr[c] = '\0';
  10534. connectorIdInt = atoi(sstr);
  10535. //***(2)expiryDate ****/
  10536. loc = strstr(sstrtemp, "expiryDate");
  10537. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10538. c = 0;
  10539. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10540. {
  10541. sstr[c] = loc[3+strlen("expiryDate")+c];
  10542. c++;
  10543. }
  10544. sstr[c] = '\0';
  10545. strcpy(expiryDatestr, sstr);
  10546. //***(3)idTag ****/
  10547. loc = strstr(sstrtemp, "idTag");
  10548. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10549. c = 0;
  10550. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10551. {
  10552. sstr[c] = loc[3+strlen("idTag")+c];
  10553. c++;
  10554. }
  10555. sstr[c] = '\0';
  10556. strcpy(idTagstr, sstr);
  10557. //***(4)parentIdTag ****/
  10558. loc = strstr(sstrtemp, "parentIdTag");
  10559. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10560. c = 0;
  10561. if(loc == NULL)
  10562. {
  10563. strcpy(parentIdTagstr, "");
  10564. }
  10565. else
  10566. {
  10567. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10568. {
  10569. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10570. c++;
  10571. }
  10572. sstr[c] = '\0';
  10573. strcpy(parentIdTagstr, sstr);
  10574. }
  10575. //***(5)reservationId ****/
  10576. c=0;
  10577. loc = strstr(sstrtemp, "reservationId");
  10578. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10579. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10580. {
  10581. sstr[c] = loc[strlen("reservationId")+2+c];
  10582. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10583. c++;
  10584. }
  10585. sstr[c] = '\0';
  10586. reservationIdInt = atoi(sstr);
  10587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10588. /*
  10589. enum SYSTEM_STATUS
  10590. {
  10591. SYS_MODE_BOOTING = 0,
  10592. SYS_MODE_IDLE = 1,
  10593. SYS_MODE_AUTHORIZING = 2,
  10594. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10595. SYS_MODE_REASSIGN = 4,
  10596. SYS_MODE_PREPARING = 5,
  10597. SYS_MODE_PREPARE_FOR_EV = 6,
  10598. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10599. SYS_MODE_CHARGING = 8,
  10600. SYS_MODE_TERMINATING = 9,
  10601. SYS_MODE_COMPLETE = 10,
  10602. SYS_MODE_ALARM = 11,
  10603. SYS_MODE_FAULT = 12,
  10604. SYS_MODE_RESERVATION = 13,
  10605. SYS_MODE_BOOKING = 14,
  10606. SYS_MODE_MAINTAIN = 15,
  10607. SYS_MODE_DEBUG = 16,
  10608. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10609. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10610. SYS_MODE_UPDATE = 19
  10611. };
  10612. */
  10613. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10614. {
  10615. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10616. goto end;
  10617. }
  10618. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10619. {
  10620. //check Transaction active
  10621. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10622. {
  10623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10624. {
  10625. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10626. }
  10627. else
  10628. {
  10629. tempIndex = connectorIdInt -1;
  10630. }
  10631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10632. {
  10633. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10634. {
  10635. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10636. {
  10637. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10638. {
  10639. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10640. {
  10641. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10643. }
  10644. 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'))
  10645. {
  10646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10647. }
  10648. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10649. {
  10650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10651. }
  10652. else
  10653. {
  10654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10655. }
  10656. }
  10657. 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
  10658. {
  10659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10660. }
  10661. }
  10662. else
  10663. {
  10664. //replace reservation
  10665. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10667. }
  10668. }
  10669. } // END FOR CHAdeMO_QUANTITY
  10670. }
  10671. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10672. {
  10673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10674. {
  10675. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10676. }
  10677. else
  10678. {
  10679. tempIndex = connectorIdInt -1;
  10680. }
  10681. for (int index = 0; index < CCS_QUANTITY; index++)
  10682. {
  10683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10684. {
  10685. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10686. {
  10687. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10688. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10689. {
  10690. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10691. {
  10692. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10694. }
  10695. 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'))
  10696. {
  10697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10698. }
  10699. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10700. {
  10701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10702. }
  10703. else
  10704. {
  10705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10706. }
  10707. }
  10708. 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
  10709. {
  10710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10711. }
  10712. }
  10713. else
  10714. {
  10715. //replace reservation
  10716. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10718. }
  10719. }
  10720. } // END FOR CCS_QUANTITY
  10721. }
  10722. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10723. {
  10724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10725. {
  10726. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10727. }
  10728. else
  10729. {
  10730. tempIndex = connectorIdInt -1;
  10731. }
  10732. for (int index = 0; index < GB_QUANTITY; index++)
  10733. {
  10734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10735. {
  10736. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10737. {
  10738. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10739. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10740. {
  10741. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10742. {
  10743. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10745. }
  10746. 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'))
  10747. {
  10748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10749. }
  10750. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10751. {
  10752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10753. }
  10754. else
  10755. {
  10756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10757. }
  10758. }
  10759. 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
  10760. {
  10761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10762. }
  10763. }
  10764. else
  10765. {
  10766. //replace reservation
  10767. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10769. }
  10770. }
  10771. }// END FOR GB_QUANTITY
  10772. }
  10773. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10774. {
  10775. tempIndex = connectorIdInt -1;
  10776. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10777. {
  10778. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10779. {
  10780. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10781. {
  10782. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10783. 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
  10784. {
  10785. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10786. {
  10787. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10789. }
  10790. 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'))
  10791. {
  10792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10793. }
  10794. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10795. {
  10796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10797. }
  10798. else
  10799. {
  10800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10801. }
  10802. }
  10803. 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
  10804. {
  10805. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10806. }
  10807. }
  10808. else
  10809. {
  10810. //replace reservation
  10811. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10813. }
  10814. }
  10815. }// END FOR GB_QUANTITY
  10816. }
  10817. else
  10818. {
  10819. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10820. {
  10821. tempIndex = 2;
  10822. }
  10823. else
  10824. {
  10825. tempIndex = (connectorIdInt -1);
  10826. }
  10827. for (int index = 0; index < AC_QUANTITY; index++)
  10828. {
  10829. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10830. {
  10831. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10832. {
  10833. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10834. {
  10835. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10836. {
  10837. 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))
  10838. {
  10839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10840. }
  10841. else
  10842. {
  10843. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10845. }
  10846. }
  10847. 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'))
  10848. {
  10849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10850. }
  10851. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10852. {
  10853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10854. }
  10855. else
  10856. {
  10857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10858. }
  10859. }
  10860. 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
  10861. {
  10862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10863. }
  10864. }
  10865. else
  10866. {
  10867. //replace reservation
  10868. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10869. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10870. }
  10871. }
  10872. } // END FOR AC_QUANTITY
  10873. }
  10874. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10875. }
  10876. else if(connectorIdInt == 0)
  10877. {
  10878. //check Transaction active
  10879. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10880. {
  10881. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10882. {
  10883. 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'))
  10884. {
  10885. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10886. goto end;
  10887. }
  10888. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10889. {
  10890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10891. goto end;
  10892. }
  10893. 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
  10894. {
  10895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10896. goto end;
  10897. }
  10898. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10899. {
  10900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10901. goto end;
  10902. }
  10903. }
  10904. }// END FOR CHAdeMO_QUANTITY
  10905. for (int index = 0; index < CCS_QUANTITY; index++)
  10906. {
  10907. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10908. {
  10909. 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'))
  10910. {
  10911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10912. goto end;
  10913. }
  10914. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10915. {
  10916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10917. goto end;
  10918. }
  10919. 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
  10920. {
  10921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10922. goto end;
  10923. }
  10924. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10925. {
  10926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10927. goto end;
  10928. }
  10929. }
  10930. } // END FOR CCS_QUANTITY
  10931. for (int index = 0; index < GB_QUANTITY; index++)
  10932. {
  10933. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10934. {
  10935. 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'))
  10936. {
  10937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10938. goto end;
  10939. }
  10940. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10941. {
  10942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10943. goto end;
  10944. }
  10945. 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
  10946. {
  10947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10948. goto end;
  10949. }
  10950. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10951. {
  10952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10953. goto end;
  10954. }
  10955. }
  10956. } // END FOR GB_QUANTITY
  10957. for (int index = 0; index < AC_QUANTITY; index++)
  10958. {
  10959. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10960. {
  10961. 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'))
  10962. {
  10963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10964. goto end;
  10965. }
  10966. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10967. {
  10968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10969. goto end;
  10970. }
  10971. 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
  10972. {
  10973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10974. goto end;
  10975. }
  10976. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10977. {
  10978. 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))
  10979. {
  10980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10981. goto end;
  10982. }
  10983. }
  10984. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10985. {
  10986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10987. goto end;
  10988. }
  10989. }
  10990. }// END FOR AC_QUANTITY
  10991. //The connectorId is 0
  10992. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10994. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10995. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10996. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10997. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10998. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10999. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11000. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11001. result = TRUE;
  11002. return result;
  11003. }
  11004. else
  11005. {
  11006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11007. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11008. }
  11009. if(strcmp(comfirmstr,"Accepted") == 0)
  11010. {
  11011. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11012. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11013. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11014. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11015. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11016. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11017. result = TRUE;
  11018. return result;
  11019. }
  11020. end:
  11021. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11022. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11023. return result;
  11024. }
  11025. int handleResetRequest(char *uuid, char *payload)
  11026. {
  11027. mtrace();
  11028. int result = FAIL;
  11029. char sstr[10]={0},sstrtemp[30]={ 0 };
  11030. char typestr[10]={0};
  11031. char comfirmstr[20]={0};
  11032. int c = 0;
  11033. char *loc;
  11034. DEBUG_INFO("handleResetRequest...\n");
  11035. strcpy(sstrtemp, stringtrimspace(payload));
  11036. loc = strstr(sstrtemp, "type");
  11037. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11038. c = 0;
  11039. while (loc[3+strlen("type")+c] != '\"')
  11040. {
  11041. sstr[c] = loc[3+strlen("type")+c];
  11042. c++;
  11043. }
  11044. sstr[c] = '\0';
  11045. strcpy(typestr,sstr);
  11046. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  11047. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11048. {
  11049. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  11050. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11051. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11052. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11053. }
  11054. else
  11055. {
  11056. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11057. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11058. result = PASS;
  11059. }
  11060. sendResetConfirmation(uuid, comfirmstr);
  11061. return result;
  11062. }
  11063. int handleSendLocalListRequest(char *uuid, char *payload)
  11064. {
  11065. mtrace();
  11066. int result = FAIL;
  11067. char comfirmstr[20];
  11068. int checkState_Faulted = FALSE;
  11069. json_object *SendLocalList;
  11070. DEBUG_INFO("handleSendLocalListRequest...\n");
  11071. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11072. {
  11073. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11074. goto end;
  11075. }
  11076. //check Charge Point state
  11077. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11078. {
  11079. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11080. {
  11081. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11082. }
  11083. }
  11084. for (int index = 0; index < CCS_QUANTITY; index++)
  11085. {
  11086. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11087. {
  11088. checkState_Faulted = TRUE; //OCPP Status
  11089. }
  11090. }
  11091. for (int index = 0; index < GB_QUANTITY; index++)
  11092. {
  11093. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11094. {
  11095. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11096. }
  11097. }
  11098. //check Charge Point state
  11099. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11100. {
  11101. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11102. {
  11103. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11104. }
  11105. }
  11106. //check Charge Point state
  11107. for (int index = 0; index < AC_QUANTITY; index++)
  11108. {
  11109. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11110. {
  11111. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11112. }
  11113. }
  11114. if(checkState_Faulted == TRUE)
  11115. {
  11116. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11117. goto end;
  11118. }
  11119. // Parsing payload
  11120. SendLocalList = json_tokener_parse(payload);
  11121. if(!is_error(SendLocalList))
  11122. {
  11123. // Required data
  11124. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11125. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11126. // Optional data
  11127. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11128. {
  11129. //Check UpdateType
  11130. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11131. {
  11132. //Local list full update
  11133. DEBUG_INFO("Local list full update.\n");
  11134. OCPP_getListVerion();
  11135. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11136. {
  11137. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11138. goto end;
  11139. }
  11140. OCPP_cleanLocalList();
  11141. }
  11142. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11143. {
  11144. //Local list different update
  11145. DEBUG_INFO("Local list different update.\n");
  11146. OCPP_getListVerion();
  11147. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11148. {
  11149. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11150. goto end;
  11151. }
  11152. }
  11153. else
  11154. {
  11155. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11156. goto end;
  11157. }
  11158. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11159. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11160. {
  11161. 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")));
  11162. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11163. {
  11164. 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")));
  11165. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11166. 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")));
  11167. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11168. 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")));
  11169. }
  11170. // Add to db
  11171. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11172. {
  11173. //Local list full update
  11174. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11175. idx,
  11176. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11177. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11178. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11179. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11180. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11181. // update list
  11182. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11183. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11184. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11185. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11186. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11187. }
  11188. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11189. {
  11190. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11191. idx,
  11192. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11193. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11194. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11195. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11196. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11197. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11198. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11199. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11200. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11201. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11202. }
  11203. }
  11204. }
  11205. else
  11206. {
  11207. //Check UpdateType
  11208. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11209. {
  11210. //Local list full update
  11211. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11212. OCPP_cleanLocalList();
  11213. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11214. goto end;
  11215. }
  11216. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11217. {
  11218. //Local list different update
  11219. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11220. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11221. goto end;
  11222. }
  11223. }
  11224. result = PASS;
  11225. }
  11226. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11227. end:
  11228. json_object_put(SendLocalList);
  11229. sendSendLocalListConfirmation(uuid, comfirmstr);
  11230. return result;
  11231. }
  11232. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11233. {
  11234. mtrace();
  11235. int result = FAIL;
  11236. struct StructSetChargingProfile SetProfileReq = {0};
  11237. int tempchargingProfileIdInt;
  11238. int chargingSchedulePeriodCount = 0;
  11239. char comfirmstr[20]={0};
  11240. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11241. char rmFileCmd[128]={0};
  11242. int profileQuantity = 0;
  11243. json_object *SetChargingProfile;
  11244. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11245. SetChargingProfile = json_tokener_parse(payload);
  11246. if(!is_error(SetChargingProfile))
  11247. {
  11248. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11249. {
  11250. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11251. }
  11252. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11253. {
  11254. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11255. {
  11256. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11257. }
  11258. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11259. {
  11260. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11261. }
  11262. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11263. {
  11264. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11265. }
  11266. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11267. {
  11268. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11269. }
  11270. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11271. {
  11272. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11273. }
  11274. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11275. {
  11276. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11277. }
  11278. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11279. {
  11280. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11281. }
  11282. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11283. {
  11284. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11285. }
  11286. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11287. {
  11288. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11289. {
  11290. 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")));
  11291. }
  11292. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11293. {
  11294. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11295. }
  11296. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11297. {
  11298. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11299. }
  11300. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11301. {
  11302. 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")));
  11303. }
  11304. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11305. {
  11306. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11307. if(chargingSchedulePeriodCount <= 10)
  11308. {
  11309. 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++)
  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), "startPeriod") != NULL)
  11312. {
  11313. 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"));
  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), "limit") != NULL)
  11316. {
  11317. 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"));
  11318. }
  11319. 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)
  11320. {
  11321. 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"));
  11322. }
  11323. }
  11324. }
  11325. }
  11326. }
  11327. }
  11328. }
  11329. // Profile periods quantity check
  11330. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11331. {
  11332. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11333. goto end;
  11334. }
  11335. // Check invalid limit
  11336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11337. {
  11338. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11339. {
  11340. 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)))) ||
  11341. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11342. {
  11343. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11344. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11345. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11346. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11347. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11348. goto end;
  11349. }
  11350. }
  11351. }
  11352. else
  11353. {
  11354. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11355. {
  11356. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:modelnameInfo.ParsingInfo[0].Current)))
  11357. {
  11358. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11359. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11360. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11361. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11362. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11363. goto end;
  11364. }
  11365. }
  11366. }
  11367. // Profile purpose info check
  11368. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11369. {
  11370. FILE *fp;
  11371. char dataLine[4096]={0};
  11372. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11373. if(SetProfileReq.ConnectorId != 0)
  11374. {
  11375. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11376. goto end;
  11377. }
  11378. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11379. if (!fp)
  11380. {
  11381. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11382. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11383. }
  11384. else
  11385. {
  11386. while(fscanf(fp, "%s", dataLine) != EOF)
  11387. {
  11388. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11389. {
  11390. profileQuantity += 1;
  11391. }
  11392. }
  11393. }
  11394. fclose(fp);
  11395. }
  11396. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11397. {
  11398. FILE *fp;
  11399. char dataLine[4096]={0};
  11400. char filename[128]={0};
  11401. int tmpProfileQuantity;
  11402. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11403. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11404. {
  11405. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11406. goto end;
  11407. }
  11408. if(SetProfileReq.ConnectorId == 0)
  11409. {
  11410. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11411. {
  11412. tmpProfileQuantity = 0;
  11413. memset(filename, 0, ARRAY_SIZE(filename));
  11414. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11415. fp = fopen(filename, "r");
  11416. if (!fp)
  11417. {
  11418. DEBUG_INFO("%s does not create.\n", filename);
  11419. fp = fopen(filename, "w+");
  11420. }
  11421. else
  11422. {
  11423. while(fscanf(fp, "%s", dataLine) != EOF)
  11424. {
  11425. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11426. {
  11427. tmpProfileQuantity += 1;
  11428. }
  11429. }
  11430. }
  11431. fclose(fp);
  11432. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11433. }
  11434. }
  11435. else
  11436. {
  11437. memset(filename, 0, ARRAY_SIZE(filename));
  11438. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11439. fp = fopen(filename, "r");
  11440. if (!fp)
  11441. {
  11442. DEBUG_INFO("%s does not create.\n", filename);
  11443. fp = fopen(filename, "w+");
  11444. }
  11445. else
  11446. {
  11447. while(fscanf(fp, "%s", dataLine) != EOF)
  11448. {
  11449. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11450. {
  11451. profileQuantity += 1;
  11452. }
  11453. }
  11454. }
  11455. fclose(fp);
  11456. }
  11457. }
  11458. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11459. {
  11460. int isMatchTransactiodId= FALSE;
  11461. FILE *fp;
  11462. char dataLine[4096]={0};
  11463. char filename[128]={0};
  11464. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11465. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11466. if(SetProfileReq.ConnectorId == 0)
  11467. {
  11468. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11469. goto end;
  11470. }
  11471. int tempIndex = 0;
  11472. //check Transaction active
  11473. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11474. {
  11475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11476. {
  11477. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11478. }
  11479. else
  11480. {
  11481. tempIndex = SetProfileReq.ConnectorId -1;
  11482. }
  11483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11484. {
  11485. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11486. {
  11487. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11488. {
  11489. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11490. {
  11491. isMatchTransactiodId = TRUE;
  11492. break;
  11493. }
  11494. }
  11495. }
  11496. }
  11497. }
  11498. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11499. {
  11500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11501. {
  11502. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11503. }
  11504. else
  11505. {
  11506. tempIndex = SetProfileReq.ConnectorId -1;
  11507. }
  11508. for (int index = 0; index < CCS_QUANTITY; index++)
  11509. {
  11510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11511. {
  11512. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11513. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11514. {
  11515. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11516. {
  11517. isMatchTransactiodId = TRUE;
  11518. break;
  11519. }
  11520. }
  11521. }
  11522. }
  11523. }
  11524. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11525. {
  11526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11527. {
  11528. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11529. }
  11530. else
  11531. {
  11532. tempIndex = SetProfileReq.ConnectorId -1;
  11533. }
  11534. for (int index = 0; index < GB_QUANTITY; index++)
  11535. {
  11536. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11537. {
  11538. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11539. {
  11540. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11541. {
  11542. isMatchTransactiodId = TRUE;
  11543. break;
  11544. }
  11545. }
  11546. }
  11547. }
  11548. }
  11549. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11550. {
  11551. tempIndex = SetProfileReq.ConnectorId -1;
  11552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11553. {
  11554. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11555. {
  11556. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11557. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11558. {
  11559. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11560. {
  11561. isMatchTransactiodId = TRUE;
  11562. break;
  11563. }
  11564. }
  11565. }
  11566. }
  11567. }
  11568. else
  11569. {
  11570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11571. {
  11572. tempIndex = 2;
  11573. }
  11574. else
  11575. {
  11576. tempIndex = (SetProfileReq.ConnectorId -1);
  11577. }
  11578. for (int index = 0; index < AC_QUANTITY; index++)
  11579. {
  11580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11581. {
  11582. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11583. {
  11584. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11585. {
  11586. isMatchTransactiodId = TRUE;
  11587. break;
  11588. }
  11589. }
  11590. }
  11591. }
  11592. }
  11593. //check Transaction active
  11594. if(isMatchTransactiodId == FALSE)
  11595. {
  11596. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11597. goto end;
  11598. }
  11599. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11600. {
  11601. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11602. goto end;
  11603. }
  11604. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11605. fp = fopen(filename, "r");
  11606. if (!fp)
  11607. {
  11608. DEBUG_INFO("%s does not create.\n", filename);
  11609. fp = fopen(filename, "w+");
  11610. }
  11611. else
  11612. {
  11613. //Check Charging Profile Count
  11614. while(fscanf(fp, "%s", dataLine) != EOF)
  11615. {
  11616. //DEBUG_INFO("word=%s\n",word);
  11617. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11618. {
  11619. profileQuantity += 1;
  11620. }
  11621. }
  11622. }
  11623. fclose(fp);
  11624. }
  11625. // Check ChargeProfileMaxStackLevel
  11626. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11627. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11628. {
  11629. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11630. goto end;
  11631. }
  11632. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11633. {
  11634. FILE *fp;
  11635. char dataLine[4096]={0};
  11636. char fnametemp[128]={0};
  11637. int tmpProfileQuantity;
  11638. //Check ChargePointMaxProfile.json exit
  11639. profileQuantity = 0;
  11640. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  11641. {
  11642. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  11643. //Check Charging Profile Count
  11644. tmpProfileQuantity = 0;
  11645. while(fscanf(fp, "%s", dataLine) != EOF)
  11646. {
  11647. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11648. {
  11649. profileQuantity += 1;
  11650. tmpProfileQuantity += 1;
  11651. }
  11652. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11653. }
  11654. fclose(fp);
  11655. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11656. }
  11657. //Check TxDefaultProfile_%d.json
  11658. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11659. {
  11660. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11661. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11662. if((access(fnametemp,F_OK))!=-1)
  11663. {
  11664. fp = fopen(fnametemp, "r");
  11665. //Check Charging Profile Count
  11666. tmpProfileQuantity = 0;
  11667. while(fscanf(fp, "%s", dataLine) != EOF)
  11668. {
  11669. //DEBUG_INFO("word=%s\n",word);
  11670. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11671. {
  11672. profileQuantity += 1;
  11673. tmpProfileQuantity += 1;
  11674. }
  11675. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11676. }
  11677. fclose(fp);
  11678. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11679. }
  11680. }
  11681. //Check TxProfile_%d.json
  11682. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11683. {
  11684. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11685. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  11686. if((access(fnametemp,F_OK))!=-1)
  11687. {
  11688. fp = fopen(fnametemp, "r");
  11689. //Check Charging Profile Count
  11690. tmpProfileQuantity = 0;
  11691. while(fscanf(fp, "%s", dataLine) != EOF)
  11692. {
  11693. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11694. {
  11695. profileQuantity += 1;
  11696. tmpProfileQuantity += 1;
  11697. }
  11698. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11699. }
  11700. fclose(fp);
  11701. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11702. }
  11703. }
  11704. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11705. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11706. {
  11707. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11708. goto end;
  11709. }
  11710. }
  11711. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11712. //**********************************Write to File********************************************************/
  11713. {
  11714. FILE *infile;
  11715. FILE *outfile;
  11716. char dataLine[4096]={0};
  11717. char filename[128]={0};
  11718. int chkChar=0;
  11719. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11720. {
  11721. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11722. {
  11723. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11724. }
  11725. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11726. {
  11727. if(SetProfileReq.ConnectorId==0)
  11728. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  11729. else
  11730. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11731. }
  11732. else
  11733. {
  11734. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11735. }
  11736. infile = fopen (filename, "r");
  11737. outfile = fopen (tempfile, "w");
  11738. chkChar = fgetc(infile);
  11739. rewind(infile);
  11740. if(chkChar == EOF)
  11741. {
  11742. // Profile is empty
  11743. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11744. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11745. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11746. fclose(infile);
  11747. fclose(outfile);
  11748. sprintf(rmFileCmd,"rm -f %s",filename);
  11749. system(rmFileCmd);
  11750. rename(tempfile, filename);
  11751. }
  11752. else
  11753. {
  11754. // Profile is not empty
  11755. int ChargingProfileAdded = FALSE;
  11756. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11757. {
  11758. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11759. json_object *tmpChargingProfile;
  11760. tmpChargingProfile = json_tokener_parse(dataLine);
  11761. if(!is_error(SetChargingProfile))
  11762. {
  11763. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11764. {
  11765. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11766. {
  11767. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11768. }
  11769. }
  11770. }
  11771. json_object_put(tmpChargingProfile);
  11772. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11773. {
  11774. if(ChargingProfileAdded == FALSE)
  11775. {
  11776. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11777. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11778. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11779. ChargingProfileAdded = TRUE;
  11780. }
  11781. }
  11782. else
  11783. {
  11784. fprintf(outfile,"%s\n",dataLine);
  11785. if(ChargingProfileAdded == FALSE)
  11786. {
  11787. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11788. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11789. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11790. ChargingProfileAdded = TRUE;
  11791. }
  11792. }
  11793. } // end of while loop
  11794. fclose(infile);
  11795. fclose(outfile);
  11796. sprintf(rmFileCmd,"rm -f %s",filename);
  11797. system(rmFileCmd);
  11798. rename(tempfile, filename);
  11799. }
  11800. }
  11801. sleep(1);
  11802. result = TRUE;
  11803. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11804. }
  11805. end:
  11806. json_object_put(SetChargingProfile);
  11807. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11808. {
  11809. if(SetProfileReq.ConnectorId == 0)
  11810. {
  11811. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11812. {
  11813. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  11814. }
  11815. }
  11816. else
  11817. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11818. }
  11819. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11820. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11821. return result;
  11822. }
  11823. int handleTriggerMessageRequest(char *uuid, char *payload)
  11824. {
  11825. mtrace();
  11826. int result = FAIL;
  11827. int connectorIdIsNULL = FALSE;
  11828. int connectorIdInt =0;
  11829. char sstr[40]={0},sstrtemp[100]={ 0 };
  11830. char requestedMessagestr[40]={0};
  11831. char comfirmstr[20]={0};
  11832. int c = 0;
  11833. char *loc;
  11834. DEBUG_INFO("handleTriggerMessageRequest\n");
  11835. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11836. strcpy(sstrtemp, stringtrimspace(payload));
  11837. c = 0;
  11838. loc = strstr(sstrtemp, "requestedMessage");
  11839. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11840. {
  11841. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11842. c++;
  11843. }
  11844. sstr[c] = '\0';
  11845. strcpy(requestedMessagestr, sstr);
  11846. c = 0;
  11847. loc = strstr(sstrtemp, "connectorId");
  11848. if(loc == NULL)
  11849. {
  11850. connectorIdIsNULL = TRUE;
  11851. }
  11852. else
  11853. {
  11854. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11855. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11856. {
  11857. sstr[c] = loc[strlen("connectorId")+2+c];
  11858. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11859. c++;
  11860. }
  11861. sstr[c] = '\0';
  11862. connectorIdInt = atoi(sstr);
  11863. }
  11864. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11865. {
  11866. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11867. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11868. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11869. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11870. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11871. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11872. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11873. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11874. {
  11875. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11876. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11877. return TRUE;
  11878. }
  11879. else
  11880. {
  11881. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11882. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11883. }
  11884. }
  11885. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11886. {
  11887. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11888. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11889. return TRUE;
  11890. }
  11891. //==========================
  11892. // Trigger message
  11893. //==========================
  11894. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11895. {
  11896. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11897. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11898. {
  11899. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11900. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11901. }
  11902. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11903. }
  11904. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11905. {
  11906. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11907. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11908. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11909. }
  11910. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11911. {
  11912. //sendBootNotificationRequest();
  11913. server_sign = FALSE;
  11914. }
  11915. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11916. {
  11917. refreshStartTimer(&clientTime.Heartbeat);
  11918. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  11919. }
  11920. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11921. {
  11922. if(connectorIdIsNULL == FALSE)
  11923. {
  11924. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11925. {
  11926. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11927. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11928. }
  11929. }
  11930. else
  11931. {
  11932. for(int idx=0;idx< gunTotalNumber;idx++)
  11933. {
  11934. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11935. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11936. }
  11937. }
  11938. }
  11939. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11940. {
  11941. if(connectorIdIsNULL == FALSE)
  11942. {
  11943. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11944. {
  11945. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11946. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11947. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11948. }
  11949. }
  11950. else
  11951. {
  11952. for(int idx=0;idx< gunTotalNumber;idx++)
  11953. {
  11954. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11955. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11956. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11957. }
  11958. }
  11959. }
  11960. return result;
  11961. }
  11962. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11963. {
  11964. mtrace();
  11965. int result = FAIL;
  11966. int connectorIdInt =0;
  11967. char comfirmstr[20]={0};
  11968. int tempIndex = 0;
  11969. json_object *UnlockConnector;
  11970. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11971. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11972. UnlockConnector = json_tokener_parse(payload);
  11973. if(!is_error(UnlockConnector))
  11974. {
  11975. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11976. {
  11977. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11978. }
  11979. }
  11980. json_object_put(UnlockConnector);
  11981. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11982. if(gunTotalNumber == 0)
  11983. {
  11984. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11985. goto end;
  11986. }
  11987. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11988. {
  11989. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11990. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11991. goto end;
  11992. }
  11993. else
  11994. {
  11995. //check Transaction active
  11996. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11997. {
  11998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11999. {
  12000. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12001. }
  12002. else
  12003. {
  12004. tempIndex = connectorIdInt -1;
  12005. }
  12006. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12007. {
  12008. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12009. {
  12010. //stop Transaction
  12011. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12012. }
  12013. }
  12014. }
  12015. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12016. {
  12017. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12018. {
  12019. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12020. }
  12021. else
  12022. {
  12023. tempIndex = connectorIdInt -1;
  12024. }
  12025. for (int index = 0; index < CCS_QUANTITY; index++)
  12026. {
  12027. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12028. {
  12029. //stop Transaction
  12030. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12031. }
  12032. }
  12033. }
  12034. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12035. {
  12036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12037. {
  12038. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12039. }
  12040. else
  12041. {
  12042. tempIndex = connectorIdInt -1;
  12043. }
  12044. for (int index = 0; index < GB_QUANTITY; index++)
  12045. {
  12046. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12047. {
  12048. //stop Transaction
  12049. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12050. }
  12051. }
  12052. }
  12053. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12054. {
  12055. tempIndex = connectorIdInt -1;
  12056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12057. {
  12058. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12059. {
  12060. //stop Transaction
  12061. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12062. }
  12063. }
  12064. }
  12065. else
  12066. {
  12067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12068. {
  12069. tempIndex = 2;
  12070. }
  12071. else
  12072. {
  12073. tempIndex = connectorIdInt-1;
  12074. }
  12075. for (int index = 0; index < AC_QUANTITY; index++)
  12076. {
  12077. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12078. {
  12079. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12080. }
  12081. }
  12082. }
  12083. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12084. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12085. result = TRUE;
  12086. return result;
  12087. }
  12088. end:
  12089. //json_object_put(obj); --- remove temporally
  12090. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12091. return result;
  12092. }
  12093. static char UpdateFirmwarepayloadData[300]={0};
  12094. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12095. {
  12096. mtrace();
  12097. int result = FAIL;
  12098. pthread_t t;
  12099. sendUpdateFirmwareConfirmation(uuid);
  12100. memset(UpdateFirmwarepayloadData, 0, 300);
  12101. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12102. if(!interLock.isUpdateFirmwareGoing)
  12103. {
  12104. interLock.isUpdateFirmwareGoing = 1;
  12105. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12106. sleep(1);
  12107. }
  12108. else
  12109. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12110. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12111. return result;
  12112. }
  12113. void *UpdateFirmwareProcess(void *data)
  12114. {
  12115. pthread_detach(pthread_self());
  12116. mtrace();
  12117. int retriesInt =0, retryIntervalInt=0;
  12118. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12119. int port=0;
  12120. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12121. int isSuccess = 0;
  12122. char ftpbuf[512];
  12123. char temp[100];
  12124. char * pch;
  12125. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12126. json_object *UpdateFirmware;
  12127. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12128. if(!is_error(UpdateFirmware))
  12129. {
  12130. // Required data
  12131. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12132. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12133. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12134. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12135. // Optional data
  12136. if(json_object_object_get(UpdateFirmware, "retries"))
  12137. {
  12138. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12139. }
  12140. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12141. {
  12142. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12143. }
  12144. }
  12145. json_object_put(UpdateFirmware);
  12146. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12147. memset(path, 0, ARRAY_SIZE(path));
  12148. // Wait retrieveData
  12149. if(strlen(retrieveDatestr) > 10)
  12150. {
  12151. do
  12152. {
  12153. sleep(1);
  12154. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12155. }
  12156. // Ready to download
  12157. system("rm -f /mnt/*");
  12158. if(strncmp(locationstr,"http", 4) == 0)
  12159. {
  12160. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12161. sprintf(ftppath,"/%s", path);
  12162. DEBUG_INFO("locationstr: %s\n", locationstr);
  12163. DEBUG_INFO("protocol: %s\n",protocol);
  12164. DEBUG_INFO("host: %s\n",host);
  12165. DEBUG_INFO("path: %s\n",path);
  12166. DEBUG_INFO("ftppath: %s\n",ftppath);
  12167. int ftppathlen=strlen(ftppath);
  12168. int i=1;
  12169. char filenametemp[50];
  12170. while(i < ftppathlen)
  12171. {
  12172. int len=ftppathlen-i;
  12173. if(ftppath[len]== 47) // '/' ascll code: 47
  12174. {
  12175. DEBUG_INFO("compare '/' all right\n");
  12176. break;
  12177. }
  12178. i=i+1;
  12179. }
  12180. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12181. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12182. filenametemp[i+1] = 0;
  12183. do
  12184. {
  12185. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12186. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12187. sleep(1);
  12188. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12189. if(!isSuccess)
  12190. {
  12191. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12192. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12193. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12194. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12195. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12196. }
  12197. else
  12198. {
  12199. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12200. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12201. }
  12202. retriesInt--;
  12203. }while((isSuccess == 0)&&(retriesInt >= 0));
  12204. }
  12205. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12206. {
  12207. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12208. memset(temp, 0, ARRAY_SIZE(temp));
  12209. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12210. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12211. int ftppathlen=strlen(ftpbuf);
  12212. int i=1;
  12213. char filenametemp[50];
  12214. while(i < ftppathlen)
  12215. {
  12216. int len=ftppathlen-i;
  12217. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12218. {
  12219. DEBUG_INFO(" compare '/' all right\n");
  12220. break;
  12221. }
  12222. i=i+1;
  12223. }
  12224. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12225. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12226. filenametemp[i+1] = 0;
  12227. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12228. pch=strchr(temp,'@');
  12229. if(pch==NULL)
  12230. {
  12231. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12232. protocol, host, &port, path);
  12233. strcpy(user,"anonymous");
  12234. strcpy(password,"");
  12235. }
  12236. else
  12237. {
  12238. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12239. protocol, user, password, host, &port, path);
  12240. }
  12241. sscanf(host,"%[^/]%s",host1, path1);
  12242. sprintf(ftppath,"%s", path1);
  12243. //DEBUG_INFO("protocol =%s\n",protocol);
  12244. //DEBUG_INFO("user =%s\n",user);
  12245. //DEBUG_INFO("password =%s\n",password);
  12246. //DEBUG_INFO("host1 =%s\n",host1);
  12247. //DEBUG_INFO("port =%d\n",port);
  12248. //DEBUG_INFO("path1 =%s\n",path1);
  12249. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12250. //ftpFile(host, user, password, port, ftppath, fname);
  12251. //download firmware pthred
  12252. if(port == 0)
  12253. {
  12254. port = 21;
  12255. }
  12256. do
  12257. {
  12258. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12259. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12260. sleep(1);
  12261. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12262. if(!isSuccess)
  12263. {
  12264. //BulldogUtil.sleepMs(interval*1000);
  12265. DEBUG_INFO("Update firmware request and download file fail.\n");
  12266. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12267. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12268. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12269. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12270. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12271. }
  12272. else
  12273. {
  12274. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12275. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12276. }
  12277. retriesInt--;
  12278. }while((!isSuccess)&&(retriesInt >= 0));
  12279. }
  12280. else
  12281. {
  12282. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12283. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12284. sleep(1);
  12285. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12286. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12287. }
  12288. // OCPPPH only, must announce CSU upgrade firmware
  12289. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  12290. interLock.isUpdateFirmwareGoing = 0;
  12291. pthread_exit(NULL);
  12292. }
  12293. int handleCertificateSignedRequest(char *uuid, char *payload)
  12294. {
  12295. mtrace();
  12296. int result = PASS;
  12297. json_object *CertificateSigned;
  12298. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12299. CertificateSigned = json_tokener_parse(payload);
  12300. if(!is_error(CertificateSigned))
  12301. {
  12302. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12303. }
  12304. json_object_put(CertificateSigned);
  12305. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12306. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12307. fclose(fp);
  12308. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12309. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12310. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12311. sendCertificateSignedConfirmation(uuid);
  12312. return result;
  12313. }
  12314. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12315. {
  12316. mtrace();
  12317. int result = PASS;
  12318. json_object *DeleteCertificate;
  12319. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12320. DeleteCertificate = json_tokener_parse(payload);
  12321. if(!is_error(DeleteCertificate))
  12322. {
  12323. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12324. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12325. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12326. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12327. }
  12328. json_object_put(DeleteCertificate);
  12329. /*
  12330. * TODO: Delete certificateSigned process
  12331. */
  12332. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12333. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12334. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12335. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12336. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12337. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12338. sendDeleteCertificateConfirmation(uuid);
  12339. return result;
  12340. }
  12341. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12342. {
  12343. mtrace();
  12344. int result = PASS;
  12345. json_object *ExtendedTriggerMessage;
  12346. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12347. ExtendedTriggerMessage = json_tokener_parse(payload);
  12348. if(!is_error(ExtendedTriggerMessage))
  12349. {
  12350. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12351. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12352. {
  12353. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12354. }
  12355. else
  12356. {
  12357. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  12358. }
  12359. }
  12360. json_object_put(ExtendedTriggerMessage);
  12361. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  12362. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  12363. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12364. {
  12365. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12366. }
  12367. else
  12368. {
  12369. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12370. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12371. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12372. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12373. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12374. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12375. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12376. {
  12377. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12378. }
  12379. else
  12380. {
  12381. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12382. }
  12383. }
  12384. sendExtendedTriggerMessageConfirmation(uuid);
  12385. //==========================
  12386. // Trigger message
  12387. //==========================
  12388. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12389. {
  12390. //sendBootNotificationRequest();
  12391. server_sign = FALSE;
  12392. }
  12393. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12394. {
  12395. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  12396. }
  12397. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12398. {
  12399. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12400. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12401. {
  12402. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12403. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12404. }
  12405. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12406. }
  12407. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12408. {
  12409. refreshStartTimer(&clientTime.Heartbeat);
  12410. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12411. }
  12412. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12413. {
  12414. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12415. {
  12416. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12417. }
  12418. else
  12419. {
  12420. for(int idx=0;idx< gunTotalNumber;idx++)
  12421. {
  12422. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12423. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12424. }
  12425. }
  12426. }
  12427. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12428. {
  12429. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  12430. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  12431. {
  12432. 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\" &");
  12433. }
  12434. }
  12435. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12436. {
  12437. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12438. {
  12439. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12440. }
  12441. else
  12442. {
  12443. for(int idx=0;idx< gunTotalNumber;idx++)
  12444. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12445. }
  12446. }
  12447. return result;
  12448. }
  12449. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12450. {
  12451. mtrace();
  12452. int result = PASS;
  12453. json_object *GetInstalledCertificateIds;
  12454. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12455. GetInstalledCertificateIds = json_tokener_parse(payload);
  12456. if(!is_error(GetInstalledCertificateIds))
  12457. {
  12458. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12459. }
  12460. json_object_put(GetInstalledCertificateIds);
  12461. /*
  12462. * TODO: Return installed certificate process
  12463. */
  12464. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12465. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  12466. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12467. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  12468. sendGetInstalledCertificateIdsConfirmation(uuid);
  12469. return result;
  12470. }
  12471. int handleGetLogRequest(char *uuid, char *payload)
  12472. {
  12473. mtrace();
  12474. int result = PASS;
  12475. json_object *GetLog;
  12476. DEBUG_INFO("handleGetLogRequest...\n");
  12477. GetLog = json_tokener_parse(payload);
  12478. if(!is_error(GetLog))
  12479. {
  12480. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12481. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12482. if(json_object_object_get(GetLog, "retries") != NULL)
  12483. {
  12484. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12485. }
  12486. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12487. {
  12488. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12489. }
  12490. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12491. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12492. {
  12493. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12494. }
  12495. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12496. {
  12497. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12498. }
  12499. }
  12500. json_object_put(GetLog);
  12501. /*
  12502. * TODO: Upload log process
  12503. */
  12504. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  12505. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  12506. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  12507. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  12508. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  12509. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  12510. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  12511. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  12512. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  12513. sendGetLogConfirmation(uuid);
  12514. return result;
  12515. }
  12516. int handleInstallCertificateRequest(char *uuid, char *payload)
  12517. {
  12518. mtrace();
  12519. int result = PASS;
  12520. json_object *InstallCertificate;
  12521. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12522. InstallCertificate = json_tokener_parse(payload);
  12523. if(!is_error(InstallCertificate))
  12524. {
  12525. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12526. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12527. /*
  12528. * TODO: Install certificate process
  12529. */
  12530. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  12531. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  12532. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  12533. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  12534. sendInstallCertificateConfirmation(uuid);
  12535. }
  12536. json_object_put(InstallCertificate);
  12537. return result;
  12538. }
  12539. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12540. {
  12541. mtrace();
  12542. int result = PASS;
  12543. json_object *SignedUpdateFirmware;
  12544. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12545. SignedUpdateFirmware = json_tokener_parse(payload);
  12546. if(!is_error(SignedUpdateFirmware))
  12547. {
  12548. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12549. {
  12550. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12551. }
  12552. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12553. {
  12554. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12555. }
  12556. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12557. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12558. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12559. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12560. {
  12561. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12562. }
  12563. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12564. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12565. }
  12566. json_object_put(SignedUpdateFirmware);
  12567. /*
  12568. * TODO: Upgrade firmware process
  12569. */
  12570. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12571. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  12572. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  12573. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  12574. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  12575. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  12576. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  12577. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  12578. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  12579. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  12580. sendInstallCertificateConfirmation(uuid);
  12581. return result;
  12582. }
  12583. int handleUnknownRequest(char *uuid, char *payload)
  12584. {
  12585. mtrace();
  12586. int result = PASS;
  12587. DEBUG_INFO("handleUnknownRequest...\n");
  12588. sendUnknownConfirmation(uuid);
  12589. result = PASS;
  12590. return result;
  12591. }
  12592. //==========================================
  12593. // Handle server response routine
  12594. //==========================================
  12595. void handleAuthorizeResponse(char *payload, int gun_index)
  12596. {
  12597. mtrace();
  12598. char expiryDatestr[30]={0};
  12599. char parentIdTagstr[20]={0};
  12600. char statusstr[20]={0};
  12601. int expiryDateISNULL=FALSE;
  12602. int parentIdTagISNULL=FALSE;
  12603. DEBUG_INFO("handleAuthorizeResponse...\n");
  12604. json_object *Authorize;
  12605. Authorize = json_tokener_parse(payload);
  12606. if(!is_error(Authorize))
  12607. {
  12608. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12609. {
  12610. // Required data
  12611. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12612. // Optional data
  12613. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12614. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12615. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12616. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12617. }
  12618. }
  12619. json_object_put(Authorize);
  12620. if(expiryDateISNULL == FALSE)
  12621. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12622. if(parentIdTagISNULL == FALSE)
  12623. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12624. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  12625. //Update idTag information to authorization cache if supproted
  12626. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12627. {
  12628. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12629. }
  12630. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  12631. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12632. authorizeRetryTimes = 0;
  12633. }
  12634. void handleBootNotificationResponse(char *payload, int gun_index)
  12635. {
  12636. mtrace();
  12637. char statusStr[12]={0};
  12638. char currentTimeStr[30]={0};
  12639. int intervalInt = 0;
  12640. DEBUG_INFO("handleBootNotificationResponse...\n");
  12641. json_object *BootNotification;
  12642. BootNotification = json_tokener_parse(payload);
  12643. if(!is_error(BootNotification))
  12644. {
  12645. // Required data
  12646. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12647. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12648. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12649. }
  12650. json_object_put(BootNotification);
  12651. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12652. BootNotificationInterval = intervalInt;
  12653. HeartBeatWaitTime = intervalInt;
  12654. //write back to ShmOCPP16DataPH->BootNotification
  12655. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  12656. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12657. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  12658. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12659. {
  12660. server_sign = TRUE;
  12661. server_pending =FALSE;
  12662. }
  12663. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12664. {
  12665. server_pending = TRUE;
  12666. }
  12667. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  12668. srand(time(NULL));
  12669. refreshStartTimer(&clientTime.Heartbeat);
  12670. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12671. SetOcppConnStatus(TRUE);
  12672. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  12673. }
  12674. void handleDataTransferResponse(char *payload, int gun_index)
  12675. {
  12676. char sstr[160]={0};//sstr[200]={ 0 };
  12677. int c = 0;
  12678. char *loc;
  12679. DEBUG_INFO("handleDataTransferResponse ...\n");
  12680. loc = strstr(payload, "status");
  12681. c = 0;
  12682. while (loc[3+strlen("status")+c] != '\"')
  12683. {
  12684. sstr[c] = loc[3+strlen("status")+c];
  12685. c++;
  12686. }
  12687. sstr[c] = '\0';
  12688. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12689. }
  12690. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12691. {
  12692. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12693. //struct json_object *obj;
  12694. // obj = json_tokener_parse(payload);
  12695. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12696. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12697. //No fields are defined.
  12698. }
  12699. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12700. {
  12701. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12702. //struct json_object *obj;
  12703. // obj = json_tokener_parse(payload);
  12704. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12705. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12706. //No fields are defined.
  12707. }
  12708. void handleHeartbeatResponse(char *payload, int gun_index)
  12709. {
  12710. mtrace();
  12711. DEBUG_INFO("handleHeartbeatResponse...\n");
  12712. json_object *Heartbeat;
  12713. Heartbeat = json_tokener_parse(payload);
  12714. if(!is_error(Heartbeat))
  12715. {
  12716. // Required data
  12717. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12718. }
  12719. json_object_put(Heartbeat);
  12720. if(FirstHeartBeat == 0)
  12721. {
  12722. FirstHeartBeat = 1;
  12723. DEBUG_INFO("FirstHeartBeat \n");
  12724. }
  12725. HeartBeatWithNOResponse = 0;
  12726. refreshStartTimer(&clientTime.Heartbeat);
  12727. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  12728. }
  12729. void handleMeterValuesResponse(char *payload, int gun_index)
  12730. {
  12731. mtrace();
  12732. DEBUG_INFO("handleMeterValuesResponse...\n");
  12733. isQueueSendable = 1;
  12734. }
  12735. void handleStartTransactionResponse(char *payload, int gun_index)
  12736. {
  12737. mtrace();
  12738. //int transactionIdInt = 0;
  12739. FILE *outfile;
  12740. char data[100]={0};
  12741. DEBUG_INFO("handleStartTransactionResponse...\n");
  12742. json_object *StartTransaction;
  12743. StartTransaction = json_tokener_parse(payload);
  12744. if(!is_error(StartTransaction))
  12745. {
  12746. // Required data
  12747. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12748. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12749. // Optional data
  12750. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12751. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12752. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12753. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12754. }
  12755. json_object_put(StartTransaction);
  12756. isQueueSendable = 1;
  12757. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12758. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12759. //-----------Start : write to the Queue TransactionId file -----------------//
  12760. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  12761. {}
  12762. else
  12763. {
  12764. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  12765. if(log == NULL)
  12766. {
  12767. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12768. return ;
  12769. }
  12770. else
  12771. {
  12772. fclose(log);
  12773. }
  12774. }
  12775. // open file for writing
  12776. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12777. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  12778. {
  12779. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  12780. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12781. fputs(data, outfile);
  12782. fclose (outfile);
  12783. }
  12784. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12785. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12786. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12787. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  12788. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12789. }
  12790. void handleStatusNotificationResponse(char *payload, int gun_index)
  12791. {
  12792. mtrace();
  12793. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12794. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12795. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12796. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12797. }
  12798. void handleStopTransactionnResponse(char *payload, int gun_index)
  12799. {
  12800. mtrace();
  12801. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12802. json_object *StopTransaction;
  12803. StopTransaction = json_tokener_parse(payload);
  12804. if(!is_error(StopTransaction))
  12805. {
  12806. // Optional data
  12807. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12808. {
  12809. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12810. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12811. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12812. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12813. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12814. }
  12815. }
  12816. json_object_put(StopTransaction);
  12817. isQueueSendable = 1;
  12818. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12819. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12820. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12821. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12822. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12823. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  12824. }
  12825. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12826. {
  12827. mtrace();
  12828. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12829. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  12830. }
  12831. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12832. {
  12833. mtrace();
  12834. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12835. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  12836. }
  12837. void handleSignCertificateResponse(char *payload, int gun_index)
  12838. {
  12839. mtrace();
  12840. DEBUG_INFO("handleSignCertificateResponse...\n");
  12841. json_object *SignCertificate;
  12842. SignCertificate = json_tokener_parse(payload);
  12843. if(!is_error(SignCertificate))
  12844. {
  12845. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12846. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  12847. }
  12848. json_object_put(SignCertificate);
  12849. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  12850. }
  12851. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12852. {
  12853. mtrace();
  12854. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12855. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12856. }
  12857. //==========================================
  12858. // Handle Error routine
  12859. //==========================================
  12860. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12861. {
  12862. mtrace();
  12863. #ifdef SystemLogMessage
  12864. DEBUG_INFO("errorCode: %s\n", errorCode);
  12865. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12866. DEBUG_INFO("errorDetails: %s\n", payload);
  12867. #endif
  12868. }
  12869. //===============================================
  12870. // Common routine
  12871. //===============================================
  12872. int initialConfigurationTable(void)
  12873. {
  12874. //clock_t start_t, end_t, total_t;
  12875. FILE *fp;
  12876. FILE *outfile;
  12877. char str[512]={0};
  12878. char sstr[256]={0};
  12879. int c = 0;
  12880. char *loc;
  12881. int confVersion = 10;
  12882. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12883. //start_t = clock();
  12884. //printf("Starting of the program, start_t = %ld\n", start_t);
  12885. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12886. // Check configuration file size is correct
  12887. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12888. {
  12889. struct stat st;
  12890. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12891. if(st.st_size < 3100)
  12892. {
  12893. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12894. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12895. }
  12896. }
  12897. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12898. {
  12899. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12900. if(outfile == NULL)
  12901. {
  12902. DEBUG_INFO("Error opening file\n");
  12903. return FALSE;
  12904. }
  12905. /*Core Profile*/
  12906. //AllowOfflineTxForUnknownId
  12907. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12909. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12911. //AuthorizationCacheEnabled
  12912. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12913. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12916. //AuthorizeRemoteTxRequests
  12917. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12921. //BlinkRepeat
  12922. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12923. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12926. //ClockAlignedDataInterval
  12927. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12931. //ConnectionTimeOut
  12932. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12934. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12936. //GetConfigurationMaxKeys
  12937. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12939. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12941. // HeartbeatInterval
  12942. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12946. // LightIntensity
  12947. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12948. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12951. // LocalAuthorizeOffline
  12952. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12954. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12956. // LocalPreAuthorize
  12957. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12958. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12961. // MaxEnergyOnInvalidId
  12962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12966. // MeterValuesAlignedData
  12967. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12969. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12970. 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" );
  12971. else
  12972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12974. // MeterValuesAlignedDataMaxLength
  12975. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12977. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12979. else
  12980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12982. // MeterValuesSampledData
  12983. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12985. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12986. 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" );
  12987. else
  12988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12990. // MeterValuesSampledDataMaxLength
  12991. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12995. else
  12996. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12998. // MeterValueSampleInterval
  12999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13003. // MinimumStatusDuration
  13004. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13007. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13009. // NumberOfConnectors
  13010. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13013. {
  13014. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13015. }
  13016. else
  13017. {
  13018. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13019. }
  13020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13021. // ResetRetries
  13022. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13024. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13026. // ConnectorPhaseRotation
  13027. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13031. // ConnectorPhaseRotationMaxLength
  13032. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13033. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13036. // StopTransactionOnEVSideDisconnect
  13037. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13039. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13041. // StopTransactionOnInvalidId
  13042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13046. // StopTxnAlignedData
  13047. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13051. // StopTxnAlignedDataMaxLength
  13052. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13054. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13056. // StopTxnSampledData
  13057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13060. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13061. else
  13062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13064. // StopTxnSampledDataMaxLength
  13065. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13068. {
  13069. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13070. }
  13071. else
  13072. {
  13073. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13074. }
  13075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13076. // SupportedFeatureProfiles
  13077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13081. // SupportedFeatureProfilesMaxLength
  13082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13086. // TransactionMessageAttempts
  13087. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13089. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13090. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13092. // TransactionMessageRetryInterval
  13093. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13094. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13095. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13096. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13098. // UnlockConnectorOnEVSideDisconnect
  13099. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13103. // WebSocketPingInterval
  13104. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13108. // QueueOffLineMeterValues
  13109. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13113. // AuthorizationKey
  13114. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  13117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13118. // SecurityProfile
  13119. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13121. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  13122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13123. // DefaultPrice
  13124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13128. // CustomDisplayCostAndPrice
  13129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13133. // CustomIdleFeeAfterStop
  13134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13138. // SystemUptimeSec
  13139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13143. // FreeVend
  13144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13148. // Configuration Version
  13149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13151. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13153. //* Local Auth List Management Profile*/
  13154. #if 0
  13155. //For OCTT Test Case
  13156. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13159. #endif
  13160. #if 1
  13161. //LocalAuthListEnabled
  13162. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13166. #endif
  13167. //LocalAuthListMaxLength
  13168. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13172. //SendLocalListMaxLength
  13173. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13174. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13177. //ReserveConnectorZeroSupported
  13178. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13179. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13180. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13182. //* Smart Charging Profile */
  13183. //ChargeProfileMaxStackLevel
  13184. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13188. // ChargingScheduleAllowedChargingRateUnit
  13189. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13193. // ChargingScheduleMaxPeriods
  13194. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13198. // ConnectorSwitch3to1PhaseSupported
  13199. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13203. // MaxChargingProfilesInstalled
  13204. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13208. fclose(outfile);
  13209. }
  13210. else
  13211. {
  13212. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13213. char keystr[60]={0};
  13214. char readonlystr[10]={0};
  13215. char valuestr[256]={0};
  13216. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13217. if(fp == NULL) {
  13218. DEBUG_INFO("Error opening file");
  13219. return FALSE;
  13220. }
  13221. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13222. {
  13223. //DEBUG_INFO("Get Configuration \n");
  13224. if(strlen(str) > 0)
  13225. {
  13226. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13227. //*************************key*********************************/
  13228. if(strstr(str, "key") != NULL)
  13229. {
  13230. loc = strstr(str, "key");
  13231. c = 0;
  13232. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13233. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13234. {
  13235. sstr[c] = loc[strlen("key")+3+c];
  13236. c++;
  13237. }
  13238. sstr[c] = '\0';
  13239. strcpy(keystr,sstr);
  13240. }
  13241. //*************************readonly*********************************/
  13242. if(strstr(str, "readonly") != NULL)
  13243. {
  13244. loc = strstr(str, "readonly");
  13245. c = 0;
  13246. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13247. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13248. {
  13249. sstr[c] = loc[strlen("readonly")+2+c];
  13250. c++;
  13251. }
  13252. sstr[c] = '\0';
  13253. strcpy(readonlystr,sstr);
  13254. }
  13255. //*************************value*********************************/
  13256. if(strstr(str, "value") != NULL)
  13257. {
  13258. loc = strstr(str, "value");
  13259. c = 0;
  13260. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13261. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13262. {
  13263. sstr[c] = loc[strlen("value")+3+c];
  13264. c++;
  13265. }
  13266. sstr[c] = '\0';
  13267. strcpy(valuestr,sstr);
  13268. }
  13269. // DEBUG_INFO("keystr=%s\n",keystr);
  13270. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13271. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13272. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13273. {
  13274. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13275. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13277. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13278. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13279. }
  13280. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13281. {
  13282. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13283. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13284. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13285. }
  13286. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13287. {
  13288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13289. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13290. }
  13291. if(strcmp(keystr, "BlinkRepeat") == 0)
  13292. {
  13293. //Charger.BlinkRepeat = Integer.parseInt(value);
  13294. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13295. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13296. }
  13297. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13298. {
  13299. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13300. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13301. }
  13302. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13303. {
  13304. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13305. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13306. }
  13307. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13308. {
  13309. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13310. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13311. }
  13312. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13313. {
  13314. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13315. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13316. HeartBeatWaitTime = atoi(valuestr);
  13317. }
  13318. if(strcmp(keystr, "LightIntensity") == 0)
  13319. {
  13320. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13321. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13322. }
  13323. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13324. {
  13325. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13326. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13327. }
  13328. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13329. {
  13330. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13331. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13332. }
  13333. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13334. {
  13335. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13336. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13337. }
  13338. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13339. {
  13340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13341. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13342. }
  13343. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13344. {
  13345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13346. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13347. }
  13348. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13349. {
  13350. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13351. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13352. }
  13353. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13354. {
  13355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13356. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13357. }
  13358. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13359. {
  13360. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13361. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13362. }
  13363. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13364. {
  13365. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13366. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13367. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13368. }
  13369. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13370. {
  13371. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13372. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13373. }
  13374. if(strcmp(keystr, "ResetRetries") == 0)
  13375. {
  13376. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13377. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13378. }
  13379. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13380. {
  13381. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13382. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13383. }
  13384. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13385. {
  13386. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13388. }
  13389. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13390. {
  13391. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13393. }
  13394. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13395. {
  13396. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13397. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13398. }
  13399. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13400. {
  13401. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13403. }
  13404. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13405. {
  13406. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13408. }
  13409. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13410. {
  13411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13413. }
  13414. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13415. {
  13416. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13417. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13418. }
  13419. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13420. {
  13421. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13422. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13423. }
  13424. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13425. {
  13426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13427. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13428. }
  13429. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13430. {
  13431. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13432. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13433. TransactionMessageAttemptsValue = atoi(valuestr);
  13434. }
  13435. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13436. {
  13437. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13438. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13439. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13440. }
  13441. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13442. {
  13443. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13444. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13445. }
  13446. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13447. {
  13448. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13449. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13450. }
  13451. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13452. {
  13453. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13454. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13455. }
  13456. if(strcmp(keystr, "AuthorizationKey") == 0)
  13457. {
  13458. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13459. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13460. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13461. }
  13462. if(strcmp(keystr, "SecurityProfile") == 0)
  13463. {
  13464. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13465. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  13466. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  13467. }
  13468. if(strcmp(keystr, "DefaultPrice") == 0)
  13469. {
  13470. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13471. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13472. }
  13473. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13474. {
  13475. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13476. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13477. }
  13478. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13479. {
  13480. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13481. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13482. }
  13483. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13484. {
  13485. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13486. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  13487. }
  13488. if(strcmp(keystr, "FreeVend") == 0)
  13489. {
  13490. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13491. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13492. }
  13493. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13494. {
  13495. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13496. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13497. }
  13498. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13499. {
  13500. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13501. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13502. }
  13503. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13504. {
  13505. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13506. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13507. }
  13508. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13509. {
  13510. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13511. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13512. }
  13513. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13514. {
  13515. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13516. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13517. }
  13518. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13519. {
  13520. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13521. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13522. }
  13523. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13524. {
  13525. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13526. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13527. }
  13528. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13529. {
  13530. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13532. }
  13533. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13534. {
  13535. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13537. }
  13538. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13539. {
  13540. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13542. }
  13543. }
  13544. }
  13545. fclose(fp);
  13546. }
  13547. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13548. {
  13549. return PASS;
  13550. }
  13551. else
  13552. {
  13553. return FAIL;
  13554. }
  13555. }
  13556. void StoreConfigurationTable(void)
  13557. {
  13558. FILE *outfile;
  13559. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13560. if(outfile == NULL)
  13561. {
  13562. DEBUG_INFO("Error opening file");
  13563. return ;
  13564. }
  13565. /*Core Profile*/
  13566. //AllowOfflineTxForUnknownId
  13567. /*
  13568. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13569. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13572. */
  13573. //DEBUG_INFO("data=%s\n",data);
  13574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13575. //AuthorizationCacheEnabled
  13576. /*
  13577. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13578. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13579. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13580. */
  13581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13582. //AuthorizeRemoteTxRequests
  13583. /*
  13584. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13586. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13587. */
  13588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13589. //BlinkRepeat
  13590. /*
  13591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13593. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13594. */
  13595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13596. //ClockAlignedDataInterval
  13597. /*
  13598. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13600. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13601. */
  13602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13603. //ConnectionTimeOut
  13604. /*
  13605. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13608. */
  13609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13610. //GetConfigurationMaxKeys
  13611. /*
  13612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13615. */
  13616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13617. // HeartbeatInterval
  13618. /*
  13619. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13620. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13621. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13622. */
  13623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13624. // LightIntensity
  13625. /*
  13626. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13629. */
  13630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13631. // LocalAuthorizeOffline
  13632. /*
  13633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13635. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13636. */
  13637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13638. // LocalPreAuthorize
  13639. /*
  13640. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13641. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13642. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13643. */
  13644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13645. // MaxEnergyOnInvalidId
  13646. /*
  13647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13649. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13650. */
  13651. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13653. // MeterValuesAlignedData
  13654. /*
  13655. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13658. */
  13659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13660. // MeterValuesAlignedDataMaxLength
  13661. /*
  13662. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13663. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13665. */
  13666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13667. // MeterValuesSampledData
  13668. /*
  13669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13671. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13672. */
  13673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13674. // MeterValuesSampledDataMaxLength
  13675. /*
  13676. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13677. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13678. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13679. */
  13680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13681. // MeterValueSampleInterval
  13682. /*
  13683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13686. */
  13687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13688. // MinimumStatusDuration
  13689. /*
  13690. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13691. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13692. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13693. */
  13694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13695. // NumberOfConnectors
  13696. /*
  13697. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13698. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13699. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13700. {
  13701. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13702. }
  13703. else
  13704. {
  13705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13706. }
  13707. */
  13708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13709. // ResetRetries
  13710. /*
  13711. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13712. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13713. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13714. */
  13715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13716. // ConnectorPhaseRotation
  13717. /*
  13718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13720. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13721. */
  13722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13723. // ConnectorPhaseRotationMaxLength
  13724. /*
  13725. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13726. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13727. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13728. */
  13729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13730. // StopTransactionOnEVSideDisconnect
  13731. /*
  13732. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13733. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13734. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13735. */
  13736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13737. // StopTransactionOnInvalidId
  13738. /*
  13739. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13741. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13742. */
  13743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13744. // StopTxnAlignedData
  13745. /*
  13746. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13748. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13749. */
  13750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13751. // StopTxnAlignedDataMaxLength
  13752. /*
  13753. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13754. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13755. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13756. */
  13757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13758. // StopTxnSampledData
  13759. /*
  13760. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13761. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13762. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13763. */
  13764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13765. // StopTxnSampledDataMaxLength
  13766. /*
  13767. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13768. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13769. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13770. */
  13771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13772. // SupportedFeatureProfiles
  13773. /*
  13774. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13775. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13776. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13777. */
  13778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13779. // SupportedFeatureProfilesMaxLength
  13780. /*
  13781. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13782. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13783. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13784. */
  13785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13786. // TransactionMessageAttempts
  13787. /*
  13788. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13791. */
  13792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13793. // TransactionMessageRetryInterval
  13794. /*
  13795. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13796. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13797. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13798. */
  13799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13800. // UnlockConnectorOnEVSideDisconnect
  13801. /*
  13802. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13803. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13805. */
  13806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13807. // WebSocketPingInterval
  13808. /*
  13809. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13811. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13812. */
  13813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13814. // QueueOffLineMeterValues
  13815. /*
  13816. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13817. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13818. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13819. */
  13820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13821. // AuthorizationKey
  13822. /*
  13823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13826. */
  13827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13828. // SecurityProfile
  13829. /*
  13830. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13833. */
  13834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13835. // DefaultPrice
  13836. /*
  13837. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13840. */
  13841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13842. // CustomDisplayCostAndPrice
  13843. /*
  13844. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13847. */
  13848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13849. // CustomIdleFeeAfterStop
  13850. /*
  13851. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13854. */
  13855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13856. // SystemUptimeSec
  13857. /*
  13858. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13861. */
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13863. // FreeVend
  13864. /*
  13865. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  13868. */
  13869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13870. // ConfigurationVersion
  13871. /*
  13872. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13875. */
  13876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13877. //* Local Auth List Management Profile*/
  13878. //LocalAuthListEnabled
  13879. /*
  13880. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13883. */
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13885. //LocalAuthListMaxLength
  13886. /*
  13887. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13890. */
  13891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13892. //SendLocalListMaxLength
  13893. /*
  13894. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13897. */
  13898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13899. //ReserveConnectorZeroSupported
  13900. /*
  13901. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13904. */
  13905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13906. //* Smart Charging Profile */
  13907. //ChargeProfileMaxStackLevel
  13908. /*
  13909. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13912. */
  13913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13914. // ChargingScheduleAllowedChargingRateUnit
  13915. /*
  13916. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13919. */
  13920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13921. // ChargingScheduleMaxPeriods
  13922. /*
  13923. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13926. */
  13927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13928. // ConnectorSwitch3to1PhaseSupported
  13929. /*
  13930. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13933. */
  13934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13935. // MaxChargingProfilesInstalled
  13936. /*
  13937. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13940. */
  13941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13942. fclose(outfile);
  13943. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13944. }
  13945. void getKeyValue(char *keyReq)
  13946. {
  13947. int isEmpty = FALSE;
  13948. int isKnowKey = FALSE;
  13949. DEBUG_INFO("keyReq = %s\n", keyReq);
  13950. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13951. isEmpty = TRUE;
  13952. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13953. {
  13954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13956. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13957. {
  13958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13959. }
  13960. else
  13961. {
  13962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13963. }
  13964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13965. isKnowKey = TRUE;
  13966. }
  13967. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13968. {
  13969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13971. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13972. {
  13973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13974. }
  13975. else
  13976. {
  13977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13978. }
  13979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13980. isKnowKey = TRUE;
  13981. }
  13982. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13983. {
  13984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13986. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13987. {
  13988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13989. }
  13990. else
  13991. {
  13992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13993. }
  13994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13995. isKnowKey = TRUE;
  13996. }
  13997. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13998. {
  13999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14001. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14002. {
  14003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14004. }
  14005. else
  14006. {
  14007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14008. }
  14009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14010. isKnowKey = TRUE;
  14011. }
  14012. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14013. {
  14014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14016. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14017. {
  14018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14019. }
  14020. else
  14021. {
  14022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14023. }
  14024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14025. isKnowKey = TRUE;
  14026. }
  14027. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14028. {
  14029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14031. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14032. {
  14033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14034. }
  14035. else
  14036. {
  14037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14038. }
  14039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14040. isKnowKey = TRUE;
  14041. }
  14042. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14043. {
  14044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14046. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14047. {
  14048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14049. }
  14050. else
  14051. {
  14052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14053. }
  14054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14055. isKnowKey = TRUE;
  14056. }
  14057. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14058. {
  14059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14061. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14062. {
  14063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14064. }
  14065. else
  14066. {
  14067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14068. }
  14069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14070. isKnowKey = TRUE;
  14071. }
  14072. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14073. {
  14074. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14076. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14077. {
  14078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14079. }
  14080. else
  14081. {
  14082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14083. }
  14084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14085. isKnowKey = TRUE;
  14086. }
  14087. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14088. {
  14089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14091. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14092. {
  14093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14094. }
  14095. else
  14096. {
  14097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14098. }
  14099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14100. isKnowKey = TRUE;
  14101. }
  14102. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14103. {
  14104. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14106. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14107. {
  14108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14109. }
  14110. else
  14111. {
  14112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14113. }
  14114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14115. isKnowKey = TRUE;
  14116. }
  14117. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14118. {
  14119. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14121. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14122. {
  14123. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14124. }
  14125. else
  14126. {
  14127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14128. }
  14129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14130. isKnowKey = TRUE;
  14131. }
  14132. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14133. {
  14134. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14136. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14137. {
  14138. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14139. }
  14140. else
  14141. {
  14142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14143. }
  14144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14145. isKnowKey = TRUE;
  14146. }
  14147. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14148. {
  14149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14151. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14152. {
  14153. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14154. }
  14155. else
  14156. {
  14157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14158. }
  14159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14160. isKnowKey = TRUE;
  14161. }
  14162. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14163. {
  14164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14166. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14167. {
  14168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14169. }
  14170. else
  14171. {
  14172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14173. }
  14174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14175. isKnowKey = TRUE;
  14176. }
  14177. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14178. {
  14179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14181. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14182. {
  14183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14184. }
  14185. else
  14186. {
  14187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14188. }
  14189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14190. isKnowKey = TRUE;
  14191. }
  14192. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14193. {
  14194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14195. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14196. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14197. {
  14198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14199. }
  14200. else
  14201. {
  14202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14203. }
  14204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14205. isKnowKey = TRUE;
  14206. }
  14207. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14208. {
  14209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14210. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14211. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14212. {
  14213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14214. }
  14215. else
  14216. {
  14217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14218. }
  14219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14220. isKnowKey = TRUE;
  14221. }
  14222. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14223. {
  14224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14225. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14226. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14227. {
  14228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14229. }
  14230. else
  14231. {
  14232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14233. }
  14234. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14236. isKnowKey = TRUE;
  14237. }
  14238. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14239. {
  14240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14242. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14243. {
  14244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14245. }
  14246. else
  14247. {
  14248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14249. }
  14250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14251. isKnowKey = TRUE;
  14252. }
  14253. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14254. {
  14255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14257. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14258. {
  14259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14260. }
  14261. else
  14262. {
  14263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14264. }
  14265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14266. isKnowKey = TRUE;
  14267. }
  14268. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14269. {
  14270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14272. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14273. {
  14274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14275. }
  14276. else
  14277. {
  14278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14279. }
  14280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14281. isKnowKey = TRUE;
  14282. }
  14283. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14284. {
  14285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14287. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14288. {
  14289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14290. }
  14291. else
  14292. {
  14293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14294. }
  14295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14296. isKnowKey = TRUE;
  14297. }
  14298. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14299. {
  14300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14302. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14303. {
  14304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14305. }
  14306. else
  14307. {
  14308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14309. }
  14310. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14311. isKnowKey = TRUE;
  14312. }
  14313. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14314. {
  14315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14317. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14318. {
  14319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14320. }
  14321. else
  14322. {
  14323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14324. }
  14325. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14326. isKnowKey = TRUE;
  14327. }
  14328. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14329. {
  14330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14332. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14333. {
  14334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14335. }
  14336. else
  14337. {
  14338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14339. }
  14340. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14341. isKnowKey = TRUE;
  14342. }
  14343. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14344. {
  14345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14347. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14348. {
  14349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14350. }
  14351. else
  14352. {
  14353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14354. }
  14355. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14356. isKnowKey = TRUE;
  14357. }
  14358. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14359. {
  14360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14362. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14363. {
  14364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14365. }
  14366. else
  14367. {
  14368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14369. }
  14370. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14371. isKnowKey = TRUE;
  14372. }
  14373. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14374. {
  14375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14377. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14378. {
  14379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14380. }
  14381. else
  14382. {
  14383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14384. }
  14385. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14386. isKnowKey = TRUE;
  14387. }
  14388. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14389. {
  14390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14392. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14393. {
  14394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14395. }
  14396. else
  14397. {
  14398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14399. }
  14400. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14401. isKnowKey = TRUE;
  14402. }
  14403. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14404. {
  14405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14407. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14408. {
  14409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14410. }
  14411. else
  14412. {
  14413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14414. }
  14415. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14416. isKnowKey = TRUE;
  14417. }
  14418. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14419. {
  14420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14422. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14423. {
  14424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14425. }
  14426. else
  14427. {
  14428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14429. }
  14430. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14431. isKnowKey = TRUE;
  14432. }
  14433. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14434. {
  14435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14437. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14438. {
  14439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14440. }
  14441. else
  14442. {
  14443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14444. }
  14445. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14446. isKnowKey = TRUE;
  14447. }
  14448. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14449. {
  14450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14452. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14453. {
  14454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14455. }
  14456. else
  14457. {
  14458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14459. }
  14460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14461. isKnowKey = TRUE;
  14462. }
  14463. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14464. {
  14465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14467. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14468. {
  14469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14470. }
  14471. else
  14472. {
  14473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14474. }
  14475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14476. isKnowKey = TRUE;
  14477. }
  14478. /*
  14479. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14480. {
  14481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14483. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14484. {
  14485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14486. }
  14487. else
  14488. {
  14489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14490. }
  14491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14492. isKnowKey = TRUE;
  14493. }*/
  14494. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14495. {
  14496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14498. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14499. {
  14500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14501. }
  14502. else
  14503. {
  14504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14505. }
  14506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14507. isKnowKey = TRUE;
  14508. }
  14509. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14510. {
  14511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14513. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14514. {
  14515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14516. }
  14517. else
  14518. {
  14519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14520. }
  14521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14522. isKnowKey = TRUE;
  14523. }
  14524. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14525. {
  14526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14528. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14529. {
  14530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14531. }
  14532. else
  14533. {
  14534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14535. }
  14536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14537. isKnowKey = TRUE;
  14538. }
  14539. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14540. {
  14541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14543. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14544. {
  14545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14546. }
  14547. else
  14548. {
  14549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14550. }
  14551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14552. isKnowKey = TRUE;
  14553. }
  14554. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14555. {
  14556. struct sysinfo s_info;
  14557. int error = sysinfo(&s_info);
  14558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14560. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14561. {
  14562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14563. }
  14564. else
  14565. {
  14566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14567. }
  14568. if(error != 0)
  14569. {
  14570. DEBUG_WARN("System uptime get error: %d\n", error);
  14571. }
  14572. else
  14573. {
  14574. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14575. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14576. }
  14577. isKnowKey = TRUE;
  14578. }
  14579. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14580. {
  14581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14583. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14584. {
  14585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14586. }
  14587. else
  14588. {
  14589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14590. }
  14591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14592. isKnowKey = TRUE;
  14593. }
  14594. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14595. {
  14596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14598. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14599. {
  14600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14601. }
  14602. else
  14603. {
  14604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14605. }
  14606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14607. isKnowKey = TRUE;
  14608. }
  14609. #if 1
  14610. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14611. {
  14612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14614. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14615. {
  14616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14617. }
  14618. else
  14619. {
  14620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14621. }
  14622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14623. isKnowKey = TRUE;
  14624. }
  14625. #endif
  14626. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14627. {
  14628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14630. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14631. {
  14632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14633. }
  14634. else
  14635. {
  14636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14637. }
  14638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14639. isKnowKey = TRUE;
  14640. }
  14641. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14642. {
  14643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14645. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14646. {
  14647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14648. }
  14649. else
  14650. {
  14651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14652. }
  14653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14654. isKnowKey = TRUE;
  14655. }
  14656. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14657. {
  14658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14660. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14661. {
  14662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14663. }
  14664. else
  14665. {
  14666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14667. }
  14668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14669. isKnowKey = TRUE;
  14670. }
  14671. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14672. {
  14673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14675. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14676. {
  14677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14678. }
  14679. else
  14680. {
  14681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14682. }
  14683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14684. isKnowKey = TRUE;
  14685. }
  14686. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14687. {
  14688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14690. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14691. {
  14692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14693. }
  14694. else
  14695. {
  14696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14697. }
  14698. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14699. isKnowKey = TRUE;
  14700. }
  14701. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14702. {
  14703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14705. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14706. {
  14707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14708. }
  14709. else
  14710. {
  14711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14712. }
  14713. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14714. isKnowKey = TRUE;
  14715. }
  14716. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14717. {
  14718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14720. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14721. {
  14722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14723. }
  14724. else
  14725. {
  14726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14727. }
  14728. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14729. isKnowKey = TRUE;
  14730. }
  14731. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14732. {
  14733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14735. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14736. {
  14737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14738. }
  14739. else
  14740. {
  14741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14742. }
  14743. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14744. isKnowKey = TRUE;
  14745. }
  14746. //=========================================================
  14747. if(!isEmpty && !isKnowKey)
  14748. {
  14749. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14750. strcpy(unknownkey[UnknownKeynum], keyReq);
  14751. UnknownKeynum = UnknownKeynum + 1;
  14752. }
  14753. }
  14754. void processUnkownKey(void)
  14755. {
  14756. DEBUG_INFO("processUnkownKey...\n");
  14757. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14758. for(int index=0; index < UnknownKeynum; index++)
  14759. {
  14760. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14761. {
  14762. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14763. }
  14764. }
  14765. }
  14766. int setKeyValue(char *key, char *value)
  14767. {
  14768. int isSuccess = NotSupported;
  14769. int check_ascii=0;
  14770. char str[256]={0};
  14771. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14772. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14773. {
  14774. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14775. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14776. {
  14777. strcpy(str, (const char*)value);
  14778. for(int i = 0; str[i]; i++){
  14779. str[i] = tolower(str[i]);
  14780. }
  14781. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14782. isSuccess = ConfigurationStatus_Accepted;
  14783. }
  14784. else
  14785. {
  14786. isSuccess = ConfigurationStatus_Rejected;
  14787. }
  14788. }
  14789. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14790. {
  14791. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14792. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14793. {
  14794. strcpy(str, (const char*)value);
  14795. for(int i = 0; str[i]; i++){
  14796. str[i] = tolower(str[i]);
  14797. }
  14798. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14799. isSuccess = ConfigurationStatus_Accepted;
  14800. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  14801. }
  14802. else
  14803. {
  14804. isSuccess = ConfigurationStatus_Rejected;
  14805. }
  14806. }
  14807. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14808. {
  14809. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14810. {
  14811. strcpy(str, (const char*)value);
  14812. for(int i = 0; str[i]; i++)
  14813. {
  14814. str[i] = tolower(str[i]);
  14815. }
  14816. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14817. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14818. isSuccess = ConfigurationStatus_Accepted;
  14819. }
  14820. else
  14821. {
  14822. isSuccess = ConfigurationStatus_Rejected;
  14823. }
  14824. }
  14825. if(strcmp(key, "BlinkRepeat") == 0)
  14826. {
  14827. //Charger.BlinkRepeat = Integer.parseInt(value);
  14828. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14829. {
  14830. check_ascii = value[0];
  14831. if( (check_ascii < 48) || (check_ascii > 57) )
  14832. {
  14833. isSuccess = ConfigurationStatus_Rejected;
  14834. }
  14835. else
  14836. {
  14837. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14838. isSuccess = ConfigurationStatus_Accepted;
  14839. }
  14840. }
  14841. else
  14842. {
  14843. isSuccess = ConfigurationStatus_Rejected;
  14844. }
  14845. }
  14846. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14847. {
  14848. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14849. {
  14850. check_ascii = value[0];
  14851. if( (check_ascii < 48) || (check_ascii > 57) )
  14852. {
  14853. isSuccess = ConfigurationStatus_Rejected;
  14854. }
  14855. else
  14856. {
  14857. if((atoi(value) == 0) || (atoi(value) >= 5))
  14858. {
  14859. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14860. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14861. isSuccess = ConfigurationStatus_Accepted;
  14862. }
  14863. else
  14864. isSuccess = ConfigurationStatus_Rejected;
  14865. }
  14866. }
  14867. else
  14868. {
  14869. isSuccess = ConfigurationStatus_Rejected;
  14870. }
  14871. }
  14872. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14873. {
  14874. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14875. {
  14876. check_ascii = value[0];
  14877. if( (check_ascii < 48) || (check_ascii > 57) )
  14878. {
  14879. isSuccess = ConfigurationStatus_Rejected;
  14880. }
  14881. else
  14882. {
  14883. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14884. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14885. isSuccess = ConfigurationStatus_Accepted;
  14886. }
  14887. }
  14888. else
  14889. {
  14890. isSuccess = ConfigurationStatus_Rejected;
  14891. }
  14892. }
  14893. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14894. {
  14895. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14896. {
  14897. check_ascii = value[0];
  14898. if( (check_ascii < 48) || (check_ascii > 57) )
  14899. {
  14900. isSuccess = ConfigurationStatus_Rejected;
  14901. }
  14902. else
  14903. {
  14904. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14905. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14906. isSuccess = ConfigurationStatus_Accepted;
  14907. }
  14908. }
  14909. else
  14910. {
  14911. isSuccess = ConfigurationStatus_Rejected;
  14912. }
  14913. }
  14914. if(strcmp(key, "HeartbeatInterval") == 0)
  14915. {
  14916. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14917. {
  14918. check_ascii = value[0];
  14919. if( (check_ascii < 48) || (check_ascii > 57) )
  14920. {
  14921. isSuccess = ConfigurationStatus_Rejected;
  14922. }
  14923. else
  14924. {
  14925. if((atoi(value) == 0) || (atoi(value) >= 10))
  14926. {
  14927. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14928. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14929. HeartBeatWaitTime = atoi(value);
  14930. isSuccess = ConfigurationStatus_Accepted;
  14931. }
  14932. else
  14933. {
  14934. isSuccess = ConfigurationStatus_Rejected;
  14935. }
  14936. }
  14937. }
  14938. else
  14939. {
  14940. isSuccess = ConfigurationStatus_Rejected;
  14941. }
  14942. }
  14943. if(strcmp(key, "LightIntensity") == 0)
  14944. {
  14945. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14946. {
  14947. check_ascii = value[0];
  14948. if( (check_ascii < 48) || (check_ascii > 57) )
  14949. {
  14950. isSuccess = ConfigurationStatus_Rejected;
  14951. }
  14952. else
  14953. {
  14954. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14955. isSuccess = ConfigurationStatus_Accepted;
  14956. }
  14957. }
  14958. else
  14959. {
  14960. isSuccess = ConfigurationStatus_Rejected;
  14961. }
  14962. }
  14963. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14964. {
  14965. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14966. {
  14967. strcpy(str, (const char*)value);
  14968. for(int i = 0; str[i]; i++)
  14969. {
  14970. str[i] = tolower(str[i]);
  14971. }
  14972. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14973. isSuccess = ConfigurationStatus_Accepted;
  14974. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14975. }
  14976. else
  14977. {
  14978. isSuccess = ConfigurationStatus_Rejected;
  14979. }
  14980. }
  14981. if(strcmp(key, "LocalPreAuthorize") == 0)
  14982. {
  14983. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14984. {
  14985. strcpy(str, (const char*)value);
  14986. for(int i = 0; str[i]; i++)
  14987. {
  14988. str[i] = tolower(str[i]);
  14989. }
  14990. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14991. isSuccess = ConfigurationStatus_Accepted;
  14992. }
  14993. else
  14994. {
  14995. isSuccess = ConfigurationStatus_Rejected;
  14996. }
  14997. }
  14998. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14999. {
  15000. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15001. {
  15002. check_ascii = value[0];
  15003. if( (check_ascii < 48) || (check_ascii > 57) )
  15004. {
  15005. isSuccess = ConfigurationStatus_Rejected;
  15006. }
  15007. else
  15008. {
  15009. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15010. isSuccess = ConfigurationStatus_Accepted;
  15011. }
  15012. }
  15013. else
  15014. {
  15015. isSuccess = ConfigurationStatus_Rejected;
  15016. }
  15017. }
  15018. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15019. {
  15020. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15021. {
  15022. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15023. isSuccess = ConfigurationStatus_Accepted;
  15024. }
  15025. else
  15026. {
  15027. isSuccess = ConfigurationStatus_Rejected;
  15028. }
  15029. }
  15030. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15031. {
  15032. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15033. {
  15034. check_ascii = value[0];
  15035. if( (check_ascii < 48) || (check_ascii > 57) )
  15036. {
  15037. isSuccess = ConfigurationStatus_Rejected;
  15038. }
  15039. else
  15040. {
  15041. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15042. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15043. isSuccess = ConfigurationStatus_Accepted;
  15044. }
  15045. }
  15046. else
  15047. {
  15048. isSuccess = ConfigurationStatus_Rejected;
  15049. }
  15050. }
  15051. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15052. {
  15053. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15054. {
  15055. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15056. isSuccess = ConfigurationStatus_Accepted;
  15057. }
  15058. else
  15059. {
  15060. isSuccess = ConfigurationStatus_Rejected;
  15061. }
  15062. }
  15063. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15064. {
  15065. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15066. {
  15067. check_ascii = value[0];
  15068. if( (check_ascii < 48) || (check_ascii > 57) )
  15069. {
  15070. isSuccess = ConfigurationStatus_Rejected;
  15071. }
  15072. else
  15073. {
  15074. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15075. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15076. isSuccess = ConfigurationStatus_Accepted;
  15077. }
  15078. }
  15079. else
  15080. {
  15081. isSuccess = ConfigurationStatus_Rejected;
  15082. }
  15083. }
  15084. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15085. {
  15086. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15087. {
  15088. check_ascii = value[0];
  15089. if( (check_ascii < 48) || (check_ascii > 57) )
  15090. {
  15091. isSuccess = ConfigurationStatus_Rejected;
  15092. }
  15093. else
  15094. {
  15095. if((atoi(value) == 0) || (atoi(value) >= 5))
  15096. {
  15097. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15098. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15099. isSuccess = ConfigurationStatus_Accepted;
  15100. }
  15101. else
  15102. {
  15103. isSuccess = ConfigurationStatus_Rejected;
  15104. }
  15105. }
  15106. }
  15107. else
  15108. {
  15109. isSuccess = ConfigurationStatus_Rejected;
  15110. }
  15111. }
  15112. if(strcmp(key, "MinimumStatusDuration") == 0)
  15113. {
  15114. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15115. {
  15116. check_ascii = value[0];
  15117. if( (check_ascii < 48) || (check_ascii > 57) )
  15118. {
  15119. isSuccess = ConfigurationStatus_Rejected;
  15120. }
  15121. else
  15122. {
  15123. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15124. {
  15125. isSuccess = ConfigurationStatus_Rejected;
  15126. }
  15127. else
  15128. {
  15129. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15130. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15131. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15132. isSuccess = ConfigurationStatus_Accepted;
  15133. }
  15134. }
  15135. }
  15136. else
  15137. {
  15138. isSuccess = ConfigurationStatus_Rejected;
  15139. }
  15140. }
  15141. if(strcmp(key, "NumberOfConnectors") == 0)
  15142. {
  15143. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15144. {
  15145. check_ascii = value[0];
  15146. if( (check_ascii < 48) || (check_ascii > 57) )
  15147. {
  15148. isSuccess = ConfigurationStatus_Rejected;
  15149. }
  15150. else
  15151. {
  15152. //Charger.ResetRetries = Integer.parseInt(value);
  15153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15154. isSuccess = ConfigurationStatus_Accepted;
  15155. }
  15156. }
  15157. else
  15158. {
  15159. isSuccess = ConfigurationStatus_Rejected;
  15160. }
  15161. }
  15162. if(strcmp(key, "ResetRetries") == 0)
  15163. {
  15164. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15165. {
  15166. check_ascii = value[0];
  15167. if( (check_ascii < 48) || (check_ascii > 57) )
  15168. {
  15169. isSuccess = ConfigurationStatus_Rejected;
  15170. }
  15171. else
  15172. {
  15173. //Charger.ResetRetries = Integer.parseInt(value);
  15174. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15175. isSuccess = ConfigurationStatus_Accepted;
  15176. }
  15177. }
  15178. else
  15179. {
  15180. isSuccess = ConfigurationStatus_Rejected;
  15181. }
  15182. }
  15183. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15184. {
  15185. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15186. {
  15187. strcpy(str, (const char*)value);
  15188. for(int i = 0; str[i]; i++)
  15189. {
  15190. str[i] = tolower(str[i]);
  15191. }
  15192. if(strcmp(str, "notapplicable")== 0)
  15193. {
  15194. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15195. isSuccess = ConfigurationStatus_Accepted;
  15196. }
  15197. else if(strcmp(str, "unknown")== 0)
  15198. {
  15199. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15200. isSuccess = ConfigurationStatus_Accepted;
  15201. }
  15202. else if(strcmp(str, "rst")== 0)
  15203. {
  15204. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15205. isSuccess = ConfigurationStatus_Accepted;
  15206. }
  15207. else if(strcmp(str, "rts")== 0)
  15208. {
  15209. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15210. isSuccess = ConfigurationStatus_Accepted;
  15211. }
  15212. else if(strcmp(str, "srt")== 0)
  15213. {
  15214. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15215. isSuccess = ConfigurationStatus_Accepted;
  15216. }
  15217. else if(strcmp(str, "str")== 0)
  15218. {
  15219. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15220. isSuccess = ConfigurationStatus_Accepted;
  15221. }
  15222. else if(strcmp(str, "trs")== 0)
  15223. {
  15224. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15225. isSuccess = ConfigurationStatus_Accepted;
  15226. }
  15227. else if(strcmp(str, "tsr")== 0)
  15228. {
  15229. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15230. isSuccess = ConfigurationStatus_Accepted;
  15231. }
  15232. else
  15233. {
  15234. isSuccess = ConfigurationStatus_Rejected;
  15235. }
  15236. }
  15237. else
  15238. {
  15239. isSuccess = ConfigurationStatus_Rejected;
  15240. }
  15241. }
  15242. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15243. {
  15244. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15245. {
  15246. check_ascii = value[0];
  15247. if( (check_ascii < 48) || (check_ascii > 57) )
  15248. {
  15249. isSuccess = ConfigurationStatus_Rejected;
  15250. }
  15251. else
  15252. {
  15253. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15254. isSuccess = ConfigurationStatus_Accepted;
  15255. }
  15256. }
  15257. else
  15258. {
  15259. isSuccess = ConfigurationStatus_Rejected;
  15260. }
  15261. }
  15262. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15263. {
  15264. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15265. {
  15266. strcpy(str, (const char*)value);
  15267. for(int i = 0; str[i]; i++)
  15268. {
  15269. str[i] = tolower(str[i]);
  15270. }
  15271. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15273. isSuccess = ConfigurationStatus_Accepted;
  15274. }
  15275. else
  15276. {
  15277. isSuccess = ConfigurationStatus_Rejected;
  15278. }
  15279. }
  15280. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15281. {
  15282. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15283. {
  15284. strcpy(str, (const char*)value);
  15285. for(int i = 0; str[i]; i++)
  15286. {
  15287. str[i] = tolower(str[i]);
  15288. }
  15289. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15290. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15291. isSuccess = ConfigurationStatus_Accepted;
  15292. }
  15293. else
  15294. {
  15295. isSuccess = ConfigurationStatus_Rejected;
  15296. }
  15297. }
  15298. if(strcmp(key, "StopTxnAlignedData") == 0)
  15299. {
  15300. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15301. {
  15302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15303. isSuccess = ConfigurationStatus_Accepted;
  15304. }
  15305. else
  15306. {
  15307. isSuccess = ConfigurationStatus_Rejected;
  15308. }
  15309. }
  15310. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15311. {
  15312. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15313. {
  15314. check_ascii = value[0];
  15315. if( (check_ascii < 48) || (check_ascii > 57) )
  15316. {
  15317. isSuccess = ConfigurationStatus_Rejected;
  15318. }
  15319. else
  15320. {
  15321. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15322. isSuccess = ConfigurationStatus_Accepted;
  15323. }
  15324. }
  15325. else
  15326. {
  15327. isSuccess = ConfigurationStatus_Rejected;
  15328. }
  15329. }
  15330. if(strcmp(key, "StopTxnSampledData") == 0)
  15331. {
  15332. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15333. {
  15334. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15335. isSuccess = ConfigurationStatus_Accepted;
  15336. }
  15337. else
  15338. {
  15339. isSuccess = ConfigurationStatus_Rejected;
  15340. }
  15341. }
  15342. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15343. {
  15344. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15345. {
  15346. check_ascii = value[0];
  15347. if( (check_ascii < 48) || (check_ascii > 57) )
  15348. {
  15349. isSuccess = ConfigurationStatus_Rejected;
  15350. }
  15351. else
  15352. {
  15353. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15354. isSuccess = ConfigurationStatus_Accepted;
  15355. }
  15356. }
  15357. else
  15358. {
  15359. isSuccess = ConfigurationStatus_Rejected;
  15360. }
  15361. }
  15362. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15363. {
  15364. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15365. {
  15366. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15367. isSuccess = ConfigurationStatus_Accepted;
  15368. }
  15369. else
  15370. {
  15371. isSuccess = ConfigurationStatus_Rejected;
  15372. }
  15373. }
  15374. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15375. {
  15376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15377. {
  15378. check_ascii = value[0];
  15379. if( (check_ascii < 48) || (check_ascii > 57) )
  15380. {
  15381. isSuccess = ConfigurationStatus_Rejected;
  15382. }
  15383. else
  15384. {
  15385. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15386. isSuccess = ConfigurationStatus_Accepted;
  15387. }
  15388. }
  15389. else
  15390. {
  15391. isSuccess = ConfigurationStatus_Rejected;
  15392. }
  15393. }
  15394. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15395. {
  15396. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15397. {
  15398. check_ascii = value[0];
  15399. if( (check_ascii < 48) || (check_ascii > 57) )
  15400. {
  15401. isSuccess = ConfigurationStatus_Rejected;
  15402. }
  15403. else
  15404. {
  15405. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15407. TransactionMessageAttemptsValue = atoi(value);
  15408. isSuccess = ConfigurationStatus_Accepted;
  15409. }
  15410. }
  15411. else
  15412. {
  15413. isSuccess = ConfigurationStatus_Rejected;
  15414. }
  15415. }
  15416. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15417. {
  15418. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15419. {
  15420. check_ascii = value[0];
  15421. if( (check_ascii < 48) || (check_ascii > 57) )
  15422. {
  15423. isSuccess = ConfigurationStatus_Rejected;
  15424. }
  15425. else
  15426. {
  15427. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15428. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15429. TransactionMessageRetryIntervalValue = atoi(value);
  15430. isSuccess = ConfigurationStatus_Accepted;
  15431. }
  15432. }
  15433. else
  15434. {
  15435. isSuccess = ConfigurationStatus_Rejected;
  15436. }
  15437. }
  15438. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15439. {
  15440. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15441. {
  15442. strcpy(str, (const char*)value);
  15443. for(int i = 0; str[i]; i++)
  15444. {
  15445. str[i] = tolower(str[i]);
  15446. }
  15447. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15449. isSuccess = ConfigurationStatus_Accepted;
  15450. }
  15451. else
  15452. {
  15453. isSuccess = ConfigurationStatus_Rejected;
  15454. }
  15455. }
  15456. if(strcmp(key, "WebSocketPingInterval") == 0)
  15457. {
  15458. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15459. {
  15460. check_ascii = value[0];
  15461. if( (check_ascii < 48) || (check_ascii > 57) )
  15462. {
  15463. isSuccess = ConfigurationStatus_Rejected;
  15464. }
  15465. else
  15466. {
  15467. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15468. isSuccess = ConfigurationStatus_Accepted;
  15469. }
  15470. }
  15471. else
  15472. {
  15473. isSuccess = ConfigurationStatus_Rejected;
  15474. }
  15475. }
  15476. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15477. {
  15478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15479. {
  15480. strcpy(str, (const char*)value);
  15481. for(int i = 0; str[i]; i++)
  15482. {
  15483. str[i] = tolower(str[i]);
  15484. }
  15485. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15486. isSuccess = ConfigurationStatus_Accepted;
  15487. }
  15488. else
  15489. {
  15490. isSuccess = ConfigurationStatus_Rejected;
  15491. }
  15492. }
  15493. if(strcmp(key, "AuthorizationKey") == 0)
  15494. {
  15495. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15496. {
  15497. strcpy(str, (const char*)value);
  15498. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15499. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15500. isSuccess = ConfigurationStatus_Accepted;
  15501. }
  15502. else
  15503. {
  15504. isSuccess = ConfigurationStatus_Rejected;
  15505. }
  15506. }
  15507. if(strcmp(key, "SecurityProfile") == 0)
  15508. {
  15509. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15510. {
  15511. check_ascii = value[0];
  15512. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15513. {
  15514. isSuccess = ConfigurationStatus_Rejected;
  15515. }
  15516. else if(check_ascii == 0x33)
  15517. {
  15518. isSuccess = NotSupported;
  15519. }
  15520. else
  15521. {
  15522. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15523. {
  15524. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15525. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15526. isSuccess = ConfigurationStatus_Accepted;
  15527. }
  15528. else
  15529. isSuccess = ConfigurationStatus_Rejected;
  15530. }
  15531. }
  15532. else
  15533. {
  15534. isSuccess = ConfigurationStatus_Rejected;
  15535. }
  15536. }
  15537. if(strcmp(key, "DefaultPrice") == 0)
  15538. {
  15539. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15540. {
  15541. strcpy(str, (const char*)value);
  15542. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15543. isSuccess = ConfigurationStatus_Accepted;
  15544. }
  15545. else
  15546. {
  15547. isSuccess = ConfigurationStatus_Rejected;
  15548. }
  15549. }
  15550. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15551. {
  15552. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15553. {
  15554. strcpy(str, (const char*)value);
  15555. for(int i = 0; str[i]; i++)
  15556. {
  15557. str[i] = tolower(str[i]);
  15558. }
  15559. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15560. isSuccess = ConfigurationStatus_Accepted;
  15561. }
  15562. else
  15563. {
  15564. isSuccess = ConfigurationStatus_Rejected;
  15565. }
  15566. }
  15567. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15568. {
  15569. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15570. {
  15571. strcpy(str, (const char*)value);
  15572. for(int i = 0; str[i]; i++)
  15573. {
  15574. str[i] = tolower(str[i]);
  15575. }
  15576. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15577. isSuccess = ConfigurationStatus_Accepted;
  15578. }
  15579. else
  15580. {
  15581. isSuccess = ConfigurationStatus_Rejected;
  15582. }
  15583. }
  15584. if(strcmp(key, "SystemUptimeSec") == 0)
  15585. {
  15586. isSuccess = NotSupported;
  15587. }
  15588. if(strcmp(key, "FreeVend") == 0)
  15589. {
  15590. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15591. {
  15592. strcpy(str, (const char*)value);
  15593. for(int i = 0; str[i]; i++)
  15594. {
  15595. str[i] = tolower(str[i]);
  15596. }
  15597. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15599. isSuccess = ConfigurationStatus_Accepted;
  15600. }
  15601. else
  15602. {
  15603. isSuccess = ConfigurationStatus_Rejected;
  15604. }
  15605. }
  15606. #if 0
  15607. //For OCPP Test Case
  15608. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15609. {
  15610. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15611. {
  15612. strcpy(str, (const char*)value);
  15613. for(int i = 0; str[i]; i++)
  15614. {
  15615. str[i] = tolower(str[i]);
  15616. }
  15617. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15618. isSuccess = ConfigurationStatus_Accepted;
  15619. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15620. }
  15621. else
  15622. {
  15623. isSuccess = ConfigurationStatus_Rejected;
  15624. }
  15625. }
  15626. #endif
  15627. #if 1
  15628. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15629. {
  15630. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15631. {
  15632. strcpy(str, (const char*)value);
  15633. for(int i = 0; str[i]; i++)
  15634. {
  15635. str[i] = tolower(str[i]);
  15636. }
  15637. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15638. isSuccess = ConfigurationStatus_Accepted;
  15639. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15640. }
  15641. else
  15642. {
  15643. isSuccess = ConfigurationStatus_Rejected;
  15644. }
  15645. }
  15646. #endif
  15647. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15648. {
  15649. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15650. {
  15651. check_ascii = value[0];
  15652. if( (check_ascii < 48) || (check_ascii > 57) )
  15653. {
  15654. isSuccess = ConfigurationStatus_Rejected;
  15655. }
  15656. else
  15657. {
  15658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15659. isSuccess = ConfigurationStatus_Accepted;
  15660. }
  15661. }
  15662. else
  15663. {
  15664. isSuccess = ConfigurationStatus_Rejected;
  15665. }
  15666. }
  15667. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15668. {
  15669. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15670. {
  15671. check_ascii = value[0];
  15672. if( (check_ascii < 48) || (check_ascii > 57) )
  15673. {
  15674. isSuccess = ConfigurationStatus_Rejected;
  15675. }
  15676. else
  15677. {
  15678. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15679. isSuccess = ConfigurationStatus_Accepted;
  15680. }
  15681. }
  15682. else
  15683. {
  15684. isSuccess = ConfigurationStatus_Rejected;
  15685. }
  15686. }
  15687. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15688. {
  15689. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15690. {
  15691. strcpy(str, (const char*)value);
  15692. for(int i = 0; str[i]; i++)
  15693. {
  15694. str[i] = tolower(str[i]);
  15695. }
  15696. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15697. isSuccess = ConfigurationStatus_Accepted;
  15698. }
  15699. else
  15700. {
  15701. isSuccess = ConfigurationStatus_Rejected;
  15702. }
  15703. }
  15704. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15705. {
  15706. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15707. {
  15708. check_ascii = value[0];
  15709. if( (check_ascii < 48) || (check_ascii > 57) )
  15710. {
  15711. isSuccess = ConfigurationStatus_Rejected;
  15712. }
  15713. else
  15714. {
  15715. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15716. isSuccess = ConfigurationStatus_Accepted;
  15717. }
  15718. }
  15719. else
  15720. {
  15721. isSuccess = ConfigurationStatus_Rejected;
  15722. }
  15723. }
  15724. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15725. {
  15726. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15727. {
  15728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15729. isSuccess = ConfigurationStatus_Accepted;
  15730. }
  15731. else
  15732. {
  15733. isSuccess = ConfigurationStatus_Rejected;
  15734. }
  15735. }
  15736. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15737. {
  15738. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15739. {
  15740. check_ascii = value[0];
  15741. if( (check_ascii < 48) || (check_ascii > 57) )
  15742. {
  15743. isSuccess = ConfigurationStatus_Rejected;
  15744. }
  15745. else
  15746. {
  15747. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15748. isSuccess = ConfigurationStatus_Accepted;
  15749. }
  15750. }
  15751. else
  15752. {
  15753. isSuccess = ConfigurationStatus_Rejected;
  15754. }
  15755. }
  15756. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15757. {
  15758. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15759. {
  15760. strcpy(str, (const char*)value);
  15761. for(int i = 0; str[i]; i++)
  15762. {
  15763. str[i] = tolower(str[i]);
  15764. }
  15765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15766. isSuccess = ConfigurationStatus_Accepted;
  15767. }
  15768. else
  15769. {
  15770. isSuccess = ConfigurationStatus_Rejected;
  15771. }
  15772. }
  15773. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15774. {
  15775. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15776. {
  15777. check_ascii = value[0];
  15778. if( (check_ascii < 48) || (check_ascii > 57) )
  15779. {
  15780. isSuccess = ConfigurationStatus_Rejected;
  15781. }
  15782. else
  15783. {
  15784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15785. isSuccess = ConfigurationStatus_Accepted;
  15786. }
  15787. }
  15788. else
  15789. {
  15790. isSuccess = ConfigurationStatus_Rejected;
  15791. }
  15792. }
  15793. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15794. return isSuccess;
  15795. }
  15796. int TransactionMessageAttemptsGet(void)
  15797. {
  15798. return TransactionMessageAttemptsValue;
  15799. }
  15800. int FirstHeartBeatResponse(void)
  15801. {
  15802. return FirstHeartBeat;
  15803. }
  15804. int TransactionMessageRetryIntervalGet(void)
  15805. {
  15806. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15807. }
  15808. int ReadHttpStatus(int sock)
  15809. {
  15810. //char c;
  15811. char buff[1024]="",*ptr=buff+1;
  15812. int bytes_received, status;
  15813. DEBUG_INFO("Begin Response ..\n");
  15814. while((bytes_received = recv(sock, ptr, 1, 0))){
  15815. if(bytes_received==-1){
  15816. perror("ReadHttpStatus");
  15817. exit(1);
  15818. }
  15819. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15820. ptr++;
  15821. }
  15822. *ptr=0;
  15823. ptr=buff+1;
  15824. sscanf(ptr,"%*s %d ", &status);
  15825. DEBUG_INFO("%s\n",ptr);
  15826. DEBUG_INFO("status=%d\n",status);
  15827. DEBUG_INFO("End Response ..\n");
  15828. return (bytes_received>0)?status:0;
  15829. }
  15830. //the only filed that it parsed is 'Content-Length'
  15831. int ParseHeader(int sock)
  15832. {
  15833. //char c;
  15834. char buff[1024]="",*ptr=buff+4;
  15835. int bytes_received;
  15836. DEBUG_INFO("Begin HEADER ..\n");
  15837. while((bytes_received = recv(sock, ptr, 1, 0))){
  15838. if(bytes_received==-1){
  15839. perror("Parse Header");
  15840. exit(1);
  15841. }
  15842. if(
  15843. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15844. (ptr[-1]=='\r') && (*ptr=='\n' )
  15845. ) break;
  15846. ptr++;
  15847. }
  15848. *ptr=0;
  15849. ptr=buff+4;
  15850. //printf("%s",ptr);
  15851. if(bytes_received){
  15852. ptr=strstr(ptr,"Content-Length:");
  15853. if(ptr){
  15854. sscanf(ptr,"%*s %d",&bytes_received);
  15855. }else
  15856. bytes_received=-1; //unknown size
  15857. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15858. }
  15859. DEBUG_INFO("End HEADER ..\n");
  15860. return bytes_received ;
  15861. }
  15862. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15863. {
  15864. int result = TRUE;
  15865. char rmFileCmd[100]={0};
  15866. char FilePath[100]={0};
  15867. char ftpbuf[200];
  15868. int systemresult;
  15869. sprintf(FilePath,"/mnt/%s",filename);
  15870. system("ping 8.8.8.8 &");
  15871. if((access(FilePath,F_OK))!=-1)
  15872. {
  15873. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15874. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15875. system(rmFileCmd);
  15876. }
  15877. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15878. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15879. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15880. systemresult = system(ftpbuf);
  15881. if(systemresult != 0)
  15882. {
  15883. DEBUG_INFO("http DownLoad error!\n");
  15884. result = FALSE;
  15885. }
  15886. system("pkill ping");
  15887. return result;
  15888. }
  15889. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15890. {
  15891. int result = TRUE;
  15892. char rmFileCmd[100]={0};
  15893. char FilePath[100]={0};
  15894. char ftpbuf[200];
  15895. int systemresult;
  15896. sprintf(FilePath,"/mnt/%s",filename);
  15897. system("ping 8.8.8.8 &");
  15898. if((access(FilePath,F_OK))!=-1)
  15899. {
  15900. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15901. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15902. system(rmFileCmd);
  15903. }
  15904. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15905. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15906. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15907. systemresult = system(ftpbuf);
  15908. if(systemresult != 0)
  15909. {
  15910. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15911. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15912. systemresult = system(ftpbuf);
  15913. if(systemresult != 0)
  15914. {
  15915. DEBUG_WARN("wget error!\n");
  15916. result = FALSE;
  15917. }
  15918. }
  15919. system("pkill ping");
  15920. return result;
  15921. }
  15922. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15923. {
  15924. char rmFileCmd[100]={0};
  15925. char FilePath[100]={0};
  15926. char buf[512];
  15927. int systemresult = 0;
  15928. //DEBUG_INFO("filename=%s\n",filename);
  15929. //DEBUG_INFO("url=%s\n",url);
  15930. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15931. if((access(FilePath,F_OK))!=-1)
  15932. {
  15933. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15934. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15935. system(rmFileCmd);
  15936. }
  15937. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15938. if(fp == NULL)
  15939. {
  15940. DEBUG_INFO("log is NULL\n");
  15941. return FALSE;
  15942. }
  15943. else
  15944. {
  15945. fprintf(fp, "%s\n", url);
  15946. fprintf(fp, "%s\n", filename);
  15947. fclose(fp);
  15948. }
  15949. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15950. if(phpFP == NULL)
  15951. {
  15952. DEBUG_INFO("PHP upload fail.\n");
  15953. return FALSE;
  15954. }
  15955. else
  15956. {
  15957. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15958. {
  15959. if(strstr(buf, "result") != NULL)
  15960. {
  15961. sscanf(buf, "result: %d", &systemresult);
  15962. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15963. }
  15964. }
  15965. pclose(phpFP);
  15966. }
  15967. if(systemresult != 1)
  15968. {
  15969. DEBUG_INFO("HTTP upload error!\n");
  15970. return FALSE;
  15971. }
  15972. return TRUE;
  15973. }
  15974. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15975. {
  15976. int result = FALSE;
  15977. char ftpbuf[200];
  15978. int systemresult;
  15979. /*
  15980. // Domaind name transfer to IP address
  15981. struct hostent* server;
  15982. char *IPbuffer;
  15983. server = gethostbyname(location);
  15984. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  15985. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15986. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  15987. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  15988. systemresult = system(ftpbuf);
  15989. if(systemresult != 0)
  15990. {
  15991. DEBUG_INFO("ftpput error!\n");
  15992. }
  15993. else
  15994. {
  15995. result = TRUE;
  15996. DEBUG_INFO("ftpput OK!\n");
  15997. }
  15998. return result;
  15999. }
  16000. int GetOcppServerURL()
  16001. {
  16002. int result = FALSE;
  16003. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16004. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16005. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16006. struct yuarel url;
  16007. char urlStr[512];
  16008. // OCPPPH only
  16009. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  16010. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16011. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  16012. {
  16013. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16014. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16015. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16016. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  16017. if(yuarel_parse(&url, urlStr) != -1)
  16018. {
  16019. sprintf(OcppProtocol, "%s", url.scheme);
  16020. sprintf(OcppHost, "%s", url.host);
  16021. if(url.path == NULL)
  16022. OcppTempPath[0] = '\0';
  16023. else
  16024. sprintf(OcppTempPath, "%s", url.path);
  16025. if(url.port == 0)
  16026. {
  16027. if(strcmp(OcppProtocol, "wss") == 0)
  16028. OcppPort = 443;
  16029. else
  16030. OcppPort = 80;
  16031. }
  16032. else
  16033. OcppPort = url.port;
  16034. result = TRUE;
  16035. }
  16036. }
  16037. else
  16038. {
  16039. strcpy(OcppHost,"");
  16040. }
  16041. return result;
  16042. }
  16043. int GetOcppPath()
  16044. {
  16045. int result = FALSE;
  16046. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16047. {
  16048. if(OcppTempPath == NULL)
  16049. {
  16050. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16051. }
  16052. else
  16053. {
  16054. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16055. }
  16056. result = TRUE;
  16057. goto End;
  16058. }
  16059. else
  16060. {
  16061. strcpy(OcppPath,"");
  16062. }
  16063. End:
  16064. return result;
  16065. }
  16066. int GetOcppPort()
  16067. {
  16068. return OcppPort;
  16069. }
  16070. int GetOcppConnStatus(void)
  16071. {
  16072. return ShmOCPP16DataPH->OcppConnStatus;
  16073. }
  16074. void SetOcppConnStatus(uint8_t status)
  16075. {
  16076. ShmOCPP16DataPH->OcppConnStatus = status;
  16077. }
  16078. int GetHeartBeatWithNOResponse(void)
  16079. {
  16080. return HeartBeatWithNOResponse;
  16081. }
  16082. void SetHeartBeatWithNOResponse(void)
  16083. {
  16084. HeartBeatWithNOResponse = 0;
  16085. }
  16086. void GetStartTransactionIdTag(int gun_index)
  16087. {
  16088. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16089. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16090. }
  16091. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16092. {
  16093. char ch;
  16094. FILE *fptr1;
  16095. int temptransactionId;
  16096. char str[100]={0};
  16097. temptransactionId = 0;
  16098. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16099. {
  16100. DEBUG_INFO("IdTag is empty.\n");
  16101. return temptransactionId;
  16102. }
  16103. /*------ Read the file ----------------*/
  16104. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  16105. if (!fptr1)
  16106. {
  16107. DEBUG_INFO("QueueTransactionId file open error.\n");
  16108. //printf(" File not found or unable to open the input file!!\n");
  16109. return temptransactionId;
  16110. }
  16111. ch=fgetc(fptr1);
  16112. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  16113. rewind(fptr1);
  16114. if(ch!=EOF)
  16115. {
  16116. // printf("%c",ch);
  16117. while (fgets(str, 100, fptr1) != NULL)
  16118. {
  16119. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16120. if(str[0]=='\0')
  16121. {
  16122. break;
  16123. }
  16124. char *revbuf[8] = {0}; // Variable store string split
  16125. int num = 0;// Quantity after string split
  16126. DEBUG_INFO("Transaction queue data= %s\n", str);
  16127. splitstring(str,",",revbuf,&num); // String split
  16128. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16129. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16130. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16131. DEBUG_INFO("------------------------------\n");
  16132. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16133. {
  16134. if(isStopTransaction)
  16135. {
  16136. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16137. {
  16138. temptransactionId = atoi(revbuf[2]);
  16139. //break;
  16140. }
  16141. }
  16142. else
  16143. {
  16144. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16145. {
  16146. temptransactionId = atoi(revbuf[2]);
  16147. //break;
  16148. }
  16149. }
  16150. }
  16151. }
  16152. }
  16153. else
  16154. DEBUG_INFO("EOF\n");
  16155. fclose(fptr1);
  16156. /*------- End of reading ---------------*/
  16157. return temptransactionId;
  16158. }
  16159. void SetTransactionIdZero(int transactionId)
  16160. {
  16161. char ch;
  16162. FILE *fptr1, *fptr2;
  16163. int temptransactionId = 0;
  16164. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  16165. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  16166. if (!fptr1)
  16167. {
  16168. //printf(" File not found or unable to open the input file!!\n");
  16169. return ;
  16170. }
  16171. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16172. if (!fptr2)
  16173. {
  16174. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16175. fclose(fptr1);
  16176. return ;
  16177. }
  16178. ch=fgetc(fptr1);
  16179. rewind(fptr1);
  16180. if(ch!=EOF)
  16181. {
  16182. // copy all contents to the temporary file except the specific line
  16183. while (fgets(str, 100, fptr1) != NULL)
  16184. {
  16185. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16186. if(str[0]=='\0')
  16187. {
  16188. break;
  16189. }
  16190. char *revbuf[8] = {0};
  16191. int num = 0;
  16192. strcpy(strtemp, str);
  16193. splitstring(str,",",revbuf,&num);
  16194. if(revbuf[2][0] != '\0')
  16195. {
  16196. temptransactionId = atoi(revbuf[2]);
  16197. if(transactionId != temptransactionId)
  16198. {
  16199. fprintf(fptr2, "%s\n", strtemp);
  16200. }
  16201. }
  16202. }
  16203. }
  16204. fclose(fptr1);
  16205. fclose(fptr2);
  16206. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  16207. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  16208. /*------ Read the file ----------------*/
  16209. }
  16210. int InternetDisconnect(void)
  16211. {
  16212. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16213. }
  16214. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16215. void storeTempStopTransaction(int gun_index)
  16216. {
  16217. char guid[37]={0};
  16218. int tempIndex = 0;
  16219. char TempStopTransaction[256];
  16220. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16221. DEBUG_INFO("storeTempStopTransaction...\n");
  16222. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16223. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  16224. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16225. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16226. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16227. {
  16228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16229. {
  16230. tempIndex = ((gun_index==2) ? 1: 0);
  16231. }
  16232. else
  16233. {
  16234. tempIndex = gun_index;
  16235. }
  16236. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16237. {
  16238. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16239. {
  16240. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16241. }
  16242. }// END OF CHAdeMO_QUANTITY
  16243. }
  16244. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16245. {
  16246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16247. {
  16248. tempIndex = ((gun_index==2) ? 1: 0);
  16249. }
  16250. else
  16251. {
  16252. tempIndex = gun_index;
  16253. }
  16254. for (int index = 0; index < CCS_QUANTITY; index++)
  16255. {
  16256. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16257. {
  16258. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16259. }
  16260. }// END OF CCS_QUANTITY
  16261. }
  16262. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16263. {
  16264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16265. {
  16266. tempIndex = ((gun_index==2) ? 1: 0);
  16267. }
  16268. else
  16269. {
  16270. tempIndex = gun_index;
  16271. }
  16272. for (int index = 0; index < GB_QUANTITY; index++)
  16273. {
  16274. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16275. {
  16276. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16277. }
  16278. }// END OF GB_QUANTITY
  16279. }
  16280. else if(gunType[gun_index] == GUN_TYPE_DO)
  16281. {
  16282. tempIndex = gun_index;
  16283. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16284. {
  16285. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16286. {
  16287. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16288. }
  16289. }
  16290. }
  16291. else
  16292. {
  16293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16294. {
  16295. tempIndex = 2;
  16296. }
  16297. else
  16298. {
  16299. tempIndex = gun_index;
  16300. }
  16301. for (int index = 0; index < AC_QUANTITY; index++)
  16302. {
  16303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16304. {
  16305. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16306. }
  16307. }// END OF AC_QUANTITY
  16308. }
  16309. //Stop Transaction Time
  16310. struct timeval tmnow;
  16311. struct tm *tm;
  16312. char buf[28];//, usec_buf[6];
  16313. gettimeofday(&tmnow, NULL);
  16314. time_t t;
  16315. t = time(NULL);
  16316. /*UTC time and date*/
  16317. tm = gmtime(&t);
  16318. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16319. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  16320. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  16321. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  16322. random_uuid(guid);
  16323. /***********************************transactionData******************************************************/
  16324. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16325. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16326. //=================================
  16327. //1. Transaction_Begin
  16328. //=================================
  16329. //============================== Energy.Active.Import.Interval ===========================================
  16330. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16331. {
  16332. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16333. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16335. 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*/]);
  16336. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16337. 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))
  16338. {
  16339. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16340. }
  16341. else
  16342. {
  16343. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16344. }
  16345. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16347. }
  16348. //=================================
  16349. //2. Transaction_End
  16350. //=================================
  16351. //2.1====================================== Current.Import L1 ==============================================
  16352. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16353. {
  16354. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16355. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16356. {
  16357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16358. {
  16359. tempIndex = ((gun_index==2) ? 1: 0);
  16360. }
  16361. else
  16362. {
  16363. tempIndex = gun_index;
  16364. }
  16365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16366. {
  16367. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16368. {
  16369. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16370. }
  16371. }// End of for CHAdeMO_QUANTITY
  16372. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16373. }
  16374. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16375. {
  16376. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16377. {
  16378. tempIndex = ((gun_index==2) ? 1: 0);
  16379. }
  16380. else
  16381. {
  16382. tempIndex = gun_index;
  16383. }
  16384. for (int index = 0; index < CCS_QUANTITY; index++)
  16385. {
  16386. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16387. {
  16388. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16389. }
  16390. }// End of for CCS_QUANTITY
  16391. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16392. }
  16393. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16394. {
  16395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16396. {
  16397. tempIndex = ((gun_index==2) ? 1: 0);
  16398. }
  16399. else
  16400. {
  16401. tempIndex = gun_index;
  16402. }
  16403. for (int index = 0; index < GB_QUANTITY; index++)
  16404. {
  16405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16406. {
  16407. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16408. }
  16409. }// End of for GB_QUANTITY
  16410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16411. }
  16412. else if(gunType[gun_index] == GUN_TYPE_DO)
  16413. {
  16414. tempIndex = gun_index;
  16415. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16416. {
  16417. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16418. {
  16419. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16420. }
  16421. }
  16422. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16423. }
  16424. else
  16425. {
  16426. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16427. {
  16428. tempIndex = 2;
  16429. }
  16430. else
  16431. {
  16432. tempIndex = gun_index;
  16433. }
  16434. for (int index = 0; index < AC_QUANTITY; index++)
  16435. {
  16436. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16437. {
  16438. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16439. }
  16440. }// End of for AC_QUANTITY
  16441. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16442. }
  16443. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16444. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16445. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16446. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16447. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16449. }
  16450. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16451. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16452. {
  16453. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16454. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16455. {
  16456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16457. {
  16458. tempIndex = ((gun_index==2) ? 1: 0);
  16459. }
  16460. else
  16461. {
  16462. tempIndex = gun_index;
  16463. }
  16464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16465. {
  16466. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16467. {
  16468. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16469. }
  16470. }// END OF CHAdeMO_QUANTITY
  16471. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16472. }
  16473. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16474. {
  16475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16476. {
  16477. tempIndex = ((gun_index==2) ? 1: 0);
  16478. }
  16479. else
  16480. {
  16481. tempIndex = gun_index;
  16482. }
  16483. for (int index = 0; index < CCS_QUANTITY; index++)
  16484. {
  16485. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16486. {
  16487. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16488. }
  16489. }// END OF CCS_QUANTITY
  16490. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16491. }
  16492. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16493. {
  16494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16495. {
  16496. tempIndex = ((gun_index==2) ? 1: 0);
  16497. }
  16498. else
  16499. {
  16500. tempIndex = gun_index;
  16501. }
  16502. for (int index = 0; index < GB_QUANTITY; index++)
  16503. {
  16504. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16505. {
  16506. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16507. }
  16508. }// END OF GB_QUANTITY
  16509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16510. }
  16511. else if(gunType[gun_index] == GUN_TYPE_DO)
  16512. {
  16513. tempIndex = gun_index;
  16514. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16515. {
  16516. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16517. {
  16518. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16519. }
  16520. }
  16521. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16522. }
  16523. else
  16524. {
  16525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16526. {
  16527. tempIndex = 2;
  16528. }
  16529. else
  16530. {
  16531. tempIndex = gun_index;
  16532. }
  16533. for (int index = 0; index < AC_QUANTITY; index++)
  16534. {
  16535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16536. {
  16537. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16538. }
  16539. }// END OF AC_QUANTITY
  16540. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16541. }
  16542. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16543. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16544. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16545. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16546. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16548. }
  16549. //2.3====================================== Power.Active.Import =========================================
  16550. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16551. {
  16552. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16553. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16554. {
  16555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16556. {
  16557. tempIndex = ((gun_index==2) ? 1: 0);
  16558. }
  16559. else
  16560. {
  16561. tempIndex = gun_index;
  16562. }
  16563. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16564. {
  16565. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16566. {
  16567. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16568. }
  16569. } // End for CHAdeMO_QUANTITY
  16570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16571. }
  16572. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16573. {
  16574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16575. {
  16576. tempIndex = ((gun_index==2) ? 1: 0);
  16577. }
  16578. else
  16579. {
  16580. tempIndex = gun_index;
  16581. }
  16582. for (int index = 0; index < CCS_QUANTITY; index++)
  16583. {
  16584. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16585. {
  16586. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16587. }
  16588. } // END for CCS_QUANTITY
  16589. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16590. }
  16591. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16592. {
  16593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16594. {
  16595. tempIndex = ((gun_index==2) ? 1: 0);
  16596. }
  16597. else
  16598. {
  16599. tempIndex = gun_index;
  16600. }
  16601. for (int index = 0; index < GB_QUANTITY; index++)
  16602. {
  16603. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16604. {
  16605. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16606. }
  16607. }// END for GB_QUANTITY
  16608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16609. }
  16610. else if(gunType[gun_index] == GUN_TYPE_DO)
  16611. {
  16612. tempIndex = gun_index;
  16613. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16614. {
  16615. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16616. {
  16617. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16618. }
  16619. }
  16620. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16621. }
  16622. else
  16623. {
  16624. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16625. {
  16626. tempIndex = 2;
  16627. }
  16628. else
  16629. {
  16630. tempIndex = gun_index;
  16631. }
  16632. for (int index = 0; index < AC_QUANTITY; index++)
  16633. {
  16634. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16635. {
  16636. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16637. }
  16638. } // END for AC_QUANTITY
  16639. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16640. }
  16641. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16642. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16643. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16644. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16645. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16646. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16647. }
  16648. //2.4====================================== Voltage L1 ====================================================
  16649. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16650. {
  16651. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16652. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16653. {
  16654. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16655. {
  16656. tempIndex = ((gun_index==2) ? 1: 0);
  16657. }
  16658. else
  16659. {
  16660. tempIndex = gun_index;
  16661. }
  16662. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16663. {
  16664. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16665. {
  16666. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16667. }
  16668. } // END OF FOR CHAdeMO_QUANTITY
  16669. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16670. }
  16671. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16672. {
  16673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16674. {
  16675. tempIndex = ((gun_index==2) ? 1: 0);
  16676. }
  16677. else
  16678. {
  16679. tempIndex = gun_index;
  16680. }
  16681. for (int index = 0; index < CCS_QUANTITY; index++)
  16682. {
  16683. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16684. {
  16685. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16686. }
  16687. } // END OF FOR CCS_QUANTITY
  16688. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16689. }
  16690. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16691. {
  16692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16693. {
  16694. tempIndex = ((gun_index==2) ? 1: 0);
  16695. }
  16696. else
  16697. {
  16698. tempIndex = gun_index;
  16699. }
  16700. for (int index = 0; index < GB_QUANTITY; index++)
  16701. {
  16702. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16703. {
  16704. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16705. }
  16706. } // END OF FOR GB_QUANTITY
  16707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16708. }
  16709. else if(gunType[gun_index] == GUN_TYPE_DO)
  16710. {
  16711. tempIndex = gun_index;
  16712. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16713. {
  16714. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16715. {
  16716. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16717. }
  16718. }
  16719. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16720. }
  16721. else
  16722. {
  16723. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16724. {
  16725. tempIndex = 2;
  16726. }
  16727. else
  16728. {
  16729. tempIndex = gun_index;
  16730. }
  16731. for (int index = 0; index < AC_QUANTITY; index++)
  16732. {
  16733. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16734. {
  16735. 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
  16736. }
  16737. } // END OF FOR AC_QUANTITY
  16738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16739. }
  16740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16743. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16744. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16746. }
  16747. //2.5============================================== End SoC =========================================================
  16748. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16749. {
  16750. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16751. 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))
  16752. {
  16753. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16754. {
  16755. tempIndex = ((gun_index==2) ? 1: 0);
  16756. }
  16757. else
  16758. {
  16759. tempIndex = gun_index;
  16760. }
  16761. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16762. {
  16763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16764. {
  16765. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16766. {
  16767. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16768. }
  16769. }
  16770. }
  16771. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16772. {
  16773. for (int index = 0; index < CCS_QUANTITY; index++)
  16774. {
  16775. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16776. {
  16777. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16778. }
  16779. }
  16780. }
  16781. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16782. {
  16783. for (int index = 0; index < GB_QUANTITY; index++)
  16784. {
  16785. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16786. {
  16787. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16788. }
  16789. }
  16790. }
  16791. else if(gunType[gun_index] == GUN_TYPE_DO)
  16792. {
  16793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16794. {
  16795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16796. {
  16797. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16798. }
  16799. }
  16800. }
  16801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16806. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16807. } // END FOR DC CASE
  16808. }
  16809. //2.6====================================== Current.Import L2 ==============================================
  16810. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16811. {
  16812. // AC 3 phase L2 current
  16813. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16814. {
  16815. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16816. {
  16817. tempIndex = 2;
  16818. }
  16819. else
  16820. {
  16821. tempIndex = gun_index;
  16822. }
  16823. for (int index = 0; index < AC_QUANTITY; index++)
  16824. {
  16825. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16826. {
  16827. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16828. }
  16829. }// End of for AC_QUANTITY
  16830. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16831. }
  16832. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16833. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16834. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16835. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16836. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16837. }
  16838. //2.7====================================== Current.Import L3 ==============================================
  16839. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16840. {
  16841. // AC 3 phase L3 current
  16842. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16843. {
  16844. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16845. {
  16846. tempIndex = 2;
  16847. }
  16848. else
  16849. {
  16850. tempIndex = gun_index;
  16851. }
  16852. for (int index = 0; index < AC_QUANTITY; index++)
  16853. {
  16854. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16855. {
  16856. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16857. }
  16858. }// End of for AC_QUANTITY
  16859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16860. }
  16861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16862. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16864. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16865. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16866. }
  16867. //2.9====================================== Voltage L2 ====================================================
  16868. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16869. {
  16870. // AC 3 phase L2 volatge
  16871. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16872. {
  16873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16874. {
  16875. tempIndex = 2;
  16876. }
  16877. else
  16878. {
  16879. tempIndex = gun_index;
  16880. }
  16881. for (int index = 0; index < AC_QUANTITY; index++)
  16882. {
  16883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16884. {
  16885. 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
  16886. }
  16887. } // END OF FOR AC_QUANTITY
  16888. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16889. }
  16890. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16891. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16892. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16893. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16894. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16895. }
  16896. //2.10====================================== Voltage L3 ====================================================
  16897. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16898. {
  16899. // AC 3 phase L3 volatge
  16900. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16901. {
  16902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16903. {
  16904. tempIndex = 2;
  16905. }
  16906. else
  16907. {
  16908. tempIndex = gun_index;
  16909. }
  16910. for (int index = 0; index < AC_QUANTITY; index++)
  16911. {
  16912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16913. {
  16914. 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
  16915. }
  16916. } // END OF FOR AC_QUANTITY
  16917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16918. }
  16919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16922. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16923. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16924. }
  16925. //====================== Start SoC ================================
  16926. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16927. {
  16928. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16929. 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))
  16930. {
  16931. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16932. {
  16933. tempIndex = ((gun_index==2) ? 1: 0);
  16934. }
  16935. else
  16936. {
  16937. tempIndex = gun_index;
  16938. }
  16939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16940. {
  16941. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16942. {
  16943. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16944. {
  16945. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16946. }
  16947. }
  16948. }
  16949. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16950. {
  16951. for (int index = 0; index < CCS_QUANTITY; index++)
  16952. {
  16953. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16954. {
  16955. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16956. }
  16957. }
  16958. }
  16959. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16960. {
  16961. for (int index = 0; index < GB_QUANTITY; index++)
  16962. {
  16963. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16964. {
  16965. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16966. }
  16967. }
  16968. }
  16969. else if(gunType[gun_index] == GUN_TYPE_DO)
  16970. {
  16971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16972. {
  16973. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16974. {
  16975. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16976. }
  16977. }
  16978. }
  16979. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16980. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16981. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16982. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16983. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16984. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16985. } // END FOR DC CASE
  16986. }
  16987. //======================================== Message create ==============================================
  16988. json_object *StopTransaction = json_object_new_object();
  16989. json_object *transactionDatas = json_object_new_array();
  16990. json_object *sampledValues = json_object_new_array();
  16991. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  16992. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  16993. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  16994. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  16995. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  16996. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16997. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  16998. {
  16999. json_object *transactionData = json_object_new_object();
  17000. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17001. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17002. {
  17003. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17004. {
  17005. json_object *sampledValue = json_object_new_object();
  17006. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17007. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17008. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17009. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17010. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17011. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17012. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17013. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17014. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17015. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17016. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17017. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17018. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17019. json_object_array_add(sampledValues, sampledValue);
  17020. }
  17021. }
  17022. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17023. json_object_array_add(transactionDatas, transactionData);
  17024. }
  17025. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17026. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17027. ,MESSAGE_TYPE_CALL
  17028. ,guid
  17029. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17030. json_object_put(StopTransaction);
  17031. // Check File "TempStopTransaction" Exist
  17032. if((access(TempStopTransaction,F_OK))!=-1)
  17033. {
  17034. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17035. fclose(fopen(TempStopTransaction, "w"));
  17036. }
  17037. else
  17038. {
  17039. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17040. FILE *log = fopen(TempStopTransaction, "w+");
  17041. if(log == NULL)
  17042. {
  17043. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17044. return ;
  17045. }
  17046. else
  17047. {
  17048. fclose(log);
  17049. }
  17050. }
  17051. //Add TempStopTransaction | Update TempStopTransaction
  17052. // open file for writing
  17053. FILE *outfile;
  17054. outfile = fopen (TempStopTransaction, "a");
  17055. //DEBUG_INFO("data = %s\n", queuedata);
  17056. fputs(queuedata, outfile);
  17057. fputs("\n", outfile);
  17058. fclose (outfile);
  17059. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17060. }
  17061. void checkTempStopTransaction(int gun_index)
  17062. {
  17063. FILE *fptr1;
  17064. char ch;
  17065. char str[QUEUE_MESSAGE_LENGTH]={0};
  17066. char guid[37]={0};
  17067. char tempdata[65]={0};
  17068. char connectorStr[2]={0};
  17069. char TempStopTransaction[256];
  17070. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17071. fptr1 = fopen(TempStopTransaction, "r");
  17072. //TempStopTransaction格式: 槍號,StopTransaction封包
  17073. if (!fptr1)
  17074. {
  17075. //printf(" File not found or unable to open the input file!!\n");
  17076. return ;
  17077. }
  17078. ch=fgetc(fptr1);
  17079. //printf(" Now the content of the file %s is : \n",fname);
  17080. rewind(fptr1);
  17081. if(ch!=EOF)
  17082. {
  17083. // copy all contents to the temporary file except the specific line
  17084. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17085. {
  17086. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17087. if(str[0]=='\0')
  17088. {
  17089. break;
  17090. }
  17091. //TempStopTransaction格式: 槍號,StopTransaction封包
  17092. strncpy(connectorStr, str, 1);
  17093. if(atoi(connectorStr) != (gun_index+1))
  17094. {
  17095. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17096. fclose(fptr1);
  17097. return ;
  17098. }
  17099. //random_uuid(guid);
  17100. strncpy(guid, str+6, 36); //copy guid
  17101. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17102. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17103. {
  17104. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17105. }
  17106. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17107. OCPP_insert_transaction_msg(NO, str);
  17108. memset(str,0,ARRAY_SIZE(str));
  17109. }
  17110. }
  17111. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17112. fclose(fptr1);
  17113. remove(TempStopTransaction); // remove the original file
  17114. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17115. }
  17116. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17117. {
  17118. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17119. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17120. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17121. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17122. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17123. }
  17124. int GetWebSocketPingInterval(void)
  17125. {
  17126. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17127. }
  17128. int GetServerSign(void)
  17129. {
  17130. return server_sign;
  17131. }
  17132. uint8_t GetOcppSecurityProfile()
  17133. {
  17134. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17135. }
  17136. void GetOcppChargerBoxId(uint8_t *data)
  17137. {
  17138. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  17139. }
  17140. void GetOcppSecurityPassword(uint8_t *data)
  17141. {
  17142. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17143. }
  17144. void SetOcppVersion(uint8_t *version)
  17145. {
  17146. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17147. DEBUG_INFO("ocpp version: %s\n", version);
  17148. if(strstr((char*)version, "ocpp1.6") != NULL)
  17149. {
  17150. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17151. }
  17152. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17153. {
  17154. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17155. system("pkill OcppBackend");
  17156. }
  17157. }
  17158. void SetServerSign(int value)
  17159. {
  17160. server_sign = value;
  17161. }
  17162. int GetBootNotificationInterval(void)
  17163. {
  17164. return BootNotificationInterval;
  17165. }
  17166. int GetInternetConn(void)
  17167. {
  17168. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17169. }
  17170. int GetBackendConnectionTimeout(void)
  17171. {
  17172. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17173. }
  17174. int isConnectorInitMode(int gun_index)
  17175. {
  17176. int tempIndex = 0;
  17177. int result = TRUE;
  17178. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17179. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17180. {
  17181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17182. {
  17183. tempIndex = ((gun_index==2) ? 1: 0);
  17184. }
  17185. else
  17186. {
  17187. tempIndex = gun_index;
  17188. }
  17189. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17190. {
  17191. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17192. {
  17193. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17194. } //end of the same index
  17195. }//end of for CHAdeMO_QUANTITY
  17196. }
  17197. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17198. {
  17199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17200. {
  17201. tempIndex = ((gun_index==2) ? 1: 0);
  17202. }
  17203. else
  17204. {
  17205. tempIndex = gun_index;
  17206. }
  17207. for (int index = 0; index < CCS_QUANTITY; index++)
  17208. {
  17209. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17210. {
  17211. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17212. } //end of the same index
  17213. } // end of for CCS_QUANTITY
  17214. }
  17215. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17216. {
  17217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17218. {
  17219. tempIndex = ((gun_index==2) ? 1: 0);
  17220. }
  17221. else
  17222. {
  17223. tempIndex = gun_index;
  17224. }
  17225. for (int index = 0; index < GB_QUANTITY; index++)
  17226. {
  17227. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17228. {
  17229. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17230. } //end of the same index
  17231. } // end of for GB_QUANTITY
  17232. }
  17233. else if(gunType[gun_index] == GUN_TYPE_DO)
  17234. {
  17235. tempIndex = gun_index;
  17236. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17237. {
  17238. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17239. {
  17240. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17241. } //end of the same index
  17242. }
  17243. }
  17244. else
  17245. {
  17246. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17247. {
  17248. tempIndex = 2;
  17249. }
  17250. else
  17251. {
  17252. tempIndex = gun_index;
  17253. }
  17254. for (int index = 0; index < AC_QUANTITY; index++)
  17255. {
  17256. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17257. {
  17258. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17259. }//end of the same index
  17260. }//end of for AC_QUANTITY
  17261. }
  17262. return result;
  17263. }
  17264. void refreshProcDogTimer()
  17265. {
  17266. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  17267. }
  17268. void InitialSystemValue(void)
  17269. {
  17270. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17271. locallistVersion=0;
  17272. BootNotificationInterval = 0;
  17273. authorizeRetryTimes = 0;
  17274. GunStatusInterval = 10;
  17275. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17276. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17277. //Hear Beat
  17278. HeartBeatWithNOResponse = 0;
  17279. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17280. FirstHeartBeat = 0;
  17281. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17282. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17283. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17284. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17285. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17286. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17287. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17288. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17289. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17290. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17291. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17292. //Status && ConnectorPlugIn Setting
  17293. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17294. {
  17295. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17296. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17297. }
  17298. for (int index = 0; index < CCS_QUANTITY; index++)
  17299. {
  17300. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17301. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17302. }
  17303. for (int index = 0; index < GB_QUANTITY; index++)
  17304. {
  17305. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17306. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17307. }
  17308. for (int index = 0; index < AC_QUANTITY; index++)
  17309. {
  17310. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17311. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17312. }
  17313. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17314. {
  17315. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17316. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17317. }
  17318. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17319. {
  17320. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17321. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17322. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17323. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17324. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17325. }
  17326. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17327. refreshStartTimer(&clientTime.Heartbeat);
  17328. sleep(1);
  17329. }
  17330. void LWS_Send(char *str)
  17331. {
  17332. //=====================================================
  17333. // Check InternetConn 0: disconnected, 1: connected
  17334. //====================================================
  17335. if(GetOcppConnStatus() == 0)
  17336. {
  17337. DEBUG_INFO("offline now !!!\n");
  17338. return;
  17339. }
  17340. // Only disable isWebsocketSendable operation initiated by charger
  17341. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17342. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17343. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17344. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17345. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17346. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17347. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17348. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17349. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17350. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17351. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17352. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17353. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17354. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17355. {
  17356. isWebsocketSendable = 0;
  17357. }
  17358. pthread_mutex_lock(&lock_send);
  17359. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17360. sprintf((char *)SendBuffer, "%s", str);
  17361. SendBufLen = strlen(str);
  17362. pthread_mutex_unlock(&lock_send);
  17363. lws_callback_on_writable(wsi_client);
  17364. //lws_service(context, 0);
  17365. //sleep(1);
  17366. }
  17367. void LWS_SendNow(char *str)
  17368. {
  17369. //=====================================================
  17370. // Check InternetConn 0: disconnected, 1: connected
  17371. //====================================================
  17372. if(GetOcppConnStatus() == 0)
  17373. {
  17374. DEBUG_INFO("offline now !!!\n");
  17375. return;
  17376. }
  17377. // Only disable isWebsocketSendable operation initiated by charger
  17378. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17379. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17380. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17381. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17382. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17383. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17384. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17385. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17386. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17387. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17388. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17389. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17390. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17391. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17392. {
  17393. isWebsocketSendable = 0;
  17394. }
  17395. pthread_mutex_lock(&lock_send);
  17396. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17397. sprintf((char *)SendBuffer, "%s", str);
  17398. SendBufLen = strlen(str);
  17399. pthread_mutex_unlock(&lock_send);
  17400. lws_callback_on_writable(wsi_client);
  17401. lws_service(context, 0);
  17402. //sleep(1);
  17403. }