MessageHandler.c 922 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985
  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 MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. 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);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. 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);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. 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));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  680. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  681. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  682. {
  683. result = FAIL;
  684. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  685. }
  686. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  687. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  688. {
  689. result = FAIL;
  690. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  691. }
  692. return result;
  693. }
  694. int OCPP_update_deduct_info(int txId, char *creditNo)
  695. {
  696. int result = PASS;
  697. char* errMsg = NULL;
  698. char sqlStr[8192];
  699. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  700. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  701. {
  702. result = FAIL;
  703. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  704. }
  705. return result;
  706. }
  707. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  708. {
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  711. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  712. atoi(columnValue[1]),
  713. columnValue[2],
  714. atoi(columnValue[3])==1?"true":"false",
  715. atoi(columnValue[4])==1?"true":"false",
  716. columnValue[5],
  717. columnValue[9]);
  718. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  719. return 0;
  720. }
  721. void OCPP_query_deduct_info()
  722. {
  723. int rc = 0;
  724. char sql[100];
  725. char zErrMsg[100];
  726. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  727. /* Execute SQL statement */
  728. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  729. if( rc != SQLITE_OK )
  730. {
  731. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  732. }
  733. }
  734. void reportReaderStatus(int gun_index)
  735. {
  736. struct timeval tmnow;
  737. struct tm *tm;
  738. char buf[28];//, usec_buf[6];
  739. gettimeofday(&tmnow, NULL);
  740. time_t t;
  741. t = time(NULL);
  742. /*UTC time and date*/
  743. tm = gmtime(&t);
  744. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  745. #if 0 // remove temporally
  746. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  747. strcat(buf,".");
  748. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  749. strcat(buf,usec_buf);
  750. #endif
  751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  754. (gun_index+1),
  755. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  756. buf,
  757. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  758. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  759. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  760. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  761. }
  762. //==========================================
  763. // Check time passed since today
  764. //==========================================
  765. long long DiffTimebWithNow(struct timeb ST)
  766. {
  767. //return milli-second
  768. struct timeb ET;
  769. long long StartTime,StopTime;
  770. ftime(&ET);
  771. StartTime=(long long)ST.time;
  772. StopTime=(long long)ET.time;
  773. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  774. }
  775. int getTimePassSinceToday(uint8_t gun_index)
  776. {
  777. int result = -1;
  778. static time_t lastTime[4];
  779. time_t t;
  780. struct tm *tmStartToday;
  781. struct timeb tbStartToday;
  782. t=time(NULL);
  783. if(difftime(t, lastTime[gun_index])>0)
  784. {
  785. tmStartToday=localtime(&t);
  786. tmStartToday->tm_hour = 0;
  787. tmStartToday->tm_min = 0;
  788. tmStartToday->tm_sec = 0;
  789. tbStartToday.time = mktime(tmStartToday);
  790. tbStartToday.millitm = 0;
  791. result = DiffTimebWithNow(tbStartToday)/1000;
  792. lastTime[gun_index] = t;
  793. }
  794. return result;
  795. }
  796. void getNowDatetime(uint8_t *data)
  797. {
  798. time_t t = time(NULL);
  799. struct tm tm = *localtime(&t);
  800. 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);
  801. }
  802. int syncDateTimeRTC(uint8_t *data)
  803. {
  804. struct ParsingResult
  805. {
  806. int result;
  807. int scanedElement;
  808. int year;
  809. int month;
  810. int mday;
  811. int hour;
  812. int min;
  813. int sec;
  814. int tz_hour;
  815. int tz_min;
  816. float minSec;
  817. }result;
  818. struct tm tmOrg;
  819. struct tm *tmTarget;
  820. struct timeb tbTarget;
  821. char buf[128];
  822. memset(&result, 0x00, sizeof(struct ParsingResult));
  823. result.result = PASS;
  824. if(strstr((char*)data, ".") != NULL)
  825. {
  826. // Original data with mini second
  827. if(strstr((char*)data, "Z") != NULL)
  828. {
  829. // Original data with Z
  830. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  831. &result.year,
  832. &result.month,
  833. &result.mday,
  834. &result.hour,
  835. &result.min,
  836. &result.sec,
  837. &result.minSec);
  838. }
  839. else
  840. {
  841. // Original data without Z
  842. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  843. &result.year,
  844. &result.month,
  845. &result.mday,
  846. &result.hour,
  847. &result.min,
  848. &result.sec,
  849. &result.minSec,
  850. &result.tz_hour,
  851. &result.tz_min);
  852. }
  853. }
  854. else
  855. {
  856. // Original data without mini second
  857. if(strstr((char*)data, "Z") != NULL)
  858. {
  859. // Original data with Z
  860. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  861. &result.year,
  862. &result.month,
  863. &result.mday,
  864. &result.hour,
  865. &result.min,
  866. &result.sec);
  867. }
  868. else
  869. {
  870. // Original data without Z
  871. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  872. &result.year,
  873. &result.month,
  874. &result.mday,
  875. &result.hour,
  876. &result.min,
  877. &result.sec,
  878. &result.tz_hour,
  879. &result.tz_min);
  880. }
  881. }
  882. tmOrg.tm_year = result.year - 1900;
  883. tmOrg.tm_mon = result.month - 1;
  884. tmOrg.tm_mday = result.mday;
  885. tmOrg.tm_hour = result.hour;
  886. tmOrg.tm_min = result.min;
  887. tmOrg.tm_sec = result.sec;
  888. tmOrg.tm_gmtoff = 0;
  889. tbTarget.time = mktime(&tmOrg);
  890. tbTarget.timezone = 0;
  891. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  892. tmTarget = gmtime(&tbTarget.time);
  893. 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);
  894. //DEBUG_INFO(" org date time: %s\n", data);
  895. //DEBUG_INFO("parse date time: %s\n", buf);
  896. system(buf);
  897. system("/sbin/hwclock -w --systohc");
  898. if(result.scanedElement < 6)
  899. result.result = FAIL;
  900. return result.result;
  901. }
  902. //==========================================
  903. // GetCompositeSchedule logic related function
  904. //==========================================
  905. int DiffTimebSec(struct timeb ST, struct timeb ET)
  906. {
  907. //return milli-second
  908. unsigned int StartTime,StopTime;
  909. StartTime=(unsigned int)ST.time;
  910. StopTime=(unsigned int)ET.time;
  911. return (StopTime-StartTime);
  912. }
  913. int DiffTimebWithNowSec(struct timeb ST)
  914. {
  915. //return milli-second
  916. struct timeb ET;
  917. unsigned int StartTime,StopTime;
  918. ftime(&ET);
  919. StartTime=(unsigned int)ST.time;
  920. StopTime=(unsigned int)ET.time;
  921. return (StopTime-StartTime);
  922. }
  923. int getStartStop(uint8_t *start, uint8_t *stop)
  924. {
  925. struct ParsingResult
  926. {
  927. int result;
  928. int scanedElement;
  929. int year;
  930. int month;
  931. int mday;
  932. int hour;
  933. int min;
  934. int sec;
  935. int tz_hour;
  936. int tz_min;
  937. float minSec;
  938. };
  939. struct ParsingResult parseStart;
  940. struct ParsingResult parseStop;
  941. int result = -1;
  942. struct tm tmStart;
  943. struct timeb tbStart;
  944. struct tm tmStop;
  945. struct timeb tbStop;
  946. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  947. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  948. // Scan start & stop date time
  949. if(strstr((char*)start, ".") != NULL)
  950. {
  951. // Original data with mini second
  952. if(strstr((char*)start, "Z") != NULL)
  953. {
  954. // Original data with Z
  955. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  956. &parseStart.year,
  957. &parseStart.month,
  958. &parseStart.mday,
  959. &parseStart.hour,
  960. &parseStart.min,
  961. &parseStart.sec,
  962. &parseStart.minSec);
  963. }
  964. else
  965. {
  966. // Original data without Z
  967. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  968. &parseStart.year,
  969. &parseStart.month,
  970. &parseStart.mday,
  971. &parseStart.hour,
  972. &parseStart.min,
  973. &parseStart.sec,
  974. &parseStart.minSec,
  975. &parseStart.tz_hour,
  976. &parseStart.tz_min);
  977. }
  978. }
  979. else
  980. {
  981. // Original data without mini second
  982. if(strstr((char*)start, "Z") != NULL)
  983. {
  984. // Original data with Z
  985. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  986. &parseStart.year,
  987. &parseStart.month,
  988. &parseStart.mday,
  989. &parseStart.hour,
  990. &parseStart.min,
  991. &parseStart.sec);
  992. }
  993. else
  994. {
  995. // Original data without Z
  996. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  997. &parseStart.year,
  998. &parseStart.month,
  999. &parseStart.mday,
  1000. &parseStart.hour,
  1001. &parseStart.min,
  1002. &parseStart.sec,
  1003. &parseStart.tz_hour,
  1004. &parseStart.tz_min);
  1005. }
  1006. }
  1007. if(strstr((char*)stop, ".") != NULL)
  1008. {
  1009. // Original data with mini second
  1010. if(strstr((char*)stop, "Z") != NULL)
  1011. {
  1012. // Original data with Z
  1013. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1014. &parseStop.year,
  1015. &parseStop.month,
  1016. &parseStop.mday,
  1017. &parseStop.hour,
  1018. &parseStop.min,
  1019. &parseStop.sec,
  1020. &parseStop.minSec);
  1021. }
  1022. else
  1023. {
  1024. // Original data without Z
  1025. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1026. &parseStop.year,
  1027. &parseStop.month,
  1028. &parseStop.mday,
  1029. &parseStop.hour,
  1030. &parseStop.min,
  1031. &parseStop.sec,
  1032. &parseStop.minSec,
  1033. &parseStop.tz_hour,
  1034. &parseStop.tz_min);
  1035. }
  1036. }
  1037. else
  1038. {
  1039. // Original data without mini second
  1040. if(strstr((char*)stop, "Z") != NULL)
  1041. {
  1042. // Original data with Z
  1043. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1044. &parseStop.year,
  1045. &parseStop.month,
  1046. &parseStop.mday,
  1047. &parseStop.hour,
  1048. &parseStop.min,
  1049. &parseStop.sec);
  1050. }
  1051. else
  1052. {
  1053. // Original data without Z
  1054. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1055. &parseStop.year,
  1056. &parseStop.month,
  1057. &parseStop.mday,
  1058. &parseStop.hour,
  1059. &parseStop.min,
  1060. &parseStop.sec,
  1061. &parseStop.tz_hour,
  1062. &parseStop.tz_min);
  1063. }
  1064. }
  1065. // Calculate date time difference
  1066. if((parseStart.scanedElement >=6) &&
  1067. (parseStop.scanedElement >=6))
  1068. {
  1069. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1070. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1071. tmStart.tm_year = parseStart.year - 1900;
  1072. tmStart.tm_mon = parseStart.month - 1;
  1073. tmStart.tm_mday = parseStart.mday;
  1074. tmStart.tm_hour = parseStart.hour;
  1075. tmStart.tm_min = parseStart.min;
  1076. tmStart.tm_sec = parseStart.sec;
  1077. tmStart.tm_gmtoff = 0;
  1078. tbStart.time = mktime(&tmStart);
  1079. tbStart.timezone = 0;
  1080. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1081. tmStop.tm_year = parseStop.year - 1900;
  1082. tmStop.tm_mon = parseStop.month - 1;
  1083. tmStop.tm_mday = parseStop.mday;
  1084. tmStop.tm_hour = parseStop.hour;
  1085. tmStop.tm_min = parseStop.min;
  1086. tmStop.tm_sec = parseStop.sec;
  1087. tmStop.tm_gmtoff = 0;
  1088. tbStop.time = mktime(&tmStop);
  1089. tbStop.timezone = 0;
  1090. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1091. result = DiffTimebSec(tbStart, tbStop);
  1092. //DEBUG_INFO("getStartStop(): %d\n", result);
  1093. }
  1094. else
  1095. {
  1096. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1097. }
  1098. return result;
  1099. }
  1100. int isOvertNow(uint8_t *start)
  1101. {
  1102. int result = NO;
  1103. struct ParsingResult
  1104. {
  1105. int result;
  1106. int scanedElement;
  1107. int year;
  1108. int month;
  1109. int mday;
  1110. int hour;
  1111. int min;
  1112. int sec;
  1113. int tz_hour;
  1114. int tz_min;
  1115. float minSec;
  1116. }parsingResult;
  1117. struct tm tmStart;
  1118. struct timeb tbStart;
  1119. if(strstr((char*)start, ".") != NULL)
  1120. {
  1121. // Original data with mini second
  1122. if(strstr((char*)start, "Z") != NULL)
  1123. {
  1124. // Original data with Z
  1125. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1126. &parsingResult.year,
  1127. &parsingResult.month,
  1128. &parsingResult.mday,
  1129. &parsingResult.hour,
  1130. &parsingResult.min,
  1131. &parsingResult.sec,
  1132. &parsingResult.minSec);
  1133. }
  1134. else
  1135. {
  1136. // Original data without Z
  1137. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1138. &parsingResult.year,
  1139. &parsingResult.month,
  1140. &parsingResult.mday,
  1141. &parsingResult.hour,
  1142. &parsingResult.min,
  1143. &parsingResult.sec,
  1144. &parsingResult.minSec,
  1145. &parsingResult.tz_hour,
  1146. &parsingResult.tz_min);
  1147. }
  1148. }
  1149. else
  1150. {
  1151. // Original data without mini second
  1152. if(strstr((char*)start, "Z") != NULL)
  1153. {
  1154. // Original data with Z
  1155. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1156. &parsingResult.year,
  1157. &parsingResult.month,
  1158. &parsingResult.mday,
  1159. &parsingResult.hour,
  1160. &parsingResult.min,
  1161. &parsingResult.sec);
  1162. }
  1163. else
  1164. {
  1165. // Original data without Z
  1166. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1167. &parsingResult.year,
  1168. &parsingResult.month,
  1169. &parsingResult.mday,
  1170. &parsingResult.hour,
  1171. &parsingResult.min,
  1172. &parsingResult.sec,
  1173. &parsingResult.tz_hour,
  1174. &parsingResult.tz_min);
  1175. }
  1176. }
  1177. if(parsingResult.scanedElement >= 6)
  1178. {
  1179. tmStart.tm_year = parsingResult.year - 1900;
  1180. tmStart.tm_mon = parsingResult.month - 1;
  1181. tmStart.tm_mday = parsingResult.mday;
  1182. tmStart.tm_hour = parsingResult.hour;
  1183. tmStart.tm_min = parsingResult.min;
  1184. tmStart.tm_sec = parsingResult.sec;
  1185. tmStart.tm_gmtoff = 0;
  1186. tbStart.time = mktime(&tmStart);
  1187. tbStart.timezone = 0;
  1188. tbStart.millitm = 0;
  1189. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1190. if(DiffTimebWithNowSec(tbStart) <= 0)
  1191. result = NO;
  1192. else
  1193. result = YES;
  1194. }
  1195. else
  1196. {
  1197. DEBUG_WARN("Start date parsing error.\n");
  1198. }
  1199. return result;
  1200. }
  1201. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1202. {
  1203. struct ParsingResult
  1204. {
  1205. int result;
  1206. int scanedElement;
  1207. int year;
  1208. int month;
  1209. int mday;
  1210. int hour;
  1211. int min;
  1212. int sec;
  1213. int tz_hour;
  1214. int tz_min;
  1215. float minSec;
  1216. };
  1217. struct ParsingResult parseStart;
  1218. struct ParsingResult parseStop;
  1219. int result = -1;
  1220. struct tm tmStart;
  1221. struct timeb tbStart;
  1222. struct tm tmStop;
  1223. struct timeb tbStop;
  1224. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1225. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1226. // Scan start & stop date time
  1227. if(strstr((char*)start, ".") != NULL)
  1228. {
  1229. // Original data with mini second
  1230. if(strstr((char*)start, "Z") != NULL)
  1231. {
  1232. // Original data with Z
  1233. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1234. &parseStart.year,
  1235. &parseStart.month,
  1236. &parseStart.mday,
  1237. &parseStart.hour,
  1238. &parseStart.min,
  1239. &parseStart.sec,
  1240. &parseStart.minSec);
  1241. }
  1242. else
  1243. {
  1244. // Original data without Z
  1245. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1246. &parseStart.year,
  1247. &parseStart.month,
  1248. &parseStart.mday,
  1249. &parseStart.hour,
  1250. &parseStart.min,
  1251. &parseStart.sec,
  1252. &parseStart.minSec,
  1253. &parseStart.tz_hour,
  1254. &parseStart.tz_min);
  1255. }
  1256. }
  1257. else
  1258. {
  1259. // Original data without mini second
  1260. if(strstr((char*)start, "Z") != NULL)
  1261. {
  1262. // Original data with Z
  1263. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1264. &parseStart.year,
  1265. &parseStart.month,
  1266. &parseStart.mday,
  1267. &parseStart.hour,
  1268. &parseStart.min,
  1269. &parseStart.sec);
  1270. }
  1271. else
  1272. {
  1273. // Original data without Z
  1274. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1275. &parseStart.year,
  1276. &parseStart.month,
  1277. &parseStart.mday,
  1278. &parseStart.hour,
  1279. &parseStart.min,
  1280. &parseStart.sec,
  1281. &parseStart.tz_hour,
  1282. &parseStart.tz_min);
  1283. }
  1284. }
  1285. if(strstr((char*)stop, ".") != NULL)
  1286. {
  1287. // Original data with mini second
  1288. if(strstr((char*)stop, "Z") != NULL)
  1289. {
  1290. // Original data with Z
  1291. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1292. &parseStop.year,
  1293. &parseStop.month,
  1294. &parseStop.mday,
  1295. &parseStop.hour,
  1296. &parseStop.min,
  1297. &parseStop.sec,
  1298. &parseStop.minSec);
  1299. }
  1300. else
  1301. {
  1302. // Original data without Z
  1303. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1304. &parseStop.year,
  1305. &parseStop.month,
  1306. &parseStop.mday,
  1307. &parseStop.hour,
  1308. &parseStop.min,
  1309. &parseStop.sec,
  1310. &parseStop.minSec,
  1311. &parseStop.tz_hour,
  1312. &parseStop.tz_min);
  1313. }
  1314. }
  1315. else
  1316. {
  1317. // Original data without mini second
  1318. if(strstr((char*)stop, "Z") != NULL)
  1319. {
  1320. // Original data with Z
  1321. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1322. &parseStop.year,
  1323. &parseStop.month,
  1324. &parseStop.mday,
  1325. &parseStop.hour,
  1326. &parseStop.min,
  1327. &parseStop.sec);
  1328. }
  1329. else
  1330. {
  1331. // Original data without Z
  1332. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1333. &parseStop.year,
  1334. &parseStop.month,
  1335. &parseStop.mday,
  1336. &parseStop.hour,
  1337. &parseStop.min,
  1338. &parseStop.sec,
  1339. &parseStop.tz_hour,
  1340. &parseStop.tz_min);
  1341. }
  1342. }
  1343. // Calculate date time difference
  1344. if((parseStart.scanedElement >=6) &&
  1345. (parseStop.scanedElement >=6))
  1346. {
  1347. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1348. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1349. tmStart.tm_year = parseStart.year - 1900;
  1350. tmStart.tm_mon = parseStart.month - 1;
  1351. tmStart.tm_mday = parseStart.mday;
  1352. tmStart.tm_hour = parseStart.hour;
  1353. tmStart.tm_min = parseStart.min;
  1354. tmStart.tm_sec = parseStart.sec;
  1355. tmStart.tm_gmtoff = 0;
  1356. tbStart.time = mktime(&tmStart);
  1357. tbStart.timezone = 0;
  1358. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1359. tmStop.tm_year = parseStop.year - 1900;
  1360. tmStop.tm_mon = parseStop.month - 1;
  1361. tmStop.tm_mday = parseStop.mday;
  1362. tmStop.tm_hour = parseStop.hour;
  1363. tmStop.tm_min = parseStop.min;
  1364. tmStop.tm_sec = parseStop.sec;
  1365. tmStop.tm_gmtoff = 0;
  1366. tbStop.time = mktime(&tmStop);
  1367. tbStop.timezone = 0;
  1368. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1369. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1370. //DEBUG_INFO("getStartStop(): %d\n", result);
  1371. }
  1372. else
  1373. {
  1374. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1375. }
  1376. return result;
  1377. }
  1378. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1379. {
  1380. FILE *fp;
  1381. char profileFileName[128];
  1382. char *line = NULL;
  1383. size_t len = 0;
  1384. time_t CurrentTime;
  1385. struct tm *tmComposite;
  1386. struct StructChargingProfile maxProfile;
  1387. struct StructChargingProfile compositeProfile;
  1388. uint8_t limitMax=0;
  1389. int compositePeriodIdx = 0;
  1390. CurrentTime = time(NULL);
  1391. tmComposite=localtime(&CurrentTime);
  1392. 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);
  1393. if(isUnitA)
  1394. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1395. else
  1396. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1397. compositeProfile.ChargingSchedule.Duration = durationReq;
  1398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1399. {
  1400. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1401. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1402. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1403. }
  1404. compositeProfile.ChargingProfileId = 0;
  1405. compositeProfile.StackLevel = 99 ;
  1406. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1407. maxProfile.ChargingProfileId = -1;
  1408. maxProfile.ChargingSchedule.Duration = -1;
  1409. system("rm -f /tmp/*.json");
  1410. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1411. // Search max profile
  1412. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1413. if((access(profileFileName, F_OK))!=-1)
  1414. {
  1415. fp = fopen(profileFileName, "r");
  1416. while(getline(&line, &len, fp) != -1)
  1417. {
  1418. json_object *obj = NULL;
  1419. obj = json_tokener_parse(line);
  1420. if(is_error(obj))
  1421. {
  1422. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1423. }
  1424. else
  1425. {
  1426. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1427. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1428. )
  1429. {
  1430. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1431. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1432. )
  1433. {
  1434. struct tm tmFrom, tmTo;
  1435. struct timeb tbFrom, tbTo;
  1436. 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) &&
  1437. (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))
  1438. {
  1439. tmFrom.tm_year -= 1900;
  1440. tmFrom.tm_mon -= 1;
  1441. tbFrom.time = mktime(&tmFrom);
  1442. tmTo.tm_year -= 1900;
  1443. tmTo.tm_mon -= 1;
  1444. tbTo.time = mktime(&tmTo);
  1445. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1446. {
  1447. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1448. {
  1449. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1450. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1451. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1452. }
  1453. if(maxProfile.ChargingProfileId == -1)
  1454. DEBUG_INFO("MaxProfile found.\n");
  1455. else
  1456. DEBUG_INFO("MaxProfile updated.\n");
  1457. // Required item
  1458. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1459. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1460. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1461. if(isUnitA)
  1462. {
  1463. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1464. 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++)
  1465. {
  1466. 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"));
  1467. 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?
  1468. 3:
  1469. 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")));
  1470. 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")));
  1471. }
  1472. }
  1473. else
  1474. {
  1475. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1476. 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++)
  1477. {
  1478. 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"));
  1479. 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?
  1480. 3:
  1481. 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")));
  1482. 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));
  1483. }
  1484. }
  1485. // Optional item
  1486. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1487. {
  1488. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1489. }
  1490. else
  1491. {
  1492. sprintf((char*)maxProfile.ValidFrom, " ");
  1493. }
  1494. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1495. {
  1496. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1497. }
  1498. else
  1499. {
  1500. sprintf((char*)maxProfile.ValidTo, " ");
  1501. }
  1502. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1503. {
  1504. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1505. }
  1506. else
  1507. {
  1508. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1509. }
  1510. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1511. {
  1512. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1513. }
  1514. else
  1515. {
  1516. maxProfile.TransactionId = -1;
  1517. }
  1518. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1519. {
  1520. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1521. }
  1522. else
  1523. {
  1524. maxProfile.ChargingSchedule.Duration = 86400;
  1525. }
  1526. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1527. {
  1528. 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")));
  1529. }
  1530. else
  1531. {
  1532. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1533. }
  1534. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1535. {
  1536. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1537. }
  1538. else
  1539. {
  1540. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. else
  1546. {
  1547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1548. {
  1549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1552. }
  1553. if(maxProfile.ChargingProfileId == -1)
  1554. DEBUG_INFO("MaxProfile found.\n");
  1555. else
  1556. DEBUG_INFO("MaxProfile updated.\n");
  1557. // Required item
  1558. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1559. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1560. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1561. if(isUnitA)
  1562. {
  1563. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1564. 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++)
  1565. {
  1566. 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"));
  1567. 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?
  1568. 3:
  1569. 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")));
  1570. 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")));
  1571. }
  1572. }
  1573. else
  1574. {
  1575. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1576. 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++)
  1577. {
  1578. 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"));
  1579. 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?
  1580. 3:
  1581. 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")));
  1582. 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));
  1583. }
  1584. }
  1585. // Optional item
  1586. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1587. {
  1588. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1589. }
  1590. else
  1591. {
  1592. sprintf((char*)maxProfile.ValidFrom, " ");
  1593. }
  1594. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1595. {
  1596. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1597. }
  1598. else
  1599. {
  1600. sprintf((char*)maxProfile.ValidTo, " ");
  1601. }
  1602. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1603. {
  1604. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1605. }
  1606. else
  1607. {
  1608. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1609. }
  1610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1611. {
  1612. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1613. }
  1614. else
  1615. {
  1616. maxProfile.TransactionId = -1;
  1617. }
  1618. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1619. {
  1620. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1621. }
  1622. else
  1623. {
  1624. maxProfile.ChargingSchedule.Duration = 86400;
  1625. }
  1626. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1627. {
  1628. 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")));
  1629. }
  1630. else
  1631. {
  1632. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1633. }
  1634. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1635. {
  1636. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1637. }
  1638. else
  1639. {
  1640. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1641. }
  1642. }
  1643. }
  1644. }
  1645. json_object_put(obj);
  1646. }
  1647. fclose(fp);
  1648. /*
  1649. if(maxProfile.ChargingProfileId !=-1)
  1650. {
  1651. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1652. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1653. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1654. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1655. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1656. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1657. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1658. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1659. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1660. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1661. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1662. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1663. {
  1664. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1665. {
  1666. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1667. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1668. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1669. }
  1670. }
  1671. }
  1672. else
  1673. DEBUG_INFO("MaxProfile not found.\n");
  1674. DEBUG_INFO("------------------------------------\n");*/
  1675. }
  1676. if(maxProfile.ChargingProfileId != -1)
  1677. {
  1678. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1679. {
  1680. if(maxProfile.ChargingSchedule.Duration != -1)
  1681. {
  1682. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1683. 0:
  1684. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1685. }
  1686. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1687. {
  1688. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1689. {
  1690. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1691. 0:
  1692. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1693. if(idxPeriod > 0)
  1694. {
  1695. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1696. {
  1697. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1704. {
  1705. if(maxProfile.ChargingSchedule.Duration != -1)
  1706. {
  1707. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1708. }
  1709. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1710. {
  1711. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1712. {
  1713. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1714. if(idxPeriod > 0)
  1715. {
  1716. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1717. {
  1718. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. }
  1724. else
  1725. {
  1726. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1727. {
  1728. if(maxProfile.ChargingSchedule.Duration != -1)
  1729. {
  1730. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1731. 0:
  1732. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1733. }
  1734. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1735. {
  1736. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1737. {
  1738. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1739. 0:
  1740. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1741. if(idxPeriod > 0)
  1742. {
  1743. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1744. {
  1745. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. else
  1752. {
  1753. if(maxProfile.ChargingSchedule.Duration != -1)
  1754. {
  1755. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1756. 0:
  1757. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1758. }
  1759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1760. {
  1761. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1762. {
  1763. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1764. 0:
  1765. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1766. if(idxPeriod > 0)
  1767. {
  1768. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1769. {
  1770. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. }
  1777. /*
  1778. DEBUG_INFO("MaxProfile after align.\n");
  1779. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1780. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1781. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1782. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1783. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1784. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1785. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1786. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1787. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1788. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1789. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1791. {
  1792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1793. {
  1794. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1795. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1796. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1797. }
  1798. }
  1799. DEBUG_INFO("------------------------------------\n");*/
  1800. }
  1801. // Find each profile period quantity
  1802. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1803. {
  1804. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1805. limitMax = idx+1;
  1806. }
  1807. if(maxProfile.ChargingProfileId != -1)
  1808. {
  1809. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1810. {
  1811. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1812. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1813. (maxProfile.ChargingSchedule.Duration > 0))
  1814. {
  1815. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1816. {
  1817. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1818. compositePeriodIdx++;
  1819. }
  1820. else
  1821. {
  1822. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1823. }
  1824. }
  1825. }
  1826. }
  1827. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1828. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1829. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1830. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1832. {
  1833. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1834. {
  1835. compositeProfile.ChargingProfileId = 1;
  1836. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1837. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1838. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1839. }
  1840. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1841. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1843. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1844. }
  1845. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1846. if(line)
  1847. free(line);
  1848. }
  1849. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1850. {
  1851. FILE *fp;
  1852. char profileFileName[128];
  1853. char *line = NULL;
  1854. size_t len = 0;
  1855. time_t CurrentTime;
  1856. struct tm *tmComposite;
  1857. struct StructChargingProfile maxProfile;
  1858. struct StructChargingProfile defaultTxProfile;
  1859. struct StructChargingProfile txProfile;
  1860. struct StructChargingProfile compositeProfile;
  1861. struct StructChargingSchedulePeriod tmpPeriod;
  1862. uint8_t limitMax=0;
  1863. uint8_t limitDef=0;
  1864. uint8_t limitTx=0;
  1865. int compositePeriodIdx = 0;
  1866. CurrentTime = time(NULL);
  1867. tmComposite=localtime(&CurrentTime);
  1868. 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);
  1869. if(isUnitA)
  1870. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1871. else
  1872. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1873. compositeProfile.ChargingSchedule.Duration = durationReq;
  1874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1875. {
  1876. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1877. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1878. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1879. }
  1880. compositeProfile.ChargingProfileId = 0;
  1881. compositeProfile.StackLevel = 99 ;
  1882. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1883. maxProfile.ChargingProfileId = -1;
  1884. defaultTxProfile.ChargingProfileId = -1;
  1885. txProfile.ChargingProfileId = -1;
  1886. maxProfile.ChargingSchedule.Duration = -1;
  1887. defaultTxProfile.ChargingSchedule.Duration = -1;
  1888. txProfile.ChargingSchedule.Duration = -1;
  1889. system("rm -f /tmp/*.json");
  1890. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1891. /*
  1892. * Search valid charging profile
  1893. */
  1894. //DEBUG_INFO("====================================\n");
  1895. // Search tx profile
  1896. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1897. if((access(profileFileName, F_OK))!=-1)
  1898. {
  1899. fp = fopen(profileFileName, "r");
  1900. while(getline(&line, &len, fp) != -1)
  1901. {
  1902. json_object *obj = NULL;
  1903. obj = json_tokener_parse(line);
  1904. if(is_error(obj))
  1905. {
  1906. DEBUG_ERROR("Parse txProfile from file error.\n");
  1907. }
  1908. else
  1909. {
  1910. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1911. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1912. )
  1913. {
  1914. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1915. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1916. )
  1917. {
  1918. struct tm tmFrom, tmTo;
  1919. struct timeb tbFrom, tbTo;
  1920. 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) &&
  1921. (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))
  1922. {
  1923. tmFrom.tm_year -= 1900;
  1924. tmFrom.tm_mon -= 1;
  1925. tbFrom.time = mktime(&tmFrom);
  1926. tmTo.tm_year -= 1900;
  1927. tmTo.tm_mon -= 1;
  1928. tbTo.time = mktime(&tmTo);
  1929. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1930. {
  1931. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1932. {
  1933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1934. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1935. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1936. }
  1937. if(txProfile.ChargingProfileId == -1)
  1938. DEBUG_INFO("TxProfile found.\n");
  1939. else
  1940. DEBUG_INFO("TxProfile updated.\n");
  1941. // Required item
  1942. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1943. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1944. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1945. if(isUnitA)
  1946. {
  1947. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1948. 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++)
  1949. {
  1950. 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"));
  1951. 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?
  1952. 3:
  1953. 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")));
  1954. 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")));
  1955. }
  1956. }
  1957. else
  1958. {
  1959. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1960. 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++)
  1961. {
  1962. 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"));
  1963. 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?
  1964. 3:
  1965. 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")));
  1966. 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));
  1967. }
  1968. }
  1969. // Optional item
  1970. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1971. {
  1972. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1973. }
  1974. else
  1975. {
  1976. sprintf((char*)txProfile.ValidFrom, " ");
  1977. }
  1978. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1979. {
  1980. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1981. }
  1982. else
  1983. {
  1984. sprintf((char*)txProfile.ValidTo, " ");
  1985. }
  1986. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1987. {
  1988. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1989. }
  1990. else
  1991. {
  1992. sprintf((char*)txProfile.RecurrencyKind, " ");
  1993. }
  1994. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1995. {
  1996. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1997. }
  1998. else
  1999. {
  2000. txProfile.TransactionId = -1;
  2001. }
  2002. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2003. {
  2004. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2005. }
  2006. else
  2007. {
  2008. txProfile.ChargingSchedule.Duration = 86400;
  2009. }
  2010. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2011. {
  2012. 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")));
  2013. }
  2014. else
  2015. {
  2016. 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));
  2017. }
  2018. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2019. {
  2020. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2021. }
  2022. else
  2023. {
  2024. txProfile.ChargingSchedule.MinChargingRate = -1;
  2025. }
  2026. }
  2027. }
  2028. }
  2029. else
  2030. {
  2031. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2032. {
  2033. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2034. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2036. }
  2037. if(txProfile.ChargingProfileId == -1)
  2038. DEBUG_INFO("TxProfile found.\n");
  2039. else
  2040. DEBUG_INFO("TxProfile updated.\n");
  2041. // Required item
  2042. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2043. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2044. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2045. if(isUnitA)
  2046. {
  2047. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2048. 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++)
  2049. {
  2050. 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"));
  2051. 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?
  2052. 3:
  2053. 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")));
  2054. 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")));
  2055. }
  2056. }
  2057. else
  2058. {
  2059. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2060. 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++)
  2061. {
  2062. 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"));
  2063. 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?
  2064. 3:
  2065. 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")));
  2066. 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));
  2067. }
  2068. }
  2069. // Optional item
  2070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2071. {
  2072. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2073. }
  2074. else
  2075. {
  2076. sprintf((char*)txProfile.ValidFrom, " ");
  2077. }
  2078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2079. {
  2080. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2081. }
  2082. else
  2083. {
  2084. sprintf((char*)txProfile.ValidTo, " ");
  2085. }
  2086. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2087. {
  2088. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)txProfile.RecurrencyKind, " ");
  2093. }
  2094. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2095. {
  2096. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2097. }
  2098. else
  2099. {
  2100. txProfile.TransactionId = -1;
  2101. }
  2102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2103. {
  2104. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2105. }
  2106. else
  2107. {
  2108. txProfile.ChargingSchedule.Duration = 86400;
  2109. }
  2110. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2111. {
  2112. 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")));
  2113. }
  2114. else
  2115. {
  2116. 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));
  2117. }
  2118. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2119. {
  2120. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2121. }
  2122. else
  2123. {
  2124. txProfile.ChargingSchedule.MinChargingRate = -1;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. json_object_put(obj);
  2130. }
  2131. fclose(fp);
  2132. /*
  2133. if(txProfile.ChargingProfileId != -1)
  2134. {
  2135. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2136. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2137. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2138. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2139. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2140. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2141. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2142. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2143. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2144. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2145. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2146. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2147. {
  2148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2149. {
  2150. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2151. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2152. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2153. }
  2154. }
  2155. }
  2156. else
  2157. DEBUG_INFO("TxProfile not found.\n");*/
  2158. }
  2159. // Search default tx profile
  2160. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2161. if((access(profileFileName, F_OK))==-1)
  2162. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2163. if((access(profileFileName, F_OK))!=-1)
  2164. {
  2165. fp = fopen(profileFileName, "r");
  2166. while(getline(&line, &len, fp) != -1)
  2167. {
  2168. json_object *obj = NULL;
  2169. obj = json_tokener_parse(line);
  2170. if(is_error(obj))
  2171. {
  2172. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2173. }
  2174. else
  2175. {
  2176. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2177. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2178. )
  2179. {
  2180. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2181. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2182. )
  2183. {
  2184. struct tm tmFrom, tmTo;
  2185. struct timeb tbFrom, tbTo;
  2186. 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) &&
  2187. (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))
  2188. {
  2189. tmFrom.tm_year -= 1900;
  2190. tmFrom.tm_mon -= 1;
  2191. tbFrom.time = mktime(&tmFrom);
  2192. tmTo.tm_year -= 1900;
  2193. tmTo.tm_mon -= 1;
  2194. tbTo.time = mktime(&tmTo);
  2195. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2196. {
  2197. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2198. {
  2199. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2200. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2201. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2202. }
  2203. if(defaultTxProfile.ChargingProfileId == -1)
  2204. DEBUG_INFO("TxDefaultProfile found.\n");
  2205. else
  2206. DEBUG_INFO("TxDefaultProfile updated.\n");
  2207. // Required item
  2208. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2209. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2210. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2211. if(isUnitA)
  2212. {
  2213. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2214. 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++)
  2215. {
  2216. 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"));
  2217. 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?
  2218. 3:
  2219. 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")));
  2220. 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")));
  2221. }
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2226. 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++)
  2227. {
  2228. 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"));
  2229. 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?
  2230. 3:
  2231. 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")));
  2232. 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));
  2233. }
  2234. }
  2235. // Optional item
  2236. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2237. {
  2238. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2239. }
  2240. else
  2241. {
  2242. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2243. }
  2244. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2245. {
  2246. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2247. }
  2248. else
  2249. {
  2250. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2251. }
  2252. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2253. {
  2254. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2255. }
  2256. else
  2257. {
  2258. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2259. }
  2260. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2261. {
  2262. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2263. }
  2264. else
  2265. {
  2266. defaultTxProfile.TransactionId = -1;
  2267. }
  2268. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2269. {
  2270. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2271. }
  2272. else
  2273. {
  2274. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2275. }
  2276. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2277. {
  2278. 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")));
  2279. }
  2280. else
  2281. {
  2282. 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));
  2283. }
  2284. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2285. {
  2286. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2287. }
  2288. else
  2289. {
  2290. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2291. }
  2292. }
  2293. }
  2294. }
  2295. else
  2296. {
  2297. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2298. {
  2299. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2302. }
  2303. if(defaultTxProfile.ChargingProfileId == -1)
  2304. DEBUG_INFO("TxDefaultProfile found.\n");
  2305. else
  2306. DEBUG_INFO("TxDefaultProfile updated.\n");
  2307. // Required item
  2308. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2309. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2310. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2311. if(isUnitA)
  2312. {
  2313. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2314. 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++)
  2315. {
  2316. 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"));
  2317. 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?
  2318. 3:
  2319. 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")));
  2320. 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")));
  2321. }
  2322. }
  2323. else
  2324. {
  2325. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2326. 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++)
  2327. {
  2328. 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"));
  2329. 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?
  2330. 3:
  2331. 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")));
  2332. 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));
  2333. }
  2334. }
  2335. // Optional item
  2336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2337. {
  2338. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2339. }
  2340. else
  2341. {
  2342. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2343. }
  2344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2345. {
  2346. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2351. }
  2352. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2353. {
  2354. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2355. }
  2356. else
  2357. {
  2358. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2359. }
  2360. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2361. {
  2362. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2363. }
  2364. else
  2365. {
  2366. defaultTxProfile.TransactionId = -1;
  2367. }
  2368. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2369. {
  2370. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2371. }
  2372. else
  2373. {
  2374. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2375. }
  2376. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2377. {
  2378. 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")));
  2379. }
  2380. else
  2381. {
  2382. 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));
  2383. }
  2384. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2385. {
  2386. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2387. }
  2388. else
  2389. {
  2390. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. json_object_put(obj);
  2396. }
  2397. fclose(fp);
  2398. /*
  2399. if(defaultTxProfile.ChargingProfileId != -1)
  2400. {
  2401. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2402. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2403. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2404. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2405. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2406. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2407. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2408. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2409. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2410. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2411. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2413. {
  2414. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2415. {
  2416. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2417. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2418. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2419. }
  2420. }
  2421. }
  2422. else
  2423. DEBUG_INFO("TxDefaultProfile not found.\n");
  2424. DEBUG_INFO("------------------------------------\n");*/
  2425. }
  2426. // Search max profile
  2427. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2428. if((access(profileFileName, F_OK))!=-1)
  2429. {
  2430. fp = fopen(profileFileName, "r");
  2431. while(getline(&line, &len, fp) != -1)
  2432. {
  2433. json_object *obj = NULL;
  2434. obj = json_tokener_parse(line);
  2435. if(is_error(obj))
  2436. {
  2437. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2438. }
  2439. else
  2440. {
  2441. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2442. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2443. )
  2444. {
  2445. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2446. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2447. )
  2448. {
  2449. struct tm tmFrom, tmTo;
  2450. struct timeb tbFrom, tbTo;
  2451. 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) &&
  2452. (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))
  2453. {
  2454. tmFrom.tm_year -= 1900;
  2455. tmFrom.tm_mon -= 1;
  2456. tbFrom.time = mktime(&tmFrom);
  2457. tmTo.tm_year -= 1900;
  2458. tmTo.tm_mon -= 1;
  2459. tbTo.time = mktime(&tmTo);
  2460. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2461. {
  2462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2463. {
  2464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2467. }
  2468. if(maxProfile.ChargingProfileId == -1)
  2469. DEBUG_INFO("MaxProfile found.\n");
  2470. else
  2471. DEBUG_INFO("MaxProfile updated.\n");
  2472. // Required item
  2473. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2474. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2475. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2476. if(isUnitA)
  2477. {
  2478. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2479. 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++)
  2480. {
  2481. 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"));
  2482. 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?
  2483. 3:
  2484. 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")));
  2485. 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")));
  2486. }
  2487. }
  2488. else
  2489. {
  2490. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2491. 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++)
  2492. {
  2493. 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"));
  2494. 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?
  2495. 3:
  2496. 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")));
  2497. 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));
  2498. }
  2499. }
  2500. // Optional item
  2501. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2502. {
  2503. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2504. }
  2505. else
  2506. {
  2507. sprintf((char*)maxProfile.ValidFrom, " ");
  2508. }
  2509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2510. {
  2511. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2512. }
  2513. else
  2514. {
  2515. sprintf((char*)maxProfile.ValidTo, " ");
  2516. }
  2517. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2518. {
  2519. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2520. }
  2521. else
  2522. {
  2523. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2524. }
  2525. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2526. {
  2527. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2528. }
  2529. else
  2530. {
  2531. maxProfile.TransactionId = -1;
  2532. }
  2533. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2534. {
  2535. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2536. }
  2537. else
  2538. {
  2539. maxProfile.ChargingSchedule.Duration = 86400;
  2540. }
  2541. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2542. {
  2543. 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")));
  2544. }
  2545. else
  2546. {
  2547. 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));
  2548. }
  2549. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2550. {
  2551. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2552. }
  2553. else
  2554. {
  2555. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2556. }
  2557. }
  2558. }
  2559. }
  2560. else
  2561. {
  2562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2563. {
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2567. }
  2568. if(maxProfile.ChargingProfileId == -1)
  2569. DEBUG_INFO("MaxProfile found.\n");
  2570. else
  2571. DEBUG_INFO("MaxProfile updated.\n");
  2572. // Required item
  2573. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2574. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2575. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2576. if(isUnitA)
  2577. {
  2578. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2579. 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++)
  2580. {
  2581. 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"));
  2582. 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?
  2583. 3:
  2584. 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")));
  2585. 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")));
  2586. }
  2587. }
  2588. else
  2589. {
  2590. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2591. 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++)
  2592. {
  2593. 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"));
  2594. 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?
  2595. 3:
  2596. 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")));
  2597. 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));
  2598. }
  2599. }
  2600. // Optional item
  2601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2602. {
  2603. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2604. }
  2605. else
  2606. {
  2607. sprintf((char*)maxProfile.ValidFrom, " ");
  2608. }
  2609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2610. {
  2611. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2612. }
  2613. else
  2614. {
  2615. sprintf((char*)maxProfile.ValidTo, " ");
  2616. }
  2617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2618. {
  2619. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2620. }
  2621. else
  2622. {
  2623. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2624. }
  2625. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2626. {
  2627. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2628. }
  2629. else
  2630. {
  2631. maxProfile.TransactionId = -1;
  2632. }
  2633. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2634. {
  2635. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2636. }
  2637. else
  2638. {
  2639. maxProfile.ChargingSchedule.Duration = 86400;
  2640. }
  2641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2642. {
  2643. 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")));
  2644. }
  2645. else
  2646. {
  2647. 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));
  2648. }
  2649. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2650. {
  2651. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2652. }
  2653. else
  2654. {
  2655. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2656. }
  2657. }
  2658. }
  2659. }
  2660. json_object_put(obj);
  2661. }
  2662. fclose(fp);
  2663. /*
  2664. if(maxProfile.ChargingProfileId !=-1)
  2665. {
  2666. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2667. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2668. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2669. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2670. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2671. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2672. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2673. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2674. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2675. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2676. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2680. {
  2681. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2682. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2683. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2684. }
  2685. }
  2686. }
  2687. else
  2688. DEBUG_INFO("MaxProfile not found.\n");
  2689. DEBUG_INFO("------------------------------------\n");*/
  2690. }
  2691. /*
  2692. * Align found profile start schedule & periods
  2693. */
  2694. //DEBUG_INFO("====================================\n");
  2695. /*
  2696. // For local test usage, force modify found profile start schedule info
  2697. 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);
  2698. 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);
  2699. 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);
  2700. */
  2701. if(txProfile.ChargingProfileId != -1)
  2702. {
  2703. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2704. {
  2705. if(txProfile.ChargingSchedule.Duration != -1)
  2706. {
  2707. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2708. 0:
  2709. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2710. }
  2711. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2712. {
  2713. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2714. {
  2715. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2716. 0:
  2717. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2718. if(idxPeriod > 0)
  2719. {
  2720. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2721. {
  2722. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2729. {
  2730. if(txProfile.ChargingSchedule.Duration != -1)
  2731. {
  2732. 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?
  2733. 0:
  2734. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2735. }
  2736. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2737. {
  2738. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2739. {
  2740. 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?
  2741. 0:
  2742. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2743. if(idxPeriod > 0)
  2744. {
  2745. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2746. {
  2747. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2748. }
  2749. }
  2750. }
  2751. }
  2752. }
  2753. else
  2754. {
  2755. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2756. {
  2757. if(txProfile.ChargingSchedule.Duration != -1)
  2758. {
  2759. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2760. 0:
  2761. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2762. }
  2763. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2764. {
  2765. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2766. {
  2767. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2768. 0:
  2769. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2770. if(idxPeriod > 0)
  2771. {
  2772. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2773. {
  2774. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2775. }
  2776. }
  2777. }
  2778. }
  2779. }
  2780. else
  2781. {
  2782. if(txProfile.ChargingSchedule.Duration != -1)
  2783. {
  2784. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2785. 0:
  2786. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2787. }
  2788. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2789. {
  2790. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2791. {
  2792. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2793. 0:
  2794. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2795. if(idxPeriod > 0)
  2796. {
  2797. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2798. {
  2799. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2800. }
  2801. }
  2802. }
  2803. }
  2804. }
  2805. }
  2806. /*
  2807. DEBUG_INFO("txProfile after align.\n");
  2808. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2809. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2810. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2811. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2812. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2813. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2814. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2815. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2816. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2817. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2818. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2819. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2820. {
  2821. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2822. {
  2823. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2824. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2825. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2826. }
  2827. }*/
  2828. }
  2829. if(defaultTxProfile.ChargingProfileId != -1)
  2830. {
  2831. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2832. {
  2833. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2834. {
  2835. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2836. 0:
  2837. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2838. }
  2839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2840. {
  2841. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2842. {
  2843. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2844. 0:
  2845. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2846. if(idxPeriod > 0)
  2847. {
  2848. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2849. {
  2850. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2857. {
  2858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2859. {
  2860. 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?
  2861. 0:
  2862. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2863. }
  2864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2867. {
  2868. 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?
  2869. 0:
  2870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2871. if(idxPeriod > 0)
  2872. {
  2873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2874. {
  2875. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. else
  2882. {
  2883. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2884. {
  2885. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2886. {
  2887. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2888. 0:
  2889. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2890. }
  2891. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2892. {
  2893. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2894. {
  2895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2896. 0:
  2897. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2898. if(idxPeriod > 0)
  2899. {
  2900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2901. {
  2902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2903. }
  2904. }
  2905. }
  2906. }
  2907. }
  2908. else
  2909. {
  2910. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2911. {
  2912. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2913. 0:
  2914. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2915. }
  2916. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2917. {
  2918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2919. {
  2920. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2921. 0:
  2922. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2923. if(idxPeriod > 0)
  2924. {
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2928. }
  2929. }
  2930. }
  2931. }
  2932. }
  2933. }
  2934. /*
  2935. DEBUG_INFO("defaultTxProfile after align.\n");
  2936. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2937. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2938. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2939. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2940. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2941. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2942. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2943. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2944. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2945. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2946. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2947. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2950. {
  2951. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2952. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2953. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2954. }
  2955. }
  2956. DEBUG_INFO("------------------------------------\n");*/
  2957. }
  2958. if(maxProfile.ChargingProfileId != -1)
  2959. {
  2960. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2961. {
  2962. if(maxProfile.ChargingSchedule.Duration != -1)
  2963. {
  2964. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2965. 0:
  2966. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2967. }
  2968. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2969. {
  2970. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2971. {
  2972. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2973. 0:
  2974. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2975. if(idxPeriod > 0)
  2976. {
  2977. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2978. {
  2979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2980. }
  2981. }
  2982. }
  2983. }
  2984. }
  2985. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2986. {
  2987. if(maxProfile.ChargingSchedule.Duration != -1)
  2988. {
  2989. 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?
  2990. 0:
  2991. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2992. }
  2993. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2994. {
  2995. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2996. {
  2997. 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?
  2998. 0:
  2999. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3000. if(idxPeriod > 0)
  3001. {
  3002. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3003. {
  3004. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3005. }
  3006. }
  3007. }
  3008. }
  3009. }
  3010. else
  3011. {
  3012. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3013. {
  3014. if(maxProfile.ChargingSchedule.Duration != -1)
  3015. {
  3016. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3017. 0:
  3018. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3019. }
  3020. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3021. {
  3022. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3023. {
  3024. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3025. 0:
  3026. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3027. if(idxPeriod > 0)
  3028. {
  3029. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3030. {
  3031. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. else
  3038. {
  3039. if(maxProfile.ChargingSchedule.Duration != -1)
  3040. {
  3041. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3042. 0:
  3043. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3044. }
  3045. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3046. {
  3047. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3048. {
  3049. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3050. 0:
  3051. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3052. if(idxPeriod > 0)
  3053. {
  3054. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3055. {
  3056. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. }
  3063. /*
  3064. DEBUG_INFO("MaxProfile after align.\n");
  3065. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3066. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3067. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3068. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3069. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3070. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3071. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3072. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3073. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3074. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3075. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3076. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3077. {
  3078. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3079. {
  3080. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3081. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3082. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3083. }
  3084. }
  3085. DEBUG_INFO("------------------------------------\n");*/
  3086. }
  3087. /*
  3088. * Merge to conposite schedule
  3089. */
  3090. //DEBUG_INFO("====================================\n");
  3091. // Find each profile period quantity
  3092. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3093. {
  3094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3095. limitMax = idx+1;
  3096. }
  3097. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3098. {
  3099. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3100. limitDef = idx+1;
  3101. }
  3102. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3103. {
  3104. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3105. limitTx = idx+1;
  3106. }
  3107. // TxProfile found, composite schedule based on it
  3108. if(txProfile.ChargingProfileId != -1)
  3109. {
  3110. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3111. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3112. {
  3113. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3114. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3115. (txProfile.ChargingSchedule.Duration > 0))
  3116. {
  3117. if(maxProfile.ChargingProfileId != -1)
  3118. {
  3119. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3120. {
  3121. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3122. {
  3123. if((maxProfile.ChargingSchedule.Duration > 0))
  3124. {
  3125. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3126. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3127. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3128. }
  3129. else
  3130. {
  3131. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3132. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3133. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3134. }
  3135. }
  3136. if(idxMaxPeriod == (limitMax-1))
  3137. {
  3138. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3139. {
  3140. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3141. {
  3142. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3143. compositePeriodIdx++;
  3144. }
  3145. else
  3146. {
  3147. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3148. }
  3149. }
  3150. }
  3151. }
  3152. }
  3153. else
  3154. {
  3155. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3156. {
  3157. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3158. compositePeriodIdx++;
  3159. }
  3160. else
  3161. {
  3162. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3163. }
  3164. }
  3165. }
  3166. if(idxTxPeriod == (limitTx-1))
  3167. {
  3168. if(defaultTxProfile.ChargingProfileId != -1)
  3169. {
  3170. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3171. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3172. {
  3173. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3174. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3175. (defaultTxProfile.ChargingSchedule.Duration>0))
  3176. {
  3177. if(maxProfile.ChargingProfileId != -1)
  3178. {
  3179. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3180. {
  3181. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3182. {
  3183. if((maxProfile.ChargingSchedule.Duration > 0))
  3184. {
  3185. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3186. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3187. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3188. }
  3189. else
  3190. {
  3191. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3192. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3193. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3194. }
  3195. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3196. {
  3197. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3198. {
  3199. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3200. compositePeriodIdx++;
  3201. }
  3202. else
  3203. {
  3204. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3205. }
  3206. }
  3207. // Delete duplicate period
  3208. if(compositePeriodIdx > 1)
  3209. {
  3210. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3211. {
  3212. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3213. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3214. compositePeriodIdx -= 1;
  3215. }
  3216. }
  3217. }
  3218. else
  3219. {
  3220. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3221. {
  3222. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3223. compositePeriodIdx++;
  3224. }
  3225. else
  3226. {
  3227. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3228. }
  3229. break;
  3230. }
  3231. }
  3232. }
  3233. else
  3234. {
  3235. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3236. {
  3237. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3238. compositePeriodIdx++;
  3239. }
  3240. else
  3241. {
  3242. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3243. }
  3244. }
  3245. }
  3246. }
  3247. }
  3248. }
  3249. }
  3250. }
  3251. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3252. else if(defaultTxProfile.ChargingProfileId != -1)
  3253. {
  3254. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3255. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3256. {
  3257. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3258. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3259. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3260. {
  3261. if(maxProfile.ChargingProfileId != -1)
  3262. {
  3263. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3264. {
  3265. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3266. {
  3267. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3268. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3269. if((maxProfile.ChargingSchedule.Duration > 0))
  3270. {
  3271. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3272. }
  3273. else
  3274. {
  3275. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3276. }
  3277. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3278. {
  3279. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3280. {
  3281. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3282. compositePeriodIdx++;
  3283. }
  3284. else
  3285. {
  3286. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3287. }
  3288. }
  3289. // Delete duplicate period
  3290. if(compositePeriodIdx > 1)
  3291. {
  3292. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3293. {
  3294. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3295. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3296. compositePeriodIdx -= 1;
  3297. }
  3298. }
  3299. }
  3300. else
  3301. {
  3302. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3303. {
  3304. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3305. compositePeriodIdx++;
  3306. }
  3307. else
  3308. {
  3309. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3310. }
  3311. break;
  3312. }
  3313. }
  3314. }
  3315. else
  3316. {
  3317. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3318. {
  3319. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3320. compositePeriodIdx++;
  3321. }
  3322. else
  3323. {
  3324. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3325. }
  3326. }
  3327. }
  3328. }
  3329. }
  3330. // Fill other period by MaxProfile
  3331. if(maxProfile.ChargingProfileId != -1)
  3332. {
  3333. if(compositePeriodIdx==0)
  3334. {
  3335. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3336. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3337. {
  3338. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3339. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3340. (maxProfile.ChargingSchedule.Duration > 0))
  3341. {
  3342. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3343. {
  3344. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3345. compositePeriodIdx++;
  3346. }
  3347. else
  3348. {
  3349. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3350. }
  3351. }
  3352. }
  3353. }
  3354. else
  3355. {
  3356. int lastCompositePeriodIdx = compositePeriodIdx;
  3357. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3358. {
  3359. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3360. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3361. (maxProfile.ChargingSchedule.Duration > 0))
  3362. {
  3363. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3364. {
  3365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3366. {
  3367. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3368. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3369. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3370. }
  3371. else
  3372. {
  3373. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3374. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3375. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3376. }
  3377. }
  3378. if(tmpPeriod.Limit != -1)
  3379. {
  3380. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3381. {
  3382. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3383. {
  3384. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3385. compositePeriodIdx++;
  3386. }
  3387. else
  3388. {
  3389. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3390. }
  3391. }
  3392. // Delete duplicate period
  3393. if(compositePeriodIdx > 1)
  3394. {
  3395. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3396. {
  3397. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3398. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3399. compositePeriodIdx -= 1;
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. compositeProfile.ChargingSchedule.Duration = durationReq;
  3408. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3409. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3410. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3411. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3413. {
  3414. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3415. {
  3416. compositeProfile.ChargingProfileId = 1;
  3417. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3418. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3419. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3420. }
  3421. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3422. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3423. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3424. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3425. }
  3426. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3427. if(line)
  3428. free(line);
  3429. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3430. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3431. }
  3432. //==========================================
  3433. // Init all share memory
  3434. //==========================================
  3435. int InitShareMemory()
  3436. {
  3437. int result = PASS;
  3438. int MeterSMId;
  3439. //creat ShmSysConfigAndInfo
  3440. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3441. {
  3442. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3443. result = FAIL;
  3444. }
  3445. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3446. {
  3447. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3448. result = FAIL;
  3449. }
  3450. else
  3451. {}
  3452. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3453. {
  3454. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3455. result = FAIL;
  3456. }
  3457. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3458. {
  3459. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3460. result = FAIL;
  3461. }
  3462. else
  3463. {}
  3464. //creat ShmPsuData
  3465. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3466. {
  3467. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3468. result = FAIL;
  3469. }
  3470. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3471. {
  3472. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3473. result = FAIL;
  3474. }
  3475. else
  3476. {}
  3477. //link ShmOCPP16Data
  3478. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3479. {
  3480. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3481. result = FAIL;
  3482. }
  3483. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3484. {
  3485. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3486. result = FAIL;
  3487. }
  3488. else
  3489. {}
  3490. //creat ShmOCPP16DataPH
  3491. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3492. {
  3493. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3494. result = FAIL;
  3495. }
  3496. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3497. {
  3498. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3499. result = FAIL;
  3500. }
  3501. else
  3502. {}
  3503. /****************************** For Initial Settings************************************************/
  3504. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3505. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3506. // allocate Configuration memory address
  3507. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3508. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3509. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3510. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3511. //offline MeterValue Interval
  3512. TempMeterValueInterval = 0;
  3513. return result;
  3514. }
  3515. int ProcessShareMemory()
  3516. {
  3517. int result = PASS;
  3518. if(InitShareMemory() == FAIL)
  3519. {
  3520. DEBUG_ERROR("InitShareMemory NG\n");
  3521. if(ShmStatusCodeData!=NULL)
  3522. {
  3523. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3524. }
  3525. result = FAIL;
  3526. }
  3527. // Model name parsing
  3528. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3529. {
  3530. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3531. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3532. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3533. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3534. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3535. ) // 'D' means DC
  3536. {
  3537. // DO series
  3538. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3539. {
  3540. SystemInitial += 1;
  3541. gunTotalNumber += 1;
  3542. gunType[gun_index] = GUN_TYPE_DO;
  3543. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3544. {
  3545. case Gun_Type_Chademo:
  3546. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3547. break;
  3548. case Gun_Type_CCS_2:
  3549. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3550. break;
  3551. case Gun_Type_GB:
  3552. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3553. break;
  3554. case Gun_Type_AC:
  3555. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3556. break;
  3557. default:
  3558. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3559. break;
  3560. }
  3561. }
  3562. }
  3563. else
  3564. {
  3565. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3566. {
  3567. SystemInitial += 1;
  3568. gunTotalNumber += 1;
  3569. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3570. {
  3571. case Gun_Type_Chademo:
  3572. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3573. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3574. break;
  3575. case Gun_Type_CCS_2:
  3576. gunType[gun_index] = GUN_TYPE_CCS;
  3577. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3578. break;
  3579. case Gun_Type_GB:
  3580. gunType[gun_index] = GUN_TYPE_GBT;
  3581. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3582. break;
  3583. case Gun_Type_AC:
  3584. gunType[gun_index] = GUN_TYPE_AC;
  3585. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3586. break;
  3587. default:
  3588. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3589. break;
  3590. }
  3591. }
  3592. }
  3593. }
  3594. else
  3595. {
  3596. DEBUG_ERROR("Model name parsing fail.\n");
  3597. result = FAIL;
  3598. }
  3599. if(result != PASS)sleep(5);
  3600. return result;
  3601. }
  3602. void checkRemoteStart(uint8_t connectorIdInt)
  3603. {
  3604. uint8_t tempIndex;
  3605. int result = PASS;
  3606. char cmdBuf[512];
  3607. //check Transaction active
  3608. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3609. {
  3610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3611. {
  3612. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3613. }
  3614. else
  3615. {
  3616. tempIndex = connectorIdInt -1;
  3617. }
  3618. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3619. {
  3620. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3621. {
  3622. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3623. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3624. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3625. {
  3626. //Reserved
  3627. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3628. }
  3629. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3630. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3631. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3632. {
  3633. //Reserved
  3634. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3635. result = FAIL;
  3636. goto end;
  3637. }
  3638. else
  3639. {
  3640. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3641. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3642. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3643. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3644. {
  3645. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3646. result = FAIL;
  3647. goto end;
  3648. }
  3649. }//END FOR ELSE
  3650. }
  3651. }// END FOR CHAdeMO_QUANTITY
  3652. }
  3653. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3654. {
  3655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3656. {
  3657. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3658. }
  3659. else
  3660. {
  3661. tempIndex = connectorIdInt -1;
  3662. }
  3663. for (int index = 0; index < CCS_QUANTITY; index++)
  3664. {
  3665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3666. {
  3667. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3668. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3669. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3670. {
  3671. //Reserved
  3672. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3673. }
  3674. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3675. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3676. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3677. {
  3678. //Reserved
  3679. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3680. result = FAIL;
  3681. goto end;
  3682. }
  3683. else
  3684. {
  3685. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3686. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3687. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3688. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3689. {
  3690. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3691. result = FAIL;
  3692. goto end;
  3693. }
  3694. }// END FOR ELSE
  3695. }
  3696. }// END FOR CCS_QUANTITY
  3697. }
  3698. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3699. {
  3700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3701. {
  3702. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3703. }
  3704. else
  3705. {
  3706. tempIndex = connectorIdInt -1;
  3707. }
  3708. for (int index = 0; index < GB_QUANTITY; index++)
  3709. {
  3710. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3711. {
  3712. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3713. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3714. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3715. {
  3716. //Reserved
  3717. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3718. }
  3719. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3720. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3721. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3722. {
  3723. //Reserved
  3724. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3725. result = FAIL;
  3726. goto end;
  3727. }
  3728. else
  3729. {
  3730. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3731. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3732. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3733. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3734. {
  3735. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3736. result = FAIL;
  3737. goto end;
  3738. }
  3739. }// END FOR ELSE
  3740. }
  3741. } // END FOR GB_QUANTITY
  3742. }
  3743. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3744. {
  3745. tempIndex = connectorIdInt -1;
  3746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3747. {
  3748. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3749. {
  3750. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3751. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3752. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3753. {
  3754. //Reserved
  3755. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3756. }
  3757. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3758. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3759. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3760. {
  3761. //Reserved
  3762. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3763. result = FAIL;
  3764. goto end;
  3765. }
  3766. else
  3767. {
  3768. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3769. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3770. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3771. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3772. {
  3773. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3774. result = FAIL;
  3775. goto end;
  3776. }
  3777. }// END FOR ELSE
  3778. }
  3779. } // END FOR GB_QUANTITY
  3780. }
  3781. else
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3784. {
  3785. tempIndex = 2;
  3786. }
  3787. else
  3788. {
  3789. tempIndex = connectorIdInt -1;
  3790. }
  3791. for (int index = 0; index < AC_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3794. {
  3795. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3796. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3797. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3798. {
  3799. //Reserved
  3800. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3801. }
  3802. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3803. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3804. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3805. {
  3806. //Reserved
  3807. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3808. result = FAIL;
  3809. goto end;
  3810. }
  3811. else
  3812. {
  3813. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3814. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3815. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3816. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3817. {
  3818. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3819. result = FAIL;
  3820. goto end;
  3821. }
  3822. }//END FOR ELSE
  3823. }
  3824. }// END FOR AC_QUANTITY
  3825. }
  3826. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3827. {
  3828. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3829. {
  3830. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3831. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3832. {
  3833. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3834. system(cmdBuf);
  3835. }
  3836. }
  3837. else
  3838. {
  3839. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3840. result = FAIL;
  3841. }
  3842. }
  3843. end:
  3844. if(result == PASS)
  3845. {
  3846. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3847. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3848. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3849. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3850. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3851. }
  3852. }
  3853. void CheckSystemValue(void)
  3854. {
  3855. char filenmae[100]={0};
  3856. char str[100]={0};
  3857. int tempIndex = 0;
  3858. //===============================
  3859. // send Heartbeat
  3860. //===============================
  3861. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3862. {
  3863. //parameter for test
  3864. sendHeartbeatRequest(0);
  3865. //==============================================
  3866. // Reset Waiting Time
  3867. //==============================================
  3868. HeartBeatWithNOResponse += 2;
  3869. }
  3870. //===============================
  3871. // Credit deduct report
  3872. //===============================
  3873. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3874. {
  3875. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3876. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3877. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3878. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3879. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3880. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3881. }
  3882. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3883. {
  3884. OCPP_query_deduct_info();
  3885. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3886. }
  3887. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3888. {
  3889. // ClockAlign MeterValue
  3890. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3891. {
  3892. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3893. {
  3894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3895. {
  3896. tempIndex = ((gun_index==2) ? 1: 0);
  3897. }
  3898. else
  3899. {
  3900. tempIndex = gun_index;
  3901. }
  3902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3903. {
  3904. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3905. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3906. {
  3907. reqClockAlignMeter[gun_index] = 1;
  3908. }
  3909. }// End for CHAdeMO
  3910. }
  3911. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3912. {
  3913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3914. {
  3915. tempIndex = ((gun_index==2) ? 1: 0);
  3916. }
  3917. else
  3918. {
  3919. tempIndex = gun_index;
  3920. }
  3921. for (int index = 0; index < CCS_QUANTITY; index++)
  3922. {
  3923. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3924. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3925. {
  3926. reqClockAlignMeter[gun_index] = 1;
  3927. }
  3928. } // End for CCS
  3929. }
  3930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3931. {
  3932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3933. {
  3934. tempIndex = ((gun_index==2) ? 1: 0);
  3935. }
  3936. else
  3937. {
  3938. tempIndex = gun_index;
  3939. }
  3940. for (int index = 0; index < GB_QUANTITY; index++)
  3941. {
  3942. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3943. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3944. {
  3945. reqClockAlignMeter[gun_index] = 1;
  3946. }
  3947. }// End for GB
  3948. }
  3949. else if(gunType[gun_index] == GUN_TYPE_DO)
  3950. {
  3951. tempIndex = gun_index;
  3952. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3953. {
  3954. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3955. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3956. {
  3957. reqClockAlignMeter[gun_index] = 1;
  3958. }
  3959. }
  3960. }
  3961. else
  3962. {
  3963. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3964. {
  3965. tempIndex = 2;
  3966. }
  3967. else
  3968. {
  3969. tempIndex = gun_index;
  3970. }
  3971. for (int index = 0; index < AC_QUANTITY; index++)
  3972. {
  3973. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3974. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3975. {
  3976. reqClockAlignMeter[gun_index] = 1;
  3977. }
  3978. }//End for AC
  3979. }
  3980. }
  3981. }
  3982. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3983. {
  3984. //==========================================
  3985. // Check remote start without connector id
  3986. //==========================================
  3987. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3988. {
  3989. int connectorIdInt = -1;
  3990. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3991. {
  3992. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3993. {
  3994. connectorIdInt = (gun_index+1);
  3995. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3996. checkRemoteStart(connectorIdInt);
  3997. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3998. break;
  3999. }
  4000. }
  4001. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4002. {
  4003. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4004. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4005. }
  4006. }
  4007. //==========================================
  4008. // csu trigger DataTransferReq
  4009. //==========================================
  4010. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4011. {
  4012. sendDataTransferRequest(gun_index);
  4013. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4014. }
  4015. //===============================
  4016. // CSU Trigger Authorize Request
  4017. //===============================
  4018. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4019. {
  4020. sendAuthorizeRequest(0);
  4021. authorizeRetryTimes = authorizeRetryTimes + 1;
  4022. if(authorizeRetryTimes < 3)
  4023. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4024. }
  4025. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4026. {
  4027. authorizeRetryTimes = 0;
  4028. SetOcppConnStatus(FALSE);
  4029. server_sign = FALSE;
  4030. }
  4031. 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))
  4032. {
  4033. sendAuthorizeRequest(0);
  4034. }
  4035. //==============================================
  4036. // Charger start transaction
  4037. //==============================================
  4038. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4039. {
  4040. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4041. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4042. sendStartTransactionRequest(gun_index);
  4043. refreshStartTimer(&clientTime.StartTransaction);
  4044. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4045. //storeTempStopTransaction(gun_index);
  4046. }
  4047. //==============================================
  4048. // Charger stop transaction
  4049. //==============================================
  4050. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4051. {
  4052. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4053. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4054. sendStopTransactionRequest(gun_index);
  4055. refreshStartTimer(&clientTime.StopTransaction);
  4056. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4057. }
  4058. //==============================================
  4059. // Charger status report
  4060. //==============================================
  4061. //--- Check Mode Change ---//
  4062. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4063. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4064. {
  4065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4066. {
  4067. tempIndex = ((gun_index==2) ? 1: 0);
  4068. }
  4069. else
  4070. {
  4071. tempIndex = gun_index;
  4072. }
  4073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4074. {
  4075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4076. {
  4077. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4078. {
  4079. // Sent unplug message for California pricing logic
  4080. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4081. {
  4082. uint8_t ts[20];
  4083. getNowDatetime(ts);
  4084. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4085. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4086. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4087. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4088. }
  4089. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4090. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4091. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4092. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4093. {
  4094. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4095. if((access(filenmae,F_OK))!=-1)
  4096. {
  4097. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4098. sprintf(str,"rm -f %s",filenmae);
  4099. system(str);
  4100. }
  4101. }
  4102. }
  4103. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4104. #if 1 // for TempStopTransaction
  4105. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4106. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4107. {
  4108. checkTempStopTransaction(gun_index);
  4109. }
  4110. #endif
  4111. }
  4112. }
  4113. }
  4114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4115. {
  4116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4117. {
  4118. tempIndex = ((gun_index==2) ? 1: 0);
  4119. }
  4120. else
  4121. {
  4122. tempIndex = gun_index;
  4123. }
  4124. for (int index = 0; index < CCS_QUANTITY; index++)
  4125. {
  4126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4127. {
  4128. 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]*/ )
  4129. {
  4130. // Sent unplug message for California pricing logic
  4131. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4132. {
  4133. uint8_t ts[20];
  4134. getNowDatetime(ts);
  4135. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4136. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4137. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4138. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4139. }
  4140. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4141. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4142. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4143. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4144. {
  4145. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4146. if((access(filenmae,F_OK))!=-1)
  4147. {
  4148. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4149. sprintf(str,"rm -f %s",filenmae);
  4150. system(str);
  4151. }
  4152. }
  4153. }
  4154. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4155. #if 1 // for TempStopTransaction
  4156. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4157. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4158. {
  4159. checkTempStopTransaction(gun_index);
  4160. }
  4161. #endif
  4162. }
  4163. }
  4164. }
  4165. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4166. {
  4167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4168. {
  4169. tempIndex = ((gun_index==2) ? 1: 0);
  4170. }
  4171. else
  4172. {
  4173. tempIndex = gun_index;
  4174. }
  4175. for (int index = 0; index < GB_QUANTITY; index++)
  4176. {
  4177. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4178. {
  4179. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4180. {
  4181. // Sent unplug message for California pricing logic
  4182. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4183. {
  4184. uint8_t ts[20];
  4185. getNowDatetime(ts);
  4186. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4187. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4188. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4189. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4190. }
  4191. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4192. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4193. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4194. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4195. {
  4196. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4197. if((access(filenmae,F_OK))!=-1)
  4198. {
  4199. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4200. sprintf(str,"rm -f %s",filenmae);
  4201. system(str);
  4202. }
  4203. }
  4204. }
  4205. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4206. #if 1 // for TempStopTransaction
  4207. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4208. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4209. {
  4210. checkTempStopTransaction(gun_index);
  4211. }
  4212. #endif
  4213. }
  4214. }
  4215. }
  4216. else if(gunType[gun_index] == GUN_TYPE_DO)
  4217. {
  4218. tempIndex = gun_index;
  4219. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4220. {
  4221. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4222. {
  4223. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4224. {
  4225. // Sent unplug message for California pricing logic
  4226. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4227. {
  4228. uint8_t ts[20];
  4229. getNowDatetime(ts);
  4230. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4231. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4232. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4233. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4234. }
  4235. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4236. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4237. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4238. 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
  4239. {
  4240. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4241. if((access(filenmae,F_OK))!=-1)
  4242. {
  4243. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4244. sprintf(str,"rm -f %s",filenmae);
  4245. system(str);
  4246. }
  4247. }
  4248. }
  4249. 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);
  4250. #if 1 // for TempStopTransaction
  4251. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4252. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4253. {
  4254. checkTempStopTransaction(gun_index);
  4255. }
  4256. #endif
  4257. }
  4258. }
  4259. }
  4260. else
  4261. {
  4262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4263. {
  4264. tempIndex = 2;
  4265. }
  4266. else
  4267. {
  4268. tempIndex = gun_index;
  4269. }
  4270. for (int index = 0; index < AC_QUANTITY; index++)
  4271. {
  4272. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4273. {
  4274. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4275. {
  4276. // Sent unplug message for California pricing logic
  4277. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4278. {
  4279. uint8_t ts[20];
  4280. getNowDatetime(ts);
  4281. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4282. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4283. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4284. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4285. }
  4286. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4287. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4288. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4289. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4290. {
  4291. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4292. if((access(filenmae,F_OK))!=-1)
  4293. {
  4294. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4295. sprintf(str,"rm -f %s",filenmae);
  4296. system(str);
  4297. }
  4298. }
  4299. }
  4300. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4301. #if 1 // for TempStopTransaction
  4302. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4303. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4304. {
  4305. checkTempStopTransaction(gun_index);
  4306. }
  4307. #endif
  4308. }
  4309. }// END
  4310. }
  4311. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4312. (
  4313. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4314. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4315. )
  4316. )
  4317. {
  4318. if(SystemInitial > 0)
  4319. SystemInitial -= 1;
  4320. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4321. sendStatusNotificationRequest(gun_index);
  4322. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4323. }
  4324. //==============================================
  4325. // TCCI reader status report
  4326. //==============================================
  4327. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4328. {
  4329. reportReaderStatus(gun_index);
  4330. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4331. }
  4332. //==============================================
  4333. // CSU Trigger Smart Charging Profile
  4334. //==============================================
  4335. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4336. {
  4337. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4338. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4339. }
  4340. //==============================================
  4341. // Meter report
  4342. //==============================================
  4343. // Trigger MeterValue
  4344. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4345. {
  4346. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4347. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4348. }
  4349. // Clock-aligned Meter value
  4350. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4351. {
  4352. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4353. reqClockAlignMeter[gun_index] = 0;
  4354. }
  4355. // Sample period MeterValue
  4356. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4357. {
  4358. //check Transaction active
  4359. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4360. {
  4361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4362. {
  4363. tempIndex = ((gun_index==2) ? 1: 0);
  4364. }
  4365. else
  4366. {
  4367. tempIndex = gun_index;
  4368. }
  4369. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4370. {
  4371. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4372. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4373. {
  4374. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4375. {
  4376. reqSampleMeter[gun_index] = 1;
  4377. }
  4378. }
  4379. }// End for CHAdeMO
  4380. }
  4381. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4382. {
  4383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4384. {
  4385. tempIndex = ((gun_index==2) ? 1: 0);
  4386. }
  4387. else
  4388. {
  4389. tempIndex = gun_index;
  4390. }
  4391. for (int index = 0; index < CCS_QUANTITY; index++)
  4392. {
  4393. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4394. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4395. {
  4396. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4397. {
  4398. reqSampleMeter[gun_index] = 1;
  4399. }
  4400. }
  4401. } // End for CCS
  4402. }
  4403. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < GB_QUANTITY; index++)
  4414. {
  4415. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4416. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4417. {
  4418. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4419. {
  4420. reqSampleMeter[gun_index] = 1;
  4421. }
  4422. }
  4423. }// End for GB
  4424. }
  4425. else if(gunType[gun_index] == GUN_TYPE_DO)
  4426. {
  4427. tempIndex = gun_index;
  4428. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4429. {
  4430. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4431. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4432. {
  4433. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4434. {
  4435. reqSampleMeter[gun_index] = 1;
  4436. }
  4437. }
  4438. }
  4439. }
  4440. else
  4441. {
  4442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4443. {
  4444. tempIndex = 2;
  4445. }
  4446. else
  4447. {
  4448. tempIndex = gun_index;
  4449. }
  4450. for (int index = 0; index < AC_QUANTITY; index++)
  4451. {
  4452. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4453. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4454. {
  4455. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4456. {
  4457. reqSampleMeter[gun_index] = 1;
  4458. }
  4459. }
  4460. }//End for AC
  4461. }
  4462. if(reqSampleMeter[gun_index] == 1)
  4463. {
  4464. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4465. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4466. //storeTempStopTransaction(gun_index);
  4467. reqSampleMeter[gun_index] = 0;
  4468. }
  4469. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4470. }
  4471. //==============================================
  4472. // Check Connector reserved
  4473. //==============================================
  4474. //===============================
  4475. // Check if Reserve is expired
  4476. //===============================
  4477. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4478. {
  4479. double diff_t;
  4480. struct tm tp;
  4481. // current time
  4482. time_t t = time(NULL);
  4483. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4484. tp.tm_isdst = -1;
  4485. time_t utc = mktime(&tp);
  4486. diff_t = difftime(utc, t);
  4487. if(diff_t <= 0)
  4488. {
  4489. DEBUG_INFO("reserve expired.\n");
  4490. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4491. }
  4492. }//END OF Check if Reserve is expired
  4493. //==========================================
  4494. // csu trigger FirmwareStatusNotificationReq
  4495. //==========================================
  4496. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4497. {
  4498. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4499. }
  4500. //==========================================
  4501. // csu trigger DiagnosticsStatusNotificationReq
  4502. //==========================================
  4503. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4504. {
  4505. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4506. }
  4507. //==========================================
  4508. // csu trigger CancelReservationConf
  4509. //==========================================
  4510. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4511. {
  4512. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4513. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4514. }
  4515. //==========================================
  4516. // csu trigger ChangeAvailabilityConf
  4517. //==========================================
  4518. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4519. {
  4520. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4521. }
  4522. //==========================================
  4523. // csu trigger UnlockConnectorConf
  4524. //==========================================
  4525. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4526. {
  4527. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4528. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4529. }
  4530. //==========================================
  4531. // csu trigger ReserveNowConf
  4532. //==========================================
  4533. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4534. {
  4535. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4536. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4537. }
  4538. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4539. {
  4540. sendSignCertificateRequest();
  4541. }
  4542. }
  4543. }
  4544. //==========================================
  4545. // send request routine
  4546. //==========================================
  4547. int sendAuthorizeRequest(int gun_index)
  4548. {
  4549. mtrace();
  4550. int result = FAIL;
  4551. char message[100]={0};
  4552. char guid[37];
  4553. char tempdata[65]={0};
  4554. DEBUG_INFO("sendAuthorizeRequest...\n");
  4555. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4556. //Local Authorize
  4557. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4558. {
  4559. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4560. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4561. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4562. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4563. result = PASS;
  4564. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4565. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4566. authorizeRetryTimes = 0;
  4567. return result;
  4568. }
  4569. 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))||
  4570. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4571. {
  4572. // Query from cache
  4573. DEBUG_INFO("Authorize from cache.\n");
  4574. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4575. // Query from list
  4576. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4577. {
  4578. DEBUG_INFO("Authorize from list.\n");
  4579. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4580. }
  4581. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4582. {
  4583. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4584. {
  4585. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4586. }
  4587. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4588. {
  4589. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4590. }
  4591. if(!GetOcppConnStatus())
  4592. {
  4593. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4594. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4595. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4596. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4597. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4598. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4599. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4600. authorizeRetryTimes = 0;
  4601. return result;
  4602. }
  4603. }
  4604. else
  4605. {
  4606. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4607. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4608. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4609. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4610. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4611. else
  4612. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4613. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4614. result = PASS;
  4615. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4616. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4617. authorizeRetryTimes = 0;
  4618. return result;
  4619. }
  4620. }
  4621. //initialize struct Authorize
  4622. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4623. //get data from shared memory
  4624. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4625. random_uuid(guid);
  4626. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4627. LWS_Send(message);
  4628. sprintf(tempdata, "Authorize,%d", gun_index);
  4629. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4630. {
  4631. result = PASS;
  4632. DEBUG_INFO("Authorize mapItem pass\n");
  4633. }
  4634. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4635. return result;
  4636. }
  4637. int sendBootNotificationRequest(void)
  4638. {
  4639. mtrace();
  4640. int result = FAIL;
  4641. char message[500]={0}, payload[700]={0};
  4642. char guid[37]={0};
  4643. char tempdata[65]={0};
  4644. // Fill BootNotification fields
  4645. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4646. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4647. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4648. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4649. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4650. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4651. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4652. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4653. ShmOCPP16DataPH->ChargeBoxId
  4654. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4655. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4656. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4657. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4658. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4659. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4660. random_uuid(guid);
  4661. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4662. LWS_Send(message);
  4663. sprintf(tempdata, "BootNotification,0");
  4664. 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*/)
  4665. {
  4666. result = PASS;
  4667. }
  4668. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4669. strcpy(queuedata,message);
  4670. return result;
  4671. }
  4672. int sendDataTransferRequest(int gun_index)
  4673. {
  4674. mtrace();
  4675. char message[1000]={0};
  4676. char guid[37]={0};
  4677. char tempdata[65]={0};
  4678. int result = FAIL;
  4679. random_uuid(guid);
  4680. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4681. MESSAGE_TYPE_CALL,
  4682. guid,
  4683. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4684. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4685. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4686. LWS_Send(message);
  4687. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4688. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4689. {
  4690. result = PASS;
  4691. DEBUG_INFO("DataTransfer mapItem pass\n");
  4692. }
  4693. return result;
  4694. }
  4695. int sendDiagnosticsStatusNotificationRequest(char *status)
  4696. {
  4697. mtrace();
  4698. int result = FAIL;
  4699. char message[110]={0};
  4700. char guid[37]={0};
  4701. char tempdata[65]={0};
  4702. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4703. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4704. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4705. random_uuid(guid);
  4706. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4707. LWS_SendNow(message);
  4708. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4709. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4710. {
  4711. result = PASS;
  4712. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4713. }
  4714. //#ifdef SystemLogMessage
  4715. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4716. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4717. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4718. //#endif
  4719. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4720. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4721. //record status
  4722. if(strcmp(status,"Idle")==0)
  4723. {
  4724. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4725. }
  4726. else if(strcmp(status,"Uploaded")==0)
  4727. {
  4728. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4729. }
  4730. else if(strcmp(status,"UploadFailed")==0)
  4731. {
  4732. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4733. }
  4734. else if(strcmp(status,"Uploading")==0)
  4735. {
  4736. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4737. }
  4738. return result;
  4739. }
  4740. int sendFirmwareStatusNotificationRequest(char *status)
  4741. {
  4742. mtrace();
  4743. int result = FAIL;
  4744. char message[110]={0};
  4745. char guid[37]={0};
  4746. char tempdata[65]={0};
  4747. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4748. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4749. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4750. random_uuid(guid);
  4751. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4752. LWS_SendNow(message);
  4753. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4754. 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*/)
  4755. {
  4756. result = PASS;
  4757. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4758. }
  4759. //#ifdef SystemLogMessage
  4760. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4761. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4762. //#endif
  4763. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4764. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4765. //record status
  4766. if(strcmp(status,"Downloaded")==0)
  4767. {
  4768. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4769. }
  4770. else if(strcmp(status,"DownloadFailed")==0)
  4771. {
  4772. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4773. }
  4774. else if(strcmp(status,"Downloading")==0)
  4775. {
  4776. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4777. }
  4778. else if(strcmp(status,"Idle")==0)
  4779. {
  4780. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4781. }
  4782. else if(strcmp(status,"InstallationFailed")==0)
  4783. {
  4784. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4785. }
  4786. else if(strcmp(status,"Installing")==0)
  4787. {
  4788. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4789. }
  4790. else if(strcmp(status,"Installed")==0)
  4791. {
  4792. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4793. }
  4794. return result;
  4795. }
  4796. int sendHeartbeatRequest(int gun_index)
  4797. {
  4798. mtrace();
  4799. int result = FAIL;
  4800. char message[80]={0};
  4801. char guid[37]={0};
  4802. char tempdata[65]={0};
  4803. random_uuid(guid);
  4804. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4805. , MESSAGE_TYPE_CALL
  4806. , guid );
  4807. LWS_Send(message);
  4808. sprintf(tempdata, "Heartbeat,%d", 0);
  4809. 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*/)
  4810. {
  4811. result = PASS;
  4812. }
  4813. return result;
  4814. }
  4815. int sendStartTransactionRequest(int gun_index)
  4816. {
  4817. mtrace();
  4818. int result = FAIL;
  4819. char message[250]={0};
  4820. char guid[37]={0};
  4821. struct timeval tmnow;
  4822. struct tm *tm;
  4823. char buf[28];//, usec_buf[6];
  4824. char tempdata[65]={0};
  4825. int tempIndex = 0;
  4826. DEBUG_INFO("sendStartTransactionRequest...\n");
  4827. gettimeofday(&tmnow, NULL);
  4828. time_t t;
  4829. t = time(NULL);
  4830. /*UTC time and date*/
  4831. tm = gmtime(&t);
  4832. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4833. #if 0 // remove temporally
  4834. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4835. strcat(buf,".");
  4836. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4837. strcat(buf,usec_buf);
  4838. #endif
  4839. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4840. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4841. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4842. // clear StartTransaction Response
  4843. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4844. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4845. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4846. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4847. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4848. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4849. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4850. {
  4851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4852. {
  4853. tempIndex = ((gun_index==2) ? 1: 0);
  4854. }
  4855. else
  4856. {
  4857. tempIndex = gun_index;
  4858. }
  4859. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4860. {
  4861. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4862. {
  4863. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4864. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4865. }
  4866. }
  4867. }
  4868. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4869. {
  4870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4871. {
  4872. tempIndex = ((gun_index==2) ? 1: 0);
  4873. }
  4874. else
  4875. {
  4876. tempIndex = gun_index;
  4877. }
  4878. for (int index = 0; index < CCS_QUANTITY; index++)
  4879. {
  4880. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4881. {
  4882. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4883. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4884. }
  4885. }
  4886. }
  4887. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4888. {
  4889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4890. {
  4891. tempIndex = ((gun_index==2) ? 1: 0);
  4892. }
  4893. else
  4894. {
  4895. tempIndex = gun_index;
  4896. }
  4897. for (int index = 0; index < GB_QUANTITY; index++)
  4898. {
  4899. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4900. {
  4901. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4902. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4903. }
  4904. }
  4905. }
  4906. else if(gunType[gun_index] == GUN_TYPE_DO)
  4907. {
  4908. tempIndex = gun_index;
  4909. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4910. {
  4911. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4912. {
  4913. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4914. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4915. }
  4916. }
  4917. }
  4918. else
  4919. {
  4920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4921. {
  4922. tempIndex = 2;
  4923. }
  4924. else
  4925. {
  4926. tempIndex = gun_index;
  4927. }
  4928. for (int index = 0; index < AC_QUANTITY; index++)
  4929. {
  4930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4931. {
  4932. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4933. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4934. }
  4935. }
  4936. }
  4937. random_uuid(guid);
  4938. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4939. {
  4940. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4941. , gun_index +1
  4942. , MESSAGE_TYPE_CALL
  4943. , guid
  4944. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4945. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4946. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4947. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4948. }
  4949. else
  4950. {
  4951. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4952. , gun_index +1
  4953. , MESSAGE_TYPE_CALL
  4954. , guid
  4955. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4956. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4957. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4958. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4959. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4960. }
  4961. #if 1
  4962. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4963. 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*/)
  4964. {
  4965. result = PASS;
  4966. }
  4967. #endif
  4968. strcpy(queuedata, message);
  4969. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4970. OCPP_insert_transaction_msg(YES, queuedata);
  4971. return result;
  4972. }
  4973. int sendStatusNotificationRequest(int gun_index)
  4974. {
  4975. mtrace();
  4976. int result = FAIL;
  4977. char message[600]={0};
  4978. char guid[37];
  4979. int currentStatus = 0;
  4980. struct timeval tmnow;
  4981. struct tm *tm;
  4982. char buf[28];//, usec_buf[6];
  4983. char tempdata[65]={0};
  4984. int tempIndex = 0;
  4985. uint8_t isStateChanged = TRUE;
  4986. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4987. gettimeofday(&tmnow, NULL);
  4988. time_t t;
  4989. t = time(NULL);
  4990. /*UTC time and date*/
  4991. tm = gmtime(&t);
  4992. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4993. #if 0 // remove temporally
  4994. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4995. strcat(buf,".");
  4996. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4997. strcat(buf,usec_buf);
  4998. #endif
  4999. //printf("%s",buf);
  5000. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5001. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5002. // it's option
  5003. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5004. /*
  5005. enum _SYSTEM_STATUS
  5006. {
  5007. S_BOOTING = 0,
  5008. S_IDLE, = 1
  5009. S_AUTHORIZING, =2
  5010. S_REASSIGN_CHECK, =3
  5011. S_REASSIGN, =4
  5012. S_PRECHARGE, =5
  5013. S_PREPARING_FOR_EV, =6
  5014. S_PREPARING_FOR_EVSE, =7
  5015. S_CHARGING, =8
  5016. S_TERMINATING, =9
  5017. S_COMPLETE, =10
  5018. S_ALARM, =11
  5019. S_FAULT =12
  5020. }
  5021. */
  5022. //check Transaction active
  5023. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5024. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5025. {
  5026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5027. {
  5028. tempIndex = ((gun_index==2) ? 1: 0);
  5029. }
  5030. else
  5031. {
  5032. tempIndex = gun_index;
  5033. }
  5034. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5035. {
  5036. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5037. {
  5038. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5039. {
  5040. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5041. {
  5042. currentStatus = Preparing; //OCPP Status: Preparing
  5043. }
  5044. else
  5045. {
  5046. currentStatus = Available; //OCPP Status: Available
  5047. }
  5048. }
  5049. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5050. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5051. ) //S_PRECHARGE
  5052. {
  5053. currentStatus = Preparing; //OCPP Status: Preparing
  5054. }
  5055. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5056. {
  5057. currentStatus = Charging; //OCPP Status: Charging
  5058. }
  5059. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5060. {
  5061. currentStatus = Finishing; //OCPP Status: Finishing
  5062. }
  5063. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5064. {
  5065. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5066. }
  5067. 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
  5068. {
  5069. currentStatus = Unavailable; //OCPP Status: Unavailable
  5070. }
  5071. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5072. {
  5073. currentStatus = Faulted; //OCPP Status: Faulted
  5074. }
  5075. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5076. {
  5077. currentStatus = Reserved; //OCPP Status: Reserved
  5078. }
  5079. } //end of the same index
  5080. }//end of for CHAdeMO_QUANTITY
  5081. }
  5082. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5083. {
  5084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5085. {
  5086. tempIndex = ((gun_index==2) ? 1: 0);
  5087. }
  5088. else
  5089. {
  5090. tempIndex = gun_index;
  5091. }
  5092. for (int index = 0; index < CCS_QUANTITY; index++)
  5093. {
  5094. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5095. {
  5096. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5097. {
  5098. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5099. {
  5100. currentStatus = Preparing; //OCPP Status: Preparing
  5101. }
  5102. else
  5103. {
  5104. currentStatus = Available; //OCPP Status: Available
  5105. }
  5106. }
  5107. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5108. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5109. ) //S_PRECHARGE
  5110. {
  5111. currentStatus = Preparing; //OCPP Status: Preparing
  5112. }
  5113. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5114. {
  5115. currentStatus = Charging; //OCPP Status: Charging
  5116. }
  5117. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5118. {
  5119. currentStatus = Finishing; //OCPP Status: Finishing
  5120. }
  5121. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5122. {
  5123. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5124. }
  5125. 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
  5126. {
  5127. currentStatus = Unavailable; //OCPP Status : Unavailable
  5128. }
  5129. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5130. {
  5131. currentStatus = Faulted; //OCPP Status: Faulted
  5132. }
  5133. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5134. {
  5135. currentStatus = Reserved; //OCPP Status: Reserved
  5136. }
  5137. } //end of the same index
  5138. } // end of for CCS_QUANTITY
  5139. }
  5140. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5141. {
  5142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5143. {
  5144. tempIndex = ((gun_index==2) ? 1: 0);
  5145. }
  5146. else
  5147. {
  5148. tempIndex = gun_index;
  5149. }
  5150. for (int index = 0; index < GB_QUANTITY; index++)
  5151. {
  5152. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5153. {
  5154. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5155. {
  5156. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5157. {
  5158. currentStatus = Preparing; //OCPP Status: Preparing
  5159. }
  5160. else
  5161. {
  5162. currentStatus = Available; //OCPP Status: Available
  5163. }
  5164. }
  5165. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5166. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5167. ) //S_PRECHARGE
  5168. {
  5169. currentStatus = Preparing; //OCPP Status: Preparing
  5170. }
  5171. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5172. {
  5173. currentStatus = Charging; //OCPP Status: Charging
  5174. }
  5175. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5176. {
  5177. currentStatus = Finishing; //OCPP Status: Finishing
  5178. }
  5179. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5180. {
  5181. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5182. }
  5183. 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
  5184. {
  5185. currentStatus = Unavailable; //OCPP Status: Unavailable
  5186. }
  5187. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5188. {
  5189. currentStatus = Faulted; //OCPP Status: Faulted
  5190. }
  5191. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5192. {
  5193. currentStatus = Reserved; //OCPP Status: Reserved
  5194. }
  5195. } //end of the same index
  5196. } // end of for GB_QUANTITY
  5197. }
  5198. else if(gunType[gun_index] == GUN_TYPE_DO)
  5199. {
  5200. tempIndex = gun_index;
  5201. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5202. {
  5203. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5204. {
  5205. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5206. {
  5207. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5208. {
  5209. currentStatus = Preparing; //OCPP Status: Preparing
  5210. }
  5211. else
  5212. {
  5213. currentStatus = Available; //OCPP Status: Available
  5214. }
  5215. }
  5216. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5217. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5218. ) //S_PRECHARGE
  5219. {
  5220. currentStatus = Preparing; //OCPP Status: Preparing
  5221. }
  5222. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5223. {
  5224. currentStatus = Charging; //OCPP Status: Charging
  5225. }
  5226. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5227. {
  5228. currentStatus = Finishing; //OCPP Status: Finishing
  5229. }
  5230. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5231. {
  5232. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5233. }
  5234. 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
  5235. {
  5236. currentStatus = Unavailable; //OCPP Status: Unavailable
  5237. }
  5238. 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
  5239. {
  5240. currentStatus = Faulted; //OCPP Status: Faulted
  5241. }
  5242. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5243. {
  5244. currentStatus = Reserved; //OCPP Status: Reserved
  5245. }
  5246. } //end of the same index
  5247. }
  5248. }
  5249. else
  5250. {
  5251. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5252. {
  5253. tempIndex = 2;
  5254. }
  5255. else
  5256. {
  5257. tempIndex = gun_index;
  5258. }
  5259. for (int index = 0; index < AC_QUANTITY; index++)
  5260. {
  5261. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5262. {
  5263. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5264. {
  5265. 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))
  5266. {
  5267. currentStatus = Preparing; //OCPP Status: Preparing
  5268. }
  5269. else
  5270. {
  5271. currentStatus = Available; //OCPP Status: Available
  5272. }
  5273. }
  5274. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5275. {
  5276. currentStatus = Preparing; //OCPP Status: Preparing
  5277. }
  5278. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5279. {
  5280. currentStatus = Charging; //OCPP Status: Charging
  5281. }
  5282. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5283. {
  5284. currentStatus = Finishing; //OCPP Status: Finishing
  5285. }
  5286. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5287. {
  5288. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5289. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5290. else
  5291. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5292. }
  5293. 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
  5294. {
  5295. currentStatus = Unavailable; //OCPP Status: Unavailable
  5296. }
  5297. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5298. {
  5299. currentStatus = Faulted; //OCPP Status: Faulted
  5300. }
  5301. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5302. {
  5303. currentStatus = Reserved; //OCPP Status: Reserved
  5304. }
  5305. }//end of the same index
  5306. }//end of for AC_QUANTITY
  5307. }
  5308. //it's option
  5309. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5310. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5311. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5312. {
  5313. isStateChanged = FALSE;
  5314. }
  5315. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5316. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5317. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5318. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5319. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5320. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5321. random_uuid(guid);
  5322. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5323. , MESSAGE_TYPE_CALL
  5324. , guid
  5325. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5326. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5327. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5328. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5329. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5330. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5331. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5332. if((server_sign == TRUE) && isStateChanged)
  5333. {
  5334. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5335. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5336. LWS_Send(message);
  5337. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5338. 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*/)
  5339. {
  5340. //DEBUG_ERROR("statusNotification mapitem pass");
  5341. result = PASS;
  5342. }
  5343. }
  5344. else
  5345. {
  5346. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5347. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5348. result = PASS;
  5349. }
  5350. return result;
  5351. }
  5352. int sendStopTransactionRequest(int gun_index)
  5353. {
  5354. mtrace();
  5355. int result = FAIL;
  5356. //char message[1500]={0};
  5357. char guid[37]={0};
  5358. char tempdata[65]={0};
  5359. int tempIndex = 0;
  5360. char TempStopTransaction[256];
  5361. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5362. //int idx_sample=0;
  5363. DEBUG_INFO("sendStopTransactionRequest \n");
  5364. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5365. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5366. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5367. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5368. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5369. {
  5370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5371. {
  5372. tempIndex = ((gun_index==2) ? 1: 0);
  5373. }
  5374. else
  5375. {
  5376. tempIndex = gun_index;
  5377. }
  5378. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5379. {
  5380. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5381. {
  5382. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5383. }
  5384. }// END OF CHAdeMO_QUANTITY
  5385. }
  5386. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5387. {
  5388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5389. {
  5390. tempIndex = ((gun_index==2) ? 1: 0);
  5391. }
  5392. else
  5393. {
  5394. tempIndex = gun_index;
  5395. }
  5396. for (int index = 0; index < CCS_QUANTITY; index++)
  5397. {
  5398. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5399. {
  5400. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5401. }
  5402. }// END OF CCS_QUANTITY
  5403. }
  5404. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5405. {
  5406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5407. {
  5408. tempIndex = ((gun_index==2) ? 1: 0);
  5409. }
  5410. else
  5411. {
  5412. tempIndex = gun_index;
  5413. }
  5414. for (int index = 0; index < GB_QUANTITY; index++)
  5415. {
  5416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5417. {
  5418. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5419. }
  5420. }// END OF GB_QUANTITY
  5421. }
  5422. else if(gunType[gun_index] == GUN_TYPE_DO)
  5423. {
  5424. tempIndex = gun_index;
  5425. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5426. {
  5427. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5428. {
  5429. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5430. }
  5431. }// END OF GB_QUANTITY
  5432. }
  5433. else
  5434. {
  5435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5436. {
  5437. tempIndex = 2;
  5438. }
  5439. else
  5440. {
  5441. tempIndex = gun_index;
  5442. }
  5443. for (int index = 0; index < AC_QUANTITY; index++)
  5444. {
  5445. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5446. {
  5447. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5448. }
  5449. }// END OF AC_QUANTITY
  5450. }
  5451. //====================================== Stop Transaction Time =====================================================
  5452. struct timeval tmnow;
  5453. struct tm *tm;
  5454. char buf[28];//, usec_buf[6];
  5455. gettimeofday(&tmnow, NULL);
  5456. time_t t;
  5457. t = time(NULL);
  5458. /*UTC time and date*/
  5459. tm = gmtime(&t);
  5460. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5461. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5462. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5463. random_uuid(guid);
  5464. /***********************************transactionData******************************************************/
  5465. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5466. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5467. //=================================
  5468. // Transaction_Begin
  5469. //=================================
  5470. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5471. {
  5472. //============================================ Energy.Active.Import.Interval ================================
  5473. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5474. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5476. 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*/]);
  5477. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5478. 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))
  5479. {
  5480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5481. }
  5482. else
  5483. {
  5484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5485. }
  5486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5488. }
  5489. //=================================
  5490. // Transaction_End
  5491. //=================================
  5492. // ================================= Current.Import L1 ===============================================
  5493. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5494. {
  5495. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5496. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5497. {
  5498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5499. {
  5500. tempIndex = ((gun_index==2) ? 1: 0);
  5501. }
  5502. else
  5503. {
  5504. tempIndex = gun_index;
  5505. }
  5506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5507. {
  5508. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5509. {
  5510. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5511. }
  5512. }// End of for CHAdeMO_QUANTITY
  5513. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5514. }
  5515. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5516. {
  5517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5518. {
  5519. tempIndex = ((gun_index==2) ? 1: 0);
  5520. }
  5521. else
  5522. {
  5523. tempIndex = gun_index;
  5524. }
  5525. for (int index = 0; index < CCS_QUANTITY; index++)
  5526. {
  5527. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5528. {
  5529. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5530. }
  5531. }// End of for CCS_QUANTITY
  5532. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5533. }
  5534. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5535. {
  5536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5537. {
  5538. tempIndex = ((gun_index==2) ? 1: 0);
  5539. }
  5540. else
  5541. {
  5542. tempIndex = gun_index;
  5543. }
  5544. for (int index = 0; index < GB_QUANTITY; index++)
  5545. {
  5546. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5547. {
  5548. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5549. }
  5550. }// End of for GB_QUANTITY
  5551. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5552. }
  5553. else if(gunType[gun_index] == GUN_TYPE_DO)
  5554. {
  5555. tempIndex = gun_index;
  5556. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5557. {
  5558. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5559. {
  5560. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5561. }
  5562. }
  5563. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5564. }
  5565. else
  5566. {
  5567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5568. {
  5569. tempIndex = 2;
  5570. }
  5571. else
  5572. {
  5573. tempIndex = gun_index;
  5574. }
  5575. for (int index = 0; index < AC_QUANTITY; index++)
  5576. {
  5577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5578. {
  5579. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5580. }
  5581. }// End of for AC_QUANTITY
  5582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5583. }
  5584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5587. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5588. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5589. }
  5590. // ================================= Energy.Active.Import.Interval ==============================================
  5591. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5592. {
  5593. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5594. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5595. {
  5596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5597. {
  5598. tempIndex = ((gun_index==2) ? 1: 0);
  5599. }
  5600. else
  5601. {
  5602. tempIndex = gun_index;
  5603. }
  5604. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5605. {
  5606. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5607. {
  5608. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5609. }
  5610. }// END OF CHAdeMO_QUANTITY
  5611. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5612. }
  5613. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5614. {
  5615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5616. {
  5617. tempIndex = ((gun_index==2) ? 1: 0);
  5618. }
  5619. else
  5620. {
  5621. tempIndex = gun_index;
  5622. }
  5623. for (int index = 0; index < CCS_QUANTITY; index++)
  5624. {
  5625. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5626. {
  5627. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5628. }
  5629. }// END OF CCS_QUANTITY
  5630. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5631. }
  5632. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5633. {
  5634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5635. {
  5636. tempIndex = ((gun_index==2) ? 1: 0);
  5637. }
  5638. else
  5639. {
  5640. tempIndex = gun_index;
  5641. }
  5642. for (int index = 0; index < GB_QUANTITY; index++)
  5643. {
  5644. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5645. {
  5646. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5647. }
  5648. }// END OF GB_QUANTITY
  5649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5650. }
  5651. else if(gunType[gun_index] == GUN_TYPE_DO)
  5652. {
  5653. tempIndex = gun_index;
  5654. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5655. {
  5656. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5657. {
  5658. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5659. }
  5660. }
  5661. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5662. }
  5663. else
  5664. {
  5665. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5666. {
  5667. tempIndex = 2;
  5668. }
  5669. else
  5670. {
  5671. tempIndex = gun_index;
  5672. }
  5673. for (int index = 0; index < AC_QUANTITY; index++)
  5674. {
  5675. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5676. {
  5677. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5678. }
  5679. }// END OF AC_QUANTITY
  5680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5681. }
  5682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5687. }
  5688. //=================================== Power.Active.Import ==================================================
  5689. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5690. {
  5691. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5692. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5693. {
  5694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5695. {
  5696. tempIndex = ((gun_index==2) ? 1: 0);
  5697. }
  5698. else
  5699. {
  5700. tempIndex = gun_index;
  5701. }
  5702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5703. {
  5704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5705. {
  5706. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5707. }
  5708. } // End for CHAdeMO_QUANTITY
  5709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5710. }
  5711. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5712. {
  5713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5714. {
  5715. tempIndex = ((gun_index==2) ? 1: 0);
  5716. }
  5717. else
  5718. {
  5719. tempIndex = gun_index;
  5720. }
  5721. for (int index = 0; index < CCS_QUANTITY; index++)
  5722. {
  5723. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5724. {
  5725. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5726. }
  5727. } // END for CCS_QUANTITY
  5728. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5729. }
  5730. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5731. {
  5732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5733. {
  5734. tempIndex = ((gun_index==2) ? 1: 0);
  5735. }
  5736. else
  5737. {
  5738. tempIndex = gun_index;
  5739. }
  5740. for (int index = 0; index < GB_QUANTITY; index++)
  5741. {
  5742. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5743. {
  5744. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5745. }
  5746. }// END for GB_QUANTITY
  5747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5748. }
  5749. else if(gunType[gun_index] == GUN_TYPE_DO)
  5750. {
  5751. tempIndex = gun_index;
  5752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5753. {
  5754. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5755. {
  5756. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5757. }
  5758. }
  5759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5760. }
  5761. else
  5762. {
  5763. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5764. {
  5765. tempIndex = 2;
  5766. }
  5767. else
  5768. {
  5769. tempIndex = gun_index;
  5770. }
  5771. for (int index = 0; index < AC_QUANTITY; index++)
  5772. {
  5773. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5774. {
  5775. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5776. }
  5777. } // END for AC_QUANTITY
  5778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5779. }
  5780. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5785. }
  5786. //============================ Voltage L1 ====================================
  5787. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5788. {
  5789. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5790. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5791. {
  5792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5793. {
  5794. tempIndex = ((gun_index==2) ? 1: 0);
  5795. }
  5796. else
  5797. {
  5798. tempIndex = gun_index;
  5799. }
  5800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5801. {
  5802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5803. {
  5804. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5805. }
  5806. } // END OF FOR CHAdeMO_QUANTITY
  5807. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5808. }
  5809. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5810. {
  5811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5812. {
  5813. tempIndex = ((gun_index==2) ? 1: 0);
  5814. }
  5815. else
  5816. {
  5817. tempIndex = gun_index;
  5818. }
  5819. for (int index = 0; index < CCS_QUANTITY; index++)
  5820. {
  5821. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5822. {
  5823. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5824. }
  5825. } // END OF FOR CCS_QUANTITY
  5826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5827. }
  5828. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  5839. {
  5840. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5841. {
  5842. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5843. }
  5844. } // END OF FOR GB_QUANTITY
  5845. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5846. }
  5847. else if(gunType[gun_index] == GUN_TYPE_DO)
  5848. {
  5849. tempIndex = gun_index;
  5850. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5851. {
  5852. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5853. {
  5854. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5855. }
  5856. }
  5857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5858. }
  5859. else
  5860. {
  5861. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5862. {
  5863. tempIndex = 2;
  5864. }
  5865. else
  5866. {
  5867. tempIndex = gun_index;
  5868. }
  5869. for (int index = 0; index < AC_QUANTITY; index++)
  5870. {
  5871. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5872. {
  5873. 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
  5874. }
  5875. } // END OF FOR AC_QUANTITY
  5876. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5877. }
  5878. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5883. }
  5884. //====================== End SoC ================================
  5885. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5886. {
  5887. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5888. 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))
  5889. {
  5890. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5891. {
  5892. tempIndex = ((gun_index==2) ? 1: 0);
  5893. }
  5894. else
  5895. {
  5896. tempIndex = gun_index;
  5897. }
  5898. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5899. {
  5900. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5901. {
  5902. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5903. {
  5904. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5905. }
  5906. }
  5907. }
  5908. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5909. {
  5910. for (int index = 0; index < CCS_QUANTITY; index++)
  5911. {
  5912. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5913. {
  5914. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5915. }
  5916. }
  5917. }
  5918. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5919. {
  5920. for (int index = 0; index < GB_QUANTITY; index++)
  5921. {
  5922. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5923. {
  5924. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5925. }
  5926. }
  5927. }
  5928. else if(gunType[gun_index] == GUN_TYPE_DO)
  5929. {
  5930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5931. {
  5932. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5933. {
  5934. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5935. }
  5936. }
  5937. }
  5938. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5944. } // END FOR DC CASE
  5945. }
  5946. // ================================= Current.Import L2 ===============================================
  5947. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5948. {
  5949. // AC 3 phse L2 current
  5950. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5951. {
  5952. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5953. {
  5954. tempIndex = 2;
  5955. }
  5956. else
  5957. {
  5958. tempIndex = gun_index;
  5959. }
  5960. for (int index = 0; index < AC_QUANTITY; index++)
  5961. {
  5962. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5963. {
  5964. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5965. }
  5966. }// End of for AC_QUANTITY
  5967. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5968. }
  5969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5974. }
  5975. // ================================= Current.Import L3 ===============================================
  5976. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5977. {
  5978. // AC 3 phse L3 current
  5979. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5980. {
  5981. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5982. {
  5983. tempIndex = 2;
  5984. }
  5985. else
  5986. {
  5987. tempIndex = gun_index;
  5988. }
  5989. for (int index = 0; index < AC_QUANTITY; index++)
  5990. {
  5991. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5992. {
  5993. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5994. }
  5995. }// End of for AC_QUANTITY
  5996. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5997. }
  5998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6003. }
  6004. //============================ Voltage L2 ====================================
  6005. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6006. {
  6007. // AC 3 phse L2 voltage
  6008. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6009. {
  6010. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6011. {
  6012. tempIndex = 2;
  6013. }
  6014. else
  6015. {
  6016. tempIndex = gun_index;
  6017. }
  6018. for (int index = 0; index < AC_QUANTITY; index++)
  6019. {
  6020. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6021. {
  6022. 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
  6023. }
  6024. } // END OF FOR AC_QUANTITY
  6025. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6026. }
  6027. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6031. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6032. }
  6033. //============================ Voltage L3 ====================================
  6034. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6035. {
  6036. // AC 3 phse L3 voltage
  6037. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6038. {
  6039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6040. {
  6041. tempIndex = 2;
  6042. }
  6043. else
  6044. {
  6045. tempIndex = gun_index;
  6046. }
  6047. for (int index = 0; index < AC_QUANTITY; index++)
  6048. {
  6049. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6050. {
  6051. 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
  6052. }
  6053. } // END OF FOR AC_QUANTITY
  6054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6055. }
  6056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6061. }
  6062. //====================== Start SoC ================================
  6063. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6064. {
  6065. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6066. 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))
  6067. {
  6068. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6069. {
  6070. tempIndex = ((gun_index==2) ? 1: 0);
  6071. }
  6072. else
  6073. {
  6074. tempIndex = gun_index;
  6075. }
  6076. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6077. {
  6078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6081. {
  6082. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6083. }
  6084. }
  6085. }
  6086. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6087. {
  6088. for (int index = 0; index < CCS_QUANTITY; index++)
  6089. {
  6090. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6091. {
  6092. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6093. }
  6094. }
  6095. }
  6096. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6097. {
  6098. for (int index = 0; index < GB_QUANTITY; index++)
  6099. {
  6100. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6101. {
  6102. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6103. }
  6104. }
  6105. }
  6106. else if(gunType[gun_index] == GUN_TYPE_DO)
  6107. {
  6108. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6111. {
  6112. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6113. }
  6114. }
  6115. }
  6116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6122. } // END FOR DC CASE
  6123. }
  6124. //================================================ Message create ====================================================
  6125. json_object *StopTransaction = json_object_new_object();
  6126. json_object *transactionDatas = json_object_new_array();
  6127. json_object *sampledValues = json_object_new_array();
  6128. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6129. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6130. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6131. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6132. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6133. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6134. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6135. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6136. {
  6137. json_object *transactionData = json_object_new_object();
  6138. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6139. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6140. {
  6141. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6142. {
  6143. json_object *sampledValue = json_object_new_object();
  6144. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6145. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6146. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6147. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6148. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6149. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6150. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6151. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6152. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6153. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6154. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6155. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6156. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6157. json_object_array_add(sampledValues, sampledValue);
  6158. }
  6159. }
  6160. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6161. json_object_array_add(transactionDatas, transactionData);
  6162. }
  6163. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6164. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6165. ,MESSAGE_TYPE_CALL
  6166. ,guid
  6167. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6168. json_object_put(StopTransaction);
  6169. #if 1 // for TempStopTransaction
  6170. //Delete TempStopTransaction
  6171. if((access(TempStopTransaction,F_OK))!=-1)
  6172. {
  6173. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6174. }
  6175. #endif
  6176. #if 1
  6177. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6178. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6179. {
  6180. result = PASS;
  6181. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6182. }
  6183. #endif
  6184. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6185. OCPP_insert_transaction_msg(NO, queuedata);
  6186. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6187. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6188. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6189. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6190. {
  6191. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6192. }
  6193. //for test
  6194. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6195. return result;
  6196. }
  6197. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6198. {
  6199. mtrace();
  6200. int result = FAIL;
  6201. char guid[37]={0};
  6202. char tempdata[65]={0};
  6203. int tempIndex = 0;
  6204. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6205. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6206. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6207. //set value
  6208. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6209. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6210. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6211. -1);
  6212. random_uuid(guid);
  6213. //UTC Date time
  6214. struct timeval tmnow;
  6215. struct tm *tm;
  6216. char buf[28];//, usec_buf[6];
  6217. gettimeofday(&tmnow, NULL);
  6218. time_t t;
  6219. t = time(NULL);
  6220. /*UTC time and date*/
  6221. tm = gmtime(&t);
  6222. if(dataType == ReadingContext_Sample_Clock)
  6223. {
  6224. struct tm *tmTarget;
  6225. struct timeb tbTarget;
  6226. tbTarget.time = mktime(tm);
  6227. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6228. tmTarget = gmtime(&tbTarget.time);
  6229. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6230. }
  6231. else
  6232. {
  6233. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6234. }
  6235. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6236. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6237. //********************************(1)Current.Import L1************************************************/
  6238. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6239. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6240. (dataType == ReadingContext_Trigger))
  6241. {
  6242. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6243. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6244. {
  6245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6246. {
  6247. tempIndex = ((gun_index==2) ? 1: 0);
  6248. }
  6249. else
  6250. {
  6251. tempIndex = gun_index;
  6252. }
  6253. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6254. {
  6255. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6256. {
  6257. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6258. }
  6259. }
  6260. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6261. }
  6262. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6263. {
  6264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6265. {
  6266. tempIndex = ((gun_index==2) ? 1: 0);
  6267. }
  6268. else
  6269. {
  6270. tempIndex = gun_index;
  6271. }
  6272. for (int index = 0; index < CCS_QUANTITY; index++)
  6273. {
  6274. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6275. {
  6276. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6277. }
  6278. }
  6279. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6280. }
  6281. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6282. {
  6283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6284. {
  6285. tempIndex = ((gun_index==2) ? 1: 0);
  6286. }
  6287. else
  6288. {
  6289. tempIndex = gun_index;
  6290. }
  6291. for (int index = 0; index < GB_QUANTITY; index++)
  6292. {
  6293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6294. {
  6295. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6296. }
  6297. }
  6298. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6299. }
  6300. else if(gunType[gun_index] == GUN_TYPE_DO)
  6301. {
  6302. tempIndex = gun_index;
  6303. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6304. {
  6305. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6306. {
  6307. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6308. }
  6309. }
  6310. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6311. }
  6312. else
  6313. {
  6314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6315. {
  6316. tempIndex = 2;
  6317. }
  6318. else
  6319. {
  6320. tempIndex = gun_index;
  6321. }
  6322. for (int index = 0; index < AC_QUANTITY; index++)
  6323. {
  6324. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6325. {
  6326. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6327. }
  6328. }
  6329. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6330. }
  6331. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6332. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6333. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6334. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6335. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6336. }
  6337. //********************************(2)Energy.Active.Import.Register ************************************************/
  6338. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6339. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6340. (dataType == ReadingContext_Trigger))
  6341. {
  6342. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6343. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6344. {
  6345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6346. {
  6347. tempIndex = ((gun_index==2) ? 1: 0);
  6348. }
  6349. else
  6350. {
  6351. tempIndex = gun_index;
  6352. }
  6353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6354. {
  6355. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6356. {
  6357. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6358. }
  6359. }
  6360. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6361. }
  6362. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6363. {
  6364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6365. {
  6366. tempIndex = ((gun_index==2) ? 1: 0);
  6367. }
  6368. else
  6369. {
  6370. tempIndex = gun_index;
  6371. }
  6372. for (int index = 0; index < CCS_QUANTITY; index++)
  6373. {
  6374. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6375. {
  6376. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6377. }
  6378. }
  6379. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6380. }
  6381. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6382. {
  6383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6384. {
  6385. tempIndex = ((gun_index==2) ? 1: 0);
  6386. }
  6387. else
  6388. {
  6389. tempIndex = gun_index;
  6390. }
  6391. for (int index = 0; index < GB_QUANTITY; index++)
  6392. {
  6393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6394. {
  6395. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6396. }
  6397. }
  6398. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6399. }
  6400. else if(gunType[gun_index] == GUN_TYPE_DO)
  6401. {
  6402. tempIndex = gun_index;
  6403. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6404. {
  6405. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6406. {
  6407. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6408. }
  6409. }
  6410. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6411. }
  6412. else
  6413. {
  6414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6415. {
  6416. tempIndex = 2;
  6417. }
  6418. else
  6419. {
  6420. tempIndex = gun_index;
  6421. }
  6422. for (int index = 0; index < AC_QUANTITY; index++)
  6423. {
  6424. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6425. {
  6426. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6427. }
  6428. }
  6429. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6430. }
  6431. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6432. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6433. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6434. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6435. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6436. }
  6437. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6438. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6439. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6440. (dataType == ReadingContext_Trigger))
  6441. {
  6442. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6443. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6444. {
  6445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6446. {
  6447. tempIndex = ((gun_index==2) ? 1: 0);
  6448. }
  6449. else
  6450. {
  6451. tempIndex = gun_index;
  6452. }
  6453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6454. {
  6455. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6456. {
  6457. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6458. }
  6459. } // END OF FOR CHAdeMO_QUANTITY
  6460. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6461. }
  6462. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6463. {
  6464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6465. {
  6466. tempIndex = ((gun_index==2) ? 1: 0);
  6467. }
  6468. else
  6469. {
  6470. tempIndex = gun_index;
  6471. }
  6472. for (int index = 0; index < CCS_QUANTITY; index++)
  6473. {
  6474. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6475. {
  6476. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6477. }
  6478. } // END OF CCS_QUANTITY
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6480. }
  6481. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6482. {
  6483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6484. {
  6485. tempIndex = ((gun_index==2) ? 1: 0);
  6486. }
  6487. else
  6488. {
  6489. tempIndex = gun_index;
  6490. }
  6491. for (int index = 0; index < GB_QUANTITY; index++)
  6492. {
  6493. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6494. {
  6495. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6496. }
  6497. } // END OF GB_QUANTITY
  6498. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6499. }
  6500. else if(gunType[gun_index] == GUN_TYPE_DO)
  6501. {
  6502. tempIndex = gun_index;
  6503. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6504. {
  6505. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6506. {
  6507. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6508. }
  6509. }
  6510. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6511. }
  6512. else
  6513. {
  6514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6515. {
  6516. tempIndex = 2;
  6517. }
  6518. else
  6519. {
  6520. tempIndex = gun_index;
  6521. }
  6522. for (int index = 0; index < AC_QUANTITY; index++)
  6523. {
  6524. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6525. {
  6526. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6527. }
  6528. }
  6529. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6530. }
  6531. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6533. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6536. }
  6537. //********************************(4)Power.Active.Import************************************************/
  6538. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6539. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6540. (dataType == ReadingContext_Trigger))
  6541. {
  6542. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6543. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6544. {
  6545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6546. {
  6547. tempIndex = ((gun_index==2) ? 1: 0);
  6548. }
  6549. else
  6550. {
  6551. tempIndex = gun_index;
  6552. }
  6553. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6554. {
  6555. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6556. {
  6557. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6558. }
  6559. } // END OF FOR
  6560. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6561. }
  6562. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6563. {
  6564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6565. {
  6566. tempIndex = ((gun_index==2) ? 1: 0);
  6567. }
  6568. else
  6569. {
  6570. tempIndex = gun_index;
  6571. }
  6572. for (int index = 0; index < CCS_QUANTITY; index++)
  6573. {
  6574. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6575. {
  6576. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6577. }
  6578. }
  6579. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6580. }
  6581. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6582. {
  6583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6584. {
  6585. tempIndex = ((gun_index==2) ? 1: 0);
  6586. }
  6587. else
  6588. {
  6589. tempIndex = gun_index;
  6590. }
  6591. for (int index = 0; index < GB_QUANTITY; index++)
  6592. {
  6593. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6594. {
  6595. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6596. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6597. }
  6598. }
  6599. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6600. }
  6601. else if(gunType[gun_index] == GUN_TYPE_DO)
  6602. {
  6603. tempIndex = gun_index;
  6604. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6605. {
  6606. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6607. {
  6608. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6609. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6610. }
  6611. }
  6612. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6613. }
  6614. else
  6615. {
  6616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6617. {
  6618. tempIndex = 2;
  6619. }
  6620. else
  6621. {
  6622. tempIndex = gun_index;
  6623. }
  6624. for (int index = 0; index < AC_QUANTITY; index++)
  6625. {
  6626. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6627. {
  6628. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6629. }
  6630. }
  6631. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6632. }
  6633. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6634. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6635. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6636. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6637. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6638. }
  6639. //***********************************************(5)VOLTAGE L1******************************************************/
  6640. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6641. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6642. (dataType == ReadingContext_Trigger))
  6643. {
  6644. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6645. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6646. {
  6647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6648. {
  6649. tempIndex = ((gun_index==2) ? 1: 0);
  6650. }
  6651. else
  6652. {
  6653. tempIndex = gun_index;
  6654. }
  6655. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6656. {
  6657. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6658. {
  6659. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6660. }
  6661. }
  6662. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6663. }
  6664. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6665. {
  6666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6667. {
  6668. tempIndex = ((gun_index==2) ? 1: 0);
  6669. }
  6670. else
  6671. {
  6672. tempIndex = gun_index;
  6673. }
  6674. for (int index = 0; index < CCS_QUANTITY; index++)
  6675. {
  6676. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6677. {
  6678. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6679. }
  6680. }
  6681. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6682. }
  6683. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6684. {
  6685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6686. {
  6687. tempIndex = ((gun_index==2) ? 1: 0);
  6688. }
  6689. else
  6690. {
  6691. tempIndex = gun_index;
  6692. }
  6693. for (int index = 0; index < GB_QUANTITY; index++)
  6694. {
  6695. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6696. {
  6697. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6698. }
  6699. }
  6700. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6701. }
  6702. else if(gunType[gun_index] == GUN_TYPE_DO)
  6703. {
  6704. tempIndex = gun_index;
  6705. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6706. {
  6707. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6708. {
  6709. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6710. }
  6711. }
  6712. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6713. }
  6714. else
  6715. {
  6716. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6717. {
  6718. tempIndex = 2;
  6719. }
  6720. else
  6721. {
  6722. tempIndex = gun_index;
  6723. }
  6724. for (int index = 0; index < AC_QUANTITY; index++)
  6725. {
  6726. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6727. {
  6728. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6729. }
  6730. }
  6731. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6732. }
  6733. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6734. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6735. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6736. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6737. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6738. }
  6739. //***********************************************(6)SOC******************************************************/
  6740. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6741. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6742. (dataType == ReadingContext_Trigger))
  6743. {
  6744. 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))
  6745. {
  6746. //idx_sample=5;
  6747. //sampledValue = NULL;
  6748. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6749. {
  6750. tempIndex = ((gun_index==2) ? 1: 0);
  6751. }
  6752. else
  6753. {
  6754. tempIndex = gun_index;
  6755. }
  6756. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6757. {
  6758. //tempIndex = ((gun_index==2) ? 1: 0);
  6759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6760. {
  6761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6762. {
  6763. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6764. }
  6765. }
  6766. }
  6767. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6768. {
  6769. //tempIndex = ((gun_index==2) ? 1: 0);
  6770. for (int index = 0; index < CCS_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6773. {
  6774. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6775. }
  6776. }
  6777. }
  6778. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6779. {
  6780. //tempIndex = ((gun_index==2) ? 1: 0);
  6781. for (int index = 0; index < GB_QUANTITY; index++)
  6782. {
  6783. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6784. {
  6785. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6786. }
  6787. }
  6788. }
  6789. else if(gunType[gun_index] == GUN_TYPE_DO)
  6790. {
  6791. //tempIndex = ((gun_index==2) ? 1: 0);
  6792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6795. {
  6796. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6797. }
  6798. }
  6799. }
  6800. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6801. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6802. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6803. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6804. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6805. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6806. }
  6807. }
  6808. //********************************(7)Current.Import L2************************************************/
  6809. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6810. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6811. (dataType == ReadingContext_Trigger))
  6812. {
  6813. // Only for AC 3 phase
  6814. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6815. {
  6816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6817. {
  6818. tempIndex = 2;
  6819. }
  6820. else
  6821. {
  6822. tempIndex = gun_index;
  6823. }
  6824. for (int index = 0; index < AC_QUANTITY; index++)
  6825. {
  6826. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6827. {
  6828. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6829. }
  6830. }
  6831. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6832. }
  6833. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6834. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6835. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6836. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6837. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6838. }
  6839. //********************************(8)Current.Import L3************************************************/
  6840. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6841. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6842. (dataType == ReadingContext_Trigger))
  6843. {
  6844. // Only for AC 3 phase
  6845. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6846. {
  6847. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6848. {
  6849. tempIndex = 2;
  6850. }
  6851. else
  6852. {
  6853. tempIndex = gun_index;
  6854. }
  6855. for (int index = 0; index < AC_QUANTITY; index++)
  6856. {
  6857. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6858. {
  6859. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6860. }
  6861. }
  6862. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6863. }
  6864. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6865. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6866. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6867. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6868. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6869. }
  6870. //***********************************************(9)VOLTAGE L2******************************************************/
  6871. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6872. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6873. (dataType == ReadingContext_Trigger))
  6874. {
  6875. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6876. {
  6877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6878. {
  6879. tempIndex = 2;
  6880. }
  6881. else
  6882. {
  6883. tempIndex = gun_index;
  6884. }
  6885. for (int index = 0; index < AC_QUANTITY; index++)
  6886. {
  6887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6888. {
  6889. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6890. }
  6891. }
  6892. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6893. }
  6894. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6895. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6896. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6897. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6898. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6899. }
  6900. //***********************************************(10)VOLTAGE L3******************************************************/
  6901. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6902. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6903. (dataType == ReadingContext_Trigger))
  6904. {
  6905. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6906. {
  6907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6908. {
  6909. tempIndex = 2;
  6910. }
  6911. else
  6912. {
  6913. tempIndex = gun_index;
  6914. }
  6915. for (int index = 0; index < AC_QUANTITY; index++)
  6916. {
  6917. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6918. {
  6919. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6920. }
  6921. }
  6922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6923. }
  6924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6926. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6927. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6928. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6929. }
  6930. //***********************************************(11)Current.Offered******************************************************/
  6931. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6932. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6933. (dataType == ReadingContext_Trigger))
  6934. {
  6935. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6936. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6937. {
  6938. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6939. {
  6940. tempIndex = ((gun_index==2) ? 1: 0);
  6941. }
  6942. else
  6943. {
  6944. tempIndex = gun_index;
  6945. }
  6946. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6947. {
  6948. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6949. {
  6950. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6951. }
  6952. } // END OF FOR CHAdeMO_QUANTITY
  6953. }
  6954. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6955. {
  6956. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6957. {
  6958. tempIndex = ((gun_index==2) ? 1: 0);
  6959. }
  6960. else
  6961. {
  6962. tempIndex = gun_index;
  6963. }
  6964. for (int index = 0; index < CCS_QUANTITY; index++)
  6965. {
  6966. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6967. {
  6968. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6969. }
  6970. } // END OF CCS_QUANTITY
  6971. }
  6972. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6973. {
  6974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6975. {
  6976. tempIndex = ((gun_index==2) ? 1: 0);
  6977. }
  6978. else
  6979. {
  6980. tempIndex = gun_index;
  6981. }
  6982. for (int index = 0; index < GB_QUANTITY; index++)
  6983. {
  6984. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6985. {
  6986. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6987. }
  6988. } // END OF GB_QUANTITY
  6989. }
  6990. else if(gunType[gun_index] == GUN_TYPE_DO)
  6991. {
  6992. tempIndex = gun_index;
  6993. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6994. {
  6995. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6996. {
  6997. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6998. }
  6999. }
  7000. }
  7001. else
  7002. {
  7003. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7004. {
  7005. tempIndex = 2;
  7006. }
  7007. else
  7008. {
  7009. tempIndex = gun_index;
  7010. }
  7011. for (int index = 0; index < AC_QUANTITY; index++)
  7012. {
  7013. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7014. {
  7015. uint16_t currentOffer;
  7016. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7017. {
  7018. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7019. }
  7020. else
  7021. {
  7022. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7023. }
  7024. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7025. }
  7026. }
  7027. }
  7028. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7029. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7030. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7031. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7032. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7033. }
  7034. //***********************************************(12)Power.Offered******************************************************/
  7035. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7036. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7037. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7038. {
  7039. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7040. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7041. {
  7042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7043. {
  7044. tempIndex = ((gun_index==2) ? 1: 0);
  7045. }
  7046. else
  7047. {
  7048. tempIndex = gun_index;
  7049. }
  7050. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7051. {
  7052. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7053. {
  7054. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7055. }
  7056. } // END OF FOR CHAdeMO_QUANTITY
  7057. }
  7058. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7059. {
  7060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7061. {
  7062. tempIndex = ((gun_index==2) ? 1: 0);
  7063. }
  7064. else
  7065. {
  7066. tempIndex = gun_index;
  7067. }
  7068. for (int index = 0; index < CCS_QUANTITY; index++)
  7069. {
  7070. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7071. {
  7072. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7073. }
  7074. } // END OF CCS_QUANTITY
  7075. }
  7076. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7077. {
  7078. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7079. {
  7080. tempIndex = ((gun_index==2) ? 1: 0);
  7081. }
  7082. else
  7083. {
  7084. tempIndex = gun_index;
  7085. }
  7086. for (int index = 0; index < GB_QUANTITY; index++)
  7087. {
  7088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7089. {
  7090. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7091. }
  7092. } // END OF GB_QUANTITY
  7093. }
  7094. else if(gunType[gun_index] == GUN_TYPE_DO)
  7095. {
  7096. tempIndex = gun_index;
  7097. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7098. {
  7099. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7100. {
  7101. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7102. }
  7103. }
  7104. }
  7105. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7107. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7110. }
  7111. // Message create ====================================================================================================
  7112. if(TRUE)
  7113. {
  7114. json_object *MeterValueReq = json_object_new_object();
  7115. json_object *MeterValues = json_object_new_array();
  7116. json_object *sampledValues = json_object_new_array();
  7117. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7118. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7119. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7120. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7121. {
  7122. json_object *MeterValue = json_object_new_object();
  7123. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7124. {
  7125. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7126. {
  7127. json_object *sampledValue = json_object_new_object();
  7128. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7129. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7130. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7131. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7132. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7133. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7134. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7135. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7136. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7137. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7138. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7139. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7140. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7141. json_object_array_add(sampledValues, sampledValue);
  7142. }
  7143. }
  7144. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7145. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7146. json_object_array_add(MeterValues, MeterValue);
  7147. }
  7148. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7149. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7150. ,gun_index + 1
  7151. ,MESSAGE_TYPE_CALL
  7152. ,guid
  7153. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7154. json_object_put(MeterValueReq);
  7155. }
  7156. // Put request guid to hash map
  7157. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7158. 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*/)
  7159. {
  7160. result = PASS;
  7161. //DEBUG_INFO("MeterValues mapitem pass\n");
  7162. }
  7163. if((dataType != ReadingContext_Trigger) &&
  7164. (dataType != ReadingContext_Sample_Clock) &&
  7165. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7166. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7167. else
  7168. {
  7169. if(FirstHeartBeat)
  7170. LWS_Send(queuedata +2);
  7171. }
  7172. return result;
  7173. }
  7174. int sendLogStatusNotificationRequest(char *status)
  7175. {
  7176. mtrace();
  7177. int result = PASS;
  7178. char message[4096]={0};
  7179. char guid[37]={0};
  7180. char tempdata[128]={0};
  7181. json_object *LogStatusNotification = json_object_new_object();
  7182. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7183. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7184. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7185. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7186. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7187. random_uuid(guid);
  7188. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7189. json_object_put(LogStatusNotification);
  7190. LWS_Send(message);
  7191. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7192. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7193. {
  7194. result = PASS;
  7195. }
  7196. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7197. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7198. return result;
  7199. }
  7200. int sendSecurityEventNotificationRequest()
  7201. {
  7202. mtrace();
  7203. int result = PASS;
  7204. char message[4096]={0};
  7205. char guid[37]={0};
  7206. char tempdata[128]={0};
  7207. json_object *SecurityEventNotification = json_object_new_object();
  7208. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7209. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7210. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7211. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7212. random_uuid(guid);
  7213. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7214. json_object_put(SecurityEventNotification);
  7215. LWS_Send(message);
  7216. sprintf(tempdata, "SecurityEventNotification,0");
  7217. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7218. {
  7219. result = PASS;
  7220. }
  7221. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7222. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7223. return result;
  7224. }
  7225. int sendSignCertificateRequest()
  7226. {
  7227. mtrace();
  7228. int result = PASS;
  7229. char message[4096]={0};
  7230. char guid[37]={0};
  7231. char tempdata[128]={0};
  7232. json_object *SignCertificate = json_object_new_object();
  7233. DEBUG_INFO("sendSignCertificateRequest...\n");
  7234. // Read csr file content
  7235. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7236. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7237. char *line = NULL;
  7238. size_t len = 0;
  7239. while(getline(&line, &len, fp) != -1)
  7240. {
  7241. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7242. {
  7243. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7244. }
  7245. }
  7246. fclose(fp);
  7247. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7248. random_uuid(guid);
  7249. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7250. json_object_put(SignCertificate);
  7251. LWS_Send(message);
  7252. sprintf(tempdata, "SignCertificate,0");
  7253. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7254. {
  7255. result = PASS;
  7256. }
  7257. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7258. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7259. return result;
  7260. }
  7261. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7262. {
  7263. mtrace();
  7264. int result = PASS;
  7265. char message[110]={0};
  7266. char guid[37]={0};
  7267. char tempdata[65]={0};
  7268. json_object *FirmwareStatusNotification = json_object_new_object();
  7269. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7270. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7271. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7272. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7273. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7274. random_uuid(guid);
  7275. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7276. json_object_put(FirmwareStatusNotification);
  7277. LWS_Send(message);
  7278. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7279. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7280. {
  7281. result = PASS;
  7282. }
  7283. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7284. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7285. return result;
  7286. }
  7287. //==========================================
  7288. // send confirm routine
  7289. //==========================================
  7290. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7291. {
  7292. mtrace();
  7293. int result = FAIL;
  7294. char message[100]={0};
  7295. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7296. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7297. LWS_Send(message);
  7298. result = TRUE;
  7299. return result;
  7300. }
  7301. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7302. {
  7303. mtrace();
  7304. int result = FAIL;
  7305. char message[100]={0};
  7306. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7307. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7308. LWS_Send(message);
  7309. result = TRUE;
  7310. return result;
  7311. }
  7312. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7313. {
  7314. mtrace();
  7315. int result = FAIL;
  7316. char message[100]={0};
  7317. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7318. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7319. LWS_Send(message);
  7320. result = TRUE;
  7321. return result;
  7322. }
  7323. int sendClearCacheConfirmation(char *uuid,char *payload)
  7324. {
  7325. mtrace();
  7326. int result = FAIL;
  7327. char message[500]={0};
  7328. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7329. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7330. LWS_Send(message);
  7331. return result;
  7332. }
  7333. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7334. {
  7335. mtrace();
  7336. int result = FAIL;
  7337. char message[500]={0};
  7338. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7339. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7340. LWS_Send(message);
  7341. return result;
  7342. }
  7343. int sendDataTransferConfirmation(char *uuid,char *payload)
  7344. {
  7345. mtrace();
  7346. char statusStr[20]={0};
  7347. char dataStr[10]={0};
  7348. char sstr[20]={0};
  7349. int c = 0;
  7350. char *loc;
  7351. int result = FAIL;
  7352. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7353. /**********************status**************************/
  7354. loc = strstr(payload, "status");
  7355. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7356. c = 0;
  7357. while (loc[3+strlen("status")+c] != '\"')
  7358. {
  7359. sstr[c] = loc[3+strlen("status")+c];
  7360. c++;
  7361. }
  7362. sstr[c] = '\0';
  7363. strcpy(statusStr, sstr);
  7364. /**********************data**************************/
  7365. loc = strstr(payload, "data");
  7366. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7367. c = 0;
  7368. while (loc[3+strlen("data")+c] != '\"')
  7369. {
  7370. sstr[c] = loc[3+strlen("data")+c];
  7371. c++;
  7372. }
  7373. sstr[c] = '\0';
  7374. strcpy(dataStr, sstr);
  7375. return result;
  7376. }
  7377. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7378. {
  7379. mtrace();
  7380. int result = FAIL;
  7381. char message[1000]={0};
  7382. int CompositeScheduleIndex = 0;
  7383. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7384. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7385. if(nPeriod == 0)
  7386. {
  7387. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7388. {
  7389. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7390. ,MESSAGE_TYPE_CALLRESULT
  7391. ,uuid
  7392. ,payload
  7393. ,connectorIdInt);
  7394. }
  7395. else
  7396. {
  7397. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7398. ,MESSAGE_TYPE_CALLRESULT
  7399. ,uuid
  7400. ,payload
  7401. ,connectorIdInt
  7402. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7403. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7404. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7405. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7406. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7407. }
  7408. }
  7409. else
  7410. {
  7411. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7412. ,MESSAGE_TYPE_CALLRESULT
  7413. ,uuid
  7414. ,payload
  7415. ,connectorIdInt
  7416. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7417. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7418. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7419. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7420. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7421. {
  7422. if (idx_sample == 0)
  7423. {
  7424. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7425. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7426. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7427. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7428. }
  7429. else
  7430. {
  7431. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7432. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7433. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7434. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7435. }
  7436. }
  7437. sprintf(message + strlen(message), "]}}]");
  7438. }
  7439. LWS_Send(message);
  7440. result = TRUE;
  7441. return result;
  7442. }
  7443. int sendGetConfigurationConfirmation(char *uuid)
  7444. {
  7445. mtrace();
  7446. int result = FAIL;
  7447. int MaxKeySupported = 0;
  7448. int sentConfigurationNumber= 0;
  7449. int sentunConfigurationNumber= 0;
  7450. char message[1024*10]={0};
  7451. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7452. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7453. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7454. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7455. ,MESSAGE_TYPE_CALLRESULT
  7456. ,uuid );
  7457. //configuration key
  7458. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7459. {
  7460. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7461. {
  7462. if (sentConfigurationNumber == 0)
  7463. {
  7464. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7465. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7466. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7467. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7468. }
  7469. else
  7470. {
  7471. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7472. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7473. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7474. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7475. }
  7476. sentConfigurationNumber = sentConfigurationNumber + 1;
  7477. }
  7478. }
  7479. sprintf(message + strlen(message), "]");
  7480. if(UnknownKeynum != 0)
  7481. {
  7482. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7483. //unkown key
  7484. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7485. {
  7486. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7487. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7488. if(sentunConfigurationNumber == 0)
  7489. {
  7490. sprintf(message + strlen(message), "\"%s\""
  7491. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7492. }
  7493. else
  7494. {
  7495. sprintf(message + strlen(message), ",\"%s\""
  7496. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7497. }
  7498. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7499. }
  7500. sprintf(message + strlen(message), "]");
  7501. }
  7502. sprintf(message + strlen(message), "}]");
  7503. LWS_Send(message);
  7504. return result;
  7505. }
  7506. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7507. {
  7508. mtrace();
  7509. int result = FAIL;
  7510. char message[400]={0};
  7511. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7512. if(strcmp(payload,"")==0)
  7513. {
  7514. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7515. }
  7516. else
  7517. {
  7518. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7519. }
  7520. LWS_Send(message);
  7521. result = TRUE;
  7522. return result;
  7523. }
  7524. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7525. {
  7526. mtrace();
  7527. int result = FAIL;
  7528. char message[80]={0};
  7529. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7530. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7531. LWS_Send(message);
  7532. result = TRUE;
  7533. return result;
  7534. }
  7535. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7536. {
  7537. mtrace();
  7538. int result = FAIL;
  7539. char message[80]={0};
  7540. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7541. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7542. LWS_Send(message);
  7543. result = TRUE;
  7544. return result;
  7545. }
  7546. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7547. {
  7548. mtrace();
  7549. int result = FAIL;
  7550. char message[80]={0};
  7551. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7552. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7553. LWS_Send(message);
  7554. result = TRUE;
  7555. return result;
  7556. }
  7557. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7558. {
  7559. mtrace();
  7560. int result = FAIL;
  7561. char message[80]={0};
  7562. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7563. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7564. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7565. LWS_Send(message);
  7566. result = TRUE;
  7567. return result;
  7568. }
  7569. int sendResetConfirmation(char *uuid,char *payload)
  7570. {
  7571. mtrace();
  7572. int result = FAIL;
  7573. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7574. char message[80]={0};
  7575. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7576. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7577. LWS_Send(message);
  7578. result = TRUE;
  7579. return result;
  7580. }
  7581. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7582. {
  7583. mtrace();
  7584. int result = FAIL;
  7585. char message[500]={0};
  7586. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7587. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7588. LWS_Send(message);
  7589. result = TRUE;
  7590. return result;
  7591. }
  7592. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7593. {
  7594. mtrace();
  7595. int result = FAIL;
  7596. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7597. char message[80]={0};
  7598. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7599. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7600. LWS_Send(message);
  7601. result = TRUE;
  7602. return result;
  7603. }
  7604. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7605. {
  7606. mtrace();
  7607. int result = FAIL;
  7608. char message[80]={0};
  7609. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7610. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7611. LWS_Send(message);
  7612. result = TRUE;
  7613. return result;
  7614. }
  7615. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7616. {
  7617. mtrace();
  7618. int result = FAIL;
  7619. char message[80]={0};
  7620. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7621. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7622. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7623. LWS_Send(message);
  7624. result = TRUE;
  7625. return result;
  7626. }
  7627. int sendUpdateFirmwareConfirmation(char *uuid)
  7628. {
  7629. mtrace();
  7630. int result = FAIL;
  7631. char message[60]={0};
  7632. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7633. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7634. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7635. LWS_Send(message);
  7636. result = TRUE;
  7637. return result;
  7638. }
  7639. int sendCertificateSignedConfirmation(char *uuid)
  7640. {
  7641. mtrace();
  7642. int result = PASS;
  7643. char message[4096]={0};
  7644. json_object *CertificateSigned = json_object_new_object();
  7645. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7646. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7647. sprintf(message,"[%d,\"%s\",%s]"
  7648. ,MESSAGE_TYPE_CALLRESULT
  7649. ,uuid
  7650. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7651. json_object_put(CertificateSigned);
  7652. LWS_Send(message);
  7653. return result;
  7654. }
  7655. int sendDeleteCertificateConfirmation(char *uuid)
  7656. {
  7657. mtrace();
  7658. int result = PASS;
  7659. char message[4096]={0};
  7660. json_object *DeleteCertificate = json_object_new_object();
  7661. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7662. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7663. sprintf(message,"[%d,\"%s\",%s]"
  7664. ,MESSAGE_TYPE_CALLRESULT
  7665. ,uuid
  7666. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7667. json_object_put(DeleteCertificate);
  7668. LWS_Send(message);
  7669. return result;
  7670. }
  7671. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7672. {
  7673. mtrace();
  7674. int result = PASS;
  7675. char message[4096]={0};
  7676. json_object *ExtendedTriggerMessage = json_object_new_object();
  7677. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7678. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7679. sprintf(message,"[%d,\"%s\",%s]"
  7680. ,MESSAGE_TYPE_CALLRESULT
  7681. ,uuid
  7682. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7683. json_object_put(ExtendedTriggerMessage);
  7684. LWS_Send(message);
  7685. return result;
  7686. }
  7687. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7688. {
  7689. mtrace();
  7690. int result = PASS;
  7691. char message[4096]={0};
  7692. json_object *GetInstalledCertificateIds = json_object_new_object();
  7693. json_object *certificateHashDataDatas = json_object_new_array();
  7694. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7695. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7696. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7697. {
  7698. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7699. {
  7700. json_object *certificateHashData = json_object_new_object();
  7701. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7702. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7703. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7704. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7705. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7706. }
  7707. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7708. }
  7709. else
  7710. {
  7711. json_object_put(certificateHashDataDatas);
  7712. }
  7713. sprintf(message,"[%d,\"%s\",%s]"
  7714. ,MESSAGE_TYPE_CALLRESULT
  7715. ,uuid
  7716. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7717. json_object_put(GetInstalledCertificateIds);
  7718. LWS_Send(message);
  7719. return result;
  7720. }
  7721. int sendGetLogConfirmation(char *uuid)
  7722. {
  7723. mtrace();
  7724. int result = PASS;
  7725. char message[4096]={0};
  7726. json_object *GetLog = json_object_new_object();
  7727. DEBUG_INFO("sendGetLogConfirmation...\n");
  7728. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7729. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7730. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7731. sprintf(message,"[%d,\"%s\",%s]"
  7732. ,MESSAGE_TYPE_CALLRESULT
  7733. ,uuid
  7734. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7735. json_object_put(GetLog);
  7736. LWS_Send(message);
  7737. return result;
  7738. }
  7739. int sendInstallCertificateConfirmation(char *uuid)
  7740. {
  7741. mtrace();
  7742. int result = PASS;
  7743. char message[4096]={0};
  7744. json_object *InstallCertificate = json_object_new_object();
  7745. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7746. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7747. sprintf(message,"[%d,\"%s\",%s]"
  7748. ,MESSAGE_TYPE_CALLRESULT
  7749. ,uuid
  7750. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7751. json_object_put(InstallCertificate);
  7752. LWS_Send(message);
  7753. return result;
  7754. }
  7755. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7756. {
  7757. mtrace();
  7758. int result = PASS;
  7759. char message[4096]={0};
  7760. json_object *SignedUpdateFirmware = json_object_new_object();
  7761. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7762. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7763. sprintf(message,"[%d,\"%s\",%s]"
  7764. ,MESSAGE_TYPE_CALLRESULT
  7765. ,uuid
  7766. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7767. json_object_put(SignedUpdateFirmware);
  7768. LWS_Send(message);
  7769. return result;
  7770. }
  7771. int sendUnknownConfirmation(char *uuid)
  7772. {
  7773. mtrace();
  7774. int result = PASS;
  7775. char message[256]={0};
  7776. DEBUG_INFO("sendUnknownConfirmation...\n");
  7777. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7778. LWS_Send(message);
  7779. return result;
  7780. }
  7781. //==========================================
  7782. // Handle server request routine Start
  7783. //==========================================
  7784. int handleCancelReservationRequest(char *uuid, char *payload)
  7785. {
  7786. mtrace();
  7787. int result = FAIL;
  7788. int gunNO = 0;
  7789. int reservationIdInt = -1;
  7790. char comfirmstr[20];
  7791. DEBUG_INFO("handleCancelReservationRequest...\n");
  7792. json_object *CancelReservation;
  7793. CancelReservation = json_tokener_parse(payload);
  7794. if(!is_error(CancelReservation))
  7795. {
  7796. // Required data
  7797. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7798. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7799. }
  7800. json_object_put(CancelReservation);
  7801. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7802. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7803. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7804. if(reservationIdInt != -1)
  7805. {
  7806. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7807. //check Transaction active
  7808. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7809. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7810. {
  7811. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7812. {
  7813. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7814. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7815. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7816. {
  7817. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7818. }
  7819. else
  7820. {
  7821. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7822. }
  7823. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7824. goto end;
  7825. }
  7826. }
  7827. for (int index = 0; index < CCS_QUANTITY; index++)
  7828. {
  7829. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7830. {
  7831. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7832. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7833. if(gunType[2] == GUN_TYPE_CCS)
  7834. {
  7835. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7836. }
  7837. else
  7838. {
  7839. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7840. }
  7841. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7842. goto end;
  7843. }
  7844. }
  7845. for (int index = 0; index < GB_QUANTITY; index++)
  7846. {
  7847. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7848. {
  7849. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7850. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7851. if(gunType[2] == GUN_TYPE_GBT)
  7852. {
  7853. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7854. }
  7855. else
  7856. {
  7857. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7858. }
  7859. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7860. goto end;
  7861. }
  7862. }
  7863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7864. {
  7865. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7866. {
  7867. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7868. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7869. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7870. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7871. goto end;
  7872. }
  7873. }
  7874. for (int index = 0; index < AC_QUANTITY; index++)
  7875. {
  7876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7877. {
  7878. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7879. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7880. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7881. {
  7882. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7883. }
  7884. else
  7885. {
  7886. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7887. }
  7888. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7889. goto end;
  7890. }
  7891. }
  7892. }
  7893. //The reservationId does NOT match the reservationId
  7894. sendCancelReservationConfirmation(uuid, comfirmstr);
  7895. end:
  7896. // Fill in ocpp packet uuid
  7897. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7898. return result;
  7899. }
  7900. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7901. {
  7902. mtrace();
  7903. int result = FAIL;
  7904. int gunIndex = -1;
  7905. char typeStr[16]={0};
  7906. char comfirmstr[20];
  7907. int specificId = FALSE;
  7908. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7909. json_object *ChangeAvailability;
  7910. ChangeAvailability = json_tokener_parse(payload);
  7911. if(!is_error(ChangeAvailability))
  7912. {
  7913. // Required data
  7914. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7915. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7916. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7917. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7918. }
  7919. json_object_put(ChangeAvailability);
  7920. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7921. {
  7922. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7923. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7924. }
  7925. else if(gunIndex == 0)
  7926. {
  7927. for(int i=0; i < gunTotalNumber; i++)
  7928. {
  7929. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7930. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7931. }
  7932. }
  7933. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7934. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7935. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7936. {
  7937. specificId = TRUE;
  7938. }
  7939. if(specificId == FALSE)
  7940. goto end;
  7941. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7942. {
  7943. //----------------------gunIndex is 0 ------------------------------------------------//
  7944. if(gunIndex == 0)
  7945. {
  7946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7947. {
  7948. for(int i=0; i < gunTotalNumber; i++)
  7949. {
  7950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7951. {
  7952. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7953. {
  7954. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7955. {
  7956. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7957. goto end;
  7958. }
  7959. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7960. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7961. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7962. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7963. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7964. {
  7965. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7966. goto end;
  7967. }
  7968. }
  7969. }//END FOR CHAdeMO_QUANTITY
  7970. for (int index = 0; index < CCS_QUANTITY; index++)
  7971. {
  7972. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7973. {
  7974. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7975. {
  7976. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7977. goto end;
  7978. }
  7979. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7980. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7981. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7982. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7983. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7984. {
  7985. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7986. goto end;
  7987. }
  7988. }
  7989. }//END FOR CCS_QUANTITY
  7990. for (int index = 0; index < GB_QUANTITY; index++)
  7991. {
  7992. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7993. {
  7994. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7995. {
  7996. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7997. goto end;
  7998. }
  7999. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8000. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8001. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8002. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8003. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8004. {
  8005. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8006. goto end;
  8007. }
  8008. }
  8009. }// END FOR GB_QUANTITY
  8010. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8011. {
  8012. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8013. {
  8014. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8015. {
  8016. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8017. goto end;
  8018. }
  8019. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8020. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8021. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8022. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8023. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8024. {
  8025. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8026. goto end;
  8027. }
  8028. }
  8029. }// END FOR GENERAL_GUN_QUANTITY
  8030. for (int index = 0; index < AC_QUANTITY; index++)
  8031. {
  8032. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8033. {
  8034. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8035. {
  8036. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8037. goto end;
  8038. }
  8039. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8040. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8041. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8042. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8043. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8044. {
  8045. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8046. goto end;
  8047. }
  8048. }
  8049. }//END FOR AC_QUANTITY
  8050. }// END FOR gunTotalNumber
  8051. }
  8052. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8053. {
  8054. for(int i=0; i < gunTotalNumber; i++)
  8055. {
  8056. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8057. {
  8058. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8059. goto end;
  8060. }
  8061. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8062. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8063. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8064. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8065. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8066. {
  8067. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8068. goto end;
  8069. }
  8070. }
  8071. }
  8072. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8073. goto end;
  8074. }
  8075. //----------------------gunIndex is not 0 ------------------------------------------------//
  8076. //check Transaction active
  8077. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8078. {
  8079. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8080. {
  8081. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8082. {
  8083. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8084. goto end;
  8085. }
  8086. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8087. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8088. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8089. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8090. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8091. {
  8092. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8093. goto end;
  8094. }
  8095. else
  8096. {
  8097. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8098. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8099. goto end;
  8100. }
  8101. }
  8102. }//END FOR CHAdeMO_QUANTITY
  8103. for (int index = 0; index < CCS_QUANTITY; index++)
  8104. {
  8105. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8106. {
  8107. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8108. {
  8109. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8110. goto end;
  8111. }
  8112. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8113. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8114. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8115. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8116. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8117. {
  8118. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8119. goto end;
  8120. }
  8121. else
  8122. {
  8123. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8124. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8125. goto end;
  8126. }
  8127. }
  8128. }//END FOR CCS_QUANTITY
  8129. for (int index = 0; index < GB_QUANTITY; index++)
  8130. {
  8131. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8132. {
  8133. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8134. {
  8135. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8136. goto end;
  8137. }
  8138. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8141. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8142. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8143. {
  8144. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8145. goto end;
  8146. }
  8147. else
  8148. {
  8149. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8150. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8151. goto end;
  8152. }
  8153. }
  8154. }// END FOR GB_QUANTITY
  8155. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8156. {
  8157. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8158. {
  8159. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8160. {
  8161. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8162. goto end;
  8163. }
  8164. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8165. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8168. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8169. {
  8170. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8171. goto end;
  8172. }
  8173. else
  8174. {
  8175. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8176. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8177. goto end;
  8178. }
  8179. }
  8180. }// END FOR GENERAL_GUN_QUANTITY
  8181. for (int index = 0; index < AC_QUANTITY; index++)
  8182. {
  8183. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8184. {
  8185. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8186. {
  8187. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8188. goto end;
  8189. }
  8190. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8191. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8192. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8193. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8194. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8195. {
  8196. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8197. goto end;
  8198. }
  8199. else
  8200. {
  8201. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8202. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8203. goto end;
  8204. }
  8205. }
  8206. }//END FOR AC_QUANTITY
  8207. }//END FOR AvailabilityTypeStr[Inoperative]
  8208. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8209. {
  8210. //----------------------gunIndex is 0 ------------------------------------------------//
  8211. if(gunIndex == 0)
  8212. {
  8213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8214. {
  8215. for(int i=0; i < gunTotalNumber; i++)
  8216. {
  8217. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8218. {
  8219. 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
  8220. {
  8221. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8222. goto end;
  8223. }
  8224. }//END FOR CHAdeMO_QUANTITY
  8225. for (int index = 0; index < CCS_QUANTITY; index++)
  8226. {
  8227. 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
  8228. {
  8229. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8230. goto end;
  8231. }
  8232. }//END FOR CCS_QUANTITY
  8233. for (int index = 0; index < GB_QUANTITY; index++)
  8234. {
  8235. 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
  8236. {
  8237. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8238. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8239. goto end;
  8240. }
  8241. }// END FOR GB_QUANTITY
  8242. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8243. {
  8244. 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
  8245. {
  8246. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8247. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8248. goto end;
  8249. }
  8250. }// END FOR GENERAL_GUN_QUANTITY
  8251. for (int index = 0; index < AC_QUANTITY; index++)
  8252. {
  8253. 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
  8254. {
  8255. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8256. goto end;
  8257. }
  8258. }//END FOR CHAdeMO_QUANTITY
  8259. }// END FOR gunTotalNumber
  8260. }
  8261. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8262. {
  8263. for(int i=0; i < gunTotalNumber; i++)
  8264. {
  8265. for (int index = 0; index < AC_QUANTITY; index++)
  8266. {
  8267. 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
  8268. {
  8269. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8270. goto end;
  8271. }
  8272. }//END FOR CHAdeMO_QUANTITY
  8273. } // END FOR gunTotalNumber
  8274. }
  8275. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8276. goto end;
  8277. }
  8278. //----------------------gunIndex is not 0 ------------------------------------------------//
  8279. //check Transaction active
  8280. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8281. {
  8282. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8283. {
  8284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8285. goto end;
  8286. }
  8287. }//END FOR CHAdeMO_QUANTITY
  8288. for (int index = 0; index < CCS_QUANTITY; index++)
  8289. {
  8290. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8291. {
  8292. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8293. goto end;
  8294. }
  8295. }//END FOR CCS_QUANTITY
  8296. for (int index = 0; index < GB_QUANTITY; index++)
  8297. {
  8298. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8299. {
  8300. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8301. goto end;
  8302. }
  8303. }// END FOR GB_QUANTITY
  8304. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8305. {
  8306. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8307. {
  8308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8309. goto end;
  8310. }
  8311. }// END FOR GENERAL_GUN_QUANTITY
  8312. for (int index = 0; index < AC_QUANTITY; index++)
  8313. {
  8314. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8315. {
  8316. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8317. goto end;
  8318. }
  8319. }//END FOR AC_QUANTITY
  8320. }//END FOR AvailabilityTypeStr[Operative]
  8321. end:
  8322. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8323. {
  8324. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8325. }
  8326. else
  8327. {
  8328. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8329. }
  8330. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8331. {
  8332. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8333. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8334. }
  8335. else if(gunIndex == 0)
  8336. {
  8337. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8338. {
  8339. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8340. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8341. }
  8342. }
  8343. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8344. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8345. return result;
  8346. }
  8347. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8348. {
  8349. mtrace();
  8350. int valueInvalid = NO;
  8351. int result = FAIL;
  8352. char keystr[40]={0};
  8353. char valuestr[501]={0}; //value should be limited in 500 bytes
  8354. char comfirmstr[20]={0};
  8355. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8356. json_object *ChangeConfiguration;
  8357. ChangeConfiguration = json_tokener_parse(payload);
  8358. if(!is_error(ChangeConfiguration))
  8359. {
  8360. // Required data
  8361. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8362. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8363. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8364. {
  8365. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8366. }
  8367. else
  8368. {
  8369. valueInvalid = YES;
  8370. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8371. }
  8372. }
  8373. json_object_put(ChangeConfiguration);
  8374. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8375. {
  8376. DEBUG_ERROR("Payload is null or not accepted.\n");
  8377. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8378. }
  8379. else
  8380. {
  8381. int status = setKeyValue(keystr, valuestr);
  8382. switch(status)
  8383. {
  8384. case ConfigurationStatus_Accepted:
  8385. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8386. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8387. StoreConfigurationTable();
  8388. break;
  8389. case RebootRequired:
  8390. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8391. StoreConfigurationTable();
  8392. break;
  8393. case NotSupported:
  8394. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8395. break;
  8396. case ConfigurationStatus_Rejected:
  8397. default:
  8398. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8399. break;
  8400. }
  8401. }
  8402. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8403. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8404. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8405. {
  8406. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8407. SetOcppConnStatus(FALSE);
  8408. }
  8409. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8410. {
  8411. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8412. }
  8413. return result;
  8414. }
  8415. int handleClearCacheRequest(char *uuid, char *payload)
  8416. {
  8417. mtrace();
  8418. int result = FAIL;
  8419. char comfirmstr[20];
  8420. char rmFileCmd[100]={0};
  8421. struct stat stats;
  8422. DEBUG_INFO("handleClearCacheRequest...\n");
  8423. stat("/Storage/OCPP_PH", &stats);
  8424. // Check for directory existence
  8425. if (S_ISDIR(stats.st_mode) == 1)
  8426. {}
  8427. else
  8428. {
  8429. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8430. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8431. system(rmFileCmd);
  8432. }
  8433. if(OCPP_cleanLocalCache())
  8434. {
  8435. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8436. }
  8437. else
  8438. {
  8439. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8440. }
  8441. sendClearCacheConfirmation(uuid, comfirmstr);
  8442. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8443. return result;
  8444. }
  8445. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8446. {
  8447. mtrace();
  8448. int result = FAIL;
  8449. int resultRename;
  8450. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8451. char chargingProfilePurposeStr[26]={0};
  8452. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8453. char tempchargingProfilePurposeStr[26]={0};
  8454. char str[100]={0};
  8455. char fname[200]={0};
  8456. char comfirmstr[20]={0};
  8457. char word[1600]={0};
  8458. int clearflag = FALSE;
  8459. int chargingProfileIdIsNULL = FALSE;
  8460. int connectorIsNULL = FALSE;
  8461. int chargingProfilePurposeIsNULL = FALSE;
  8462. int stackLevelIsNULL = FALSE;
  8463. //int GotoEnd = FALSE;
  8464. FILE *fptr1, *fptr2;
  8465. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8466. int n_chargingProfile=0;
  8467. int isEmptyFile = FALSE;
  8468. char sLineWord[1600]={0};
  8469. char chargingProfiles[10][100]={0};
  8470. int ChargeProfileCount = 0;
  8471. int ch;
  8472. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8473. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8474. json_object *ClearChargingProfile;
  8475. ClearChargingProfile = json_tokener_parse(payload);
  8476. if(!is_error(ClearChargingProfile))
  8477. {
  8478. // Optional data
  8479. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8480. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8481. else
  8482. chargingProfileIdIsNULL = TRUE;
  8483. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8484. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8485. else
  8486. connectorIsNULL = TRUE;
  8487. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8488. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8489. else
  8490. chargingProfilePurposeIsNULL = TRUE;
  8491. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8492. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8493. else
  8494. stackLevelIsNULL = TRUE;
  8495. }
  8496. json_object_put(ClearChargingProfile);
  8497. if(connectorIsNULL == FALSE)
  8498. {
  8499. switch(connectorIdInt)
  8500. {
  8501. case 0:
  8502. if(chargingProfilePurposeIsNULL == TRUE)
  8503. {
  8504. int l = 0;
  8505. strcpy(fname, ChargePointMaxProfile_JSON);
  8506. if((access(fname,F_OK))!=-1)
  8507. {
  8508. strcpy(chargingProfiles[l], fname);
  8509. l = l + 1;
  8510. }
  8511. strcpy(fname, TxDefaultProfile_0_JSON);
  8512. if((access(fname,F_OK))!=-1)
  8513. {
  8514. strcpy(chargingProfiles[l], fname);
  8515. l = l + 1;
  8516. }
  8517. ChargeProfileCount = l;
  8518. }
  8519. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8520. {
  8521. strcpy(fname, ChargePointMaxProfile_JSON);
  8522. if((access(fname,F_OK))!=-1)
  8523. {
  8524. strcpy(chargingProfiles[0], fname);
  8525. ChargeProfileCount = 1;
  8526. }
  8527. }
  8528. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8529. {
  8530. strcpy(fname, TxDefaultProfile_0_JSON);
  8531. if((access(fname,F_OK))!=-1)
  8532. {
  8533. strcpy(chargingProfiles[0], fname);
  8534. ChargeProfileCount = 1;
  8535. }
  8536. }
  8537. break;
  8538. default:
  8539. if(chargingProfilePurposeIsNULL == TRUE)
  8540. {
  8541. int m = 0;
  8542. memset(fname, 0, ARRAY_SIZE(fname));
  8543. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8544. if((access(fname,F_OK))!=-1)
  8545. {
  8546. strcpy(chargingProfiles[m], fname);
  8547. m = m + 1;
  8548. }
  8549. memset(fname, 0, ARRAY_SIZE(fname));
  8550. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8551. if((access(fname,F_OK))!=-1)
  8552. {
  8553. strcpy(chargingProfiles[m], fname);
  8554. m = m + 1;
  8555. }
  8556. ChargeProfileCount = m;
  8557. }
  8558. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8559. {
  8560. //strcpy(fname, TxDefaultProfile_1_JSON);
  8561. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8562. if((access(fname,F_OK))!=-1)
  8563. {
  8564. strcpy(chargingProfiles[0], fname);
  8565. ChargeProfileCount = 1;
  8566. }
  8567. }
  8568. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8569. {
  8570. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8571. if((access(fname,F_OK))!=-1)
  8572. {
  8573. strcpy(chargingProfiles[0], fname);
  8574. ChargeProfileCount = 1;
  8575. }
  8576. //strcpy(fname, TxProfile_1_JSON);
  8577. }
  8578. //strcpy(fname, ChargePointMaxProfile_JSON );
  8579. break;
  8580. }
  8581. }
  8582. else // Check all Charging Profiles
  8583. {
  8584. int i = 0;
  8585. char fnametemp[200]={0};
  8586. ChargeProfileCount = 0;
  8587. //Check ChargePointMaxProfile.json exit
  8588. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8589. {
  8590. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8591. i = i + 1;
  8592. }
  8593. //Check TxDefaultProfile_0.json exit
  8594. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8595. {
  8596. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8597. i = i + 1;
  8598. }
  8599. //Check TxDefaultProfile_%d.json
  8600. for(int j=1; j <= gunTotalNumber; j++)
  8601. {
  8602. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8603. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8604. if((access(fnametemp,F_OK))!=-1)
  8605. {
  8606. strcpy(chargingProfiles[i], fnametemp);
  8607. i = i + 1;
  8608. }
  8609. }
  8610. //Check TxProfile_%d.json
  8611. for(int j=1; j <= gunTotalNumber; j++)
  8612. {
  8613. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8614. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8615. if((access(fnametemp,F_OK))!=-1)
  8616. {
  8617. strcpy(chargingProfiles[i], fnametemp);
  8618. i = i + 1;
  8619. }
  8620. }
  8621. ChargeProfileCount = i;
  8622. }// End connectorIsNULL is TRUE
  8623. if(ChargeProfileCount == 0)
  8624. {
  8625. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8626. goto end;
  8627. }
  8628. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8629. {
  8630. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8631. goto end;
  8632. }
  8633. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8634. {
  8635. memset(str, 0, ARRAY_SIZE(str));
  8636. // clear temp file
  8637. sprintf(str,"rm -f %s",temp);
  8638. system(str);
  8639. for(int k=0; k < ChargeProfileCount; k++)
  8640. {
  8641. memset(str, 0, ARRAY_SIZE(str));
  8642. //clear file in C
  8643. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8644. system(str);
  8645. }
  8646. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8647. goto end;
  8648. }
  8649. else if(connectorIsNULL == TRUE)
  8650. {
  8651. for(int k=0; k < ChargeProfileCount; k++)
  8652. {
  8653. fptr1 = fopen(chargingProfiles[k], "r");
  8654. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8655. //Check Charging Profile Count
  8656. while(fscanf(fptr1, "%s", word) != EOF)
  8657. {
  8658. //DEBUG_INFO("word=%s\n",word);
  8659. if(strstr(word, "chargingProfileId")!= NULL)
  8660. {
  8661. //DEBUG_INFO("test chargingProfileId \n");
  8662. n_chargingProfile = n_chargingProfile + 1;
  8663. //DEBUG_INFO("chargingProfileId Found\n");
  8664. }
  8665. }
  8666. rewind(fptr1);
  8667. //search Charging Profile Element
  8668. //int i= 0;
  8669. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8670. {
  8671. json_object *tmpProfilee;
  8672. tmpProfilee = json_tokener_parse(sLineWord);
  8673. if(!is_error(tmpProfilee))
  8674. {
  8675. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8676. {
  8677. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8678. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8679. }
  8680. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8681. {
  8682. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8683. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8684. }
  8685. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8686. {
  8687. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8688. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8689. }
  8690. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8691. {
  8692. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8693. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8694. }
  8695. }
  8696. json_object_put(tmpProfilee);
  8697. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8698. {
  8699. //------- not write to fptr2-------//
  8700. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8701. //clearflag = TRUE;
  8702. }
  8703. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8704. {
  8705. //------- not write to fptr2-------//
  8706. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8707. }
  8708. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8709. {
  8710. //------- not write to fptr2-------//
  8711. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8712. }
  8713. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8714. {
  8715. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8716. }
  8717. else
  8718. {
  8719. fprintf(fptr2, sLineWord);//writing data into file
  8720. }
  8721. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8722. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8723. if(clearflag == TRUE)
  8724. {
  8725. fclose(fptr1);
  8726. fclose(fptr2);
  8727. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8728. system(str);
  8729. // clear temp file
  8730. sprintf(str,"rm -f %s",temp);
  8731. system(str);
  8732. }
  8733. else
  8734. {
  8735. fclose(fptr1);
  8736. fclose(fptr2);
  8737. memset(str, 0, ARRAY_SIZE(str));
  8738. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8739. system(str);
  8740. resultRename = rename(temp, chargingProfiles[k]);
  8741. if(resultRename == 0)
  8742. {
  8743. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8744. }
  8745. else
  8746. {
  8747. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8748. }
  8749. if(comfirmstr[0]== 0)
  8750. {
  8751. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8752. }
  8753. //Check chargingProfile is empty file
  8754. /*------ Read the file ----------------*/
  8755. fptr1=fopen(chargingProfiles[k],"r");
  8756. ch=fgetc(fptr1);
  8757. rewind(fptr1);
  8758. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8759. if(ch!=EOF)
  8760. {
  8761. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8762. {
  8763. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8764. if(sLineWord[0]=='\0')
  8765. {
  8766. isEmptyFile = TRUE;
  8767. break;
  8768. }
  8769. else
  8770. {
  8771. isEmptyFile = FALSE;
  8772. break;
  8773. }
  8774. }
  8775. }
  8776. else
  8777. isEmptyFile = TRUE;
  8778. fclose(fptr1);
  8779. if(isEmptyFile == TRUE)
  8780. {
  8781. memset(str, 0, ARRAY_SIZE(str));
  8782. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8783. system(str);
  8784. }
  8785. }
  8786. }// End of while(int k=0; k < ChargePointCount; k++)
  8787. }
  8788. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8789. {
  8790. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8791. for(int k=0; k < ChargeProfileCount; k++)
  8792. {
  8793. fptr1 = fopen(chargingProfiles[k], "r");
  8794. fptr2 = fopen(temp, "w+");
  8795. //Check Charging Profile Count
  8796. while(fscanf(fptr1, "%s", word) != EOF)
  8797. {
  8798. //DEBUG_INFO("word=%s\n",word);
  8799. if(strstr(word, "chargingProfileId")!= NULL)
  8800. {
  8801. n_chargingProfile = n_chargingProfile + 1;
  8802. }
  8803. }
  8804. rewind(fptr1);
  8805. //search Charging Profile Element
  8806. //int i= 0;
  8807. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8808. {
  8809. json_object *tmpProfilee;
  8810. tmpProfilee = json_tokener_parse(sLineWord);
  8811. if(!is_error(tmpProfilee))
  8812. {
  8813. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8814. {
  8815. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8816. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8817. }
  8818. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8819. {
  8820. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8821. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8822. }
  8823. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8824. {
  8825. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8826. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8827. }
  8828. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8829. {
  8830. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8831. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8832. }
  8833. }
  8834. json_object_put(tmpProfilee);
  8835. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8836. {
  8837. //------- not write to fptr2-------//
  8838. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8839. //clearflag = TRUE;
  8840. }
  8841. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8842. {
  8843. //------- not write to fptr2-------//
  8844. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8845. }
  8846. else if(stackLevelIsNULL == TRUE)
  8847. {
  8848. //Clear Whole File
  8849. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8850. clearflag = TRUE;
  8851. break;
  8852. }
  8853. else
  8854. {
  8855. fprintf(fptr2, sLineWord);//writing data into file
  8856. }
  8857. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8858. }
  8859. if(clearflag == TRUE)
  8860. {
  8861. fclose(fptr1);
  8862. fclose(fptr2);
  8863. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8864. system(str);
  8865. // clear temp file
  8866. sprintf(str,"rm -f %s",temp);
  8867. system(str);
  8868. }
  8869. else
  8870. {
  8871. fclose(fptr1);
  8872. fclose(fptr2);
  8873. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8874. system(str);
  8875. resultRename = rename(temp, chargingProfiles[k]);
  8876. if(resultRename == 0)
  8877. {
  8878. DEBUG_INFO("File ChargingProfile renamed successfully");
  8879. }
  8880. else
  8881. {
  8882. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8883. }
  8884. if(comfirmstr[0]== 0)
  8885. {
  8886. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8887. }
  8888. //Check chargingProfile is empty file
  8889. /*------ Read the file ----------------*/
  8890. fptr1=fopen(chargingProfiles[k],"r");
  8891. ch=fgetc(fptr1);
  8892. rewind(fptr1);
  8893. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8894. if(ch!=EOF)
  8895. {
  8896. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8897. {
  8898. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8899. if(sLineWord[0]=='\0')
  8900. {
  8901. isEmptyFile = TRUE;
  8902. break;
  8903. }
  8904. else
  8905. {
  8906. isEmptyFile = FALSE;
  8907. break;
  8908. }
  8909. }
  8910. }
  8911. else
  8912. isEmptyFile = TRUE;
  8913. fclose(fptr1);
  8914. if(isEmptyFile == TRUE)
  8915. {
  8916. memset(str, 0, ARRAY_SIZE(str));
  8917. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8918. system(str);
  8919. }
  8920. /*------- End of reading ---------------*/
  8921. }
  8922. } // while(int k=0; k < ChargeProfileCount; k++)
  8923. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8924. end:
  8925. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8926. {
  8927. if(connectorIdInt == 0)
  8928. {
  8929. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8930. {
  8931. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8932. }
  8933. }
  8934. else
  8935. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8936. }
  8937. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8938. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8939. return result;
  8940. }
  8941. void createFirmwareVersionByDataTransfer(void)
  8942. {
  8943. json_object *FirmwareDataTransfer = json_object_new_object();
  8944. // AC & DC model
  8945. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8946. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8947. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8948. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8949. // DC model
  8950. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8951. {
  8952. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8953. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8954. (gunType[3] != GUN_TYPE_UNKNOWN))
  8955. {
  8956. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8957. }
  8958. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8959. {
  8960. // DS DM DW
  8961. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8962. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8963. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8964. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8965. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8966. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8967. }
  8968. else
  8969. {
  8970. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8971. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8972. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8973. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8974. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8975. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8976. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8977. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8978. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8979. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8980. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8981. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8982. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8983. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8984. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8985. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8986. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8987. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8988. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8989. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8990. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8991. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8992. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8993. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8994. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8995. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8996. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8997. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8998. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8999. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9000. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9001. }
  9002. }
  9003. // 4G model
  9004. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9005. {
  9006. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9007. }
  9008. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9009. json_object_put(FirmwareDataTransfer);
  9010. }
  9011. int handleDataTransferRequest(char *uuid, char *payload)
  9012. {
  9013. mtrace();
  9014. json_object *response = json_object_new_object();
  9015. int result = FAIL;
  9016. char tempvendorId[255]={0};
  9017. char tempmessageId[50]={0};
  9018. char tempdata[512]={0};
  9019. char message[2048]={0};
  9020. DEBUG_INFO("handleDataTransferRequest...\n");
  9021. if((uuid != NULL) && (payload != NULL))
  9022. {
  9023. json_object *DataTransfer;
  9024. DataTransfer = json_tokener_parse(payload);
  9025. if(!is_error(DataTransfer))
  9026. {
  9027. // Required data
  9028. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9029. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9030. // Optional data
  9031. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9032. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9033. if(json_object_object_get(DataTransfer, "data") != NULL)
  9034. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9035. result = PASS;
  9036. }
  9037. json_object_put(DataTransfer);
  9038. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9039. {
  9040. // Send all moudle firmware version on EVSE
  9041. createFirmwareVersionByDataTransfer();
  9042. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9043. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9044. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9045. json_object_put(response);
  9046. }
  9047. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9048. {
  9049. system("/usr/bin/run_tmate_restart.sh &");
  9050. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9051. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9052. json_object_put(response);
  9053. }
  9054. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9055. {
  9056. json_object *data;
  9057. data = json_tokener_parse(tempdata);
  9058. if(!is_error(data))
  9059. {
  9060. 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))
  9061. {
  9062. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9063. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9064. if(json_object_object_get(data, "SOC") != NULL)
  9065. {
  9066. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9067. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9068. }
  9069. if(json_object_object_get(data, "Energy") != NULL)
  9070. {
  9071. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9072. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9073. }
  9074. if(json_object_object_get(data, "Duration") != NULL)
  9075. {
  9076. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9077. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9078. }
  9079. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9080. }
  9081. else
  9082. {
  9083. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9084. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9085. }
  9086. }
  9087. else
  9088. {
  9089. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9090. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9091. }
  9092. json_object_put(data);
  9093. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9094. json_object_put(response);
  9095. }
  9096. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9097. {
  9098. json_object *data;
  9099. data = json_tokener_parse(tempdata);
  9100. if(!is_error(data))
  9101. {
  9102. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9103. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9104. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9105. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9106. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9107. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9108. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9109. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9110. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9111. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9112. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9113. }
  9114. else
  9115. {
  9116. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9117. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9118. }
  9119. json_object_put(data);
  9120. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9121. json_object_put(response);
  9122. }
  9123. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9124. {
  9125. json_object *data;
  9126. data = json_tokener_parse(tempdata);
  9127. if(!is_error(data))
  9128. {
  9129. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9130. if(json_object_object_get(data, "idToken") != NULL)
  9131. {
  9132. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9133. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9134. }
  9135. if(json_object_object_get(data, "price") != NULL)
  9136. {
  9137. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9138. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9139. }
  9140. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9141. }
  9142. else
  9143. {
  9144. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9145. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9146. }
  9147. json_object_put(data);
  9148. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9149. json_object_put(response);
  9150. }
  9151. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9152. {
  9153. json_object *data;
  9154. data = json_tokener_parse(tempdata);
  9155. if(!is_error(data))
  9156. {
  9157. if(json_object_object_get(data, "txId") != NULL)
  9158. {
  9159. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9160. for(int idx = 0;idx<gunTotalNumber;idx++)
  9161. {
  9162. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9163. {
  9164. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9165. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9166. if(json_object_object_get(data, "description") != NULL)
  9167. {
  9168. // California pricing V1.0
  9169. DEBUG_INFO("California pricing V1.0\n");
  9170. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9171. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9172. }
  9173. else
  9174. {
  9175. // California pricing V1.1
  9176. DEBUG_INFO("California pricing V1.1\n");
  9177. if(json_object_object_get(data, "timestamp") != NULL)
  9178. {
  9179. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9180. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9181. }
  9182. if(json_object_object_get(data, "meterValue") != NULL)
  9183. {
  9184. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9185. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9186. }
  9187. if(json_object_object_get(data, "cost") != NULL)
  9188. {
  9189. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9190. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9191. }
  9192. if(json_object_object_get(data, "state") != NULL)
  9193. {
  9194. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9195. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9196. }
  9197. if(json_object_object_get(data, "chargingPrice") != NULL)
  9198. {
  9199. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9200. {
  9201. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9202. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9203. }
  9204. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9205. {
  9206. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9207. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9208. }
  9209. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9210. {
  9211. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9212. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9213. }
  9214. }
  9215. if(json_object_object_get(data, "idlePrice") != NULL)
  9216. {
  9217. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9218. {
  9219. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9220. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9221. }
  9222. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9223. {
  9224. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9225. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9226. }
  9227. }
  9228. if(json_object_object_get(data, "nextPeriod") != NULL)
  9229. {
  9230. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9231. {
  9232. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9233. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9234. }
  9235. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9236. {
  9237. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9238. {
  9239. 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")));
  9240. 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"));
  9241. }
  9242. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9243. {
  9244. 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")));
  9245. 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"));
  9246. }
  9247. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9248. {
  9249. 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")));
  9250. 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"));
  9251. }
  9252. }
  9253. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9254. {
  9255. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9256. {
  9257. 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")));
  9258. 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"));
  9259. }
  9260. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9261. {
  9262. 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")));
  9263. 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"));
  9264. }
  9265. }
  9266. }
  9267. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9268. {
  9269. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9270. {
  9271. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9272. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9273. }
  9274. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9275. {
  9276. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9277. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9278. }
  9279. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9280. {
  9281. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9282. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9283. }
  9284. }
  9285. }
  9286. }
  9287. }
  9288. }
  9289. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9290. }
  9291. else
  9292. {
  9293. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9294. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9295. }
  9296. json_object_put(data);
  9297. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9298. json_object_put(response);
  9299. }
  9300. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9301. {
  9302. json_object *data;
  9303. data = json_tokener_parse(tempdata);
  9304. if(!is_error(data))
  9305. {
  9306. if(json_object_object_get(data, "txId") != NULL)
  9307. {
  9308. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9309. for(int idx = 0;idx<gunTotalNumber;idx++)
  9310. {
  9311. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9312. {
  9313. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9314. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9315. if(json_object_object_get(data, "description") != NULL)
  9316. {
  9317. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9318. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9319. }
  9320. }
  9321. }
  9322. }
  9323. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9324. }
  9325. else
  9326. {
  9327. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9328. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9329. }
  9330. json_object_put(data);
  9331. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9332. json_object_put(response);
  9333. }
  9334. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9335. {
  9336. json_object *data;
  9337. data = json_tokener_parse(tempdata);
  9338. if(!is_error(data))
  9339. {
  9340. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9341. if(json_object_object_get(data, "Content_Type") != NULL)
  9342. {
  9343. 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))
  9344. {
  9345. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9346. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9347. {
  9348. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9349. }
  9350. }
  9351. else
  9352. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9353. }
  9354. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9355. }
  9356. else
  9357. {
  9358. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9359. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9360. }
  9361. json_object_put(data);
  9362. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9363. json_object_put(response);
  9364. }
  9365. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9366. {
  9367. json_object *data;
  9368. data = json_tokener_parse(tempdata);
  9369. if(!is_error(data))
  9370. {
  9371. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9372. if(json_object_object_get(data, "ConnectorId") != NULL)
  9373. {
  9374. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9375. }
  9376. if(json_object_object_get(data, "SerialNo") != NULL)
  9377. {
  9378. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9379. }
  9380. if(json_object_object_get(data, "Page_Index") != NULL)
  9381. {
  9382. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9383. }
  9384. if(json_object_object_get(data, "Duration") != NULL)
  9385. {
  9386. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9387. }
  9388. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9389. }
  9390. else
  9391. {
  9392. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9393. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9394. }
  9395. json_object_put(data);
  9396. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9397. json_object_put(response);
  9398. }
  9399. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9400. {
  9401. json_object *data;
  9402. data = json_tokener_parse(tempdata);
  9403. if(!is_error(data))
  9404. {
  9405. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9406. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9407. {
  9408. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9409. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9410. else
  9411. {
  9412. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9413. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9414. }
  9415. }
  9416. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9417. {
  9418. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9419. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9420. else
  9421. {
  9422. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9423. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9424. }
  9425. }
  9426. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9427. {
  9428. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9429. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9430. else
  9431. {
  9432. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9433. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9434. }
  9435. }
  9436. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9437. {
  9438. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9439. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9440. else
  9441. {
  9442. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9443. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9444. }
  9445. }
  9446. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9447. {
  9448. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9449. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9450. else
  9451. {
  9452. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9453. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9454. }
  9455. }
  9456. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9457. {
  9458. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9459. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9460. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9461. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9462. else
  9463. {
  9464. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9465. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9466. }
  9467. }
  9468. if(json_object_object_get(data, "isAuthentication") != NULL)
  9469. {
  9470. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9471. {
  9472. case 0:
  9473. case 1:
  9474. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9475. break;
  9476. default:
  9477. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9478. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9479. break;
  9480. }
  9481. }
  9482. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9483. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9484. }
  9485. else
  9486. {
  9487. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9488. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9489. }
  9490. json_object_put(data);
  9491. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9492. json_object_put(response);
  9493. }
  9494. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9495. {
  9496. json_object *data;
  9497. data = json_tokener_parse(tempdata);
  9498. if(!is_error(data))
  9499. {
  9500. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9501. if(json_object_object_get(data, "stationName") != NULL)
  9502. {
  9503. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9504. }
  9505. else
  9506. {
  9507. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9508. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9509. }
  9510. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9511. {
  9512. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9513. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9514. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9515. }
  9516. }
  9517. else
  9518. {
  9519. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9520. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9521. }
  9522. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9523. json_object_put(response);
  9524. }
  9525. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9526. {
  9527. json_object *data;
  9528. data = json_tokener_parse(tempdata);
  9529. if(!is_error(data))
  9530. {
  9531. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9532. if(json_object_object_get(data, "weatherId") != NULL)
  9533. {
  9534. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9535. }
  9536. else
  9537. {
  9538. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9539. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9540. }
  9541. if(json_object_object_get(data, "Temperature") != NULL)
  9542. {
  9543. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9544. }
  9545. else
  9546. {
  9547. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9548. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9549. }
  9550. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9551. {
  9552. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9553. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9554. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9555. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9556. }
  9557. }
  9558. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9559. {
  9560. json_object *data;
  9561. data = json_tokener_parse(tempdata);
  9562. if(!is_error(data))
  9563. {
  9564. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9565. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9566. {
  9567. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9568. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9569. }
  9570. else
  9571. {
  9572. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9573. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9574. }
  9575. }
  9576. else
  9577. {
  9578. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9579. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9580. }
  9581. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9582. json_object_put(response);
  9583. }
  9584. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9585. {
  9586. json_object *data;
  9587. data = json_tokener_parse(tempdata);
  9588. if(!is_error(data))
  9589. {
  9590. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9591. {
  9592. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9593. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9594. if(gun_index < gunTotalNumber)
  9595. {
  9596. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9597. {
  9598. json_object *responsedata = json_object_new_object();
  9599. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9600. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9601. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9602. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9603. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9604. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9605. }
  9606. else
  9607. {
  9608. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9609. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9610. }
  9611. }
  9612. else
  9613. {
  9614. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9615. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9616. }
  9617. }
  9618. else
  9619. {
  9620. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9621. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9622. }
  9623. }
  9624. else
  9625. {
  9626. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9627. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9628. }
  9629. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9630. json_object_put(response);
  9631. }
  9632. else
  9633. {
  9634. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9635. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9636. }
  9637. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9638. json_object_put(response);
  9639. }
  9640. else
  9641. {
  9642. // Can not find valid message id
  9643. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9644. }
  9645. }
  9646. else
  9647. {
  9648. // Payload is null
  9649. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9650. }
  9651. LWS_Send(message);
  9652. return result;
  9653. }
  9654. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9655. {
  9656. mtrace();
  9657. int result = FAIL;
  9658. int connectorIdInt, durationInt;
  9659. char chargingRateUnitStr[4]={0};
  9660. char comfirmstr[20];
  9661. int confirmPeriods = 0;
  9662. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9663. json_object *GetCompositeSchedule;
  9664. GetCompositeSchedule = json_tokener_parse(payload);
  9665. if(!is_error(GetCompositeSchedule))
  9666. {
  9667. // Required data
  9668. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9669. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9670. else
  9671. connectorIdInt = -1;
  9672. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9673. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9674. else
  9675. durationInt = 86400;
  9676. // Optional data
  9677. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9678. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9679. }
  9680. json_object_put(GetCompositeSchedule);
  9681. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9682. if((connectorIdInt == 0) ||
  9683. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9684. {
  9685. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9686. struct StructChargingProfile tmpProfile[1];
  9687. if(strstr(chargingRateUnitStr, "W") != NULL)
  9688. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9689. else
  9690. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9691. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9692. {
  9693. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9694. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9695. }
  9696. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9697. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9698. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9699. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9700. {
  9701. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9702. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9703. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9704. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9705. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9706. {
  9707. confirmPeriods = idx;
  9708. break;
  9709. }
  9710. }
  9711. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9712. {
  9713. confirmPeriods += 1;
  9714. }
  9715. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9716. }
  9717. else
  9718. {
  9719. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9720. }
  9721. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9722. return result;
  9723. }
  9724. int handleGetConfigurationRequest(char *uuid, char *payload)
  9725. {
  9726. mtrace();
  9727. int result = FAIL;
  9728. int MaxKeySupported = 0;
  9729. int n_keys = 0;
  9730. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9731. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9732. json_object *GetConfiguration;
  9733. GetConfiguration = json_tokener_parse(payload);
  9734. if(!is_error(GetConfiguration))
  9735. {
  9736. // Optional data
  9737. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9738. {
  9739. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9740. {
  9741. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9742. n_keys = idx + 1;
  9743. }
  9744. }
  9745. }
  9746. json_object_put(GetConfiguration);
  9747. UnknownKeynum = 0;
  9748. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9749. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9750. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9751. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9752. if(n_keys != 0)
  9753. {
  9754. for(int i=0;i<n_keys;i++)
  9755. {
  9756. getKeyValue(requestKey[i]);
  9757. }
  9758. }
  9759. else
  9760. {
  9761. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9762. getKeyValue("");
  9763. }
  9764. processUnkownKey();
  9765. sendGetConfigurationConfirmation(uuid);
  9766. return result;
  9767. }
  9768. static char fnamePlusPath[100]={0};
  9769. static char fnamePWithNoPath[60]={0};
  9770. void checkUploadLog(void)
  9771. {
  9772. FILE *fp;
  9773. /* Open the command for reading. */
  9774. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9775. if (fp == NULL) {
  9776. DEBUG_WARN("Failed to run command\n" );
  9777. exit(1);
  9778. }
  9779. int ftppathlen = 0;
  9780. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9781. int i = 0;
  9782. /* Read the output a line at a time - output it. */
  9783. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9784. if(i==0)
  9785. {
  9786. ftppathlen = strlen(fnamePlusPath);
  9787. DEBUG_INFO("%s\n", fnamePlusPath);
  9788. fnamePlusPath[ftppathlen]='\0';
  9789. break;
  9790. }
  9791. i= i+1;
  9792. }
  9793. /* close */
  9794. pclose(fp);
  9795. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9796. {
  9797. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9798. {
  9799. fnamePlusPath[k]='\0';
  9800. }
  9801. }
  9802. i=1;
  9803. //char fname[60]={0};
  9804. while(i < ftppathlen)
  9805. {
  9806. int len=ftppathlen-i;
  9807. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9808. {
  9809. DEBUG_INFO("compare '/' all right\n");
  9810. break;
  9811. }
  9812. i=i+1;
  9813. }
  9814. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9815. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9816. fnamePWithNoPath[i+1] = '\0';
  9817. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9818. {
  9819. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9820. {
  9821. fnamePWithNoPath[j]='\0';
  9822. }
  9823. }
  9824. FILE* fp1 = fopen(fnamePlusPath, "r");
  9825. if (fp1)
  9826. {
  9827. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9828. // file exists
  9829. fclose(fp1);
  9830. }
  9831. else
  9832. {
  9833. // file doesn't exist
  9834. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9835. }
  9836. }
  9837. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9838. {
  9839. mtrace();
  9840. int result = FAIL;
  9841. time_t CurrentTime;
  9842. struct tm *tm;
  9843. pthread_t th_Status;
  9844. CurrentTime = time(NULL);
  9845. tm = localtime(&CurrentTime);
  9846. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9847. 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);
  9848. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9849. if(!interLock.isGetDiagnosticGoing)
  9850. {
  9851. interLock.isGetDiagnosticGoing = 1;
  9852. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9853. sleep(1);
  9854. }
  9855. else
  9856. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9857. return result;
  9858. }
  9859. void* GetDiagnosticsProcess(void* data)
  9860. {
  9861. pthread_detach(pthread_self());
  9862. mtrace();
  9863. int retriesInt=0, retryIntervalInt=0;
  9864. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9865. 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};
  9866. int port=0;
  9867. int isSuccess = FALSE;
  9868. char ftpbuf[200]={0};
  9869. char cmdBuf[2048];
  9870. struct tm *tmNow;
  9871. time_t CurrentTime;
  9872. struct tm tmStart;
  9873. struct tm tmStop;
  9874. CurrentTime = time(NULL);
  9875. tmNow=localtime(&CurrentTime);
  9876. uint16_t targetYear, targetMonth;
  9877. json_object *GetDiagnostics;
  9878. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9879. GetDiagnostics = json_tokener_parse(data);
  9880. if(!is_error(GetDiagnostics))
  9881. {
  9882. // Required data
  9883. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9884. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9885. // Optional data
  9886. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9887. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9888. else
  9889. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9890. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9891. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9892. else
  9893. retryIntervalInt = 30;
  9894. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9895. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9896. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9897. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9898. }
  9899. json_object_put(GetDiagnostics);
  9900. // Pack log to compress file
  9901. 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) &&
  9902. (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))
  9903. {
  9904. // Pack system log
  9905. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9906. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9907. targetYear = tmStart.tm_year;
  9908. targetMonth = tmStart.tm_mon;
  9909. do
  9910. {
  9911. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9912. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9913. if(targetMonth+1>=13)
  9914. {
  9915. targetYear += 1;
  9916. targetMonth = 1;
  9917. }
  9918. else
  9919. {
  9920. targetMonth += 1;
  9921. }
  9922. }while((targetYear < (tmNow->tm_year+1900)) ||
  9923. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9924. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9925. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9926. system(cmdBuf);
  9927. // Pack charging & event log
  9928. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9929. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9930. targetYear = tmStart.tm_year;
  9931. targetMonth = tmStart.tm_mon;
  9932. do
  9933. {
  9934. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9935. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9936. if(targetMonth+1>=13)
  9937. {
  9938. targetYear += 1;
  9939. targetMonth = 1;
  9940. }
  9941. else
  9942. {
  9943. targetMonth += 1;
  9944. }
  9945. }while((targetYear < (tmNow->tm_year+1900)) ||
  9946. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9947. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9948. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9949. system(cmdBuf);
  9950. // Combine log file
  9951. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9952. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9953. }
  9954. else
  9955. {
  9956. system("exec /root/logPackTools 'log' 6");
  9957. }
  9958. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9959. system(cmdBuf);
  9960. checkUploadLog();
  9961. //****************location*******************/
  9962. if(strcmp(locationstr,"")==0)
  9963. {
  9964. DEBUG_INFO("location is <Empty>!\n");
  9965. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9966. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9967. goto end;
  9968. }
  9969. memset(protocol, 0, ARRAY_SIZE(protocol));
  9970. memset(user, 0, ARRAY_SIZE(user) );
  9971. memset(password, 0, ARRAY_SIZE(password));
  9972. memset(host, 0, ARRAY_SIZE(host));
  9973. memset(path, 0, ARRAY_SIZE(path));
  9974. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9975. memset(host1, 0, ARRAY_SIZE(host1));
  9976. memset(path1, 0, ARRAY_SIZE(path1));
  9977. /*location: ftp://user:password@host:port/path*/
  9978. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9979. if((access(fnamePlusPath,F_OK))!=-1)
  9980. {
  9981. DEBUG_INFO("fnamePlusPath exist.\n");
  9982. }
  9983. else
  9984. {
  9985. DEBUG_INFO("fnamePlusPath not exist!\n");
  9986. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9987. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9988. goto end;
  9989. }
  9990. if(strchr(locationstr,'@')==NULL)
  9991. {
  9992. sscanf(locationstr,
  9993. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9994. protocol, host, &port, path);
  9995. strcpy(user,"anonymous");
  9996. strcpy(password,"");
  9997. }
  9998. else
  9999. {
  10000. //DEBUG_INFO("pch=%s\n", pch);
  10001. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10002. protocol, user, password, host, &port, path);
  10003. }
  10004. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10005. {
  10006. DEBUG_INFO("protocol is not ftp/http ! \n");
  10007. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10008. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10009. goto end;
  10010. }
  10011. if(strncmp(locationstr,"http", 4) == 0)
  10012. {
  10013. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10014. sprintf(ftppath,"/%s", path);
  10015. do
  10016. {
  10017. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10018. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10019. sleep(3);
  10020. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10021. if(!isSuccess)
  10022. {
  10023. DEBUG_INFO("Diagnostics fail.\n");
  10024. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10025. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10026. sleep(retryIntervalInt);
  10027. }
  10028. else
  10029. {
  10030. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10031. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10032. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10033. }
  10034. retriesInt--;
  10035. }while((isSuccess == 0)&&(retriesInt >= 0));
  10036. }
  10037. else
  10038. {
  10039. sscanf(host,"%[^/]%s",host1, path1);
  10040. if(strlen(path) > 0)
  10041. sprintf(ftppath,"/%s", path);
  10042. else
  10043. sprintf(ftppath,"/%s", path1);
  10044. int ftppathlen=strlen(ftppath);
  10045. int i=1;
  10046. char filenametemp[50];
  10047. while(i < ftppathlen)
  10048. {
  10049. int len=ftppathlen-i;
  10050. if(ftppath[len]== 47) // '/' ascll code: 47
  10051. {
  10052. DEBUG_INFO("find '/' all right\n");
  10053. break;
  10054. }
  10055. i=i+1;
  10056. }
  10057. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10058. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10059. filenametemp[i+1] = 0;
  10060. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10061. if(port == 0)
  10062. port = 21;
  10063. do
  10064. {
  10065. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10066. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10067. sleep(3);
  10068. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10069. if(!isSuccess)
  10070. {
  10071. DEBUG_INFO("Diagnostics fail.\n");
  10072. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10073. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10074. sleep(retryIntervalInt);
  10075. }
  10076. else
  10077. {
  10078. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10079. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10080. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10081. }
  10082. retriesInt--;
  10083. }while((!isSuccess)&&(retriesInt >= 0));
  10084. }
  10085. end:
  10086. system("rm -f /mnt/*");
  10087. sleep(5);
  10088. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10089. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10090. interLock.isGetDiagnosticGoing = 0;
  10091. pthread_exit(NULL);
  10092. }
  10093. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10094. {
  10095. mtrace();
  10096. int result = FAIL;
  10097. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10098. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10099. {
  10100. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10101. locallistVersion = -1;
  10102. }
  10103. else
  10104. {
  10105. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10106. OCPP_getListVerion();
  10107. }
  10108. //from db.OCPP_getListVerion
  10109. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10110. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10111. sendGetLocalListVersionConfirmation(uuid,"");
  10112. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10113. return result;
  10114. }
  10115. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10116. {
  10117. mtrace();
  10118. int result = FAIL;
  10119. int connectorIdInt=-1;
  10120. int tempIndex = 0;
  10121. int connectorIdIsNULL, chargingProfileIsNULL;
  10122. char comfirmstr[20]={0};
  10123. char cmdBuf[512];
  10124. json_object *RemoteStartTransaction;
  10125. FILE *fp;
  10126. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10127. if(server_pending == TRUE)
  10128. {
  10129. return 0;
  10130. }
  10131. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10132. RemoteStartTransaction = json_tokener_parse(payload);
  10133. if(!is_error(RemoteStartTransaction))
  10134. {
  10135. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10136. {
  10137. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10138. }
  10139. else
  10140. {
  10141. connectorIdIsNULL = TRUE;
  10142. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10143. {
  10144. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10145. {
  10146. connectorIdIsNULL = FALSE;
  10147. connectorIdInt = (gun_index+1);
  10148. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10149. break;
  10150. }
  10151. }
  10152. }
  10153. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10154. {
  10155. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10156. // Required data
  10157. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10158. // Optional data
  10159. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10160. {
  10161. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10162. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10163. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10164. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10165. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10166. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10167. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10168. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10169. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10170. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10171. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10172. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10173. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10174. {
  10175. 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")));
  10176. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10177. 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"));
  10178. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10179. 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"));
  10180. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10181. 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")));
  10182. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10183. {
  10184. 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++)
  10185. {
  10186. 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"));
  10187. 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"));
  10188. 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)
  10189. 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"));
  10190. }
  10191. }
  10192. }
  10193. }
  10194. else
  10195. {
  10196. chargingProfileIsNULL = TRUE;
  10197. }
  10198. }
  10199. }
  10200. else
  10201. {
  10202. connectorIdIsNULL = TRUE;
  10203. }
  10204. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10205. {
  10206. DEBUG_WARN("Connector id is NULL\n.");
  10207. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10208. goto end;
  10209. }
  10210. /*
  10211. enum _SYSTEM_STATUS
  10212. {
  10213. S_BOOTING = 0,
  10214. S_IDLE, = 1
  10215. S_AUTHORIZING, = 2
  10216. S_REASSIGN_CHECK, = 3
  10217. S_REASSIGN, = 4
  10218. S_PRECHARGE, = 5
  10219. S_PREPARING_FOR_EV, = 6
  10220. S_PREPARING_FOR_EVSE, = 7
  10221. S_CHARGING, = 8
  10222. S_TERMINATING, = 9
  10223. S_COMPLETE, = 10
  10224. S_ALARM, = 11
  10225. S_FAULT = 12
  10226. }
  10227. */
  10228. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10229. {
  10230. //check Transaction active
  10231. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10232. {
  10233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10234. {
  10235. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10236. }
  10237. else
  10238. {
  10239. tempIndex = connectorIdInt -1;
  10240. }
  10241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10242. {
  10243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10244. {
  10245. 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))
  10246. {
  10247. //Reserved
  10248. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10249. }
  10250. 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))
  10251. {
  10252. //Reserved
  10253. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10254. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10255. goto end;
  10256. }
  10257. else
  10258. {
  10259. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10260. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10261. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10262. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10263. {
  10264. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10265. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10266. goto end;
  10267. }
  10268. }//END FOR ELSE
  10269. }
  10270. }// END FOR CHAdeMO_QUANTITY
  10271. }
  10272. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10273. {
  10274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10275. {
  10276. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10277. }
  10278. else
  10279. {
  10280. tempIndex = connectorIdInt -1;
  10281. }
  10282. for (int index = 0; index < CCS_QUANTITY; index++)
  10283. {
  10284. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10285. {
  10286. 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))
  10287. {
  10288. //Reserved
  10289. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10290. }
  10291. 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))
  10292. {
  10293. //Reserved
  10294. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10295. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10296. goto end;
  10297. }
  10298. else
  10299. {
  10300. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10301. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10302. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10303. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10304. {
  10305. DEBUG_WARN("CCS connector not allow start\n.");
  10306. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10307. goto end;
  10308. }
  10309. }// END FOR ELSE
  10310. }
  10311. }// END FOR CCS_QUANTITY
  10312. }
  10313. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10314. {
  10315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10316. {
  10317. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10318. }
  10319. else
  10320. {
  10321. tempIndex = connectorIdInt -1;
  10322. }
  10323. for (int index = 0; index < GB_QUANTITY; index++)
  10324. {
  10325. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10326. {
  10327. 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))
  10328. {
  10329. //Reserved
  10330. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10331. }
  10332. 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))
  10333. {
  10334. //Reserved
  10335. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10337. goto end;
  10338. }
  10339. else
  10340. {
  10341. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10342. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10343. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10344. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10345. {
  10346. DEBUG_WARN("GB connector not allow start\n.");
  10347. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10348. goto end;
  10349. }
  10350. }// END FOR ELSE
  10351. }
  10352. } // END FOR GB_QUANTITY
  10353. }
  10354. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10355. {
  10356. tempIndex = connectorIdInt -1;
  10357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10358. {
  10359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10360. {
  10361. 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))
  10362. {
  10363. //Reserved
  10364. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10365. }
  10366. 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))
  10367. {
  10368. //Reserved
  10369. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10370. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10371. goto end;
  10372. }
  10373. else
  10374. {
  10375. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10376. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10377. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10378. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10379. {
  10380. DEBUG_WARN("GB connector not allow start\n.");
  10381. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10382. goto end;
  10383. }
  10384. }// END FOR ELSE
  10385. }
  10386. } // END FOR GB_QUANTITY
  10387. }
  10388. else
  10389. {
  10390. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10391. {
  10392. tempIndex = 2;
  10393. }
  10394. else
  10395. {
  10396. tempIndex = connectorIdInt -1;
  10397. }
  10398. for (int index = 0; index < AC_QUANTITY; index++)
  10399. {
  10400. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10401. {
  10402. 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))
  10403. {
  10404. //Reserved
  10405. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10406. }
  10407. 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))
  10408. {
  10409. //Reserved
  10410. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10411. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10412. goto end;
  10413. }
  10414. else
  10415. {
  10416. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10417. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10418. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10419. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10420. {
  10421. DEBUG_WARN("AC connector not allow start\n.");
  10422. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10423. goto end;
  10424. }
  10425. }//END FOR ELSE
  10426. }
  10427. }// END FOR AC_QUANTITY
  10428. }
  10429. if(chargingProfileIsNULL == FALSE)
  10430. {
  10431. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10432. {
  10433. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10434. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10435. //memset idTag
  10436. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10437. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10438. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10439. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10440. // Save profile to file
  10441. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10442. system(cmdBuf);
  10443. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10444. fp = fopen(cmdBuf, "w");
  10445. 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));
  10446. fclose(fp);
  10447. }
  10448. else
  10449. {
  10450. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10451. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10452. }
  10453. }
  10454. else
  10455. {
  10456. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10457. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10458. //memset idTag
  10459. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10460. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10461. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10463. }
  10464. }
  10465. else
  10466. {
  10467. DEBUG_WARN("Connector id over\n.");
  10468. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10469. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10470. }
  10471. end:
  10472. json_object_put(RemoteStartTransaction);
  10473. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10474. {
  10475. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10476. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10477. }
  10478. //OCPP send RemoteStartConfirmation by first.
  10479. sendRemoteStartConfirmation(uuid, comfirmstr);
  10480. return result;
  10481. }
  10482. int handleRemoteStartRequest(char *uuid, char *payload)
  10483. {
  10484. mtrace();
  10485. int result = PASS;
  10486. int connectorIdInt=-1;
  10487. int tempIndex = 0;
  10488. char comfirmstr[20]={0};
  10489. char cmdBuf[512];
  10490. json_object *RemoteStartTransaction;
  10491. FILE *fp;
  10492. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10493. if(server_pending == TRUE)
  10494. {
  10495. result = FAIL;
  10496. }
  10497. RemoteStartTransaction = json_tokener_parse(payload);
  10498. if(!is_error(RemoteStartTransaction))
  10499. {
  10500. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10501. {
  10502. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10503. }
  10504. else
  10505. {
  10506. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10507. {
  10508. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10509. {
  10510. connectorIdInt = (gun_index+1);
  10511. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10512. break;
  10513. }
  10514. }
  10515. }
  10516. if(connectorIdInt == 0)
  10517. {
  10518. DEBUG_WARN("Connector id shall not equal 0.\n");
  10519. result = FAIL;
  10520. }
  10521. else if(connectorIdInt == -1)
  10522. {
  10523. DEBUG_INFO("Connector id does not specific.\n");
  10524. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10525. {
  10526. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10527. // Required data
  10528. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10529. // Optional data
  10530. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10531. {
  10532. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10533. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10534. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10535. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10536. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10537. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10538. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10539. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10540. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10541. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10542. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10543. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10544. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10545. {
  10546. 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")));
  10547. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10548. 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"));
  10549. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10550. 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"));
  10551. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10552. 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")));
  10553. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10554. {
  10555. 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++)
  10556. {
  10557. 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"));
  10558. 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"));
  10559. 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)
  10560. 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"));
  10561. }
  10562. }
  10563. }
  10564. }
  10565. else
  10566. {
  10567. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10568. }
  10569. }
  10570. }
  10571. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10572. {
  10573. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10574. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10575. // Required data
  10576. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10577. // Optional data
  10578. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10579. {
  10580. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10581. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10582. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10583. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10584. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10585. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10586. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10587. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10588. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10589. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10590. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10591. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10592. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10593. {
  10594. 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")));
  10595. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10596. 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"));
  10597. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10598. 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"));
  10599. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10600. 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")));
  10601. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10602. {
  10603. 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++)
  10604. {
  10605. 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"));
  10606. 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"));
  10607. 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)
  10608. 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"));
  10609. }
  10610. }
  10611. }
  10612. }
  10613. else
  10614. {
  10615. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10616. }
  10617. }
  10618. else
  10619. {
  10620. DEBUG_WARN("Connector id is over maximun value.\n");
  10621. result = FAIL;
  10622. }
  10623. }
  10624. if(result == PASS)
  10625. {
  10626. if(connectorIdInt > 0)
  10627. {
  10628. //check Transaction active
  10629. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10630. {
  10631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10632. {
  10633. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10634. }
  10635. else
  10636. {
  10637. tempIndex = connectorIdInt -1;
  10638. }
  10639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10640. {
  10641. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10642. {
  10643. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10644. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10645. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10646. {
  10647. //Reserved
  10648. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10649. }
  10650. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10651. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10652. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10653. {
  10654. //Reserved
  10655. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10656. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10657. goto end;
  10658. }
  10659. else
  10660. {
  10661. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10662. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10663. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10664. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10665. {
  10666. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10667. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10668. goto end;
  10669. }
  10670. }//END FOR ELSE
  10671. }
  10672. }// END FOR CHAdeMO_QUANTITY
  10673. }
  10674. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10675. {
  10676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10677. {
  10678. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10679. }
  10680. else
  10681. {
  10682. tempIndex = connectorIdInt -1;
  10683. }
  10684. for (int index = 0; index < CCS_QUANTITY; index++)
  10685. {
  10686. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10687. {
  10688. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10689. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10690. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10691. {
  10692. //Reserved
  10693. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10694. }
  10695. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10696. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10697. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10698. {
  10699. //Reserved
  10700. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10702. goto end;
  10703. }
  10704. else
  10705. {
  10706. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10707. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10708. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10709. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10710. {
  10711. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10712. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10713. goto end;
  10714. }
  10715. }// END FOR ELSE
  10716. }
  10717. }// END FOR CCS_QUANTITY
  10718. }
  10719. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10720. {
  10721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10722. {
  10723. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10724. }
  10725. else
  10726. {
  10727. tempIndex = connectorIdInt -1;
  10728. }
  10729. for (int index = 0; index < GB_QUANTITY; index++)
  10730. {
  10731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10732. {
  10733. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10734. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10735. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10736. {
  10737. //Reserved
  10738. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10739. }
  10740. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10741. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10742. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10743. {
  10744. //Reserved
  10745. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10746. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10747. goto end;
  10748. }
  10749. else
  10750. {
  10751. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10752. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10753. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10754. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10755. {
  10756. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10757. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10758. goto end;
  10759. }
  10760. }// END FOR ELSE
  10761. }
  10762. } // END FOR GB_QUANTITY
  10763. }
  10764. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10765. {
  10766. tempIndex = connectorIdInt -1;
  10767. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10768. {
  10769. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10770. {
  10771. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10772. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10773. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10774. {
  10775. //Reserved
  10776. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10777. }
  10778. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10779. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10780. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10781. {
  10782. //Reserved
  10783. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10784. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10785. goto end;
  10786. }
  10787. else
  10788. {
  10789. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10790. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10791. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10792. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10793. {
  10794. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10795. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10796. goto end;
  10797. }
  10798. }// END FOR ELSE
  10799. }
  10800. } // END FOR GB_QUANTITY
  10801. }
  10802. else
  10803. {
  10804. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10805. {
  10806. tempIndex = 2;
  10807. }
  10808. else
  10809. {
  10810. tempIndex = connectorIdInt -1;
  10811. }
  10812. for (int index = 0; index < AC_QUANTITY; index++)
  10813. {
  10814. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10815. {
  10816. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10817. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10818. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10819. {
  10820. //Reserved
  10821. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10822. }
  10823. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10824. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10825. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10826. {
  10827. //Reserved
  10828. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10829. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10830. goto end;
  10831. }
  10832. else
  10833. {
  10834. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10835. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10836. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10837. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10838. {
  10839. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10840. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10841. goto end;
  10842. }
  10843. }//END FOR ELSE
  10844. }
  10845. }// END FOR AC_QUANTITY
  10846. }
  10847. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10848. {
  10849. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10850. {
  10851. // Save profile to file
  10852. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10853. system(cmdBuf);
  10854. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10855. fp = fopen(cmdBuf, "w");
  10856. 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));
  10857. fclose(fp);
  10858. }
  10859. else
  10860. {
  10861. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10862. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10863. goto end;
  10864. }
  10865. }
  10866. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10867. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10868. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10869. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10870. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10871. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10872. }
  10873. else
  10874. {
  10875. uint8_t isHasIdleConnector = FALSE;
  10876. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10877. {
  10878. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10879. {
  10880. isHasIdleConnector = TRUE;
  10881. break;
  10882. }
  10883. }
  10884. if(isHasIdleConnector == TRUE)
  10885. {
  10886. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10887. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10888. {
  10889. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10890. {
  10891. // Save profile to file
  10892. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10893. system(cmdBuf);
  10894. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10895. fp = fopen(cmdBuf, "w");
  10896. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10897. fclose(fp);
  10898. refreshStartTimer(&clientTime.RemoteStartWait);
  10899. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10900. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10901. }
  10902. else
  10903. {
  10904. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10905. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10906. }
  10907. }
  10908. else
  10909. {
  10910. refreshStartTimer(&clientTime.RemoteStartWait);
  10911. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10912. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10913. }
  10914. }
  10915. else
  10916. {
  10917. DEBUG_INFO("There is not any connector is idle.\n");
  10918. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10919. }
  10920. }
  10921. }
  10922. else
  10923. {
  10924. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10925. }
  10926. end:
  10927. json_object_put(RemoteStartTransaction);
  10928. sendRemoteStartConfirmation(uuid, comfirmstr);
  10929. return result;
  10930. }
  10931. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10932. {
  10933. mtrace();
  10934. int result = FAIL;
  10935. int match = FALSE;
  10936. int GunNO = 0;
  10937. int tempIndex = 0;
  10938. int transactionIdInt=0;
  10939. int transactionIdIsNULL= TRUE;
  10940. char comfirmstr[20];
  10941. json_object *RemoteStopTransaction;
  10942. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10943. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10944. if(server_pending == TRUE)
  10945. {
  10946. return 0;
  10947. }
  10948. RemoteStopTransaction = json_tokener_parse(payload);
  10949. if(!is_error(RemoteStopTransaction))
  10950. {
  10951. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10952. {
  10953. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10954. transactionIdIsNULL = FALSE;
  10955. }
  10956. }
  10957. json_object_put(RemoteStopTransaction);
  10958. if(transactionIdIsNULL == FALSE)
  10959. {
  10960. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10961. {
  10962. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10963. {
  10964. //check Transaction active
  10965. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10966. {
  10967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10968. {
  10969. tempIndex = ((gun_index==2) ? 1: 0);
  10970. }
  10971. else
  10972. {
  10973. tempIndex = gun_index;
  10974. }
  10975. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10976. {
  10977. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10978. {
  10979. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10980. {
  10981. match = TRUE;
  10982. GunNO = gun_index;
  10983. }
  10984. }
  10985. }// END FOR CHAdeMO_QUANTITY
  10986. }
  10987. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10988. {
  10989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10990. {
  10991. tempIndex = ((gun_index==2) ? 1: 0);
  10992. }
  10993. else
  10994. {
  10995. tempIndex = gun_index;
  10996. }
  10997. for (int index = 0; index < CCS_QUANTITY; index++)
  10998. {
  10999. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11000. {
  11001. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11002. {
  11003. match = TRUE;
  11004. GunNO = gun_index;
  11005. }
  11006. }
  11007. }// END FOR CCS_QUANTITY
  11008. }
  11009. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11010. {
  11011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11012. {
  11013. tempIndex = ((gun_index==2) ? 1: 0);
  11014. }
  11015. else
  11016. {
  11017. tempIndex = gun_index;
  11018. }
  11019. for (int index = 0; index < GB_QUANTITY; index++)
  11020. {
  11021. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11022. {
  11023. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11024. {
  11025. match = TRUE;
  11026. GunNO = gun_index;
  11027. }
  11028. }
  11029. }// END FOR GB_QUANTITY
  11030. }
  11031. else if(gunType[gun_index] == GUN_TYPE_DO)
  11032. {
  11033. tempIndex = gun_index;
  11034. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11035. {
  11036. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11037. {
  11038. 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
  11039. {
  11040. match = TRUE;
  11041. GunNO = gun_index;
  11042. }
  11043. }
  11044. }// END FOR GB_QUANTITY
  11045. }
  11046. else
  11047. {
  11048. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11049. {
  11050. tempIndex = 2;
  11051. }
  11052. else
  11053. {
  11054. tempIndex = gun_index;
  11055. }
  11056. for (int index = 0; index < AC_QUANTITY; index++)
  11057. {
  11058. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11059. {
  11060. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11061. {
  11062. match = TRUE;
  11063. GunNO = gun_index;
  11064. }
  11065. }
  11066. }// END FOR CHAdeMO_QUANTITY
  11067. } // END FOR AC ELSE
  11068. }// CHECK IF ResponseTransactionId == transactionIdInt
  11069. }//END FOR
  11070. if( match == TRUE)
  11071. {
  11072. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11073. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11074. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11075. }
  11076. else
  11077. {
  11078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11079. }
  11080. }
  11081. else
  11082. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11083. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11084. return result;
  11085. }
  11086. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11087. {
  11088. mtrace();
  11089. int result = FAIL;
  11090. int connectorIdInt=0, reservationIdInt=0;
  11091. int tempIndex = 0;
  11092. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11093. char comfirmstr[20]={0};
  11094. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11095. int c = 0;
  11096. char *loc;
  11097. //char *ptr;
  11098. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11099. strcpy(sstrtemp, stringtrimspace(payload));
  11100. //***(1)connectorId ****/
  11101. c=0;
  11102. loc = strstr(sstrtemp, "connectorId");
  11103. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11104. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11105. {
  11106. sstr[c] = loc[strlen("connectorId")+2+c];
  11107. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11108. c++;
  11109. }
  11110. sstr[c] = '\0';
  11111. connectorIdInt = atoi(sstr);
  11112. //***(2)expiryDate ****/
  11113. loc = strstr(sstrtemp, "expiryDate");
  11114. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11115. c = 0;
  11116. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11117. {
  11118. sstr[c] = loc[3+strlen("expiryDate")+c];
  11119. c++;
  11120. }
  11121. sstr[c] = '\0';
  11122. strcpy(expiryDatestr, sstr);
  11123. //***(3)idTag ****/
  11124. loc = strstr(sstrtemp, "idTag");
  11125. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11126. c = 0;
  11127. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11128. {
  11129. sstr[c] = loc[3+strlen("idTag")+c];
  11130. c++;
  11131. }
  11132. sstr[c] = '\0';
  11133. strcpy(idTagstr, sstr);
  11134. //***(4)parentIdTag ****/
  11135. loc = strstr(sstrtemp, "parentIdTag");
  11136. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11137. c = 0;
  11138. if(loc == NULL)
  11139. {
  11140. strcpy(parentIdTagstr, "");
  11141. }
  11142. else
  11143. {
  11144. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11145. {
  11146. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11147. c++;
  11148. }
  11149. sstr[c] = '\0';
  11150. strcpy(parentIdTagstr, sstr);
  11151. }
  11152. //***(5)reservationId ****/
  11153. c=0;
  11154. loc = strstr(sstrtemp, "reservationId");
  11155. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11156. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11157. {
  11158. sstr[c] = loc[strlen("reservationId")+2+c];
  11159. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11160. c++;
  11161. }
  11162. sstr[c] = '\0';
  11163. reservationIdInt = atoi(sstr);
  11164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11165. /*
  11166. enum SYSTEM_STATUS
  11167. {
  11168. SYS_MODE_BOOTING = 0,
  11169. SYS_MODE_IDLE = 1,
  11170. SYS_MODE_AUTHORIZING = 2,
  11171. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11172. SYS_MODE_REASSIGN = 4,
  11173. SYS_MODE_PREPARING = 5,
  11174. SYS_MODE_PREPARE_FOR_EV = 6,
  11175. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11176. SYS_MODE_CHARGING = 8,
  11177. SYS_MODE_TERMINATING = 9,
  11178. SYS_MODE_COMPLETE = 10,
  11179. SYS_MODE_ALARM = 11,
  11180. SYS_MODE_FAULT = 12,
  11181. SYS_MODE_RESERVATION = 13,
  11182. SYS_MODE_BOOKING = 14,
  11183. SYS_MODE_MAINTAIN = 15,
  11184. SYS_MODE_DEBUG = 16,
  11185. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11186. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11187. SYS_MODE_UPDATE = 19
  11188. };
  11189. */
  11190. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11191. {
  11192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11193. goto end;
  11194. }
  11195. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11196. {
  11197. //check Transaction active
  11198. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11199. {
  11200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11201. {
  11202. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11203. }
  11204. else
  11205. {
  11206. tempIndex = connectorIdInt -1;
  11207. }
  11208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11209. {
  11210. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11211. {
  11212. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11213. {
  11214. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11215. {
  11216. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11217. {
  11218. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11220. }
  11221. 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'))
  11222. {
  11223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11224. }
  11225. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11226. {
  11227. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11228. }
  11229. else
  11230. {
  11231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11232. }
  11233. }
  11234. 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
  11235. {
  11236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11237. }
  11238. }
  11239. else
  11240. {
  11241. //replace reservation
  11242. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11244. }
  11245. }
  11246. } // END FOR CHAdeMO_QUANTITY
  11247. }
  11248. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11249. {
  11250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11251. {
  11252. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11253. }
  11254. else
  11255. {
  11256. tempIndex = connectorIdInt -1;
  11257. }
  11258. for (int index = 0; index < CCS_QUANTITY; index++)
  11259. {
  11260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11261. {
  11262. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11263. {
  11264. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11265. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11266. {
  11267. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11268. {
  11269. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11271. }
  11272. 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'))
  11273. {
  11274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11275. }
  11276. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11277. {
  11278. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11279. }
  11280. else
  11281. {
  11282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11283. }
  11284. }
  11285. 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
  11286. {
  11287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11288. }
  11289. }
  11290. else
  11291. {
  11292. //replace reservation
  11293. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11294. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11295. }
  11296. }
  11297. } // END FOR CCS_QUANTITY
  11298. }
  11299. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11300. {
  11301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11302. {
  11303. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11304. }
  11305. else
  11306. {
  11307. tempIndex = connectorIdInt -1;
  11308. }
  11309. for (int index = 0; index < GB_QUANTITY; index++)
  11310. {
  11311. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11312. {
  11313. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11314. {
  11315. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11316. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11317. {
  11318. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11319. {
  11320. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11322. }
  11323. 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'))
  11324. {
  11325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11326. }
  11327. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11328. {
  11329. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11330. }
  11331. else
  11332. {
  11333. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11334. }
  11335. }
  11336. 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
  11337. {
  11338. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11339. }
  11340. }
  11341. else
  11342. {
  11343. //replace reservation
  11344. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11345. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11346. }
  11347. }
  11348. }// END FOR GB_QUANTITY
  11349. }
  11350. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11351. {
  11352. tempIndex = connectorIdInt -1;
  11353. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11354. {
  11355. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11356. {
  11357. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11358. {
  11359. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11360. 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
  11361. {
  11362. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11363. {
  11364. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11365. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11366. }
  11367. 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'))
  11368. {
  11369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11370. }
  11371. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11372. {
  11373. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11374. }
  11375. else
  11376. {
  11377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11378. }
  11379. }
  11380. 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
  11381. {
  11382. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11383. }
  11384. }
  11385. else
  11386. {
  11387. //replace reservation
  11388. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11389. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11390. }
  11391. }
  11392. }// END FOR GB_QUANTITY
  11393. }
  11394. else
  11395. {
  11396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11397. {
  11398. tempIndex = 2;
  11399. }
  11400. else
  11401. {
  11402. tempIndex = (connectorIdInt -1);
  11403. }
  11404. for (int index = 0; index < AC_QUANTITY; index++)
  11405. {
  11406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11407. {
  11408. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11409. {
  11410. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11411. {
  11412. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11413. {
  11414. 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))
  11415. {
  11416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11417. }
  11418. else
  11419. {
  11420. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11422. }
  11423. }
  11424. 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'))
  11425. {
  11426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11427. }
  11428. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11429. {
  11430. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11431. }
  11432. else
  11433. {
  11434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11435. }
  11436. }
  11437. 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
  11438. {
  11439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11440. }
  11441. }
  11442. else
  11443. {
  11444. //replace reservation
  11445. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11447. }
  11448. }
  11449. } // END FOR AC_QUANTITY
  11450. }
  11451. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11452. }
  11453. else if(connectorIdInt == 0)
  11454. {
  11455. //check Transaction active
  11456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11457. {
  11458. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11459. {
  11460. 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'))
  11461. {
  11462. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11463. goto end;
  11464. }
  11465. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11466. {
  11467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11468. goto end;
  11469. }
  11470. 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
  11471. {
  11472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11473. goto end;
  11474. }
  11475. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11476. {
  11477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11478. goto end;
  11479. }
  11480. }
  11481. }// END FOR CHAdeMO_QUANTITY
  11482. for (int index = 0; index < CCS_QUANTITY; index++)
  11483. {
  11484. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11485. {
  11486. 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'))
  11487. {
  11488. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11489. goto end;
  11490. }
  11491. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11492. {
  11493. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11494. goto end;
  11495. }
  11496. 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
  11497. {
  11498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11499. goto end;
  11500. }
  11501. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11502. {
  11503. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11504. goto end;
  11505. }
  11506. }
  11507. } // END FOR CCS_QUANTITY
  11508. for (int index = 0; index < GB_QUANTITY; index++)
  11509. {
  11510. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11511. {
  11512. 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'))
  11513. {
  11514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11515. goto end;
  11516. }
  11517. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11518. {
  11519. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11520. goto end;
  11521. }
  11522. 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
  11523. {
  11524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11525. goto end;
  11526. }
  11527. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11528. {
  11529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11530. goto end;
  11531. }
  11532. }
  11533. } // END FOR GB_QUANTITY
  11534. for (int index = 0; index < AC_QUANTITY; index++)
  11535. {
  11536. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11537. {
  11538. 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'))
  11539. {
  11540. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11541. goto end;
  11542. }
  11543. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11544. {
  11545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11546. goto end;
  11547. }
  11548. 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
  11549. {
  11550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11551. goto end;
  11552. }
  11553. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11554. {
  11555. 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))
  11556. {
  11557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11558. goto end;
  11559. }
  11560. }
  11561. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11562. {
  11563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11564. goto end;
  11565. }
  11566. }
  11567. }// END FOR AC_QUANTITY
  11568. //The connectorId is 0
  11569. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11571. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11572. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11573. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11574. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11575. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11576. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11577. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11578. result = TRUE;
  11579. return result;
  11580. }
  11581. else
  11582. {
  11583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11584. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11585. }
  11586. if(strcmp(comfirmstr,"Accepted") == 0)
  11587. {
  11588. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11589. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11590. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11591. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11592. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11593. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11594. result = TRUE;
  11595. return result;
  11596. }
  11597. end:
  11598. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11599. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11600. return result;
  11601. }
  11602. int handleResetRequest(char *uuid, char *payload)
  11603. {
  11604. mtrace();
  11605. int result = FAIL;
  11606. char sstr[10]={0},sstrtemp[30]={ 0 };
  11607. char typestr[10]={0};
  11608. char comfirmstr[20]={0};
  11609. int c = 0;
  11610. char *loc;
  11611. DEBUG_INFO("handleResetRequest...\n");
  11612. strcpy(sstrtemp, stringtrimspace(payload));
  11613. loc = strstr(sstrtemp, "type");
  11614. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11615. c = 0;
  11616. while (loc[3+strlen("type")+c] != '\"')
  11617. {
  11618. sstr[c] = loc[3+strlen("type")+c];
  11619. c++;
  11620. }
  11621. sstr[c] = '\0';
  11622. strcpy(typestr,sstr);
  11623. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11624. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11625. {
  11626. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11627. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11628. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11629. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11630. }
  11631. else
  11632. {
  11633. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11634. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11635. result = PASS;
  11636. }
  11637. sendResetConfirmation(uuid, comfirmstr);
  11638. return result;
  11639. }
  11640. int handleSendLocalListRequest(char *uuid, char *payload)
  11641. {
  11642. mtrace();
  11643. int result = FAIL;
  11644. char comfirmstr[20];
  11645. int checkState_Faulted = FALSE;
  11646. json_object *SendLocalList;
  11647. DEBUG_INFO("handleSendLocalListRequest...\n");
  11648. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11649. {
  11650. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11651. goto end;
  11652. }
  11653. //check Charge Point state
  11654. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11655. {
  11656. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11657. {
  11658. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11659. }
  11660. }
  11661. for (int index = 0; index < CCS_QUANTITY; index++)
  11662. {
  11663. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11664. {
  11665. checkState_Faulted = TRUE; //OCPP Status
  11666. }
  11667. }
  11668. for (int index = 0; index < GB_QUANTITY; index++)
  11669. {
  11670. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11671. {
  11672. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11673. }
  11674. }
  11675. //check Charge Point state
  11676. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11677. {
  11678. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11679. {
  11680. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11681. }
  11682. }
  11683. //check Charge Point state
  11684. for (int index = 0; index < AC_QUANTITY; index++)
  11685. {
  11686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11687. {
  11688. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11689. }
  11690. }
  11691. if(checkState_Faulted == TRUE)
  11692. {
  11693. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11694. goto end;
  11695. }
  11696. // Parsing payload
  11697. SendLocalList = json_tokener_parse(payload);
  11698. if(!is_error(SendLocalList))
  11699. {
  11700. // Required data
  11701. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11702. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11703. // Optional data
  11704. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11705. {
  11706. //Check UpdateType
  11707. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11708. {
  11709. //Local list full update
  11710. DEBUG_INFO("Local list full update.\n");
  11711. OCPP_getListVerion();
  11712. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11713. {
  11714. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11715. goto end;
  11716. }
  11717. OCPP_cleanLocalList();
  11718. }
  11719. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11720. {
  11721. //Local list different update
  11722. DEBUG_INFO("Local list different update.\n");
  11723. OCPP_getListVerion();
  11724. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11725. {
  11726. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11727. goto end;
  11728. }
  11729. }
  11730. else
  11731. {
  11732. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11733. goto end;
  11734. }
  11735. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11736. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11737. {
  11738. 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")));
  11739. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11740. {
  11741. 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")));
  11742. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11743. 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")));
  11744. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11745. 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")));
  11746. }
  11747. // Add to db
  11748. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11749. {
  11750. //Local list full update
  11751. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11752. idx,
  11753. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11754. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11755. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11756. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11757. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11758. // update list
  11759. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11760. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11761. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11762. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11763. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11764. }
  11765. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11766. {
  11767. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11768. idx,
  11769. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11770. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11771. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11772. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11773. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11774. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11775. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11776. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11777. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11778. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11779. }
  11780. }
  11781. }
  11782. else
  11783. {
  11784. //Check UpdateType
  11785. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11786. {
  11787. //Local list full update
  11788. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11789. OCPP_cleanLocalList();
  11790. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11791. goto end;
  11792. }
  11793. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11794. {
  11795. //Local list different update
  11796. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11797. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11798. goto end;
  11799. }
  11800. }
  11801. result = PASS;
  11802. }
  11803. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11804. end:
  11805. json_object_put(SendLocalList);
  11806. sendSendLocalListConfirmation(uuid, comfirmstr);
  11807. return result;
  11808. }
  11809. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11810. {
  11811. mtrace();
  11812. int result = FAIL;
  11813. struct StructSetChargingProfile SetProfileReq = {0};
  11814. int tempchargingProfileIdInt;
  11815. int tempstackLevelInt;
  11816. int chargingSchedulePeriodCount = 0;
  11817. char comfirmstr[20]={0};
  11818. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11819. char rmFileCmd[128]={0};
  11820. int profileQuantity = 0;
  11821. int isReplaceable = FALSE;
  11822. json_object *SetChargingProfile;
  11823. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11824. SetChargingProfile = json_tokener_parse(payload);
  11825. if(!is_error(SetChargingProfile))
  11826. {
  11827. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11828. {
  11829. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11830. }
  11831. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11832. {
  11833. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11834. {
  11835. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11836. }
  11837. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11838. {
  11839. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11840. }
  11841. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11842. {
  11843. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11844. }
  11845. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11846. {
  11847. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11848. }
  11849. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11850. {
  11851. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11852. }
  11853. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11854. {
  11855. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11856. }
  11857. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11858. {
  11859. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11860. }
  11861. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11862. {
  11863. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11864. }
  11865. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11866. {
  11867. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11868. {
  11869. 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")));
  11870. }
  11871. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11872. {
  11873. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11874. }
  11875. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11876. {
  11877. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11878. }
  11879. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11880. {
  11881. 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")));
  11882. }
  11883. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11884. {
  11885. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11886. if(chargingSchedulePeriodCount <= 10)
  11887. {
  11888. 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++)
  11889. {
  11890. 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)
  11891. {
  11892. 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"));
  11893. }
  11894. 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)
  11895. {
  11896. 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"));
  11897. }
  11898. 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)
  11899. {
  11900. 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"));
  11901. }
  11902. }
  11903. }
  11904. }
  11905. }
  11906. }
  11907. }
  11908. // Profile periods quantity check
  11909. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11910. {
  11911. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11912. goto end;
  11913. }
  11914. // Check invalid limit
  11915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11916. {
  11917. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11918. {
  11919. 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)))) ||
  11920. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11921. {
  11922. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11923. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11924. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11925. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11926. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11927. goto end;
  11928. }
  11929. }
  11930. }
  11931. else
  11932. {
  11933. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11934. {
  11935. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower))
  11936. {
  11937. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11938. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11939. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11940. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11941. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11942. goto end;
  11943. }
  11944. }
  11945. }
  11946. // Profile purpose info check
  11947. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11948. {
  11949. FILE *fp;
  11950. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11951. if(SetProfileReq.ConnectorId != 0)
  11952. {
  11953. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11954. goto end;
  11955. }
  11956. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11957. if (!fp)
  11958. {
  11959. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11960. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11961. }
  11962. else
  11963. {
  11964. char *line = NULL;
  11965. size_t len = 0;
  11966. while(getline(&line, &len, fp) != -1)
  11967. {
  11968. json_object *obj = NULL;
  11969. obj = json_tokener_parse(line);
  11970. if(is_error(obj))
  11971. {
  11972. DEBUG_ERROR("Parse txProfile from file error.\n");
  11973. }
  11974. else
  11975. {
  11976. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11977. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11978. {
  11979. profileQuantity += 1;
  11980. }
  11981. else
  11982. isReplaceable = TRUE;
  11983. }
  11984. }
  11985. }
  11986. fclose(fp);
  11987. }
  11988. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11989. {
  11990. FILE *fp;
  11991. char filename[128]={0};
  11992. int tmpProfileQuantity;
  11993. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11994. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11995. {
  11996. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11997. goto end;
  11998. }
  11999. if(SetProfileReq.ConnectorId == 0)
  12000. {
  12001. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12002. {
  12003. tmpProfileQuantity = 0;
  12004. memset(filename, 0, ARRAY_SIZE(filename));
  12005. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12006. fp = fopen(filename, "r");
  12007. if (!fp)
  12008. {
  12009. DEBUG_INFO("%s does not create.\n", filename);
  12010. fp = fopen(filename, "w+");
  12011. }
  12012. else
  12013. {
  12014. char *line = NULL;
  12015. size_t len = 0;
  12016. while(getline(&line, &len, fp) != -1)
  12017. {
  12018. json_object *obj = NULL;
  12019. obj = json_tokener_parse(line);
  12020. if(is_error(obj))
  12021. {
  12022. DEBUG_ERROR("Parse txProfile from file error.\n");
  12023. }
  12024. else
  12025. {
  12026. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12027. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12028. {
  12029. tmpProfileQuantity += 1;
  12030. }
  12031. else
  12032. isReplaceable = TRUE;
  12033. }
  12034. }
  12035. }
  12036. fclose(fp);
  12037. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12038. }
  12039. }
  12040. else
  12041. {
  12042. memset(filename, 0, ARRAY_SIZE(filename));
  12043. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12044. fp = fopen(filename, "r");
  12045. if (!fp)
  12046. {
  12047. DEBUG_INFO("%s does not create.\n", filename);
  12048. fp = fopen(filename, "w+");
  12049. }
  12050. else
  12051. {
  12052. char *line = NULL;
  12053. size_t len = 0;
  12054. while(getline(&line, &len, fp) != -1)
  12055. {
  12056. json_object *obj = NULL;
  12057. obj = json_tokener_parse(line);
  12058. if(is_error(obj))
  12059. {
  12060. DEBUG_ERROR("Parse txProfile from file error.\n");
  12061. }
  12062. else
  12063. {
  12064. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12065. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12066. {
  12067. profileQuantity += 1;
  12068. }
  12069. else
  12070. isReplaceable = TRUE;
  12071. }
  12072. }
  12073. }
  12074. fclose(fp);
  12075. }
  12076. }
  12077. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12078. {
  12079. int isMatchTransactiodId= FALSE;
  12080. FILE *fp;
  12081. char filename[128]={0};
  12082. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12083. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12084. if(SetProfileReq.ConnectorId == 0)
  12085. {
  12086. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12087. goto end;
  12088. }
  12089. int tempIndex = 0;
  12090. //check Transaction active
  12091. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12092. {
  12093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12094. {
  12095. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12096. }
  12097. else
  12098. {
  12099. tempIndex = SetProfileReq.ConnectorId -1;
  12100. }
  12101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12102. {
  12103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12104. {
  12105. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12106. {
  12107. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12108. {
  12109. isMatchTransactiodId = TRUE;
  12110. break;
  12111. }
  12112. }
  12113. }
  12114. }
  12115. }
  12116. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12117. {
  12118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12119. {
  12120. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12121. }
  12122. else
  12123. {
  12124. tempIndex = SetProfileReq.ConnectorId -1;
  12125. }
  12126. for (int index = 0; index < CCS_QUANTITY; index++)
  12127. {
  12128. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12129. {
  12130. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12131. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12132. {
  12133. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12134. {
  12135. isMatchTransactiodId = TRUE;
  12136. break;
  12137. }
  12138. }
  12139. }
  12140. }
  12141. }
  12142. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12143. {
  12144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12145. {
  12146. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12147. }
  12148. else
  12149. {
  12150. tempIndex = SetProfileReq.ConnectorId -1;
  12151. }
  12152. for (int index = 0; index < GB_QUANTITY; index++)
  12153. {
  12154. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12155. {
  12156. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12157. {
  12158. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12159. {
  12160. isMatchTransactiodId = TRUE;
  12161. break;
  12162. }
  12163. }
  12164. }
  12165. }
  12166. }
  12167. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12168. {
  12169. tempIndex = SetProfileReq.ConnectorId -1;
  12170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12171. {
  12172. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12173. {
  12174. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12175. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12176. {
  12177. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12178. {
  12179. isMatchTransactiodId = TRUE;
  12180. break;
  12181. }
  12182. }
  12183. }
  12184. }
  12185. }
  12186. else
  12187. {
  12188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12189. {
  12190. tempIndex = 2;
  12191. }
  12192. else
  12193. {
  12194. tempIndex = (SetProfileReq.ConnectorId -1);
  12195. }
  12196. for (int index = 0; index < AC_QUANTITY; index++)
  12197. {
  12198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12199. {
  12200. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12201. {
  12202. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12203. {
  12204. isMatchTransactiodId = TRUE;
  12205. break;
  12206. }
  12207. }
  12208. }
  12209. }
  12210. }
  12211. //check Transaction active
  12212. if(isMatchTransactiodId == FALSE)
  12213. {
  12214. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12215. goto end;
  12216. }
  12217. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12218. {
  12219. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12220. goto end;
  12221. }
  12222. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12223. fp = fopen(filename, "r");
  12224. if (!fp)
  12225. {
  12226. DEBUG_INFO("%s does not create.\n", filename);
  12227. fp = fopen(filename, "w+");
  12228. }
  12229. else
  12230. {
  12231. char *line = NULL;
  12232. size_t len = 0;
  12233. while(getline(&line, &len, fp) != -1)
  12234. {
  12235. json_object *obj = NULL;
  12236. obj = json_tokener_parse(line);
  12237. if(is_error(obj))
  12238. {
  12239. DEBUG_ERROR("Parse txProfile from file error.\n");
  12240. }
  12241. else
  12242. {
  12243. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12244. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12245. {
  12246. profileQuantity += 1;
  12247. }
  12248. else
  12249. isReplaceable = TRUE;
  12250. }
  12251. }
  12252. }
  12253. fclose(fp);
  12254. }
  12255. // Check ChargeProfileMaxStackLevel
  12256. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12257. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12258. {
  12259. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12260. goto end;
  12261. }
  12262. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12263. {
  12264. FILE *fp;
  12265. char dataLine[4096]={0};
  12266. char fnametemp[128]={0};
  12267. int tmpProfileQuantity;
  12268. //Check ChargePointMaxProfile.json exit
  12269. profileQuantity = 0;
  12270. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12271. {
  12272. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12273. //Check Charging Profile Count
  12274. tmpProfileQuantity = 0;
  12275. while(fscanf(fp, "%s", dataLine) != EOF)
  12276. {
  12277. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12278. {
  12279. profileQuantity += 1;
  12280. tmpProfileQuantity += 1;
  12281. }
  12282. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12283. }
  12284. fclose(fp);
  12285. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12286. }
  12287. //Check TxDefaultProfile_%d.json
  12288. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12289. {
  12290. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12291. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12292. if((access(fnametemp,F_OK))!=-1)
  12293. {
  12294. fp = fopen(fnametemp, "r");
  12295. //Check Charging Profile Count
  12296. tmpProfileQuantity = 0;
  12297. while(fscanf(fp, "%s", dataLine) != EOF)
  12298. {
  12299. //DEBUG_INFO("word=%s\n",word);
  12300. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12301. {
  12302. profileQuantity += 1;
  12303. tmpProfileQuantity += 1;
  12304. }
  12305. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12306. }
  12307. fclose(fp);
  12308. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12309. }
  12310. }
  12311. //Check TxProfile_%d.json
  12312. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12313. {
  12314. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12315. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12316. if((access(fnametemp,F_OK))!=-1)
  12317. {
  12318. fp = fopen(fnametemp, "r");
  12319. //Check Charging Profile Count
  12320. tmpProfileQuantity = 0;
  12321. while(fscanf(fp, "%s", dataLine) != EOF)
  12322. {
  12323. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12324. {
  12325. profileQuantity += 1;
  12326. tmpProfileQuantity += 1;
  12327. }
  12328. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12329. }
  12330. fclose(fp);
  12331. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12332. }
  12333. }
  12334. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12335. if((profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12336. {
  12337. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12338. goto end;
  12339. }
  12340. }
  12341. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12342. //**********************************Write to File********************************************************/
  12343. {
  12344. FILE *infile;
  12345. FILE *outfile;
  12346. char dataLine[4096]={0};
  12347. char filename[128]={0};
  12348. int chkChar=0;
  12349. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12350. {
  12351. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12352. {
  12353. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12354. }
  12355. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12356. {
  12357. if(SetProfileReq.ConnectorId==0)
  12358. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12359. else
  12360. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12361. }
  12362. else
  12363. {
  12364. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12365. }
  12366. infile = fopen (filename, "r");
  12367. outfile = fopen (tempfile, "w");
  12368. chkChar = fgetc(infile);
  12369. rewind(infile);
  12370. if(chkChar == EOF)
  12371. {
  12372. // Profile is empty
  12373. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12374. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12375. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12376. fclose(infile);
  12377. fclose(outfile);
  12378. sprintf(rmFileCmd,"rm -f %s",filename);
  12379. system(rmFileCmd);
  12380. rename(tempfile, filename);
  12381. }
  12382. else
  12383. {
  12384. // Profile is not empty
  12385. int ChargingProfileAdded = FALSE;
  12386. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12387. {
  12388. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12389. json_object *tmpChargingProfile;
  12390. tmpChargingProfile = json_tokener_parse(dataLine);
  12391. if(!is_error(SetChargingProfile))
  12392. {
  12393. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12394. {
  12395. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12396. {
  12397. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12398. }
  12399. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12400. {
  12401. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12402. }
  12403. }
  12404. }
  12405. json_object_put(tmpChargingProfile);
  12406. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12407. {
  12408. if(ChargingProfileAdded == FALSE)
  12409. {
  12410. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12411. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12412. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12413. ChargingProfileAdded = TRUE;
  12414. }
  12415. }
  12416. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12417. {
  12418. if(ChargingProfileAdded == FALSE)
  12419. {
  12420. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12421. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12422. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12423. ChargingProfileAdded = TRUE;
  12424. }
  12425. }
  12426. else
  12427. {
  12428. fprintf(outfile,"%s\n",dataLine);
  12429. if(ChargingProfileAdded == FALSE)
  12430. {
  12431. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12432. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12433. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12434. ChargingProfileAdded = TRUE;
  12435. }
  12436. }
  12437. } // end of while loop
  12438. fclose(infile);
  12439. fclose(outfile);
  12440. sprintf(rmFileCmd,"rm -f %s",filename);
  12441. system(rmFileCmd);
  12442. rename(tempfile, filename);
  12443. }
  12444. }
  12445. sleep(1);
  12446. result = TRUE;
  12447. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12448. }
  12449. end:
  12450. json_object_put(SetChargingProfile);
  12451. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12452. {
  12453. if(SetProfileReq.ConnectorId == 0)
  12454. {
  12455. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12456. {
  12457. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12458. }
  12459. }
  12460. else
  12461. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12462. }
  12463. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12464. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12465. return result;
  12466. }
  12467. int handleTriggerMessageRequest(char *uuid, char *payload)
  12468. {
  12469. mtrace();
  12470. int result = FAIL;
  12471. int connectorIdIsNULL = FALSE;
  12472. int connectorIdInt =0;
  12473. char sstr[40]={0},sstrtemp[100]={ 0 };
  12474. char requestedMessagestr[40]={0};
  12475. char comfirmstr[20]={0};
  12476. int c = 0;
  12477. char *loc;
  12478. DEBUG_INFO("handleTriggerMessageRequest\n");
  12479. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12480. strcpy(sstrtemp, stringtrimspace(payload));
  12481. c = 0;
  12482. loc = strstr(sstrtemp, "requestedMessage");
  12483. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12484. {
  12485. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12486. c++;
  12487. }
  12488. sstr[c] = '\0';
  12489. strcpy(requestedMessagestr, sstr);
  12490. c = 0;
  12491. loc = strstr(sstrtemp, "connectorId");
  12492. if(loc == NULL)
  12493. {
  12494. connectorIdIsNULL = TRUE;
  12495. }
  12496. else
  12497. {
  12498. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12499. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12500. {
  12501. sstr[c] = loc[strlen("connectorId")+2+c];
  12502. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12503. c++;
  12504. }
  12505. sstr[c] = '\0';
  12506. connectorIdInt = atoi(sstr);
  12507. }
  12508. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12509. {
  12510. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12511. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12512. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12513. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12514. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12515. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12516. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12517. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12518. {
  12519. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12520. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12521. return TRUE;
  12522. }
  12523. else
  12524. {
  12525. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12526. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12527. }
  12528. }
  12529. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12530. {
  12531. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12532. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12533. return TRUE;
  12534. }
  12535. //==========================
  12536. // Trigger message
  12537. //==========================
  12538. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12539. {
  12540. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12541. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12542. {
  12543. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12544. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12545. }
  12546. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12547. }
  12548. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12549. {
  12550. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12551. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12552. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12553. }
  12554. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12555. {
  12556. //sendBootNotificationRequest();
  12557. server_sign = FALSE;
  12558. }
  12559. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12560. {
  12561. refreshStartTimer(&clientTime.Heartbeat);
  12562. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12563. }
  12564. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12565. {
  12566. if(connectorIdIsNULL == FALSE)
  12567. {
  12568. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12569. {
  12570. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12571. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12572. }
  12573. }
  12574. else
  12575. {
  12576. for(int idx=0;idx< gunTotalNumber;idx++)
  12577. {
  12578. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12579. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12580. }
  12581. }
  12582. }
  12583. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12584. {
  12585. if(connectorIdIsNULL == FALSE)
  12586. {
  12587. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12588. {
  12589. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12590. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12591. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12592. }
  12593. }
  12594. else
  12595. {
  12596. for(int idx=0;idx< gunTotalNumber;idx++)
  12597. {
  12598. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12599. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12600. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12601. }
  12602. }
  12603. }
  12604. return result;
  12605. }
  12606. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12607. {
  12608. mtrace();
  12609. int result = FAIL;
  12610. int connectorIdInt =0;
  12611. char comfirmstr[20]={0};
  12612. int tempIndex = 0;
  12613. json_object *UnlockConnector;
  12614. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12615. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12616. UnlockConnector = json_tokener_parse(payload);
  12617. if(!is_error(UnlockConnector))
  12618. {
  12619. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12620. {
  12621. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12622. }
  12623. }
  12624. json_object_put(UnlockConnector);
  12625. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12626. if(gunTotalNumber == 0)
  12627. {
  12628. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12629. goto end;
  12630. }
  12631. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12632. {
  12633. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12634. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12635. goto end;
  12636. }
  12637. else
  12638. {
  12639. //check Transaction active
  12640. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12641. {
  12642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12643. {
  12644. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12645. }
  12646. else
  12647. {
  12648. tempIndex = connectorIdInt -1;
  12649. }
  12650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12651. {
  12652. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12653. {
  12654. //stop Transaction
  12655. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12656. }
  12657. }
  12658. }
  12659. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12660. {
  12661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12662. {
  12663. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12664. }
  12665. else
  12666. {
  12667. tempIndex = connectorIdInt -1;
  12668. }
  12669. for (int index = 0; index < CCS_QUANTITY; index++)
  12670. {
  12671. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12672. {
  12673. //stop Transaction
  12674. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12675. }
  12676. }
  12677. }
  12678. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12679. {
  12680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12681. {
  12682. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12683. }
  12684. else
  12685. {
  12686. tempIndex = connectorIdInt -1;
  12687. }
  12688. for (int index = 0; index < GB_QUANTITY; index++)
  12689. {
  12690. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12691. {
  12692. //stop Transaction
  12693. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12694. }
  12695. }
  12696. }
  12697. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12698. {
  12699. tempIndex = connectorIdInt -1;
  12700. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12701. {
  12702. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12703. {
  12704. //stop Transaction
  12705. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12706. }
  12707. }
  12708. }
  12709. else
  12710. {
  12711. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12712. {
  12713. tempIndex = 2;
  12714. }
  12715. else
  12716. {
  12717. tempIndex = connectorIdInt-1;
  12718. }
  12719. for (int index = 0; index < AC_QUANTITY; index++)
  12720. {
  12721. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12722. {
  12723. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12724. }
  12725. }
  12726. }
  12727. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12728. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12729. result = TRUE;
  12730. return result;
  12731. }
  12732. end:
  12733. //json_object_put(obj); --- remove temporally
  12734. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12735. return result;
  12736. }
  12737. static char UpdateFirmwarepayloadData[300]={0};
  12738. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12739. {
  12740. mtrace();
  12741. int result = FAIL;
  12742. pthread_t t;
  12743. sendUpdateFirmwareConfirmation(uuid);
  12744. memset(UpdateFirmwarepayloadData, 0, 300);
  12745. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12746. if(!interLock.isUpdateFirmwareGoing)
  12747. {
  12748. interLock.isUpdateFirmwareGoing = 1;
  12749. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12750. sleep(1);
  12751. }
  12752. else
  12753. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12754. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12755. return result;
  12756. }
  12757. void *UpdateFirmwareProcess(void *data)
  12758. {
  12759. pthread_detach(pthread_self());
  12760. mtrace();
  12761. int retriesInt =0, retryIntervalInt=0;
  12762. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12763. int port=0;
  12764. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12765. int isSuccess = 0;
  12766. char ftpbuf[512];
  12767. char temp[100];
  12768. char * pch;
  12769. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12770. json_object *UpdateFirmware;
  12771. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12772. if(!is_error(UpdateFirmware))
  12773. {
  12774. // Required data
  12775. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12776. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12777. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12778. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12779. // Optional data
  12780. if(json_object_object_get(UpdateFirmware, "retries"))
  12781. {
  12782. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12783. }
  12784. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12785. {
  12786. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12787. }
  12788. }
  12789. json_object_put(UpdateFirmware);
  12790. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12791. memset(path, 0, ARRAY_SIZE(path));
  12792. // Wait retrieveData
  12793. if(strlen(retrieveDatestr) > 10)
  12794. {
  12795. do
  12796. {
  12797. sleep(1);
  12798. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12799. }
  12800. // Ready to download
  12801. system("rm -f /mnt/*");
  12802. if(strncmp(locationstr,"http", 4) == 0)
  12803. {
  12804. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12805. sprintf(ftppath,"/%s", path);
  12806. DEBUG_INFO("locationstr: %s\n", locationstr);
  12807. DEBUG_INFO("protocol: %s\n",protocol);
  12808. DEBUG_INFO("host: %s\n",host);
  12809. DEBUG_INFO("path: %s\n",path);
  12810. DEBUG_INFO("ftppath: %s\n",ftppath);
  12811. int ftppathlen=strlen(ftppath);
  12812. int i=1;
  12813. char filenametemp[50];
  12814. while(i < ftppathlen)
  12815. {
  12816. int len=ftppathlen-i;
  12817. if(ftppath[len]== 47) // '/' ascll code: 47
  12818. {
  12819. DEBUG_INFO("compare '/' all right\n");
  12820. break;
  12821. }
  12822. i=i+1;
  12823. }
  12824. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12825. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12826. filenametemp[i+1] = 0;
  12827. do
  12828. {
  12829. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12830. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12831. sleep(1);
  12832. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12833. if(!isSuccess)
  12834. {
  12835. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12836. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12837. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12838. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12839. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12840. }
  12841. else
  12842. {
  12843. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12844. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12845. }
  12846. retriesInt--;
  12847. }while((isSuccess == 0)&&(retriesInt >= 0));
  12848. }
  12849. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12850. {
  12851. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12852. memset(temp, 0, ARRAY_SIZE(temp));
  12853. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12854. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12855. int ftppathlen=strlen(ftpbuf);
  12856. int i=1;
  12857. char filenametemp[50];
  12858. while(i < ftppathlen)
  12859. {
  12860. int len=ftppathlen-i;
  12861. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12862. {
  12863. DEBUG_INFO(" compare '/' all right\n");
  12864. break;
  12865. }
  12866. i=i+1;
  12867. }
  12868. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12869. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12870. filenametemp[i+1] = 0;
  12871. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12872. pch=strchr(temp,'@');
  12873. if(pch==NULL)
  12874. {
  12875. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12876. protocol, host, &port, path);
  12877. strcpy(user,"anonymous");
  12878. strcpy(password,"");
  12879. }
  12880. else
  12881. {
  12882. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12883. protocol, user, password, host, &port, path);
  12884. }
  12885. sscanf(host,"%[^/]%s",host1, path1);
  12886. sprintf(ftppath,"%s", path1);
  12887. //DEBUG_INFO("protocol =%s\n",protocol);
  12888. //DEBUG_INFO("user =%s\n",user);
  12889. //DEBUG_INFO("password =%s\n",password);
  12890. //DEBUG_INFO("host1 =%s\n",host1);
  12891. //DEBUG_INFO("port =%d\n",port);
  12892. //DEBUG_INFO("path1 =%s\n",path1);
  12893. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12894. //ftpFile(host, user, password, port, ftppath, fname);
  12895. //download firmware pthred
  12896. if(port == 0)
  12897. {
  12898. port = 21;
  12899. }
  12900. do
  12901. {
  12902. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12903. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12904. sleep(1);
  12905. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12906. if(!isSuccess)
  12907. {
  12908. //BulldogUtil.sleepMs(interval*1000);
  12909. DEBUG_INFO("Update firmware request and download file fail.\n");
  12910. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12911. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12912. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12913. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12914. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12915. }
  12916. else
  12917. {
  12918. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12919. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12920. }
  12921. retriesInt--;
  12922. }while((!isSuccess)&&(retriesInt >= 0));
  12923. }
  12924. else
  12925. {
  12926. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12927. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12928. sleep(1);
  12929. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12930. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12931. }
  12932. // OCPPPH only, must announce CSU upgrade firmware
  12933. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12934. interLock.isUpdateFirmwareGoing = 0;
  12935. pthread_exit(NULL);
  12936. }
  12937. int handleCertificateSignedRequest(char *uuid, char *payload)
  12938. {
  12939. mtrace();
  12940. int result = PASS;
  12941. json_object *CertificateSigned;
  12942. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12943. CertificateSigned = json_tokener_parse(payload);
  12944. if(!is_error(CertificateSigned))
  12945. {
  12946. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12947. }
  12948. json_object_put(CertificateSigned);
  12949. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12950. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12951. fclose(fp);
  12952. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12953. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12954. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12955. sendCertificateSignedConfirmation(uuid);
  12956. return result;
  12957. }
  12958. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12959. {
  12960. mtrace();
  12961. int result = PASS;
  12962. json_object *DeleteCertificate;
  12963. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12964. DeleteCertificate = json_tokener_parse(payload);
  12965. if(!is_error(DeleteCertificate))
  12966. {
  12967. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12968. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12969. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12970. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12971. }
  12972. json_object_put(DeleteCertificate);
  12973. /*
  12974. * TODO: Delete certificateSigned process
  12975. */
  12976. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12977. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12978. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12979. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12980. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12981. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12982. sendDeleteCertificateConfirmation(uuid);
  12983. return result;
  12984. }
  12985. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12986. {
  12987. mtrace();
  12988. int result = PASS;
  12989. json_object *ExtendedTriggerMessage;
  12990. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12991. ExtendedTriggerMessage = json_tokener_parse(payload);
  12992. if(!is_error(ExtendedTriggerMessage))
  12993. {
  12994. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12995. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12996. {
  12997. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12998. }
  12999. else
  13000. {
  13001. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13002. }
  13003. }
  13004. json_object_put(ExtendedTriggerMessage);
  13005. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13006. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13007. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13008. {
  13009. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13010. }
  13011. else
  13012. {
  13013. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13014. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13015. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13016. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13017. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13018. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13019. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13020. {
  13021. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13022. }
  13023. else
  13024. {
  13025. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13026. }
  13027. }
  13028. sendExtendedTriggerMessageConfirmation(uuid);
  13029. //==========================
  13030. // Trigger message
  13031. //==========================
  13032. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13033. {
  13034. //sendBootNotificationRequest();
  13035. server_sign = FALSE;
  13036. }
  13037. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13038. {
  13039. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13040. }
  13041. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13042. {
  13043. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13044. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13045. {
  13046. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13047. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13048. }
  13049. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13050. }
  13051. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13052. {
  13053. refreshStartTimer(&clientTime.Heartbeat);
  13054. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13055. }
  13056. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13057. {
  13058. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13059. {
  13060. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13061. }
  13062. else
  13063. {
  13064. for(int idx=0;idx< gunTotalNumber;idx++)
  13065. {
  13066. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13067. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13068. }
  13069. }
  13070. }
  13071. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13072. {
  13073. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13074. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13075. {
  13076. 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\" &");
  13077. }
  13078. }
  13079. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13080. {
  13081. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13082. {
  13083. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13084. }
  13085. else
  13086. {
  13087. for(int idx=0;idx< gunTotalNumber;idx++)
  13088. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13089. }
  13090. }
  13091. return result;
  13092. }
  13093. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13094. {
  13095. mtrace();
  13096. int result = PASS;
  13097. json_object *GetInstalledCertificateIds;
  13098. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13099. GetInstalledCertificateIds = json_tokener_parse(payload);
  13100. if(!is_error(GetInstalledCertificateIds))
  13101. {
  13102. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13103. }
  13104. json_object_put(GetInstalledCertificateIds);
  13105. /*
  13106. * TODO: Return installed certificate process
  13107. */
  13108. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13109. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13110. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13111. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13112. sendGetInstalledCertificateIdsConfirmation(uuid);
  13113. return result;
  13114. }
  13115. int handleGetLogRequest(char *uuid, char *payload)
  13116. {
  13117. mtrace();
  13118. int result = PASS;
  13119. json_object *GetLog;
  13120. DEBUG_INFO("handleGetLogRequest...\n");
  13121. GetLog = json_tokener_parse(payload);
  13122. if(!is_error(GetLog))
  13123. {
  13124. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13125. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13126. if(json_object_object_get(GetLog, "retries") != NULL)
  13127. {
  13128. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13129. }
  13130. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13131. {
  13132. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13133. }
  13134. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13135. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13136. {
  13137. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13138. }
  13139. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13140. {
  13141. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13142. }
  13143. }
  13144. json_object_put(GetLog);
  13145. /*
  13146. * TODO: Upload log process
  13147. */
  13148. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13149. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13150. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13151. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13152. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13153. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13154. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13155. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13156. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13157. sendGetLogConfirmation(uuid);
  13158. return result;
  13159. }
  13160. int handleInstallCertificateRequest(char *uuid, char *payload)
  13161. {
  13162. mtrace();
  13163. int result = PASS;
  13164. json_object *InstallCertificate;
  13165. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13166. InstallCertificate = json_tokener_parse(payload);
  13167. if(!is_error(InstallCertificate))
  13168. {
  13169. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13170. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13171. /*
  13172. * TODO: Install certificate process
  13173. */
  13174. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13175. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13176. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13177. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13178. sendInstallCertificateConfirmation(uuid);
  13179. }
  13180. json_object_put(InstallCertificate);
  13181. return result;
  13182. }
  13183. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13184. {
  13185. mtrace();
  13186. int result = PASS;
  13187. json_object *SignedUpdateFirmware;
  13188. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13189. SignedUpdateFirmware = json_tokener_parse(payload);
  13190. if(!is_error(SignedUpdateFirmware))
  13191. {
  13192. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13193. {
  13194. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13195. }
  13196. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13197. {
  13198. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13199. }
  13200. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13201. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13202. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13203. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13204. {
  13205. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13206. }
  13207. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13208. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13209. }
  13210. json_object_put(SignedUpdateFirmware);
  13211. /*
  13212. * TODO: Upgrade firmware process
  13213. */
  13214. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13215. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13216. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13217. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13218. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13219. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13220. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13221. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13222. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13223. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13224. sendInstallCertificateConfirmation(uuid);
  13225. return result;
  13226. }
  13227. int handleUnknownRequest(char *uuid, char *payload)
  13228. {
  13229. mtrace();
  13230. int result = PASS;
  13231. DEBUG_INFO("handleUnknownRequest...\n");
  13232. sendUnknownConfirmation(uuid);
  13233. result = PASS;
  13234. return result;
  13235. }
  13236. //==========================================
  13237. // Handle server response routine
  13238. //==========================================
  13239. void handleAuthorizeResponse(char *payload, int gun_index)
  13240. {
  13241. mtrace();
  13242. char expiryDatestr[30]={0};
  13243. char parentIdTagstr[20]={0};
  13244. char statusstr[20]={0};
  13245. int expiryDateISNULL=FALSE;
  13246. int parentIdTagISNULL=FALSE;
  13247. DEBUG_INFO("handleAuthorizeResponse...\n");
  13248. json_object *Authorize;
  13249. Authorize = json_tokener_parse(payload);
  13250. if(!is_error(Authorize))
  13251. {
  13252. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13253. {
  13254. // Required data
  13255. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13256. // Optional data
  13257. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13258. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13259. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13260. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13261. }
  13262. }
  13263. json_object_put(Authorize);
  13264. if(expiryDateISNULL == FALSE)
  13265. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13266. if(parentIdTagISNULL == FALSE)
  13267. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13268. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13269. //Update idTag information to authorization cache if supproted
  13270. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13271. {
  13272. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13273. }
  13274. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13275. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13276. authorizeRetryTimes = 0;
  13277. }
  13278. void handleBootNotificationResponse(char *payload, int gun_index)
  13279. {
  13280. mtrace();
  13281. char statusStr[12]={0};
  13282. char currentTimeStr[30]={0};
  13283. int intervalInt = 0;
  13284. DEBUG_INFO("handleBootNotificationResponse...\n");
  13285. json_object *BootNotification;
  13286. BootNotification = json_tokener_parse(payload);
  13287. if(!is_error(BootNotification))
  13288. {
  13289. // Required data
  13290. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13291. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13292. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13293. }
  13294. json_object_put(BootNotification);
  13295. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13296. BootNotificationInterval = intervalInt;
  13297. //write back to ShmOCPP16DataPH->BootNotification
  13298. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13299. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13300. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13301. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13302. {
  13303. BootNotificationInterval = 0;
  13304. if((intervalInt == 0) || (intervalInt >= 10))
  13305. {
  13306. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13307. HeartBeatWaitTime = intervalInt;
  13308. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13309. }
  13310. server_sign = TRUE;
  13311. server_pending =FALSE;
  13312. }
  13313. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13314. {
  13315. server_pending = TRUE;
  13316. }
  13317. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13318. srand(time(NULL));
  13319. refreshStartTimer(&clientTime.Heartbeat);
  13320. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13321. SetOcppConnStatus(TRUE);
  13322. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13323. }
  13324. void handleDataTransferResponse(char *payload, int gun_index)
  13325. {
  13326. json_object *DataTransfer = json_tokener_parse(payload);
  13327. if(!is_error(DataTransfer))
  13328. {
  13329. // Required data
  13330. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13331. // Optional data
  13332. if(json_object_object_get(DataTransfer, "data") != NULL)
  13333. {
  13334. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13335. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13336. if(!is_error(Data))
  13337. {
  13338. if(json_object_object_get(Data, "msgId") != NULL)
  13339. {
  13340. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13341. {
  13342. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  13343. }
  13344. }
  13345. }
  13346. json_object_put(Data);
  13347. }
  13348. }
  13349. json_object_put(DataTransfer);
  13350. }
  13351. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13352. {
  13353. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13354. //struct json_object *obj;
  13355. // obj = json_tokener_parse(payload);
  13356. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13357. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13358. //No fields are defined.
  13359. }
  13360. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13361. {
  13362. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13363. //struct json_object *obj;
  13364. // obj = json_tokener_parse(payload);
  13365. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13366. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13367. //No fields are defined.
  13368. }
  13369. void handleHeartbeatResponse(char *payload, int gun_index)
  13370. {
  13371. mtrace();
  13372. DEBUG_INFO("handleHeartbeatResponse...\n");
  13373. json_object *Heartbeat;
  13374. Heartbeat = json_tokener_parse(payload);
  13375. if(!is_error(Heartbeat))
  13376. {
  13377. // Required data
  13378. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13379. }
  13380. json_object_put(Heartbeat);
  13381. if(FirstHeartBeat == 0)
  13382. {
  13383. FirstHeartBeat = 1;
  13384. DEBUG_INFO("FirstHeartBeat \n");
  13385. }
  13386. HeartBeatWithNOResponse = 0;
  13387. refreshStartTimer(&clientTime.Heartbeat);
  13388. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13389. }
  13390. void handleMeterValuesResponse(char *payload, int gun_index)
  13391. {
  13392. mtrace();
  13393. DEBUG_INFO("handleMeterValuesResponse...\n");
  13394. isQueueSendable = 1;
  13395. }
  13396. void handleStartTransactionResponse(char *payload, int gun_index)
  13397. {
  13398. mtrace();
  13399. //int transactionIdInt = 0;
  13400. FILE *outfile;
  13401. char data[100]={0};
  13402. DEBUG_INFO("handleStartTransactionResponse...\n");
  13403. json_object *StartTransaction;
  13404. StartTransaction = json_tokener_parse(payload);
  13405. if(!is_error(StartTransaction))
  13406. {
  13407. // Required data
  13408. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13409. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13410. // Optional data
  13411. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13412. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13413. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13414. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13415. }
  13416. json_object_put(StartTransaction);
  13417. isQueueSendable = 1;
  13418. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13419. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13420. //-----------Start : write to the Queue TransactionId file -----------------//
  13421. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13422. {}
  13423. else
  13424. {
  13425. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13426. if(log == NULL)
  13427. {
  13428. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13429. return ;
  13430. }
  13431. else
  13432. {
  13433. fclose(log);
  13434. }
  13435. }
  13436. // open file for writing
  13437. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13438. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13439. {
  13440. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13441. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13442. fputs(data, outfile);
  13443. fclose (outfile);
  13444. }
  13445. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13446. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13447. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13448. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13449. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13450. }
  13451. void handleStatusNotificationResponse(char *payload, int gun_index)
  13452. {
  13453. mtrace();
  13454. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13455. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13456. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13457. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13458. }
  13459. void handleStopTransactionnResponse(char *payload, int gun_index)
  13460. {
  13461. mtrace();
  13462. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13463. json_object *StopTransaction;
  13464. StopTransaction = json_tokener_parse(payload);
  13465. if(!is_error(StopTransaction))
  13466. {
  13467. // Optional data
  13468. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13469. {
  13470. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13471. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13472. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13473. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13474. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13475. }
  13476. }
  13477. json_object_put(StopTransaction);
  13478. isQueueSendable = 1;
  13479. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13480. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13481. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13482. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13483. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13484. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13485. }
  13486. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13487. {
  13488. mtrace();
  13489. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13490. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13491. }
  13492. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13493. {
  13494. mtrace();
  13495. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13496. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13497. }
  13498. void handleSignCertificateResponse(char *payload, int gun_index)
  13499. {
  13500. mtrace();
  13501. DEBUG_INFO("handleSignCertificateResponse...\n");
  13502. json_object *SignCertificate;
  13503. SignCertificate = json_tokener_parse(payload);
  13504. if(!is_error(SignCertificate))
  13505. {
  13506. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13507. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13508. }
  13509. json_object_put(SignCertificate);
  13510. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13511. }
  13512. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13513. {
  13514. mtrace();
  13515. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13516. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13517. }
  13518. //==========================================
  13519. // Handle Error routine
  13520. //==========================================
  13521. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13522. {
  13523. mtrace();
  13524. #ifdef SystemLogMessage
  13525. DEBUG_INFO("errorCode: %s\n", errorCode);
  13526. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13527. DEBUG_INFO("errorDetails: %s\n", payload);
  13528. #endif
  13529. }
  13530. //===============================================
  13531. // Common routine
  13532. //===============================================
  13533. int initialConfigurationTable(void)
  13534. {
  13535. //clock_t start_t, end_t, total_t;
  13536. FILE *fp;
  13537. FILE *outfile;
  13538. char str[512]={0};
  13539. char sstr[256]={0};
  13540. int c = 0;
  13541. char *loc;
  13542. int confVersion = 13;
  13543. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13544. //start_t = clock();
  13545. //printf("Starting of the program, start_t = %ld\n", start_t);
  13546. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13547. // Check configuration file size is correct
  13548. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13549. {
  13550. struct stat st;
  13551. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13552. if(st.st_size < 3100)
  13553. {
  13554. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13555. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13556. }
  13557. }
  13558. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13559. {
  13560. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13561. if(outfile == NULL)
  13562. {
  13563. DEBUG_INFO("Error opening file\n");
  13564. return FALSE;
  13565. }
  13566. /*Core Profile*/
  13567. //AllowOfflineTxForUnknownId
  13568. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13569. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13572. //AuthorizationCacheEnabled
  13573. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13574. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13575. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13577. //AuthorizeRemoteTxRequests
  13578. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13579. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13582. //BlinkRepeat
  13583. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13584. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13587. //ClockAlignedDataInterval
  13588. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13589. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13590. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13592. //ConnectionTimeOut
  13593. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13594. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13595. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13597. //GetConfigurationMaxKeys
  13598. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13600. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13602. // HeartbeatInterval
  13603. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13604. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13605. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13607. // LightIntensity
  13608. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13610. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13612. // LocalAuthorizeOffline
  13613. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13617. // LocalPreAuthorize
  13618. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13619. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13620. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13622. // MaxEnergyOnInvalidId
  13623. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13624. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13625. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13627. // MeterValuesAlignedData
  13628. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13631. 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" );
  13632. else
  13633. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13635. // MeterValuesAlignedDataMaxLength
  13636. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13639. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13640. else
  13641. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13643. // MeterValuesSampledData
  13644. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13645. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13647. 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" );
  13648. else
  13649. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13651. // MeterValuesSampledDataMaxLength
  13652. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13653. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13656. else
  13657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13659. // MeterValueSampleInterval
  13660. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13661. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13662. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13664. // MinimumStatusDuration
  13665. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13667. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13668. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13670. // NumberOfConnectors
  13671. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13674. {
  13675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13676. }
  13677. else
  13678. {
  13679. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13680. }
  13681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13682. // ResetRetries
  13683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13687. // ConnectorPhaseRotation
  13688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13692. // ConnectorPhaseRotationMaxLength
  13693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13697. // StopTransactionOnEVSideDisconnect
  13698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13699. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13702. // StopTransactionOnInvalidId
  13703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13707. // StopTxnAlignedData
  13708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13712. // StopTxnAlignedDataMaxLength
  13713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13717. // StopTxnSampledData
  13718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13721. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13722. else
  13723. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13725. // StopTxnSampledDataMaxLength
  13726. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13727. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13728. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13729. {
  13730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13731. }
  13732. else
  13733. {
  13734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13735. }
  13736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13737. // SupportedFeatureProfiles
  13738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13739. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13742. // SupportedFeatureProfilesMaxLength
  13743. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13744. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13745. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13747. // TransactionMessageAttempts
  13748. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13749. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13750. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13751. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13753. // TransactionMessageRetryInterval
  13754. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13755. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13756. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13757. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13758. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13759. // UnlockConnectorOnEVSideDisconnect
  13760. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13761. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13762. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13764. // WebSocketPingInterval
  13765. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13766. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13767. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13769. // QueueOffLineMeterValues
  13770. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13771. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13772. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13774. // AuthorizationKey
  13775. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13776. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13779. // SecurityProfile
  13780. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13781. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13782. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13784. // DefaultPrice
  13785. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13786. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13787. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13789. // CustomDisplayCostAndPrice
  13790. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13791. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13792. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13794. // CustomIdleFeeAfterStop
  13795. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13796. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13797. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13799. // SystemUptimeSec
  13800. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13801. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13802. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13804. // FreeVend
  13805. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13807. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13809. // FreeVendIdtag
  13810. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13811. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13814. // OcppServer
  13815. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13817. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13819. // MaintainServer
  13820. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13822. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13824. // StatusNotificationPeriodically
  13825. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13829. // StatusNotificationInterval
  13830. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13834. // Configuration Version
  13835. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13836. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13837. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13839. //* Local Auth List Management Profile*/
  13840. #if 0
  13841. //For OCTT Test Case
  13842. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13843. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13845. #endif
  13846. #if 1
  13847. //LocalAuthListEnabled
  13848. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13849. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13852. #endif
  13853. //LocalAuthListMaxLength
  13854. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13856. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13858. //SendLocalListMaxLength
  13859. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13863. //ReserveConnectorZeroSupported
  13864. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13868. //* Smart Charging Profile */
  13869. //ChargeProfileMaxStackLevel
  13870. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13871. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13874. // ChargingScheduleAllowedChargingRateUnit
  13875. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13879. // ChargingScheduleMaxPeriods
  13880. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13884. // ConnectorSwitch3to1PhaseSupported
  13885. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13889. // MaxChargingProfilesInstalled
  13890. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13894. fclose(outfile);
  13895. }
  13896. else
  13897. {
  13898. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13899. char keystr[60]={0};
  13900. char readonlystr[10]={0};
  13901. char valuestr[256]={0};
  13902. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13903. if(fp == NULL) {
  13904. DEBUG_INFO("Error opening file");
  13905. return FALSE;
  13906. }
  13907. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13908. {
  13909. //DEBUG_INFO("Get Configuration \n");
  13910. if(strlen(str) > 0)
  13911. {
  13912. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13913. //*************************key*********************************/
  13914. if(strstr(str, "key") != NULL)
  13915. {
  13916. loc = strstr(str, "key");
  13917. c = 0;
  13918. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13919. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13920. {
  13921. sstr[c] = loc[strlen("key")+3+c];
  13922. c++;
  13923. }
  13924. sstr[c] = '\0';
  13925. strcpy(keystr,sstr);
  13926. }
  13927. //*************************readonly*********************************/
  13928. if(strstr(str, "readonly") != NULL)
  13929. {
  13930. loc = strstr(str, "readonly");
  13931. c = 0;
  13932. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13933. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13934. {
  13935. sstr[c] = loc[strlen("readonly")+2+c];
  13936. c++;
  13937. }
  13938. sstr[c] = '\0';
  13939. strcpy(readonlystr,sstr);
  13940. }
  13941. //*************************value*********************************/
  13942. if(strstr(str, "value") != NULL)
  13943. {
  13944. loc = strstr(str, "value");
  13945. c = 0;
  13946. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13947. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13948. {
  13949. sstr[c] = loc[strlen("value")+3+c];
  13950. c++;
  13951. }
  13952. sstr[c] = '\0';
  13953. strcpy(valuestr,sstr);
  13954. }
  13955. // DEBUG_INFO("keystr=%s\n",keystr);
  13956. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13957. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13958. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13959. {
  13960. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13961. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13962. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13963. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13964. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13965. }
  13966. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13967. {
  13968. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13970. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13971. }
  13972. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13973. {
  13974. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13975. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13976. }
  13977. if(strcmp(keystr, "BlinkRepeat") == 0)
  13978. {
  13979. //Charger.BlinkRepeat = Integer.parseInt(value);
  13980. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13981. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13982. }
  13983. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13984. {
  13985. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13986. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13987. }
  13988. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13989. {
  13990. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13991. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13992. }
  13993. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13994. {
  13995. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13996. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13997. }
  13998. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13999. {
  14000. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14001. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14002. HeartBeatWaitTime = atoi(valuestr);
  14003. }
  14004. if(strcmp(keystr, "LightIntensity") == 0)
  14005. {
  14006. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14007. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14008. }
  14009. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14010. {
  14011. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14012. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14013. }
  14014. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14015. {
  14016. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14017. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14018. }
  14019. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14020. {
  14021. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14022. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14023. }
  14024. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14025. {
  14026. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14027. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14028. }
  14029. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14030. {
  14031. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14032. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14033. }
  14034. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14035. {
  14036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14037. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14038. }
  14039. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14040. {
  14041. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14042. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14043. }
  14044. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14045. {
  14046. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14047. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14048. }
  14049. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14050. {
  14051. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14052. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14053. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14054. }
  14055. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14056. {
  14057. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14058. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14059. }
  14060. if(strcmp(keystr, "ResetRetries") == 0)
  14061. {
  14062. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14063. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14064. }
  14065. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14066. {
  14067. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14068. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14069. }
  14070. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14071. {
  14072. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14073. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14074. }
  14075. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14076. {
  14077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14078. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14079. }
  14080. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14081. {
  14082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14083. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14084. }
  14085. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14086. {
  14087. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14088. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14089. }
  14090. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14091. {
  14092. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14093. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14094. }
  14095. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14096. {
  14097. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14098. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14099. }
  14100. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14101. {
  14102. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14103. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14104. }
  14105. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14106. {
  14107. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14108. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14109. }
  14110. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14111. {
  14112. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14113. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14114. }
  14115. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14116. {
  14117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14118. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14119. TransactionMessageAttemptsValue = atoi(valuestr);
  14120. }
  14121. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14122. {
  14123. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14124. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14125. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14126. }
  14127. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14128. {
  14129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14130. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14131. }
  14132. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14133. {
  14134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14135. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14136. }
  14137. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14138. {
  14139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14140. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14141. }
  14142. if(strcmp(keystr, "AuthorizationKey") == 0)
  14143. {
  14144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14145. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14146. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14147. }
  14148. if(strcmp(keystr, "SecurityProfile") == 0)
  14149. {
  14150. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14151. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14153. }
  14154. if(strcmp(keystr, "DefaultPrice") == 0)
  14155. {
  14156. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14157. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14158. }
  14159. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14160. {
  14161. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14162. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14163. }
  14164. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14165. {
  14166. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14167. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14168. }
  14169. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14170. {
  14171. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14172. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14173. }
  14174. if(strcmp(keystr, "FreeVend") == 0)
  14175. {
  14176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14177. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14178. }
  14179. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14180. {
  14181. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14182. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14183. }
  14184. if(strcmp(keystr, "OcppServer") == 0)
  14185. {
  14186. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14187. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14188. }
  14189. if(strcmp(keystr, "MaintainServer") == 0)
  14190. {
  14191. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14192. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14193. }
  14194. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14195. {
  14196. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14197. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14198. }
  14199. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14200. {
  14201. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14202. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14203. }
  14204. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14205. {
  14206. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14207. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14208. }
  14209. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14210. {
  14211. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14212. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14213. }
  14214. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14215. {
  14216. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14217. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14218. }
  14219. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14220. {
  14221. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14222. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14223. }
  14224. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14225. {
  14226. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14227. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14228. }
  14229. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14230. {
  14231. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14232. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14233. }
  14234. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14235. {
  14236. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14237. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14238. }
  14239. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14240. {
  14241. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14242. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14243. }
  14244. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14245. {
  14246. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14247. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14248. }
  14249. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14250. {
  14251. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14252. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14253. }
  14254. }
  14255. }
  14256. fclose(fp);
  14257. }
  14258. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14259. {
  14260. return PASS;
  14261. }
  14262. else
  14263. {
  14264. return FAIL;
  14265. }
  14266. }
  14267. void StoreConfigurationTable(void)
  14268. {
  14269. FILE *outfile;
  14270. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14271. if(outfile == NULL)
  14272. {
  14273. DEBUG_INFO("Error opening file");
  14274. return ;
  14275. }
  14276. /*Core Profile*/
  14277. //AllowOfflineTxForUnknownId
  14278. /*
  14279. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14280. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14281. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14282. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14283. */
  14284. //DEBUG_INFO("data=%s\n",data);
  14285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14286. //AuthorizationCacheEnabled
  14287. /*
  14288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14291. */
  14292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14293. //AuthorizeRemoteTxRequests
  14294. /*
  14295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14298. */
  14299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14300. //BlinkRepeat
  14301. /*
  14302. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14305. */
  14306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14307. //ClockAlignedDataInterval
  14308. /*
  14309. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14310. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14312. */
  14313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14314. //ConnectionTimeOut
  14315. /*
  14316. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14317. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14319. */
  14320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14321. //GetConfigurationMaxKeys
  14322. /*
  14323. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14326. */
  14327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14328. // HeartbeatInterval
  14329. /*
  14330. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14333. */
  14334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14335. // LightIntensity
  14336. /*
  14337. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14340. */
  14341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14342. // LocalAuthorizeOffline
  14343. /*
  14344. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14345. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14347. */
  14348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14349. // LocalPreAuthorize
  14350. /*
  14351. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14352. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14354. */
  14355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14356. // MaxEnergyOnInvalidId
  14357. /*
  14358. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14359. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14361. */
  14362. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14364. // MeterValuesAlignedData
  14365. /*
  14366. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14367. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14369. */
  14370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14371. // MeterValuesAlignedDataMaxLength
  14372. /*
  14373. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14376. */
  14377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14378. // MeterValuesSampledData
  14379. /*
  14380. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14381. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14383. */
  14384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14385. // MeterValuesSampledDataMaxLength
  14386. /*
  14387. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14388. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14390. */
  14391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14392. // MeterValueSampleInterval
  14393. /*
  14394. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14396. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14397. */
  14398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14399. // MinimumStatusDuration
  14400. /*
  14401. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14404. */
  14405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14406. // NumberOfConnectors
  14407. /*
  14408. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14411. {
  14412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14413. }
  14414. else
  14415. {
  14416. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14417. }
  14418. */
  14419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14420. // ResetRetries
  14421. /*
  14422. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14423. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14424. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14425. */
  14426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14427. // ConnectorPhaseRotation
  14428. /*
  14429. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14430. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14432. */
  14433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14434. // ConnectorPhaseRotationMaxLength
  14435. /*
  14436. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14437. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14439. */
  14440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14441. // StopTransactionOnEVSideDisconnect
  14442. /*
  14443. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14444. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14445. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14446. */
  14447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14448. // StopTransactionOnInvalidId
  14449. /*
  14450. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14451. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14452. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14453. */
  14454. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14455. // StopTxnAlignedData
  14456. /*
  14457. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14458. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14459. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14460. */
  14461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14462. // StopTxnAlignedDataMaxLength
  14463. /*
  14464. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14465. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14466. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14467. */
  14468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14469. // StopTxnSampledData
  14470. /*
  14471. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14473. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14474. */
  14475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14476. // StopTxnSampledDataMaxLength
  14477. /*
  14478. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14479. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14480. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14481. */
  14482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14483. // SupportedFeatureProfiles
  14484. /*
  14485. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14486. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14487. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14488. */
  14489. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14490. // SupportedFeatureProfilesMaxLength
  14491. /*
  14492. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14493. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14495. */
  14496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14497. // TransactionMessageAttempts
  14498. /*
  14499. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14500. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14501. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14502. */
  14503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14504. // TransactionMessageRetryInterval
  14505. /*
  14506. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14507. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14508. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14509. */
  14510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14511. // UnlockConnectorOnEVSideDisconnect
  14512. /*
  14513. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14514. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14515. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14516. */
  14517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14518. // WebSocketPingInterval
  14519. /*
  14520. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14521. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14522. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14523. */
  14524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14525. // QueueOffLineMeterValues
  14526. /*
  14527. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14529. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14530. */
  14531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14532. // AuthorizationKey
  14533. /*
  14534. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14535. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14536. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14537. */
  14538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14539. // SecurityProfile
  14540. /*
  14541. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14542. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14543. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14544. */
  14545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14546. // DefaultPrice
  14547. /*
  14548. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14549. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14550. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14551. */
  14552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14553. // CustomDisplayCostAndPrice
  14554. /*
  14555. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14556. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14557. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14558. */
  14559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14560. // CustomIdleFeeAfterStop
  14561. /*
  14562. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14563. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14565. */
  14566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14567. // SystemUptimeSec
  14568. /*
  14569. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14572. */
  14573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14574. // FreeVend
  14575. /*
  14576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14577. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14578. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14579. */
  14580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14581. // FreeVendIdtag
  14582. /*
  14583. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14584. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14586. */
  14587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14588. // OcppServer
  14589. /*
  14590. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14591. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14593. */
  14594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14595. // MaintainServer
  14596. /*
  14597. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14600. */
  14601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14602. // StatusNotificationPeriodically
  14603. /*
  14604. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14605. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14607. */
  14608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14609. // StatusNotificationInterval
  14610. /*
  14611. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14612. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14614. */
  14615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14616. // ConfigurationVersion
  14617. /*
  14618. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14619. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14620. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14621. */
  14622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14623. //* Local Auth List Management Profile*/
  14624. //LocalAuthListEnabled
  14625. /*
  14626. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14629. */
  14630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14631. //LocalAuthListMaxLength
  14632. /*
  14633. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14635. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14636. */
  14637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14638. //SendLocalListMaxLength
  14639. /*
  14640. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14641. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14642. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14643. */
  14644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14645. //ReserveConnectorZeroSupported
  14646. /*
  14647. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14649. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14650. */
  14651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14652. //* Smart Charging Profile */
  14653. //ChargeProfileMaxStackLevel
  14654. /*
  14655. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14658. */
  14659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14660. // ChargingScheduleAllowedChargingRateUnit
  14661. /*
  14662. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14663. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14665. */
  14666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14667. // ChargingScheduleMaxPeriods
  14668. /*
  14669. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14671. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14672. */
  14673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14674. // ConnectorSwitch3to1PhaseSupported
  14675. /*
  14676. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14677. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14678. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14679. */
  14680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14681. // MaxChargingProfilesInstalled
  14682. /*
  14683. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14686. */
  14687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14688. fclose(outfile);
  14689. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14690. }
  14691. void getKeyValue(char *keyReq)
  14692. {
  14693. int isEmpty = FALSE;
  14694. int isKnowKey = FALSE;
  14695. DEBUG_INFO("keyReq = %s\n", keyReq);
  14696. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14697. isEmpty = TRUE;
  14698. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14699. {
  14700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14702. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14703. {
  14704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14705. }
  14706. else
  14707. {
  14708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14709. }
  14710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14711. isKnowKey = TRUE;
  14712. }
  14713. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14714. {
  14715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14717. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14718. {
  14719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14720. }
  14721. else
  14722. {
  14723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14724. }
  14725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14726. isKnowKey = TRUE;
  14727. }
  14728. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14729. {
  14730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14732. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14733. {
  14734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14735. }
  14736. else
  14737. {
  14738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14739. }
  14740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14741. isKnowKey = TRUE;
  14742. }
  14743. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14744. {
  14745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14747. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14748. {
  14749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14750. }
  14751. else
  14752. {
  14753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14754. }
  14755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14756. isKnowKey = TRUE;
  14757. }
  14758. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14759. {
  14760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14762. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14763. {
  14764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14765. }
  14766. else
  14767. {
  14768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14769. }
  14770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14771. isKnowKey = TRUE;
  14772. }
  14773. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14774. {
  14775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14777. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14778. {
  14779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14780. }
  14781. else
  14782. {
  14783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14784. }
  14785. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14786. isKnowKey = TRUE;
  14787. }
  14788. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14789. {
  14790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14792. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14793. {
  14794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14795. }
  14796. else
  14797. {
  14798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14799. }
  14800. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14801. isKnowKey = TRUE;
  14802. }
  14803. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14804. {
  14805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14807. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14808. {
  14809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14810. }
  14811. else
  14812. {
  14813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14814. }
  14815. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14816. isKnowKey = TRUE;
  14817. }
  14818. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14819. {
  14820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14822. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14823. {
  14824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14825. }
  14826. else
  14827. {
  14828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14829. }
  14830. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14831. isKnowKey = TRUE;
  14832. }
  14833. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14834. {
  14835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14837. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14838. {
  14839. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14840. }
  14841. else
  14842. {
  14843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14844. }
  14845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14846. isKnowKey = TRUE;
  14847. }
  14848. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14849. {
  14850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14852. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14853. {
  14854. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14855. }
  14856. else
  14857. {
  14858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14859. }
  14860. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14861. isKnowKey = TRUE;
  14862. }
  14863. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14864. {
  14865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14867. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14868. {
  14869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14870. }
  14871. else
  14872. {
  14873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14874. }
  14875. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14876. isKnowKey = TRUE;
  14877. }
  14878. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14879. {
  14880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14882. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14883. {
  14884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14885. }
  14886. else
  14887. {
  14888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14889. }
  14890. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14891. isKnowKey = TRUE;
  14892. }
  14893. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14894. {
  14895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14897. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14898. {
  14899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14900. }
  14901. else
  14902. {
  14903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14904. }
  14905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14906. isKnowKey = TRUE;
  14907. }
  14908. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14909. {
  14910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14912. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14913. {
  14914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14915. }
  14916. else
  14917. {
  14918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14919. }
  14920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14921. isKnowKey = TRUE;
  14922. }
  14923. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14924. {
  14925. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14927. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14928. {
  14929. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14930. }
  14931. else
  14932. {
  14933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14934. }
  14935. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14936. isKnowKey = TRUE;
  14937. }
  14938. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14939. {
  14940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14942. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14943. {
  14944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14945. }
  14946. else
  14947. {
  14948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14949. }
  14950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14951. isKnowKey = TRUE;
  14952. }
  14953. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14954. {
  14955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14957. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14958. {
  14959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14960. }
  14961. else
  14962. {
  14963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14964. }
  14965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14966. isKnowKey = TRUE;
  14967. }
  14968. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14969. {
  14970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14972. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14973. {
  14974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14975. }
  14976. else
  14977. {
  14978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14979. }
  14980. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14982. isKnowKey = TRUE;
  14983. }
  14984. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14985. {
  14986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14988. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14989. {
  14990. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14991. }
  14992. else
  14993. {
  14994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14995. }
  14996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14997. isKnowKey = TRUE;
  14998. }
  14999. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15000. {
  15001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15003. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15004. {
  15005. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15006. }
  15007. else
  15008. {
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15010. }
  15011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15012. isKnowKey = TRUE;
  15013. }
  15014. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15015. {
  15016. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15018. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15019. {
  15020. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15021. }
  15022. else
  15023. {
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15025. }
  15026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15027. isKnowKey = TRUE;
  15028. }
  15029. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15030. {
  15031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15033. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15034. {
  15035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15036. }
  15037. else
  15038. {
  15039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15040. }
  15041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15042. isKnowKey = TRUE;
  15043. }
  15044. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15045. {
  15046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15048. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15049. {
  15050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15051. }
  15052. else
  15053. {
  15054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15055. }
  15056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15057. isKnowKey = TRUE;
  15058. }
  15059. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15060. {
  15061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15063. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15064. {
  15065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15066. }
  15067. else
  15068. {
  15069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15070. }
  15071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15072. isKnowKey = TRUE;
  15073. }
  15074. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15075. {
  15076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15078. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15079. {
  15080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15081. }
  15082. else
  15083. {
  15084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15085. }
  15086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15087. isKnowKey = TRUE;
  15088. }
  15089. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15090. {
  15091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15093. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15094. {
  15095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15096. }
  15097. else
  15098. {
  15099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15100. }
  15101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15102. isKnowKey = TRUE;
  15103. }
  15104. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15105. {
  15106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15108. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15109. {
  15110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15111. }
  15112. else
  15113. {
  15114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15115. }
  15116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15117. isKnowKey = TRUE;
  15118. }
  15119. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15120. {
  15121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15123. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15124. {
  15125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15126. }
  15127. else
  15128. {
  15129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15130. }
  15131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15132. isKnowKey = TRUE;
  15133. }
  15134. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15135. {
  15136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15138. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15139. {
  15140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15141. }
  15142. else
  15143. {
  15144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15145. }
  15146. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15147. isKnowKey = TRUE;
  15148. }
  15149. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15150. {
  15151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15153. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15154. {
  15155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15156. }
  15157. else
  15158. {
  15159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15160. }
  15161. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15162. isKnowKey = TRUE;
  15163. }
  15164. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15165. {
  15166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15168. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15169. {
  15170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15171. }
  15172. else
  15173. {
  15174. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15175. }
  15176. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15177. isKnowKey = TRUE;
  15178. }
  15179. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15180. {
  15181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15183. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15184. {
  15185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15186. }
  15187. else
  15188. {
  15189. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15190. }
  15191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15192. isKnowKey = TRUE;
  15193. }
  15194. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15195. {
  15196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15198. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15199. {
  15200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15201. }
  15202. else
  15203. {
  15204. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15205. }
  15206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15207. isKnowKey = TRUE;
  15208. }
  15209. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15210. {
  15211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15213. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15214. {
  15215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15216. }
  15217. else
  15218. {
  15219. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15220. }
  15221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15222. isKnowKey = TRUE;
  15223. }
  15224. /*
  15225. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15226. {
  15227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15229. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15230. {
  15231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15232. }
  15233. else
  15234. {
  15235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15236. }
  15237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15238. isKnowKey = TRUE;
  15239. }*/
  15240. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15241. {
  15242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15244. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15245. {
  15246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15247. }
  15248. else
  15249. {
  15250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15251. }
  15252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15253. isKnowKey = TRUE;
  15254. }
  15255. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15256. {
  15257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15259. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15260. {
  15261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15262. }
  15263. else
  15264. {
  15265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15266. }
  15267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15268. isKnowKey = TRUE;
  15269. }
  15270. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15271. {
  15272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15274. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15275. {
  15276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15277. }
  15278. else
  15279. {
  15280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15281. }
  15282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15283. isKnowKey = TRUE;
  15284. }
  15285. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15286. {
  15287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15289. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15290. {
  15291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15292. }
  15293. else
  15294. {
  15295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15296. }
  15297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15298. isKnowKey = TRUE;
  15299. }
  15300. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15301. {
  15302. struct sysinfo s_info;
  15303. int error = sysinfo(&s_info);
  15304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15306. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15307. {
  15308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15309. }
  15310. else
  15311. {
  15312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15313. }
  15314. if(error != 0)
  15315. {
  15316. DEBUG_WARN("System uptime get error: %d\n", error);
  15317. }
  15318. else
  15319. {
  15320. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15321. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15322. }
  15323. isKnowKey = TRUE;
  15324. }
  15325. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15326. {
  15327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15329. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15330. {
  15331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15332. }
  15333. else
  15334. {
  15335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15336. }
  15337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15338. isKnowKey = TRUE;
  15339. }
  15340. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15341. {
  15342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15344. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15345. {
  15346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15347. }
  15348. else
  15349. {
  15350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15351. }
  15352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15353. isKnowKey = TRUE;
  15354. }
  15355. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15356. {
  15357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15359. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15360. {
  15361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15362. }
  15363. else
  15364. {
  15365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15366. }
  15367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15368. isKnowKey = TRUE;
  15369. }
  15370. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15371. {
  15372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15374. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15375. {
  15376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15377. }
  15378. else
  15379. {
  15380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15381. }
  15382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15383. isKnowKey = TRUE;
  15384. }
  15385. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15386. {
  15387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15389. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15390. {
  15391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15392. }
  15393. else
  15394. {
  15395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15396. }
  15397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15398. isKnowKey = TRUE;
  15399. }
  15400. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15401. {
  15402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15404. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15405. {
  15406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15407. }
  15408. else
  15409. {
  15410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15411. }
  15412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15413. isKnowKey = TRUE;
  15414. }
  15415. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15416. {
  15417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15419. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15420. {
  15421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15422. }
  15423. else
  15424. {
  15425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15426. }
  15427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15428. isKnowKey = TRUE;
  15429. }
  15430. #if 1
  15431. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15432. {
  15433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15435. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15436. {
  15437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15438. }
  15439. else
  15440. {
  15441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15442. }
  15443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15444. isKnowKey = TRUE;
  15445. }
  15446. #endif
  15447. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15448. {
  15449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15451. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15452. {
  15453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15454. }
  15455. else
  15456. {
  15457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15458. }
  15459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15460. isKnowKey = TRUE;
  15461. }
  15462. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15463. {
  15464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15466. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15467. {
  15468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15469. }
  15470. else
  15471. {
  15472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15473. }
  15474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15475. isKnowKey = TRUE;
  15476. }
  15477. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15478. {
  15479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15481. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15482. {
  15483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15484. }
  15485. else
  15486. {
  15487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15488. }
  15489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15490. isKnowKey = TRUE;
  15491. }
  15492. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15493. {
  15494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15496. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15497. {
  15498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15499. }
  15500. else
  15501. {
  15502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15503. }
  15504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15505. isKnowKey = TRUE;
  15506. }
  15507. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15508. {
  15509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15511. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15512. {
  15513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15514. }
  15515. else
  15516. {
  15517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15518. }
  15519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15520. isKnowKey = TRUE;
  15521. }
  15522. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15523. {
  15524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15526. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15527. {
  15528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15529. }
  15530. else
  15531. {
  15532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15533. }
  15534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15535. isKnowKey = TRUE;
  15536. }
  15537. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15538. {
  15539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15541. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15542. {
  15543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15544. }
  15545. else
  15546. {
  15547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15548. }
  15549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15550. isKnowKey = TRUE;
  15551. }
  15552. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15553. {
  15554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15556. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15557. {
  15558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15559. }
  15560. else
  15561. {
  15562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15563. }
  15564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15565. isKnowKey = TRUE;
  15566. }
  15567. //=========================================================
  15568. if(!isEmpty && !isKnowKey)
  15569. {
  15570. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15571. strcpy(unknownkey[UnknownKeynum], keyReq);
  15572. UnknownKeynum = UnknownKeynum + 1;
  15573. }
  15574. }
  15575. void processUnkownKey(void)
  15576. {
  15577. DEBUG_INFO("processUnkownKey...\n");
  15578. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15579. for(int index=0; index < UnknownKeynum; index++)
  15580. {
  15581. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15582. {
  15583. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15584. }
  15585. }
  15586. }
  15587. int setKeyValue(char *key, char *value)
  15588. {
  15589. int isSuccess = NotSupported;
  15590. int check_ascii=0;
  15591. char str[501]={0};
  15592. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15593. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15594. {
  15595. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15596. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15597. {
  15598. strcpy(str, (const char*)value);
  15599. for(int i = 0; str[i]; i++){
  15600. str[i] = tolower(str[i]);
  15601. }
  15602. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15603. isSuccess = ConfigurationStatus_Accepted;
  15604. }
  15605. else
  15606. {
  15607. isSuccess = ConfigurationStatus_Rejected;
  15608. }
  15609. }
  15610. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15611. {
  15612. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15613. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15614. {
  15615. strcpy(str, (const char*)value);
  15616. for(int i = 0; str[i]; i++){
  15617. str[i] = tolower(str[i]);
  15618. }
  15619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15620. isSuccess = ConfigurationStatus_Accepted;
  15621. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15622. }
  15623. else
  15624. {
  15625. isSuccess = ConfigurationStatus_Rejected;
  15626. }
  15627. }
  15628. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15629. {
  15630. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].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. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15638. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15639. isSuccess = ConfigurationStatus_Accepted;
  15640. }
  15641. else
  15642. {
  15643. isSuccess = ConfigurationStatus_Rejected;
  15644. }
  15645. }
  15646. if(strcmp(key, "BlinkRepeat") == 0)
  15647. {
  15648. //Charger.BlinkRepeat = Integer.parseInt(value);
  15649. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].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.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15659. isSuccess = ConfigurationStatus_Accepted;
  15660. }
  15661. }
  15662. else
  15663. {
  15664. isSuccess = ConfigurationStatus_Rejected;
  15665. }
  15666. }
  15667. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15668. {
  15669. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].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. if((atoi(value) == 0) || (atoi(value) >= 5))
  15679. {
  15680. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15681. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15682. isSuccess = ConfigurationStatus_Accepted;
  15683. }
  15684. else
  15685. isSuccess = ConfigurationStatus_Rejected;
  15686. }
  15687. }
  15688. else
  15689. {
  15690. isSuccess = ConfigurationStatus_Rejected;
  15691. }
  15692. }
  15693. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15694. {
  15695. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15696. {
  15697. check_ascii = value[0];
  15698. if( (check_ascii < 48) || (check_ascii > 57) )
  15699. {
  15700. isSuccess = ConfigurationStatus_Rejected;
  15701. }
  15702. else
  15703. {
  15704. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15706. isSuccess = ConfigurationStatus_Accepted;
  15707. }
  15708. }
  15709. else
  15710. {
  15711. isSuccess = ConfigurationStatus_Rejected;
  15712. }
  15713. }
  15714. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15715. {
  15716. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15717. {
  15718. check_ascii = value[0];
  15719. if( (check_ascii < 48) || (check_ascii > 57) )
  15720. {
  15721. isSuccess = ConfigurationStatus_Rejected;
  15722. }
  15723. else
  15724. {
  15725. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15726. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15727. isSuccess = ConfigurationStatus_Accepted;
  15728. }
  15729. }
  15730. else
  15731. {
  15732. isSuccess = ConfigurationStatus_Rejected;
  15733. }
  15734. }
  15735. if(strcmp(key, "HeartbeatInterval") == 0)
  15736. {
  15737. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15738. {
  15739. check_ascii = value[0];
  15740. if( (check_ascii < 48) || (check_ascii > 57) )
  15741. {
  15742. isSuccess = ConfigurationStatus_Rejected;
  15743. }
  15744. else
  15745. {
  15746. if((atoi(value) == 0) || (atoi(value) >= 10))
  15747. {
  15748. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15750. HeartBeatWaitTime = atoi(value);
  15751. isSuccess = ConfigurationStatus_Accepted;
  15752. }
  15753. else
  15754. {
  15755. isSuccess = ConfigurationStatus_Rejected;
  15756. }
  15757. }
  15758. }
  15759. else
  15760. {
  15761. isSuccess = ConfigurationStatus_Rejected;
  15762. }
  15763. }
  15764. if(strcmp(key, "LightIntensity") == 0)
  15765. {
  15766. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15767. {
  15768. check_ascii = value[0];
  15769. if( (check_ascii < 48) || (check_ascii > 57) )
  15770. {
  15771. isSuccess = ConfigurationStatus_Rejected;
  15772. }
  15773. else
  15774. {
  15775. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15776. isSuccess = ConfigurationStatus_Accepted;
  15777. }
  15778. }
  15779. else
  15780. {
  15781. isSuccess = ConfigurationStatus_Rejected;
  15782. }
  15783. }
  15784. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15785. {
  15786. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15787. {
  15788. strcpy(str, (const char*)value);
  15789. for(int i = 0; str[i]; i++)
  15790. {
  15791. str[i] = tolower(str[i]);
  15792. }
  15793. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15794. isSuccess = ConfigurationStatus_Accepted;
  15795. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15796. }
  15797. else
  15798. {
  15799. isSuccess = ConfigurationStatus_Rejected;
  15800. }
  15801. }
  15802. if(strcmp(key, "LocalPreAuthorize") == 0)
  15803. {
  15804. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15805. {
  15806. strcpy(str, (const char*)value);
  15807. for(int i = 0; str[i]; i++)
  15808. {
  15809. str[i] = tolower(str[i]);
  15810. }
  15811. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15812. isSuccess = ConfigurationStatus_Accepted;
  15813. }
  15814. else
  15815. {
  15816. isSuccess = ConfigurationStatus_Rejected;
  15817. }
  15818. }
  15819. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15820. {
  15821. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15822. {
  15823. check_ascii = value[0];
  15824. if( (check_ascii < 48) || (check_ascii > 57) )
  15825. {
  15826. isSuccess = ConfigurationStatus_Rejected;
  15827. }
  15828. else
  15829. {
  15830. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15831. isSuccess = ConfigurationStatus_Accepted;
  15832. }
  15833. }
  15834. else
  15835. {
  15836. isSuccess = ConfigurationStatus_Rejected;
  15837. }
  15838. }
  15839. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15840. {
  15841. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15842. {
  15843. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15844. isSuccess = ConfigurationStatus_Accepted;
  15845. }
  15846. else
  15847. {
  15848. isSuccess = ConfigurationStatus_Rejected;
  15849. }
  15850. }
  15851. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15852. {
  15853. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15854. {
  15855. check_ascii = value[0];
  15856. if( (check_ascii < 48) || (check_ascii > 57) )
  15857. {
  15858. isSuccess = ConfigurationStatus_Rejected;
  15859. }
  15860. else
  15861. {
  15862. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15863. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15864. isSuccess = ConfigurationStatus_Accepted;
  15865. }
  15866. }
  15867. else
  15868. {
  15869. isSuccess = ConfigurationStatus_Rejected;
  15870. }
  15871. }
  15872. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15873. {
  15874. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15875. {
  15876. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15877. isSuccess = ConfigurationStatus_Accepted;
  15878. }
  15879. else
  15880. {
  15881. isSuccess = ConfigurationStatus_Rejected;
  15882. }
  15883. }
  15884. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15885. {
  15886. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15887. {
  15888. check_ascii = value[0];
  15889. if( (check_ascii < 48) || (check_ascii > 57) )
  15890. {
  15891. isSuccess = ConfigurationStatus_Rejected;
  15892. }
  15893. else
  15894. {
  15895. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15896. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15897. isSuccess = ConfigurationStatus_Accepted;
  15898. }
  15899. }
  15900. else
  15901. {
  15902. isSuccess = ConfigurationStatus_Rejected;
  15903. }
  15904. }
  15905. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15906. {
  15907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15908. {
  15909. check_ascii = value[0];
  15910. if( (check_ascii < 48) || (check_ascii > 57) )
  15911. {
  15912. isSuccess = ConfigurationStatus_Rejected;
  15913. }
  15914. else
  15915. {
  15916. if((atoi(value) == 0) || (atoi(value) >= 3))
  15917. {
  15918. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15919. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15920. isSuccess = ConfigurationStatus_Accepted;
  15921. }
  15922. else
  15923. {
  15924. isSuccess = ConfigurationStatus_Rejected;
  15925. }
  15926. }
  15927. }
  15928. else
  15929. {
  15930. isSuccess = ConfigurationStatus_Rejected;
  15931. }
  15932. }
  15933. if(strcmp(key, "MinimumStatusDuration") == 0)
  15934. {
  15935. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15936. {
  15937. check_ascii = value[0];
  15938. if( (check_ascii < 48) || (check_ascii > 57) )
  15939. {
  15940. isSuccess = ConfigurationStatus_Rejected;
  15941. }
  15942. else
  15943. {
  15944. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15945. {
  15946. isSuccess = ConfigurationStatus_Rejected;
  15947. }
  15948. else
  15949. {
  15950. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15951. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15952. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15953. isSuccess = ConfigurationStatus_Accepted;
  15954. }
  15955. }
  15956. }
  15957. else
  15958. {
  15959. isSuccess = ConfigurationStatus_Rejected;
  15960. }
  15961. }
  15962. if(strcmp(key, "NumberOfConnectors") == 0)
  15963. {
  15964. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15965. {
  15966. check_ascii = value[0];
  15967. if( (check_ascii < 48) || (check_ascii > 57) )
  15968. {
  15969. isSuccess = ConfigurationStatus_Rejected;
  15970. }
  15971. else
  15972. {
  15973. //Charger.ResetRetries = Integer.parseInt(value);
  15974. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15975. isSuccess = ConfigurationStatus_Accepted;
  15976. }
  15977. }
  15978. else
  15979. {
  15980. isSuccess = ConfigurationStatus_Rejected;
  15981. }
  15982. }
  15983. if(strcmp(key, "ResetRetries") == 0)
  15984. {
  15985. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15986. {
  15987. check_ascii = value[0];
  15988. if( (check_ascii < 48) || (check_ascii > 57) )
  15989. {
  15990. isSuccess = ConfigurationStatus_Rejected;
  15991. }
  15992. else
  15993. {
  15994. //Charger.ResetRetries = Integer.parseInt(value);
  15995. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15996. isSuccess = ConfigurationStatus_Accepted;
  15997. }
  15998. }
  15999. else
  16000. {
  16001. isSuccess = ConfigurationStatus_Rejected;
  16002. }
  16003. }
  16004. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16005. {
  16006. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16007. {
  16008. strcpy(str, (const char*)value);
  16009. for(int i = 0; str[i]; i++)
  16010. {
  16011. str[i] = tolower(str[i]);
  16012. }
  16013. if(strcmp(str, "notapplicable")== 0)
  16014. {
  16015. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16016. isSuccess = ConfigurationStatus_Accepted;
  16017. }
  16018. else if(strcmp(str, "unknown")== 0)
  16019. {
  16020. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16021. isSuccess = ConfigurationStatus_Accepted;
  16022. }
  16023. else if(strcmp(str, "rst")== 0)
  16024. {
  16025. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16026. isSuccess = ConfigurationStatus_Accepted;
  16027. }
  16028. else if(strcmp(str, "rts")== 0)
  16029. {
  16030. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16031. isSuccess = ConfigurationStatus_Accepted;
  16032. }
  16033. else if(strcmp(str, "srt")== 0)
  16034. {
  16035. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16036. isSuccess = ConfigurationStatus_Accepted;
  16037. }
  16038. else if(strcmp(str, "str")== 0)
  16039. {
  16040. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16041. isSuccess = ConfigurationStatus_Accepted;
  16042. }
  16043. else if(strcmp(str, "trs")== 0)
  16044. {
  16045. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16046. isSuccess = ConfigurationStatus_Accepted;
  16047. }
  16048. else if(strcmp(str, "tsr")== 0)
  16049. {
  16050. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16051. isSuccess = ConfigurationStatus_Accepted;
  16052. }
  16053. else
  16054. {
  16055. isSuccess = ConfigurationStatus_Rejected;
  16056. }
  16057. }
  16058. else
  16059. {
  16060. isSuccess = ConfigurationStatus_Rejected;
  16061. }
  16062. }
  16063. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16064. {
  16065. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16066. {
  16067. check_ascii = value[0];
  16068. if( (check_ascii < 48) || (check_ascii > 57) )
  16069. {
  16070. isSuccess = ConfigurationStatus_Rejected;
  16071. }
  16072. else
  16073. {
  16074. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16075. isSuccess = ConfigurationStatus_Accepted;
  16076. }
  16077. }
  16078. else
  16079. {
  16080. isSuccess = ConfigurationStatus_Rejected;
  16081. }
  16082. }
  16083. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16084. {
  16085. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16086. {
  16087. strcpy(str, (const char*)value);
  16088. for(int i = 0; str[i]; i++)
  16089. {
  16090. str[i] = tolower(str[i]);
  16091. }
  16092. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16093. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16094. isSuccess = ConfigurationStatus_Accepted;
  16095. }
  16096. else
  16097. {
  16098. isSuccess = ConfigurationStatus_Rejected;
  16099. }
  16100. }
  16101. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16102. {
  16103. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16104. {
  16105. strcpy(str, (const char*)value);
  16106. for(int i = 0; str[i]; i++)
  16107. {
  16108. str[i] = tolower(str[i]);
  16109. }
  16110. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16112. isSuccess = ConfigurationStatus_Accepted;
  16113. }
  16114. else
  16115. {
  16116. isSuccess = ConfigurationStatus_Rejected;
  16117. }
  16118. }
  16119. if(strcmp(key, "StopTxnAlignedData") == 0)
  16120. {
  16121. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16122. {
  16123. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16124. isSuccess = ConfigurationStatus_Accepted;
  16125. }
  16126. else
  16127. {
  16128. isSuccess = ConfigurationStatus_Rejected;
  16129. }
  16130. }
  16131. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16132. {
  16133. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16134. {
  16135. check_ascii = value[0];
  16136. if( (check_ascii < 48) || (check_ascii > 57) )
  16137. {
  16138. isSuccess = ConfigurationStatus_Rejected;
  16139. }
  16140. else
  16141. {
  16142. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16143. isSuccess = ConfigurationStatus_Accepted;
  16144. }
  16145. }
  16146. else
  16147. {
  16148. isSuccess = ConfigurationStatus_Rejected;
  16149. }
  16150. }
  16151. if(strcmp(key, "StopTxnSampledData") == 0)
  16152. {
  16153. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16154. {
  16155. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16156. isSuccess = ConfigurationStatus_Accepted;
  16157. }
  16158. else
  16159. {
  16160. isSuccess = ConfigurationStatus_Rejected;
  16161. }
  16162. }
  16163. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16164. {
  16165. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16166. {
  16167. check_ascii = value[0];
  16168. if( (check_ascii < 48) || (check_ascii > 57) )
  16169. {
  16170. isSuccess = ConfigurationStatus_Rejected;
  16171. }
  16172. else
  16173. {
  16174. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16175. isSuccess = ConfigurationStatus_Accepted;
  16176. }
  16177. }
  16178. else
  16179. {
  16180. isSuccess = ConfigurationStatus_Rejected;
  16181. }
  16182. }
  16183. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16184. {
  16185. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16186. {
  16187. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16188. isSuccess = ConfigurationStatus_Accepted;
  16189. }
  16190. else
  16191. {
  16192. isSuccess = ConfigurationStatus_Rejected;
  16193. }
  16194. }
  16195. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16196. {
  16197. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16198. {
  16199. check_ascii = value[0];
  16200. if( (check_ascii < 48) || (check_ascii > 57) )
  16201. {
  16202. isSuccess = ConfigurationStatus_Rejected;
  16203. }
  16204. else
  16205. {
  16206. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16207. isSuccess = ConfigurationStatus_Accepted;
  16208. }
  16209. }
  16210. else
  16211. {
  16212. isSuccess = ConfigurationStatus_Rejected;
  16213. }
  16214. }
  16215. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16216. {
  16217. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16218. {
  16219. check_ascii = value[0];
  16220. if( (check_ascii < 48) || (check_ascii > 57) )
  16221. {
  16222. isSuccess = ConfigurationStatus_Rejected;
  16223. }
  16224. else
  16225. {
  16226. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16227. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16228. TransactionMessageAttemptsValue = atoi(value);
  16229. isSuccess = ConfigurationStatus_Accepted;
  16230. }
  16231. }
  16232. else
  16233. {
  16234. isSuccess = ConfigurationStatus_Rejected;
  16235. }
  16236. }
  16237. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16238. {
  16239. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16240. {
  16241. check_ascii = value[0];
  16242. if( (check_ascii < 48) || (check_ascii > 57) )
  16243. {
  16244. isSuccess = ConfigurationStatus_Rejected;
  16245. }
  16246. else
  16247. {
  16248. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16249. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16250. TransactionMessageRetryIntervalValue = atoi(value);
  16251. isSuccess = ConfigurationStatus_Accepted;
  16252. }
  16253. }
  16254. else
  16255. {
  16256. isSuccess = ConfigurationStatus_Rejected;
  16257. }
  16258. }
  16259. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16260. {
  16261. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16262. {
  16263. strcpy(str, (const char*)value);
  16264. for(int i = 0; str[i]; i++)
  16265. {
  16266. str[i] = tolower(str[i]);
  16267. }
  16268. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16269. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16270. isSuccess = ConfigurationStatus_Accepted;
  16271. }
  16272. else
  16273. {
  16274. isSuccess = ConfigurationStatus_Rejected;
  16275. }
  16276. }
  16277. if(strcmp(key, "WebSocketPingInterval") == 0)
  16278. {
  16279. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16280. {
  16281. check_ascii = value[0];
  16282. if( (check_ascii < 48) || (check_ascii > 57) )
  16283. {
  16284. isSuccess = ConfigurationStatus_Rejected;
  16285. }
  16286. else
  16287. {
  16288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16289. isSuccess = ConfigurationStatus_Accepted;
  16290. if((atoi(value) == 0) || (atoi(value) >= 10))
  16291. {
  16292. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16293. isSuccess = ConfigurationStatus_Accepted;
  16294. }
  16295. else
  16296. isSuccess = ConfigurationStatus_Rejected;
  16297. }
  16298. }
  16299. else
  16300. {
  16301. isSuccess = ConfigurationStatus_Rejected;
  16302. }
  16303. }
  16304. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16305. {
  16306. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16307. {
  16308. strcpy(str, (const char*)value);
  16309. for(int i = 0; str[i]; i++)
  16310. {
  16311. str[i] = tolower(str[i]);
  16312. }
  16313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16314. isSuccess = ConfigurationStatus_Accepted;
  16315. }
  16316. else
  16317. {
  16318. isSuccess = ConfigurationStatus_Rejected;
  16319. }
  16320. }
  16321. if(strcmp(key, "AuthorizationKey") == 0)
  16322. {
  16323. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16324. {
  16325. strcpy(str, (const char*)value);
  16326. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16327. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16328. isSuccess = ConfigurationStatus_Accepted;
  16329. }
  16330. else
  16331. {
  16332. isSuccess = ConfigurationStatus_Rejected;
  16333. }
  16334. }
  16335. if(strcmp(key, "SecurityProfile") == 0)
  16336. {
  16337. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16338. {
  16339. check_ascii = value[0];
  16340. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16341. {
  16342. isSuccess = ConfigurationStatus_Rejected;
  16343. }
  16344. else if(check_ascii == 0x33)
  16345. {
  16346. isSuccess = NotSupported;
  16347. }
  16348. else
  16349. {
  16350. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16351. {
  16352. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16353. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16354. isSuccess = ConfigurationStatus_Accepted;
  16355. }
  16356. else
  16357. isSuccess = ConfigurationStatus_Rejected;
  16358. }
  16359. }
  16360. else
  16361. {
  16362. isSuccess = ConfigurationStatus_Rejected;
  16363. }
  16364. }
  16365. if(strcmp(key, "DefaultPrice") == 0)
  16366. {
  16367. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16368. {
  16369. strcpy(str, (const char*)value);
  16370. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16371. isSuccess = ConfigurationStatus_Accepted;
  16372. }
  16373. else
  16374. {
  16375. isSuccess = ConfigurationStatus_Rejected;
  16376. }
  16377. }
  16378. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16379. {
  16380. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16381. {
  16382. strcpy(str, (const char*)value);
  16383. for(int i = 0; str[i]; i++)
  16384. {
  16385. str[i] = tolower(str[i]);
  16386. }
  16387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16388. isSuccess = ConfigurationStatus_Accepted;
  16389. }
  16390. else
  16391. {
  16392. isSuccess = ConfigurationStatus_Rejected;
  16393. }
  16394. }
  16395. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16396. {
  16397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16398. {
  16399. strcpy(str, (const char*)value);
  16400. for(int i = 0; str[i]; i++)
  16401. {
  16402. str[i] = tolower(str[i]);
  16403. }
  16404. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16405. isSuccess = ConfigurationStatus_Accepted;
  16406. }
  16407. else
  16408. {
  16409. isSuccess = ConfigurationStatus_Rejected;
  16410. }
  16411. }
  16412. if(strcmp(key, "SystemUptimeSec") == 0)
  16413. {
  16414. isSuccess = NotSupported;
  16415. }
  16416. if(strcmp(key, "FreeVend") == 0)
  16417. {
  16418. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16419. {
  16420. strcpy(str, (const char*)value);
  16421. for(int i = 0; str[i]; i++)
  16422. {
  16423. str[i] = tolower(str[i]);
  16424. }
  16425. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16426. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16427. isSuccess = ConfigurationStatus_Accepted;
  16428. }
  16429. else
  16430. {
  16431. isSuccess = ConfigurationStatus_Rejected;
  16432. }
  16433. }
  16434. if(strcmp(key, "FreeVendIdtag") == 0)
  16435. {
  16436. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16437. {
  16438. strcpy(str, (const char*)value);
  16439. if(strlen(str) <= 20)
  16440. {
  16441. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16442. isSuccess = ConfigurationStatus_Accepted;
  16443. }
  16444. else
  16445. {
  16446. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16447. isSuccess = ConfigurationStatus_Rejected;
  16448. }
  16449. }
  16450. else
  16451. {
  16452. isSuccess = ConfigurationStatus_Rejected;
  16453. }
  16454. }
  16455. if(strcmp(key, "OcppServer") == 0)
  16456. {
  16457. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16458. {
  16459. strcpy(str, (const char*)value);
  16460. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16461. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16462. isSuccess = ConfigurationStatus_Accepted;
  16463. }
  16464. else
  16465. {
  16466. isSuccess = ConfigurationStatus_Rejected;
  16467. }
  16468. }
  16469. if(strcmp(key, "MaintainServer") == 0)
  16470. {
  16471. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16472. {
  16473. strcpy(str, (const char*)value);
  16474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16475. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16476. isSuccess = ConfigurationStatus_Accepted;
  16477. }
  16478. else
  16479. {
  16480. isSuccess = ConfigurationStatus_Rejected;
  16481. }
  16482. }
  16483. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16484. {
  16485. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16486. {
  16487. strcpy(str, (const char*)value);
  16488. for(int i = 0; str[i]; i++)
  16489. {
  16490. str[i] = tolower(str[i]);
  16491. }
  16492. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16493. isSuccess = ConfigurationStatus_Accepted;
  16494. }
  16495. else
  16496. {
  16497. isSuccess = ConfigurationStatus_Rejected;
  16498. }
  16499. }
  16500. if(strcmp(key, "StatusNotificationInterval") == 0)
  16501. {
  16502. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16503. {
  16504. check_ascii = value[0];
  16505. if( (check_ascii < 48) || (check_ascii > 57) )
  16506. {
  16507. isSuccess = ConfigurationStatus_Rejected;
  16508. }
  16509. else
  16510. {
  16511. if((atoi(value) == 0) || (atoi(value) >= 10))
  16512. {
  16513. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16514. isSuccess = ConfigurationStatus_Accepted;
  16515. }
  16516. else
  16517. isSuccess = ConfigurationStatus_Rejected;
  16518. }
  16519. }
  16520. else
  16521. {
  16522. isSuccess = ConfigurationStatus_Rejected;
  16523. }
  16524. }
  16525. #if 0
  16526. //For OCPP Test Case
  16527. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16528. {
  16529. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16530. {
  16531. strcpy(str, (const char*)value);
  16532. for(int i = 0; str[i]; i++)
  16533. {
  16534. str[i] = tolower(str[i]);
  16535. }
  16536. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16537. isSuccess = ConfigurationStatus_Accepted;
  16538. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16539. }
  16540. else
  16541. {
  16542. isSuccess = ConfigurationStatus_Rejected;
  16543. }
  16544. }
  16545. #endif
  16546. #if 1
  16547. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16548. {
  16549. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16550. {
  16551. strcpy(str, (const char*)value);
  16552. for(int i = 0; str[i]; i++)
  16553. {
  16554. str[i] = tolower(str[i]);
  16555. }
  16556. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16557. isSuccess = ConfigurationStatus_Accepted;
  16558. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16559. }
  16560. else
  16561. {
  16562. isSuccess = ConfigurationStatus_Rejected;
  16563. }
  16564. }
  16565. #endif
  16566. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16567. {
  16568. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16569. {
  16570. check_ascii = value[0];
  16571. if( (check_ascii < 48) || (check_ascii > 57) )
  16572. {
  16573. isSuccess = ConfigurationStatus_Rejected;
  16574. }
  16575. else
  16576. {
  16577. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16578. isSuccess = ConfigurationStatus_Accepted;
  16579. }
  16580. }
  16581. else
  16582. {
  16583. isSuccess = ConfigurationStatus_Rejected;
  16584. }
  16585. }
  16586. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16587. {
  16588. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16589. {
  16590. check_ascii = value[0];
  16591. if( (check_ascii < 48) || (check_ascii > 57) )
  16592. {
  16593. isSuccess = ConfigurationStatus_Rejected;
  16594. }
  16595. else
  16596. {
  16597. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16598. isSuccess = ConfigurationStatus_Accepted;
  16599. }
  16600. }
  16601. else
  16602. {
  16603. isSuccess = ConfigurationStatus_Rejected;
  16604. }
  16605. }
  16606. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16607. {
  16608. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16609. {
  16610. strcpy(str, (const char*)value);
  16611. for(int i = 0; str[i]; i++)
  16612. {
  16613. str[i] = tolower(str[i]);
  16614. }
  16615. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16616. isSuccess = ConfigurationStatus_Accepted;
  16617. }
  16618. else
  16619. {
  16620. isSuccess = ConfigurationStatus_Rejected;
  16621. }
  16622. }
  16623. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16624. {
  16625. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16626. {
  16627. check_ascii = value[0];
  16628. if( (check_ascii < 48) || (check_ascii > 57) )
  16629. {
  16630. isSuccess = ConfigurationStatus_Rejected;
  16631. }
  16632. else
  16633. {
  16634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16635. isSuccess = ConfigurationStatus_Accepted;
  16636. }
  16637. }
  16638. else
  16639. {
  16640. isSuccess = ConfigurationStatus_Rejected;
  16641. }
  16642. }
  16643. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16644. {
  16645. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16646. {
  16647. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16648. isSuccess = ConfigurationStatus_Accepted;
  16649. }
  16650. else
  16651. {
  16652. isSuccess = ConfigurationStatus_Rejected;
  16653. }
  16654. }
  16655. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16656. {
  16657. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16658. {
  16659. check_ascii = value[0];
  16660. if( (check_ascii < 48) || (check_ascii > 57) )
  16661. {
  16662. isSuccess = ConfigurationStatus_Rejected;
  16663. }
  16664. else
  16665. {
  16666. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16667. isSuccess = ConfigurationStatus_Accepted;
  16668. }
  16669. }
  16670. else
  16671. {
  16672. isSuccess = ConfigurationStatus_Rejected;
  16673. }
  16674. }
  16675. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16676. {
  16677. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16678. {
  16679. strcpy(str, (const char*)value);
  16680. for(int i = 0; str[i]; i++)
  16681. {
  16682. str[i] = tolower(str[i]);
  16683. }
  16684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16685. isSuccess = ConfigurationStatus_Accepted;
  16686. }
  16687. else
  16688. {
  16689. isSuccess = ConfigurationStatus_Rejected;
  16690. }
  16691. }
  16692. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16693. {
  16694. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16695. {
  16696. check_ascii = value[0];
  16697. if( (check_ascii < 48) || (check_ascii > 57) )
  16698. {
  16699. isSuccess = ConfigurationStatus_Rejected;
  16700. }
  16701. else
  16702. {
  16703. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16704. isSuccess = ConfigurationStatus_Accepted;
  16705. }
  16706. }
  16707. else
  16708. {
  16709. isSuccess = ConfigurationStatus_Rejected;
  16710. }
  16711. }
  16712. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16713. return isSuccess;
  16714. }
  16715. int TransactionMessageAttemptsGet(void)
  16716. {
  16717. return TransactionMessageAttemptsValue;
  16718. }
  16719. int FirstHeartBeatResponse(void)
  16720. {
  16721. return FirstHeartBeat;
  16722. }
  16723. int TransactionMessageRetryIntervalGet(void)
  16724. {
  16725. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16726. }
  16727. int ReadHttpStatus(int sock)
  16728. {
  16729. //char c;
  16730. char buff[1024]="",*ptr=buff+1;
  16731. int bytes_received, status;
  16732. DEBUG_INFO("Begin Response ..\n");
  16733. while((bytes_received = recv(sock, ptr, 1, 0))){
  16734. if(bytes_received==-1){
  16735. perror("ReadHttpStatus");
  16736. exit(1);
  16737. }
  16738. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16739. ptr++;
  16740. }
  16741. *ptr=0;
  16742. ptr=buff+1;
  16743. sscanf(ptr,"%*s %d ", &status);
  16744. DEBUG_INFO("%s\n",ptr);
  16745. DEBUG_INFO("status=%d\n",status);
  16746. DEBUG_INFO("End Response ..\n");
  16747. return (bytes_received>0)?status:0;
  16748. }
  16749. //the only filed that it parsed is 'Content-Length'
  16750. int ParseHeader(int sock)
  16751. {
  16752. //char c;
  16753. char buff[1024]="",*ptr=buff+4;
  16754. int bytes_received;
  16755. DEBUG_INFO("Begin HEADER ..\n");
  16756. while((bytes_received = recv(sock, ptr, 1, 0))){
  16757. if(bytes_received==-1){
  16758. perror("Parse Header");
  16759. exit(1);
  16760. }
  16761. if(
  16762. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16763. (ptr[-1]=='\r') && (*ptr=='\n' )
  16764. ) break;
  16765. ptr++;
  16766. }
  16767. *ptr=0;
  16768. ptr=buff+4;
  16769. //printf("%s",ptr);
  16770. if(bytes_received){
  16771. ptr=strstr(ptr,"Content-Length:");
  16772. if(ptr){
  16773. sscanf(ptr,"%*s %d",&bytes_received);
  16774. }else
  16775. bytes_received=-1; //unknown size
  16776. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16777. }
  16778. DEBUG_INFO("End HEADER ..\n");
  16779. return bytes_received ;
  16780. }
  16781. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16782. {
  16783. int result = TRUE;
  16784. char rmFileCmd[100]={0};
  16785. char FilePath[100]={0};
  16786. char ftpbuf[200];
  16787. int systemresult;
  16788. sprintf(FilePath,"/mnt/%s",filename);
  16789. system("ping 8.8.8.8 &");
  16790. if((access(FilePath,F_OK))!=-1)
  16791. {
  16792. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16793. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16794. system(rmFileCmd);
  16795. }
  16796. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16797. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16798. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16799. systemresult = system(ftpbuf);
  16800. if(systemresult != 0)
  16801. {
  16802. DEBUG_INFO("http DownLoad error!\n");
  16803. result = FALSE;
  16804. }
  16805. system("pkill ping");
  16806. return result;
  16807. }
  16808. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16809. {
  16810. int result = TRUE;
  16811. char rmFileCmd[100]={0};
  16812. char FilePath[100]={0};
  16813. char ftpbuf[200];
  16814. int systemresult;
  16815. sprintf(FilePath,"/mnt/%s",filename);
  16816. system("ping 8.8.8.8 &");
  16817. if((access(FilePath,F_OK))!=-1)
  16818. {
  16819. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16820. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16821. system(rmFileCmd);
  16822. }
  16823. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16824. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16825. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16826. systemresult = system(ftpbuf);
  16827. if(systemresult != 0)
  16828. {
  16829. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16830. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16831. systemresult = system(ftpbuf);
  16832. if(systemresult != 0)
  16833. {
  16834. DEBUG_WARN("wget error!\n");
  16835. result = FALSE;
  16836. }
  16837. }
  16838. system("pkill ping");
  16839. return result;
  16840. }
  16841. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16842. {
  16843. char rmFileCmd[100]={0};
  16844. char FilePath[100]={0};
  16845. char buf[512];
  16846. int systemresult = 0;
  16847. //DEBUG_INFO("filename=%s\n",filename);
  16848. //DEBUG_INFO("url=%s\n",url);
  16849. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16850. if((access(FilePath,F_OK))!=-1)
  16851. {
  16852. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16853. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16854. system(rmFileCmd);
  16855. }
  16856. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16857. if(fp == NULL)
  16858. {
  16859. DEBUG_INFO("log is NULL\n");
  16860. return FALSE;
  16861. }
  16862. else
  16863. {
  16864. fprintf(fp, "%s\n", url);
  16865. fprintf(fp, "%s\n", filename);
  16866. fclose(fp);
  16867. }
  16868. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16869. if(phpFP == NULL)
  16870. {
  16871. DEBUG_INFO("PHP upload fail.\n");
  16872. return FALSE;
  16873. }
  16874. else
  16875. {
  16876. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16877. {
  16878. if(strstr(buf, "result") != NULL)
  16879. {
  16880. sscanf(buf, "result: %d", &systemresult);
  16881. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16882. }
  16883. }
  16884. pclose(phpFP);
  16885. }
  16886. if(systemresult != 1)
  16887. {
  16888. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  16889. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  16890. if(phpFP == NULL)
  16891. {
  16892. DEBUG_WARN("PHP PUT upload fail.\n");
  16893. return FALSE;
  16894. }
  16895. else
  16896. {
  16897. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16898. {
  16899. if(strstr(buf, "result") != NULL)
  16900. {
  16901. sscanf(buf, "result: %d", &systemresult);
  16902. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  16903. }
  16904. }
  16905. pclose(phpFP);
  16906. }
  16907. }
  16908. return TRUE;
  16909. }
  16910. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16911. {
  16912. int result = FALSE;
  16913. char ftpbuf[200];
  16914. int systemresult;
  16915. /*
  16916. // Domaind name transfer to IP address
  16917. struct hostent* server;
  16918. char *IPbuffer;
  16919. server = gethostbyname(location);
  16920. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16921. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16922. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16923. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16924. systemresult = system(ftpbuf);
  16925. if(systemresult != 0)
  16926. {
  16927. DEBUG_INFO("ftpput error!\n");
  16928. }
  16929. else
  16930. {
  16931. result = TRUE;
  16932. DEBUG_INFO("ftpput OK!\n");
  16933. }
  16934. return result;
  16935. }
  16936. int GetOcppServerURL()
  16937. {
  16938. int result = FALSE;
  16939. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16940. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16941. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16942. struct yuarel url;
  16943. char urlStr[512];
  16944. // OCPPPH only
  16945. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16946. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16947. {
  16948. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16949. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16950. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16951. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16952. if(yuarel_parse(&url, urlStr) != -1)
  16953. {
  16954. sprintf(OcppProtocol, "%s", url.scheme);
  16955. sprintf(OcppHost, "%s", url.host);
  16956. if(url.path == NULL)
  16957. OcppTempPath[0] = '\0';
  16958. else
  16959. sprintf(OcppTempPath, "%s", url.path);
  16960. if(url.port == 0)
  16961. {
  16962. if(strcmp(OcppProtocol, "wss") == 0)
  16963. OcppPort = 443;
  16964. else
  16965. OcppPort = 80;
  16966. }
  16967. else
  16968. OcppPort = url.port;
  16969. result = TRUE;
  16970. }
  16971. }
  16972. else
  16973. {
  16974. strcpy(OcppHost,"");
  16975. }
  16976. return result;
  16977. }
  16978. int GetOcppPath()
  16979. {
  16980. int result = FALSE;
  16981. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16982. {
  16983. if(OcppTempPath == NULL)
  16984. {
  16985. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16986. }
  16987. else
  16988. {
  16989. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16990. }
  16991. result = TRUE;
  16992. goto End;
  16993. }
  16994. else
  16995. {
  16996. strcpy(OcppPath,"");
  16997. }
  16998. End:
  16999. return result;
  17000. }
  17001. int GetOcppPort()
  17002. {
  17003. return OcppPort;
  17004. }
  17005. int GetOcppConnStatus(void)
  17006. {
  17007. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17008. }
  17009. void SetOcppConnStatus(uint8_t status)
  17010. {
  17011. ShmOCPP16DataPH->OcppConnStatus = status;
  17012. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17013. }
  17014. int GetHeartBeatWithNOResponse(void)
  17015. {
  17016. return HeartBeatWithNOResponse;
  17017. }
  17018. void SetHeartBeatWithNOResponse(void)
  17019. {
  17020. HeartBeatWithNOResponse = 0;
  17021. }
  17022. void GetStartTransactionIdTag(int gun_index)
  17023. {
  17024. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17025. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17026. }
  17027. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17028. {
  17029. char ch;
  17030. FILE *fptr1;
  17031. int temptransactionId;
  17032. char str[100]={0};
  17033. temptransactionId = 0;
  17034. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17035. {
  17036. DEBUG_INFO("IdTag is empty.\n");
  17037. return temptransactionId;
  17038. }
  17039. /*------ Read the file ----------------*/
  17040. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17041. if (!fptr1)
  17042. {
  17043. DEBUG_INFO("QueueTransactionId file open error.\n");
  17044. //printf(" File not found or unable to open the input file!!\n");
  17045. return temptransactionId;
  17046. }
  17047. ch=fgetc(fptr1);
  17048. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17049. rewind(fptr1);
  17050. if(ch!=EOF)
  17051. {
  17052. // printf("%c",ch);
  17053. while (fgets(str, 100, fptr1) != NULL)
  17054. {
  17055. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17056. if(str[0]=='\0')
  17057. {
  17058. break;
  17059. }
  17060. char *revbuf[8] = {0}; // Variable store string split
  17061. int num = 0;// Quantity after string split
  17062. DEBUG_INFO("Transaction queue data= %s\n", str);
  17063. splitstring(str,",",revbuf,&num); // String split
  17064. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17065. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17066. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17067. DEBUG_INFO("------------------------------\n");
  17068. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17069. {
  17070. if(isStopTransaction)
  17071. {
  17072. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17073. {
  17074. temptransactionId = atoi(revbuf[2]);
  17075. //break;
  17076. }
  17077. }
  17078. else
  17079. {
  17080. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17081. {
  17082. temptransactionId = atoi(revbuf[2]);
  17083. //break;
  17084. }
  17085. }
  17086. }
  17087. }
  17088. }
  17089. else
  17090. DEBUG_INFO("EOF\n");
  17091. fclose(fptr1);
  17092. /*------- End of reading ---------------*/
  17093. return temptransactionId;
  17094. }
  17095. void SetTransactionIdZero(int transactionId)
  17096. {
  17097. char ch;
  17098. FILE *fptr1, *fptr2;
  17099. int temptransactionId = 0;
  17100. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17101. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17102. if (!fptr1)
  17103. {
  17104. //printf(" File not found or unable to open the input file!!\n");
  17105. return ;
  17106. }
  17107. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17108. if (!fptr2)
  17109. {
  17110. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17111. fclose(fptr1);
  17112. return ;
  17113. }
  17114. ch=fgetc(fptr1);
  17115. rewind(fptr1);
  17116. if(ch!=EOF)
  17117. {
  17118. // copy all contents to the temporary file except the specific line
  17119. while (fgets(str, 100, fptr1) != NULL)
  17120. {
  17121. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17122. if(str[0]=='\0')
  17123. {
  17124. break;
  17125. }
  17126. char *revbuf[8] = {0};
  17127. int num = 0;
  17128. strcpy(strtemp, str);
  17129. splitstring(str,",",revbuf,&num);
  17130. if(revbuf[2][0] != '\0')
  17131. {
  17132. temptransactionId = atoi(revbuf[2]);
  17133. if(transactionId != temptransactionId)
  17134. {
  17135. fprintf(fptr2, "%s\n", strtemp);
  17136. }
  17137. }
  17138. }
  17139. }
  17140. fclose(fptr1);
  17141. fclose(fptr2);
  17142. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17143. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17144. /*------ Read the file ----------------*/
  17145. }
  17146. int InternetDisconnect(void)
  17147. {
  17148. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17149. }
  17150. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17151. void storeTempStopTransaction(int gun_index)
  17152. {
  17153. char guid[37]={0};
  17154. int tempIndex = 0;
  17155. char TempStopTransaction[256];
  17156. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17157. DEBUG_INFO("storeTempStopTransaction...\n");
  17158. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17159. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17160. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17161. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17162. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17163. {
  17164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17165. {
  17166. tempIndex = ((gun_index==2) ? 1: 0);
  17167. }
  17168. else
  17169. {
  17170. tempIndex = gun_index;
  17171. }
  17172. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17173. {
  17174. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17175. {
  17176. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17177. }
  17178. }// END OF CHAdeMO_QUANTITY
  17179. }
  17180. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17181. {
  17182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17183. {
  17184. tempIndex = ((gun_index==2) ? 1: 0);
  17185. }
  17186. else
  17187. {
  17188. tempIndex = gun_index;
  17189. }
  17190. for (int index = 0; index < CCS_QUANTITY; index++)
  17191. {
  17192. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17193. {
  17194. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17195. }
  17196. }// END OF CCS_QUANTITY
  17197. }
  17198. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17199. {
  17200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17201. {
  17202. tempIndex = ((gun_index==2) ? 1: 0);
  17203. }
  17204. else
  17205. {
  17206. tempIndex = gun_index;
  17207. }
  17208. for (int index = 0; index < GB_QUANTITY; index++)
  17209. {
  17210. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17211. {
  17212. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17213. }
  17214. }// END OF GB_QUANTITY
  17215. }
  17216. else if(gunType[gun_index] == GUN_TYPE_DO)
  17217. {
  17218. tempIndex = gun_index;
  17219. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17220. {
  17221. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17222. {
  17223. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17224. }
  17225. }
  17226. }
  17227. else
  17228. {
  17229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17230. {
  17231. tempIndex = 2;
  17232. }
  17233. else
  17234. {
  17235. tempIndex = gun_index;
  17236. }
  17237. for (int index = 0; index < AC_QUANTITY; index++)
  17238. {
  17239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17240. {
  17241. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17242. }
  17243. }// END OF AC_QUANTITY
  17244. }
  17245. //Stop Transaction Time
  17246. struct timeval tmnow;
  17247. struct tm *tm;
  17248. char buf[28];//, usec_buf[6];
  17249. gettimeofday(&tmnow, NULL);
  17250. time_t t;
  17251. t = time(NULL);
  17252. /*UTC time and date*/
  17253. tm = gmtime(&t);
  17254. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17255. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17256. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17258. random_uuid(guid);
  17259. /***********************************transactionData******************************************************/
  17260. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17261. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17262. //=================================
  17263. //1. Transaction_Begin
  17264. //=================================
  17265. //============================== Energy.Active.Import.Interval ===========================================
  17266. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17267. {
  17268. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17270. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17271. 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*/]);
  17272. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17273. 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))
  17274. {
  17275. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17276. }
  17277. else
  17278. {
  17279. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17280. }
  17281. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17283. }
  17284. //=================================
  17285. //2. Transaction_End
  17286. //=================================
  17287. //2.1====================================== Current.Import L1 ==============================================
  17288. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17289. {
  17290. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17291. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17292. {
  17293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17294. {
  17295. tempIndex = ((gun_index==2) ? 1: 0);
  17296. }
  17297. else
  17298. {
  17299. tempIndex = gun_index;
  17300. }
  17301. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17302. {
  17303. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17304. {
  17305. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17306. }
  17307. }// End of for CHAdeMO_QUANTITY
  17308. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17309. }
  17310. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17311. {
  17312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17313. {
  17314. tempIndex = ((gun_index==2) ? 1: 0);
  17315. }
  17316. else
  17317. {
  17318. tempIndex = gun_index;
  17319. }
  17320. for (int index = 0; index < CCS_QUANTITY; index++)
  17321. {
  17322. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17323. {
  17324. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17325. }
  17326. }// End of for CCS_QUANTITY
  17327. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17328. }
  17329. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17330. {
  17331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17332. {
  17333. tempIndex = ((gun_index==2) ? 1: 0);
  17334. }
  17335. else
  17336. {
  17337. tempIndex = gun_index;
  17338. }
  17339. for (int index = 0; index < GB_QUANTITY; index++)
  17340. {
  17341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17342. {
  17343. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17344. }
  17345. }// End of for GB_QUANTITY
  17346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17347. }
  17348. else if(gunType[gun_index] == GUN_TYPE_DO)
  17349. {
  17350. tempIndex = gun_index;
  17351. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17352. {
  17353. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17354. {
  17355. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17356. }
  17357. }
  17358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17359. }
  17360. else
  17361. {
  17362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17363. {
  17364. tempIndex = 2;
  17365. }
  17366. else
  17367. {
  17368. tempIndex = gun_index;
  17369. }
  17370. for (int index = 0; index < AC_QUANTITY; index++)
  17371. {
  17372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17373. {
  17374. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17375. }
  17376. }// End of for AC_QUANTITY
  17377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17378. }
  17379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17382. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17383. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17384. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17385. }
  17386. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17387. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17388. {
  17389. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17390. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17391. {
  17392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17393. {
  17394. tempIndex = ((gun_index==2) ? 1: 0);
  17395. }
  17396. else
  17397. {
  17398. tempIndex = gun_index;
  17399. }
  17400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17401. {
  17402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17403. {
  17404. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17405. }
  17406. }// END OF CHAdeMO_QUANTITY
  17407. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17408. }
  17409. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17410. {
  17411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17412. {
  17413. tempIndex = ((gun_index==2) ? 1: 0);
  17414. }
  17415. else
  17416. {
  17417. tempIndex = gun_index;
  17418. }
  17419. for (int index = 0; index < CCS_QUANTITY; index++)
  17420. {
  17421. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17422. {
  17423. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17424. }
  17425. }// END OF CCS_QUANTITY
  17426. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17427. }
  17428. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17429. {
  17430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17431. {
  17432. tempIndex = ((gun_index==2) ? 1: 0);
  17433. }
  17434. else
  17435. {
  17436. tempIndex = gun_index;
  17437. }
  17438. for (int index = 0; index < GB_QUANTITY; index++)
  17439. {
  17440. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17441. {
  17442. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17443. }
  17444. }// END OF GB_QUANTITY
  17445. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17446. }
  17447. else if(gunType[gun_index] == GUN_TYPE_DO)
  17448. {
  17449. tempIndex = gun_index;
  17450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17451. {
  17452. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17453. {
  17454. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17455. }
  17456. }
  17457. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17458. }
  17459. else
  17460. {
  17461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17462. {
  17463. tempIndex = 2;
  17464. }
  17465. else
  17466. {
  17467. tempIndex = gun_index;
  17468. }
  17469. for (int index = 0; index < AC_QUANTITY; index++)
  17470. {
  17471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17472. {
  17473. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17474. }
  17475. }// END OF AC_QUANTITY
  17476. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17477. }
  17478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17481. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17483. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17484. }
  17485. //2.3====================================== Power.Active.Import =========================================
  17486. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17487. {
  17488. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17489. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17490. {
  17491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17492. {
  17493. tempIndex = ((gun_index==2) ? 1: 0);
  17494. }
  17495. else
  17496. {
  17497. tempIndex = gun_index;
  17498. }
  17499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17500. {
  17501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17502. {
  17503. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17504. }
  17505. } // End for CHAdeMO_QUANTITY
  17506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17507. }
  17508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17509. {
  17510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17511. {
  17512. tempIndex = ((gun_index==2) ? 1: 0);
  17513. }
  17514. else
  17515. {
  17516. tempIndex = gun_index;
  17517. }
  17518. for (int index = 0; index < CCS_QUANTITY; index++)
  17519. {
  17520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17521. {
  17522. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17523. }
  17524. } // END for CCS_QUANTITY
  17525. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17526. }
  17527. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17528. {
  17529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17530. {
  17531. tempIndex = ((gun_index==2) ? 1: 0);
  17532. }
  17533. else
  17534. {
  17535. tempIndex = gun_index;
  17536. }
  17537. for (int index = 0; index < GB_QUANTITY; index++)
  17538. {
  17539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17540. {
  17541. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17542. }
  17543. }// END for GB_QUANTITY
  17544. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17545. }
  17546. else if(gunType[gun_index] == GUN_TYPE_DO)
  17547. {
  17548. tempIndex = gun_index;
  17549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17550. {
  17551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17552. {
  17553. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17554. }
  17555. }
  17556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17557. }
  17558. else
  17559. {
  17560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17561. {
  17562. tempIndex = 2;
  17563. }
  17564. else
  17565. {
  17566. tempIndex = gun_index;
  17567. }
  17568. for (int index = 0; index < AC_QUANTITY; index++)
  17569. {
  17570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17571. {
  17572. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17573. }
  17574. } // END for AC_QUANTITY
  17575. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17576. }
  17577. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17579. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17580. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17581. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17583. }
  17584. //2.4====================================== Voltage L1 ====================================================
  17585. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17586. {
  17587. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17589. {
  17590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17591. {
  17592. tempIndex = ((gun_index==2) ? 1: 0);
  17593. }
  17594. else
  17595. {
  17596. tempIndex = gun_index;
  17597. }
  17598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17599. {
  17600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17601. {
  17602. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17603. }
  17604. } // END OF FOR CHAdeMO_QUANTITY
  17605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17606. }
  17607. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17608. {
  17609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17610. {
  17611. tempIndex = ((gun_index==2) ? 1: 0);
  17612. }
  17613. else
  17614. {
  17615. tempIndex = gun_index;
  17616. }
  17617. for (int index = 0; index < CCS_QUANTITY; index++)
  17618. {
  17619. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17620. {
  17621. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17622. }
  17623. } // END OF FOR CCS_QUANTITY
  17624. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17625. }
  17626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17627. {
  17628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17629. {
  17630. tempIndex = ((gun_index==2) ? 1: 0);
  17631. }
  17632. else
  17633. {
  17634. tempIndex = gun_index;
  17635. }
  17636. for (int index = 0; index < GB_QUANTITY; index++)
  17637. {
  17638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17639. {
  17640. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17641. }
  17642. } // END OF FOR GB_QUANTITY
  17643. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17644. }
  17645. else if(gunType[gun_index] == GUN_TYPE_DO)
  17646. {
  17647. tempIndex = gun_index;
  17648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17649. {
  17650. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17651. {
  17652. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17653. }
  17654. }
  17655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17656. }
  17657. else
  17658. {
  17659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17660. {
  17661. tempIndex = 2;
  17662. }
  17663. else
  17664. {
  17665. tempIndex = gun_index;
  17666. }
  17667. for (int index = 0; index < AC_QUANTITY; index++)
  17668. {
  17669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17670. {
  17671. 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
  17672. }
  17673. } // END OF FOR AC_QUANTITY
  17674. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17675. }
  17676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17679. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17682. }
  17683. //2.5============================================== End SoC =========================================================
  17684. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17685. {
  17686. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17687. 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))
  17688. {
  17689. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17690. {
  17691. tempIndex = ((gun_index==2) ? 1: 0);
  17692. }
  17693. else
  17694. {
  17695. tempIndex = gun_index;
  17696. }
  17697. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17698. {
  17699. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17700. {
  17701. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17702. {
  17703. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17704. }
  17705. }
  17706. }
  17707. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17708. {
  17709. for (int index = 0; index < CCS_QUANTITY; index++)
  17710. {
  17711. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17712. {
  17713. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17714. }
  17715. }
  17716. }
  17717. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17718. {
  17719. for (int index = 0; index < GB_QUANTITY; index++)
  17720. {
  17721. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17722. {
  17723. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17724. }
  17725. }
  17726. }
  17727. else if(gunType[gun_index] == GUN_TYPE_DO)
  17728. {
  17729. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17730. {
  17731. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17732. {
  17733. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17734. }
  17735. }
  17736. }
  17737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17743. } // END FOR DC CASE
  17744. }
  17745. //2.6====================================== Current.Import L2 ==============================================
  17746. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17747. {
  17748. // AC 3 phase L2 current
  17749. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17750. {
  17751. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17752. {
  17753. tempIndex = 2;
  17754. }
  17755. else
  17756. {
  17757. tempIndex = gun_index;
  17758. }
  17759. for (int index = 0; index < AC_QUANTITY; index++)
  17760. {
  17761. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17762. {
  17763. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17764. }
  17765. }// End of for AC_QUANTITY
  17766. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17767. }
  17768. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17769. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17770. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17771. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17772. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17773. }
  17774. //2.7====================================== Current.Import L3 ==============================================
  17775. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17776. {
  17777. // AC 3 phase L3 current
  17778. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17779. {
  17780. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17781. {
  17782. tempIndex = 2;
  17783. }
  17784. else
  17785. {
  17786. tempIndex = gun_index;
  17787. }
  17788. for (int index = 0; index < AC_QUANTITY; index++)
  17789. {
  17790. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17791. {
  17792. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17793. }
  17794. }// End of for AC_QUANTITY
  17795. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17796. }
  17797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17802. }
  17803. //2.9====================================== Voltage L2 ====================================================
  17804. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17805. {
  17806. // AC 3 phase L2 volatge
  17807. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17808. {
  17809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17810. {
  17811. tempIndex = 2;
  17812. }
  17813. else
  17814. {
  17815. tempIndex = gun_index;
  17816. }
  17817. for (int index = 0; index < AC_QUANTITY; index++)
  17818. {
  17819. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17820. {
  17821. 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
  17822. }
  17823. } // END OF FOR AC_QUANTITY
  17824. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17825. }
  17826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17829. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17830. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17831. }
  17832. //2.10====================================== Voltage L3 ====================================================
  17833. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17834. {
  17835. // AC 3 phase L3 volatge
  17836. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17837. {
  17838. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17839. {
  17840. tempIndex = 2;
  17841. }
  17842. else
  17843. {
  17844. tempIndex = gun_index;
  17845. }
  17846. for (int index = 0; index < AC_QUANTITY; index++)
  17847. {
  17848. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17849. {
  17850. 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
  17851. }
  17852. } // END OF FOR AC_QUANTITY
  17853. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17854. }
  17855. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17856. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17860. }
  17861. //====================== Start SoC ================================
  17862. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17863. {
  17864. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17865. 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))
  17866. {
  17867. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17868. {
  17869. tempIndex = ((gun_index==2) ? 1: 0);
  17870. }
  17871. else
  17872. {
  17873. tempIndex = gun_index;
  17874. }
  17875. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17876. {
  17877. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17878. {
  17879. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17880. {
  17881. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17882. }
  17883. }
  17884. }
  17885. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17886. {
  17887. for (int index = 0; index < CCS_QUANTITY; index++)
  17888. {
  17889. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17890. {
  17891. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17892. }
  17893. }
  17894. }
  17895. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17896. {
  17897. for (int index = 0; index < GB_QUANTITY; index++)
  17898. {
  17899. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17900. {
  17901. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17902. }
  17903. }
  17904. }
  17905. else if(gunType[gun_index] == GUN_TYPE_DO)
  17906. {
  17907. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17908. {
  17909. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17910. {
  17911. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17912. }
  17913. }
  17914. }
  17915. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17916. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17921. } // END FOR DC CASE
  17922. }
  17923. //======================================== Message create ==============================================
  17924. json_object *StopTransaction = json_object_new_object();
  17925. json_object *transactionDatas = json_object_new_array();
  17926. json_object *sampledValues = json_object_new_array();
  17927. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17928. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17929. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17930. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17931. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17932. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17933. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17934. {
  17935. json_object *transactionData = json_object_new_object();
  17936. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17937. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17938. {
  17939. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17940. {
  17941. json_object *sampledValue = json_object_new_object();
  17942. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17943. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17944. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17945. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17946. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17947. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17948. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17949. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17950. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17951. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17952. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17953. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17954. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17955. json_object_array_add(sampledValues, sampledValue);
  17956. }
  17957. }
  17958. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17959. json_object_array_add(transactionDatas, transactionData);
  17960. }
  17961. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17962. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17963. ,MESSAGE_TYPE_CALL
  17964. ,guid
  17965. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17966. json_object_put(StopTransaction);
  17967. // Check File "TempStopTransaction" Exist
  17968. if((access(TempStopTransaction,F_OK))!=-1)
  17969. {
  17970. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17971. fclose(fopen(TempStopTransaction, "w"));
  17972. }
  17973. else
  17974. {
  17975. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17976. FILE *log = fopen(TempStopTransaction, "w+");
  17977. if(log == NULL)
  17978. {
  17979. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17980. return ;
  17981. }
  17982. else
  17983. {
  17984. fclose(log);
  17985. }
  17986. }
  17987. //Add TempStopTransaction | Update TempStopTransaction
  17988. // open file for writing
  17989. FILE *outfile;
  17990. outfile = fopen (TempStopTransaction, "a");
  17991. //DEBUG_INFO("data = %s\n", queuedata);
  17992. fputs(queuedata, outfile);
  17993. fputs("\n", outfile);
  17994. fclose (outfile);
  17995. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17996. }
  17997. void checkTempStopTransaction(int gun_index)
  17998. {
  17999. FILE *fptr1;
  18000. char ch;
  18001. char str[QUEUE_MESSAGE_LENGTH]={0};
  18002. char guid[37]={0};
  18003. char tempdata[65]={0};
  18004. char connectorStr[2]={0};
  18005. char TempStopTransaction[256];
  18006. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18007. fptr1 = fopen(TempStopTransaction, "r");
  18008. //TempStopTransaction格式: 槍號,StopTransaction封包
  18009. if (!fptr1)
  18010. {
  18011. //printf(" File not found or unable to open the input file!!\n");
  18012. return ;
  18013. }
  18014. ch=fgetc(fptr1);
  18015. //printf(" Now the content of the file %s is : \n",fname);
  18016. rewind(fptr1);
  18017. if(ch!=EOF)
  18018. {
  18019. // copy all contents to the temporary file except the specific line
  18020. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18021. {
  18022. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18023. if(str[0]=='\0')
  18024. {
  18025. break;
  18026. }
  18027. //TempStopTransaction格式: 槍號,StopTransaction封包
  18028. strncpy(connectorStr, str, 1);
  18029. if(atoi(connectorStr) != (gun_index+1))
  18030. {
  18031. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18032. fclose(fptr1);
  18033. return ;
  18034. }
  18035. //random_uuid(guid);
  18036. strncpy(guid, str+6, 36); //copy guid
  18037. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18038. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18039. {
  18040. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18041. }
  18042. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18043. OCPP_insert_transaction_msg(NO, str);
  18044. memset(str,0,ARRAY_SIZE(str));
  18045. }
  18046. }
  18047. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18048. fclose(fptr1);
  18049. remove(TempStopTransaction); // remove the original file
  18050. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18051. }
  18052. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18053. {
  18054. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18055. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18056. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18057. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18058. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18059. }
  18060. int GetWebSocketPingInterval(void)
  18061. {
  18062. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18063. }
  18064. int GetServerSign(void)
  18065. {
  18066. return server_sign;
  18067. }
  18068. uint8_t GetOcppSecurityProfile()
  18069. {
  18070. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18071. }
  18072. void GetOcppChargerBoxId(uint8_t *data)
  18073. {
  18074. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18075. }
  18076. void GetOcppSecurityPassword(uint8_t *data)
  18077. {
  18078. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18079. }
  18080. void SetOcppVersion(uint8_t *version)
  18081. {
  18082. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18083. DEBUG_INFO("ocpp version: %s\n", version);
  18084. if(strstr((char*)version, "ocpp1.6") != NULL)
  18085. {
  18086. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18087. }
  18088. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18089. {
  18090. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18091. system("pkill OcppBackend");
  18092. }
  18093. }
  18094. void SetServerSign(int value)
  18095. {
  18096. server_sign = value;
  18097. }
  18098. int GetBootNotificationInterval(void)
  18099. {
  18100. return BootNotificationInterval;
  18101. }
  18102. int GetInternetConn(void)
  18103. {
  18104. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18105. }
  18106. int GetBackendConnectionTimeout(void)
  18107. {
  18108. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18109. }
  18110. int isConnectorInitMode(int gun_index)
  18111. {
  18112. int tempIndex = 0;
  18113. int result = TRUE;
  18114. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18115. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18116. {
  18117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18118. {
  18119. tempIndex = ((gun_index==2) ? 1: 0);
  18120. }
  18121. else
  18122. {
  18123. tempIndex = gun_index;
  18124. }
  18125. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18126. {
  18127. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18128. {
  18129. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18130. } //end of the same index
  18131. }//end of for CHAdeMO_QUANTITY
  18132. }
  18133. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18134. {
  18135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18136. {
  18137. tempIndex = ((gun_index==2) ? 1: 0);
  18138. }
  18139. else
  18140. {
  18141. tempIndex = gun_index;
  18142. }
  18143. for (int index = 0; index < CCS_QUANTITY; index++)
  18144. {
  18145. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18146. {
  18147. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18148. } //end of the same index
  18149. } // end of for CCS_QUANTITY
  18150. }
  18151. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18152. {
  18153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18154. {
  18155. tempIndex = ((gun_index==2) ? 1: 0);
  18156. }
  18157. else
  18158. {
  18159. tempIndex = gun_index;
  18160. }
  18161. for (int index = 0; index < GB_QUANTITY; index++)
  18162. {
  18163. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18164. {
  18165. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18166. } //end of the same index
  18167. } // end of for GB_QUANTITY
  18168. }
  18169. else if(gunType[gun_index] == GUN_TYPE_DO)
  18170. {
  18171. tempIndex = gun_index;
  18172. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18173. {
  18174. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18175. {
  18176. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18177. } //end of the same index
  18178. }
  18179. }
  18180. else
  18181. {
  18182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18183. {
  18184. tempIndex = 2;
  18185. }
  18186. else
  18187. {
  18188. tempIndex = gun_index;
  18189. }
  18190. for (int index = 0; index < AC_QUANTITY; index++)
  18191. {
  18192. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18193. {
  18194. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18195. }//end of the same index
  18196. }//end of for AC_QUANTITY
  18197. }
  18198. return result;
  18199. }
  18200. void refreshProcDogTimer()
  18201. {
  18202. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18203. }
  18204. void InitialSystemValue(void)
  18205. {
  18206. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18207. locallistVersion=0;
  18208. BootNotificationInterval = 0;
  18209. authorizeRetryTimes = 0;
  18210. GunStatusInterval = 10;
  18211. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18212. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18213. //Hear Beat
  18214. HeartBeatWithNOResponse = 0;
  18215. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18216. FirstHeartBeat = 0;
  18217. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18218. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18219. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18220. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18221. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18222. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18223. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18224. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18225. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18226. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18227. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18228. //Status && ConnectorPlugIn Setting
  18229. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18230. {
  18231. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18232. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18233. }
  18234. for (int index = 0; index < CCS_QUANTITY; index++)
  18235. {
  18236. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18237. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18238. }
  18239. for (int index = 0; index < GB_QUANTITY; index++)
  18240. {
  18241. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18242. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18243. }
  18244. for (int index = 0; index < AC_QUANTITY; index++)
  18245. {
  18246. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18247. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18248. }
  18249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18250. {
  18251. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18252. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18253. }
  18254. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18255. {
  18256. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18257. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18258. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18259. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18260. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18261. }
  18262. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18263. refreshStartTimer(&clientTime.Heartbeat);
  18264. sleep(1);
  18265. }
  18266. void LWS_Send(char *str)
  18267. {
  18268. //=====================================================
  18269. // Check InternetConn 0: disconnected, 1: connected
  18270. //====================================================
  18271. if(GetOcppConnStatus() == 0)
  18272. {
  18273. DEBUG_INFO("offline now !!!\n");
  18274. return;
  18275. }
  18276. // Only disable isWebsocketSendable operation initiated by charger
  18277. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18278. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18279. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18280. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18281. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18282. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18283. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18284. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18285. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18286. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18287. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18288. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18289. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18290. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18291. {
  18292. isWebsocketSendable = 0;
  18293. }
  18294. pthread_mutex_lock(&lock_send);
  18295. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18296. sprintf((char *)SendBuffer, "%s", str);
  18297. SendBufLen = strlen(str);
  18298. pthread_mutex_unlock(&lock_send);
  18299. lws_callback_on_writable(wsi_client);
  18300. //lws_service(context, 0);
  18301. //sleep(1);
  18302. }
  18303. void LWS_SendNow(char *str)
  18304. {
  18305. //=====================================================
  18306. // Check InternetConn 0: disconnected, 1: connected
  18307. //====================================================
  18308. if(GetOcppConnStatus() == 0)
  18309. {
  18310. DEBUG_INFO("offline now !!!\n");
  18311. return;
  18312. }
  18313. // Only disable isWebsocketSendable operation initiated by charger
  18314. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18315. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18316. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18317. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18318. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18319. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18320. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18321. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18322. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18323. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18324. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18325. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18326. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18327. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18328. {
  18329. isWebsocketSendable = 0;
  18330. }
  18331. pthread_mutex_lock(&lock_send);
  18332. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18333. sprintf((char *)SendBuffer, "%s", str);
  18334. SendBufLen = strlen(str);
  18335. pthread_mutex_unlock(&lock_send);
  18336. lws_callback_on_writable(wsi_client);
  18337. lws_service(context, 0);
  18338. //sleep(1);
  18339. }